From 415bc9b17dae5059c5f30c4eadb96923837c7ff5 Mon Sep 17 00:00:00 2001 From: Henry Loenwind Date: Tue, 19 Apr 2016 20:40:24 +0200 Subject: [PATCH] Allow "default handling for getPickBlock" to not crash on blocks without TE --- .../com/enderio/core/common/BlockEnder.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/enderio/core/common/BlockEnder.java b/src/main/java/com/enderio/core/common/BlockEnder.java index 5b7a358..55e490c 100644 --- a/src/main/java/com/enderio/core/common/BlockEnder.java +++ b/src/main/java/com/enderio/core/common/BlockEnder.java @@ -28,7 +28,7 @@ import cpw.mods.fml.relauncher.SideOnly; public abstract class BlockEnder extends Block { - protected final Class teClass; + protected final @Nullable Class teClass; protected final String name; protected final boolean hasComparatorInputOverride; @@ -143,11 +143,11 @@ public abstract class BlockEnder extends Block { @Override public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, @Nullable EntityPlayer player) { - return getNBTDrop(world, x, y, z, getTileEntityEio(world, x, y, z)); + return getNBTDrop(world, x, y, z, teClass != null ? getTileEntityEio(world, x, y, z) : null); } - public ItemStack getNBTDrop(World world, int x, int y, int z, TileEntityEnder te) { - int meta = damageDropped(te.getBlockMetadata()); + public ItemStack getNBTDrop(World world, int x, int y, int z, @Nullable TileEntityEnder te) { + int meta = te != null ? damageDropped(te.getBlockMetadata()) : world.getBlockMetadata(x, y, z); ItemStack itemStack = new ItemStack(this, 1, meta); processDrop(world, x, y, z, te, itemStack); return itemStack; @@ -156,10 +156,13 @@ public abstract class BlockEnder extends Block { protected void processDrop(World world, int x, int y, int z, @Nullable TileEntityEnder te, ItemStack drop) { } - protected TileEntityEnder getTileEntityEio(IBlockAccess world, int x, int y, int z) { - TileEntity te = world.getTileEntity(x, y, z); - if (teClass.isInstance(te)) { - return (TileEntityEnder) te; + @SuppressWarnings("null") + protected @Nullable TileEntityEnder getTileEntityEio(IBlockAccess world, int x, int y, int z) { + if (teClass != null) { + TileEntity te = world.getTileEntity(x, y, z); + if (teClass.isInstance(te)) { // no need to null-check teClass here, it was checked 2 lines above and is *final* + return (TileEntityEnder) te; + } } return null; }