Fixed the phantom placer crashing in pulse mode.

Closes #216
This commit is contained in:
Ellpeck 2016-08-24 13:17:12 +02:00
parent 1f31705dc4
commit 124df2dd70
2 changed files with 20 additions and 18 deletions

View file

@ -132,27 +132,29 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
} }
private void doWork(){ private void doWork(){
if(this.isBreaker){ if(this.isBoundThingInRange()){
Block blockToBreak = this.worldObj.getBlockState(this.boundPosition).getBlock(); if(this.isBreaker){
if(blockToBreak != null && blockToBreak.getBlockHardness(this.worldObj.getBlockState(this.boundPosition), this.worldObj, this.boundPosition) > -1.0F){ Block blockToBreak = this.worldObj.getBlockState(this.boundPosition).getBlock();
ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); if(blockToBreak != null && blockToBreak.getBlockHardness(this.worldObj.getBlockState(this.boundPosition), this.worldObj, this.boundPosition) > -1.0F){
drops.addAll(blockToBreak.getDrops(this.worldObj, this.boundPosition, this.worldObj.getBlockState(this.boundPosition), 0)); ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
drops.addAll(blockToBreak.getDrops(this.worldObj, this.boundPosition, this.worldObj.getBlockState(this.boundPosition), 0));
if(WorldUtil.addToInventory(this, drops, false, true)){ if(WorldUtil.addToInventory(this, drops, false, true)){
if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){
this.worldObj.playEvent(2001, this.boundPosition, Block.getStateId(this.worldObj.getBlockState(this.boundPosition))); 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{
else{ int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
int theSlot = WorldUtil.findFirstFilledSlot(this.slots); this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots[theSlot]));
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){
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){ this.slots[theSlot] = null;
this.slots[theSlot] = null; }
} }
} }
} }

View file

@ -181,7 +181,7 @@ public final class WorldUtil{
} }
public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){ 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); BlockPos offsetPos = pos.offset(side);
IBlockState state = world.getBlockState(offsetPos); IBlockState state = world.getBlockState(offsetPos);
Block block = state.getBlock(); Block block = state.getBlock();