Search in sources :

Example 1 with IngredientDistribution

use of codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution in project BluePower by Qmunity.

the class ProjectTableOverlayHandler method moveIngredients.

@SuppressWarnings("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
    for (IngredientDistribution distrib : assignedIngredients) {
        ItemStack pstack = distrib.permutation;
        int transferCap = quantity * pstack.stackSize;
        int transferred = 0;
        int destSlotIndex = 0;
        Slot dest = distrib.slots[0];
        int slotTransferred = 0;
        int slotTransferCap = pstack.getMaxStackSize();
        for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
            if (!slot.getHasStack() || !(slot.inventory instanceof TileProjectTable) && !(slot.inventory instanceof InventoryPlayer))
                continue;
            ItemStack stack = slot.getStack();
            if (!InventoryUtils.canStack(stack, pstack))
                continue;
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            int amount = Math.min(transferCap - transferred, stack.stackSize);
            for (int c = 0; c < amount; c++) {
                FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
                transferred++;
                slotTransferred++;
                if (slotTransferred >= slotTransferCap) {
                    destSlotIndex++;
                    if (destSlotIndex == distrib.slots.length) {
                        dest = null;
                        break;
                    }
                    dest = distrib.slots[destSlotIndex];
                    slotTransferred = 0;
                }
            }
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            if (transferred >= transferCap || dest == null)
                break;
        }
    }
}
Also used : IngredientDistribution(codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) TileProjectTable(com.bluepowermod.tile.tier1.TileProjectTable) Slot(net.minecraft.inventory.Slot) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IngredientDistribution

use of codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution in project BluePower by Qmunity.

the class ProjectTableOverlayHandler method assignIngredients.

private List<IngredientDistribution> assignIngredients(List<PositionedStack> ingredients, List<DistributedIngred> ingredStacks) {
    ArrayList<IngredientDistribution> assignedIngredients = new ArrayList<IngredientDistribution>();
    for (// assign what we need and have
    PositionedStack posstack : // assign what we need and have
    ingredients) {
        DistributedIngred biggestIngred = null;
        ItemStack permutation = null;
        int biggestSize = 0;
        for (ItemStack pstack : posstack.items) {
            for (int j = 0; j < ingredStacks.size(); j++) {
                DistributedIngred istack = ingredStacks.get(j);
                if (!InventoryUtils.canStack(pstack, istack.stack) || istack.invAmount - istack.distributed < pstack.stackSize)
                    continue;
                int relsize = (istack.invAmount - istack.invAmount / istack.recipeAmount * istack.distributed) / pstack.stackSize;
                if (relsize > biggestSize) {
                    biggestSize = relsize;
                    biggestIngred = istack;
                    permutation = pstack;
                    break;
                }
            }
        }
        if (// not enough ingreds
        biggestIngred == null)
            return null;
        biggestIngred.distributed += permutation.stackSize;
        assignedIngredients.add(new IngredientDistribution(biggestIngred, permutation));
    }
    return assignedIngredients;
}
Also used : IngredientDistribution(codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution) PositionedStack(codechicken.nei.PositionedStack) ArrayList(java.util.ArrayList) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IngredientDistribution

use of codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution in project BluePower by Qmunity.

the class ProjectTableOverlayHandler method calculateRecipeQuantity.

private int calculateRecipeQuantity(List<IngredientDistribution> assignedIngredients) {
    int quantity = Integer.MAX_VALUE;
    for (IngredientDistribution distrib : assignedIngredients) {
        DistributedIngred istack = distrib.distrib;
        if (istack.numSlots == 0)
            return 0;
        int allSlots = istack.invAmount;
        if (allSlots / istack.numSlots > istack.stack.getMaxStackSize())
            allSlots = istack.numSlots * istack.stack.getMaxStackSize();
        quantity = Math.min(quantity, allSlots / istack.distributed);
    }
    return quantity;
}
Also used : IngredientDistribution(codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred)

Aggregations

IngredientDistribution (codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution)3 DistributedIngred (codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 PositionedStack (codechicken.nei.PositionedStack)1 TileProjectTable (com.bluepowermod.tile.tier1.TileProjectTable)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 Slot (net.minecraft.inventory.Slot)1