Improved Door Code

1. Removed code from BaseDimDoor that was already implemented almost
identically in BlockDoor. Clarified some uses of setBlock() by changing
them to setBlockToAir() instead.
2. Removed TileEntityDimDoor.invalidate() and moved the regeneration
scheduling code to BaseDimDoor.breakBlock(). I would prefer to move away
from overriding the invalidate() method. This also simplifies the code
since we don't need to perform some of the checks we had in
breakBlock().
This commit is contained in:
SenseiKiwi
2014-07-11 03:44:26 -04:00
parent 71e7fdaafc
commit 29c8a09218
2 changed files with 13 additions and 24 deletions

View File

@@ -306,7 +306,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
{
if (world.getBlockId(x, y - 1, z) != this.blockID)
{
world.setBlock(x, y, z, 0);
world.setBlockToAir(x, y, z);
}
if (neighborID > 0 && neighborID != this.blockID)
@@ -318,7 +318,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
{
if (world.getBlockId(x, y + 1, z) != this.blockID)
{
world.setBlock(x, y, z, 0);
world.setBlockToAir(x, y, z);
if (!world.isRemote)
{
this.dropBlockAsItem(world, x, y, z, metadata, 0);
@@ -354,18 +354,6 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
return isUpperDoorBlock(metadata) ? 0 : this.getDrops();
}
/**
* Called when the block is attempted to be harvested
*/
@Override
public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer)
{
if (par6EntityPlayer.capabilities.isCreativeMode && (par5 & 8) != 0 && par1World.getBlockId(par2, par3 - 1, par4) == this.blockID)
{
par1World.setBlock(par2, par3 - 1, par4, 0);
}
}
@Override
public TileEntity createNewTileEntity(World world)
{
@@ -445,4 +433,15 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
world.setBlockTileEntity(x, y, z, te);
return te;
}
@Override
public void breakBlock(World world, int x, int y, int z, int oldBlockID, int oldMeta)
{
// This function runs on the server side after a block is replaced
// We MUST call super.breakBlock() since it involves removing tile entities
super.breakBlock(world, x, y, z, oldBlockID, oldMeta);
// Schedule rift regeneration for this block
mod_pocketDim.riftRegenerator.scheduleFastRegeneration(x, y, z, world);
}
}

View File

@@ -34,16 +34,6 @@ public class TileEntityDimDoor extends DDTileEntityBase
return null;
}
@Override
public void invalidate()
{
super.invalidate();
if (!worldObj.isRemote && worldObj.getBlockId(xCoord, yCoord, zCoord) == 0)
{
mod_pocketDim.riftRegenerator.scheduleFastRegeneration(xCoord, yCoord, zCoord, worldObj);
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{