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