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:
@@ -306,7 +306,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
|
|||||||
{
|
{
|
||||||
if (world.getBlockId(x, y - 1, z) != this.blockID)
|
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)
|
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)
|
if (world.getBlockId(x, y + 1, z) != this.blockID)
|
||||||
{
|
{
|
||||||
world.setBlock(x, y, z, 0);
|
world.setBlockToAir(x, y, z);
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
this.dropBlockAsItem(world, x, y, z, metadata, 0);
|
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();
|
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
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world)
|
public TileEntity createNewTileEntity(World world)
|
||||||
{
|
{
|
||||||
@@ -445,4 +433,15 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
|
|||||||
world.setBlockTileEntity(x, y, z, te);
|
world.setBlockTileEntity(x, y, z, te);
|
||||||
return 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -34,16 +34,6 @@ public class TileEntityDimDoor extends DDTileEntityBase
|
|||||||
return null;
|
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
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt)
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user