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;
}
}
}
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;
}
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;
}
Aggregations