From 124df2dd70abde854aa36d0118b0cae903715344 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 24 Aug 2016 13:17:12 +0200 Subject: [PATCH] Fixed the phantom placer crashing in pulse mode. Closes #216 --- .../mod/tile/TileEntityPhantomPlacer.java | 36 ++++++++++--------- .../actuallyadditions/mod/util/WorldUtil.java | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java index 88fd6c1b6..fef2da05b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java @@ -132,27 +132,29 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements } private void doWork(){ - if(this.isBreaker){ - Block blockToBreak = this.worldObj.getBlockState(this.boundPosition).getBlock(); - if(blockToBreak != null && blockToBreak.getBlockHardness(this.worldObj.getBlockState(this.boundPosition), this.worldObj, this.boundPosition) > -1.0F){ - ArrayList drops = new ArrayList(); - drops.addAll(blockToBreak.getDrops(this.worldObj, this.boundPosition, this.worldObj.getBlockState(this.boundPosition), 0)); + if(this.isBoundThingInRange()){ + if(this.isBreaker){ + Block blockToBreak = this.worldObj.getBlockState(this.boundPosition).getBlock(); + if(blockToBreak != null && blockToBreak.getBlockHardness(this.worldObj.getBlockState(this.boundPosition), this.worldObj, this.boundPosition) > -1.0F){ + ArrayList drops = new ArrayList(); + drops.addAll(blockToBreak.getDrops(this.worldObj, this.boundPosition, this.worldObj.getBlockState(this.boundPosition), 0)); - if(WorldUtil.addToInventory(this, drops, false, true)){ - if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ - this.worldObj.playEvent(2001, this.boundPosition, Block.getStateId(this.worldObj.getBlockState(this.boundPosition))); + if(WorldUtil.addToInventory(this, drops, false, true)){ + if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ + this.worldObj.playEvent(2001, this.boundPosition, Block.getStateId(this.worldObj.getBlockState(this.boundPosition))); + } + this.worldObj.setBlockToAir(this.boundPosition); + WorldUtil.addToInventory(this, drops, true, true); + this.markDirty(); } - this.worldObj.setBlockToAir(this.boundPosition); - WorldUtil.addToInventory(this, drops, true, true); - this.markDirty(); } } - } - else{ - int theSlot = WorldUtil.findFirstFilledSlot(this.slots); - this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots[theSlot])); - if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){ - this.slots[theSlot] = null; + else{ + int theSlot = WorldUtil.findFirstFilledSlot(this.slots); + this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots[theSlot])); + if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){ + this.slots[theSlot] = null; + } } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index 3d51eafce..3e9898083 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -181,7 +181,7 @@ public final class WorldUtil{ } public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){ - if(world instanceof WorldServer && stack != null && stack.getItem() != null){ + if(world instanceof WorldServer && stack != null && stack.getItem() != null && pos != null){ BlockPos offsetPos = pos.offset(side); IBlockState state = world.getBlockState(offsetPos); Block block = state.getBlock();