Search in sources :

Example 1 with ContainerBackpack

use of forestry.storage.gui.ContainerBackpack in project ForestryMC by ForestryMC.

the class PickupHandlerStorage method onItemPickup.

@Override
public boolean onItemPickup(EntityPlayer player, EntityItem entityitem) {
    ItemStack itemstack = entityitem.getItem();
    if (itemstack.isEmpty()) {
        return false;
    }
    // Do not pick up if a backpack is open
    if (player.openContainer instanceof ContainerBackpack || player.openContainer instanceof ContainerNaturalistBackpack) {
        return false;
    }
    // Make sure to top off manually placed itemstacks in player inventory first
    topOffPlayerInventory(player, itemstack);
    for (ItemStack pack : player.inventory.mainInventory) {
        if (itemstack.isEmpty()) {
            break;
        }
        if (pack.isEmpty() || !(pack.getItem() instanceof ItemBackpack)) {
            continue;
        }
        ItemBackpack backpack = (ItemBackpack) pack.getItem();
        IBackpackDefinition backpackDefinition = backpack.getDefinition();
        if (backpackDefinition.getFilter().test(itemstack)) {
            ItemBackpack.tryStowing(player, pack, itemstack);
        }
    }
    return itemstack.isEmpty();
}
Also used : IBackpackDefinition(forestry.api.storage.IBackpackDefinition) ContainerBackpack(forestry.storage.gui.ContainerBackpack) ContainerNaturalistBackpack(forestry.storage.gui.ContainerNaturalistBackpack) ItemBackpack(forestry.storage.items.ItemBackpack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IBackpackDefinition (forestry.api.storage.IBackpackDefinition)1 ContainerBackpack (forestry.storage.gui.ContainerBackpack)1 ContainerNaturalistBackpack (forestry.storage.gui.ContainerNaturalistBackpack)1 ItemBackpack (forestry.storage.items.ItemBackpack)1 ItemStack (net.minecraft.item.ItemStack)1