Better method of removing nodes

This commit is contained in:
raoulvdberge
2017-02-26 19:49:38 +01:00
parent 51daaf498c
commit 0621708967

View File

@@ -11,6 +11,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@@ -47,11 +48,24 @@ public abstract class BlockNode extends BlockBase {
} }
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) { public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state) {
super.breakBlock(world, pos, state); super.onBlockDestroyedByPlayer(world, pos, state);
// Sanity check if (!world.isRemote) {
if (world.getBlockState(pos).getBlock() == this) { removeNode(world, pos);
}
}
@Override
public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) {
super.onBlockDestroyedByExplosion(world, pos, explosion);
if (!world.isRemote) {
removeNode(world, pos);
}
}
private void removeNode(World world, BlockPos pos) {
INetworkNodeManager manager = API.instance().getNetworkNodeManager(world.provider.getDimension()); INetworkNodeManager manager = API.instance().getNetworkNodeManager(world.provider.getDimension());
INetworkNode node = manager.getNode(pos); INetworkNode node = manager.getNode(pos);
@@ -64,7 +78,6 @@ public abstract class BlockNode extends BlockBase {
node.getNetwork().getNodeGraph().rebuild(); node.getNetwork().getNodeGraph().rebuild();
} }
} }
}
@Override @Override
protected BlockStateContainer.Builder createBlockStateBuilder() { protected BlockStateContainer.Builder createBlockStateBuilder() {