Search in sources :

Example 1 with IBackpackDefinition

use of forestry.api.storage.IBackpackDefinition 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 IBackpackDefinition

use of forestry.api.storage.IBackpackDefinition 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 IBackpackDefinition

use of forestry.api.storage.IBackpackDefinition in project ForestryMC by ForestryMC.

the class ModuleBackpacks method processIMCMessage.

@Override
public boolean processIMCMessage(IMCMessage message) {
    if (message.key.equals("add-backpack-items")) {
        String[] tokens = message.getStringValue().split("@");
        if (tokens.length != 2) {
            IMCUtil.logInvalidIMCMessage(message);
            return true;
        }
        String backpackUid = tokens[0];
        String itemStackStrings = tokens[1];
        IBackpackDefinition backpackDefinition = BackpackManager.backpackInterface.getBackpackDefinition(backpackUid);
        if (backpackDefinition == null) {
            String errorMessage = IMCUtil.getInvalidIMCMessageText(message);
            Log.error("{} For non-existent backpack {}.", errorMessage, backpackUid);
            return true;
        }
        List<ItemStack> itemStacks = ItemStackUtil.parseItemStackStrings(itemStackStrings, 0);
        for (ItemStack itemStack : itemStacks) {
            BackpackManager.backpackInterface.addItemToForestryBackpack(backpackUid, itemStack);
        }
        return true;
    }
    return false;
}
Also used : IBackpackDefinition(forestry.api.storage.IBackpackDefinition) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IBackpackDefinition

use of forestry.api.storage.IBackpackDefinition 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)4 ItemBackpack (forestry.storage.items.ItemBackpack)3 ItemStack (net.minecraft.item.ItemStack)2 ContainerBackpack (forestry.storage.gui.ContainerBackpack)1 ContainerNaturalistBackpack (forestry.storage.gui.ContainerNaturalistBackpack)1 ItemBackpackNaturalist (forestry.storage.items.ItemBackpackNaturalist)1