Search in sources :

Example 1 with ItemBackpack

use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.

the class BackpackInterface method createNaturalistBackpack.

@Override
public Item createNaturalistBackpack(String backpackUid, ISpeciesRoot speciesRoot) {
    Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
    Preconditions.checkNotNull(speciesRoot, "speciesRoot must not be null");
    IBackpackDefinition definition = definitions.get(backpackUid);
    if (definition == null) {
        throw new IllegalArgumentException("No backpack definition was registered for UID: " + backpackUid);
    }
    ItemBackpack backpack = new ItemBackpackNaturalist(speciesRoot, definition);
    Proxies.common.registerItem(backpack);
    return backpack;
}
Also used : IBackpackDefinition(forestry.api.storage.IBackpackDefinition) ItemBackpackNaturalist(forestry.storage.items.ItemBackpackNaturalist) ItemBackpack(forestry.storage.items.ItemBackpack)

Example 2 with ItemBackpack

use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.

the class BackpackInterface method createBackpack.

@Override
public Item createBackpack(String backpackUid, EnumBackpackType type) {
    Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
    Preconditions.checkNotNull(type, "type must not be null");
    Preconditions.checkArgument(type != EnumBackpackType.NATURALIST, "type must not be NATURALIST. Use createNaturalistBackpack instead.");
    IBackpackDefinition definition = definitions.get(backpackUid);
    if (definition == null) {
        throw new IllegalArgumentException("No backpack definition was registered for UID: " + backpackUid);
    }
    ItemBackpack backpack = new ItemBackpack(definition, type);
    Proxies.common.registerItem(backpack);
    return backpack;
}
Also used : IBackpackDefinition(forestry.api.storage.IBackpackDefinition) ItemBackpack(forestry.storage.items.ItemBackpack)

Example 3 with ItemBackpack

use of forestry.storage.items.ItemBackpack 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)

Example 4 with ItemBackpack

use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.

the class ResupplyHandler method resupply.

@Override
public void resupply(EntityPlayer player) {
    // Do not attempt resupplying if this backpack is already opened.
    if (!(player.openContainer instanceof ContainerPlayer)) {
        return;
    }
    for (ItemStack backpack : getBackpacks(player.inventory)) {
        if (ItemBackpack.getMode(backpack) == BackpackMode.RESUPPLY) {
            // Load their inventory
            ItemBackpack backpackItem = (ItemBackpack) backpack.getItem();
            ItemInventory backpackInventory = new ItemInventoryBackpack(player, backpackItem.getBackpackSize(), backpack);
            Event event = new BackpackResupplyEvent(player, backpackItem.getDefinition(), backpackInventory);
            if (!MinecraftForge.EVENT_BUS.post(event)) {
                for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
                    ItemStack itemStack = backpackInventory.getStackInSlot(i);
                    if (topOffPlayerInventory(player, itemStack)) {
                        backpackInventory.setInventorySlotContents(i, itemStack);
                        break;
                    }
                }
            }
        }
    }
}
Also used : ContainerPlayer(net.minecraft.inventory.ContainerPlayer) ItemInventory(forestry.core.inventory.ItemInventory) ItemInventoryBackpack(forestry.storage.inventory.ItemInventoryBackpack) BackpackResupplyEvent(forestry.api.storage.BackpackResupplyEvent) Event(net.minecraftforge.fml.common.eventhandler.Event) BackpackResupplyEvent(forestry.api.storage.BackpackResupplyEvent) ItemBackpack(forestry.storage.items.ItemBackpack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemBackpack (forestry.storage.items.ItemBackpack)4 IBackpackDefinition (forestry.api.storage.IBackpackDefinition)3 ItemStack (net.minecraft.item.ItemStack)2 BackpackResupplyEvent (forestry.api.storage.BackpackResupplyEvent)1 ItemInventory (forestry.core.inventory.ItemInventory)1 ContainerBackpack (forestry.storage.gui.ContainerBackpack)1 ContainerNaturalistBackpack (forestry.storage.gui.ContainerNaturalistBackpack)1 ItemInventoryBackpack (forestry.storage.inventory.ItemInventoryBackpack)1 ItemBackpackNaturalist (forestry.storage.items.ItemBackpackNaturalist)1 ContainerPlayer (net.minecraft.inventory.ContainerPlayer)1 Event (net.minecraftforge.fml.common.eventhandler.Event)1