use of net.glowstone.block.state.GlowHopper in project Glowstone by GlowstoneMC.
the class BlockHopper method pushItems.
private boolean pushItems(GlowBlock block, HopperEntity hopper) {
if (hopper.getInventory() == null || hopper.getInventory().getContents().length == 0) {
return false;
}
GlowBlock target = block.getRelative(((Hopper) block.getState().getData()).getFacing());
if (target.getType() != null && target.getBlockEntity() instanceof ContainerEntity) {
if (target.getState() instanceof GlowHopper) {
if (((Hopper) block.getState().getData()).getFacing() == BlockFace.DOWN) {
// If the hopper is facing downwards, the target hopper can do the pulling task itself
return false;
}
}
ItemStack item = getFirstItem(hopper);
if (item == null) {
return false;
}
ItemStack clone = item.clone();
clone.setAmount(1);
if (((ContainerEntity) target.getBlockEntity()).getInventory().addItem(clone).size() > 0) {
return false;
}
if (item.getAmount() - 1 == 0) {
hopper.getInventory().remove(item);
} else {
item.setAmount(item.getAmount() - 1);
}
return true;
}
return false;
}
Aggregations