net.minecraftforge.items.wrapper.CombinedInvWrapper Java Examples

The following examples show how to use net.minecraftforge.items.wrapper.CombinedInvWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CapabilityProviderItem.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing)
{
    Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;

    List<IItemHandlerModifiable> handlers = Lists.newLinkedList();

    for (ItemModule module : modules.values())
    {
        if (module.hasCapability(capability, facing))
            handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing));
    }

    if (handlers.size() == 1)
        return handlers.get(0);
    else if (handlers.size() > 1)
        return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()]));
    else
        return null;
}
 
Example #2
Source File: TileEntitySimple.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing)
{
    Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;

    List<IItemHandlerModifiable> handlers = Lists.newLinkedList();

    for (TileEntityModule module : modules.values())
    {
        if (module.hasCapability(capability, facing))
            handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing));
    }

    if (handlers.size() == 1)
        return handlers.get(0);
    else if (handlers.size() > 1)
        return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()]));
    else
        return null;
}
 
Example #3
Source File: TileEntityModuleMachine.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private Optional<IItemHandler> handlerForSide(EnumFacing facing)
{
    List<IItemHandlerModifiable> handlers = Lists.newArrayList();
    if (ArrayUtils.contains(supplier.sidesInput, facing))
        handlers.add(invHandler.getInputHandler());
    if (ArrayUtils.contains(supplier.sidesOutput, facing))
        handlers.add(invHandler.getOutputHandler());
    if (ArrayUtils.contains(supplier.sidesFuel, facing))
        handlers.add(invHandler.getFuelHandler());

    return Optional.ofNullable(handlers.isEmpty() ? null : new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()])));
}
 
Example #4
Source File: TileEntityCreationStation.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds one more of each item in the recipe into the crafting grid, if possible
 * @param invId
 * @param recipeId
 */
protected boolean addOneSetOfRecipeItemsIntoGrid(IItemHandler invCrafting, int invId, int recipeId, EntityPlayer player)
{
    invId = MathHelper.clamp(invId, 0, 1);
    int maskOreDict = invId == 1 ? MODE_BIT_RIGHT_CRAFTING_OREDICT : MODE_BIT_LEFT_CRAFTING_OREDICT;
    boolean useOreDict = (this.modeMask & maskOreDict) != 0;

    IItemHandlerModifiable playerInv = (IItemHandlerModifiable) player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
    IItemHandler invWrapper = new CombinedInvWrapper(this.itemInventory, playerInv);

    NonNullList<ItemStack> template = this.getRecipeItems(invId);
    InventoryUtils.clearInventoryToMatchTemplate(invCrafting, invWrapper, template);

    return InventoryUtils.restockInventoryBasedOnTemplate(invCrafting, invWrapper, template, 1, true, useOreDict);
}
 
Example #5
Source File: TileEntityCreationStation.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void fillCraftingGrid(IItemHandler invCrafting, int invId, int recipeId, EntityPlayer player)
{
    invId = MathHelper.clamp(invId, 0, 1);
    int largestStack = InventoryUtils.getLargestExistingStackSize(invCrafting);

    // If all stacks only have one item, then try to fill them all the way to maxStackSize
    if (largestStack == 1)
    {
        largestStack = 64;
    }

    NonNullList<ItemStack> template = InventoryUtils.createInventorySnapshot(invCrafting);
    int maskOreDict = invId == 1 ? MODE_BIT_RIGHT_CRAFTING_OREDICT : MODE_BIT_LEFT_CRAFTING_OREDICT;
    boolean useOreDict = (this.modeMask & maskOreDict) != 0;

    Map<ItemType, Integer> slotCounts = InventoryUtils.getSlotCountPerItem(invCrafting);

    // Clear old contents and then fill all the slots back up
    if (InventoryUtils.tryMoveAllItems(invCrafting, this.itemInventory) == InvResult.MOVED_ALL)
    {
        IItemHandlerModifiable playerInv = (IItemHandlerModifiable) player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
        IItemHandler invWrapper = new CombinedInvWrapper(this.itemInventory, playerInv);

        // Next we find out how many items we have available for each item type on the crafting grid
        // and we cap the max stack size to that value, so the stacks will be balanced
        Iterator<Entry<ItemType, Integer>> iter = slotCounts.entrySet().iterator();

        while (iter.hasNext())
        {
            Entry<ItemType, Integer> entry = iter.next();
            ItemType item = entry.getKey();

            if (item.getStack().getMaxStackSize() == 1)
            {
                continue;
            }

            int numFound = InventoryUtils.getNumberOfMatchingItemsInInventory(invWrapper, item.getStack(), useOreDict);
            int numSlots = entry.getValue();
            int maxSize = numFound / numSlots;

            if (maxSize < largestStack)
            {
                largestStack = maxSize;
            }
        }

        InventoryUtils.restockInventoryBasedOnTemplate(invCrafting, invWrapper, template, largestStack, false, useOreDict);
    }
}