Fixed the dropper dropping into unloaded chunks

Closes #465
This commit is contained in:
Ellpeck 2016-12-08 14:25:16 +01:00
parent 91dc0f4ce1
commit 91170ea432
2 changed files with 15 additions and 10 deletions

View file

@ -65,11 +65,12 @@ public class TileEntityDropper extends TileEntityInventoryBase{
} }
private void doWork(){ private void doWork(){
if(StackUtil.isValid(this.removeFromInventory(false))){ ItemStack theoreticalRemove = this.removeFromInventory(false);
ItemStack stack = this.removeFromInventory(true); if(StackUtil.isValid(theoreticalRemove)){
stack = StackUtil.setStackSize(stack, 1);
IBlockState state = this.world.getBlockState(this.pos); IBlockState state = this.world.getBlockState(this.pos);
WorldUtil.dropItemAtSide(WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)), this.world, this.pos, stack); if(WorldUtil.dropItemAtSide(WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)), this.world, this.pos, StackUtil.setStackSize(theoreticalRemove.copy(), 1))){
this.removeFromInventory(true);
}
} }
} }

View file

@ -181,13 +181,17 @@ public final class WorldUtil{
return stack; return stack;
} }
public static void dropItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){ public static boolean dropItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){
BlockPos coords = pos.offset(side); BlockPos coords = pos.offset(side);
if(world.isBlockLoaded(coords)){
EntityItem item = new EntityItem(world, coords.getX()+0.5, coords.getY()+0.5, coords.getZ()+0.5, stack); EntityItem item = new EntityItem(world, coords.getX()+0.5, coords.getY()+0.5, coords.getZ()+0.5, stack);
item.motionX = 0; item.motionX = 0;
item.motionY = 0; item.motionY = 0;
item.motionZ = 0; item.motionZ = 0;
world.spawnEntity(item);
return world.spawnEntity(item);
}
return false;
} }
public static EnumFacing getDirectionBySidesInOrder(int side){ public static EnumFacing getDirectionBySidesInOrder(int side){