Search in sources :

Example 1 with GlowHopper

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;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowHopper(net.glowstone.block.state.GlowHopper) ContainerEntity(net.glowstone.block.entity.ContainerEntity) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)1 ContainerEntity (net.glowstone.block.entity.ContainerEntity)1 GlowHopper (net.glowstone.block.state.GlowHopper)1 ItemStack (org.bukkit.inventory.ItemStack)1