Search in sources :

Example 1 with DistributedIngred

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

the class ProjectTableOverlayHandler method findInventoryQuantities.

@SuppressWarnings("unchecked")
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
    for (// work out how much we have to go round
    Slot slot : // work out how much we have to go round
    (List<Slot>) gui.inventorySlots.inventorySlots) {
        if (slot.getHasStack() && (slot.inventory instanceof TileProjectTable || slot.inventory instanceof InventoryPlayer)) {
            ItemStack pstack = slot.getStack();
            DistributedIngred istack = findIngred(ingredStacks, pstack);
            if (istack != null)
                istack.invAmount += pstack.stackSize;
        }
    }
}
Also used : 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) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred)

Example 2 with DistributedIngred

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

the class ProjectTableOverlayHandler method getPermutationIngredients.

private List<DistributedIngred> getPermutationIngredients(List<PositionedStack> ingredients) {
    ArrayList<DistributedIngred> ingredStacks = new ArrayList<DistributedIngred>();
    for (// work out what we need
    PositionedStack posstack : // work out what we need
    ingredients) {
        for (ItemStack pstack : posstack.items) {
            DistributedIngred istack = findIngred(ingredStacks, pstack);
            if (istack == null)
                ingredStacks.add(istack = new DistributedIngred(pstack));
            istack.recipeAmount += pstack.stackSize;
        }
    }
    return ingredStacks;
}
Also used : PositionedStack(codechicken.nei.PositionedStack) ArrayList(java.util.ArrayList) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred) ItemStack(net.minecraft.item.ItemStack)

Example 3 with DistributedIngred

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

the class ProjectTableOverlayHandler method assignIngredSlots.

private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingredients, List<IngredientDistribution> assignedIngredients) {
    // setup the slot map
    Slot[][] recipeSlots = mapIngredSlots(gui, ingredients);
    HashMap<Slot, Integer> distribution = new HashMap<Slot, Integer>();
    for (Slot[] recipeSlot : recipeSlots) for (Slot slot : recipeSlot) if (!distribution.containsKey(slot))
        distribution.put(slot, -1);
    HashSet<Slot> avaliableSlots = new HashSet<Slot>(distribution.keySet());
    HashSet<Integer> remainingIngreds = new HashSet<Integer>();
    ArrayList<LinkedList<Slot>> assignedSlots = new ArrayList<LinkedList<Slot>>();
    for (int i = 0; i < ingredients.size(); i++) {
        remainingIngreds.add(i);
        assignedSlots.add(new LinkedList<Slot>());
    }
    while (avaliableSlots.size() > 0 && remainingIngreds.size() > 0) {
        for (Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext(); ) {
            int i = iterator.next();
            boolean assigned = false;
            DistributedIngred istack = assignedIngredients.get(i).distrib;
            for (Slot slot : recipeSlots[i]) {
                if (avaliableSlots.contains(slot)) {
                    avaliableSlots.remove(slot);
                    if (slot.getHasStack())
                        continue;
                    istack.numSlots++;
                    assignedSlots.get(i).add(slot);
                    assigned = true;
                    break;
                }
            }
            if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount)
                iterator.remove();
        }
    }
    for (int i = 0; i < ingredients.size(); i++) assignedIngredients.get(i).slots = assignedSlots.get(i).toArray(new Slot[0]);
    return recipeSlots;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Slot(net.minecraft.inventory.Slot) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred) HashSet(java.util.HashSet)

Example 4 with DistributedIngred

use of codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred 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 5 with DistributedIngred

use of codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred 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

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