Java Code Examples for codechicken.lib.inventory.InventoryUtils#canStack()
The following examples show how to use
codechicken.lib.inventory.InventoryUtils#canStack() .
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: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 5 votes |
private List<IngredientDistribution> assignIngredients(List<PositionedStack> ingredients, List<DistributedIngred> ingredStacks) { ArrayList<IngredientDistribution> assignedIngredients = new ArrayList<>(); for (PositionedStack posstack : ingredients)//assign what we need and have { 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.getCount()) { continue; } int relsize = (istack.invAmount - istack.invAmount / istack.recipeAmount * istack.distributed) / pstack.getCount(); if (relsize > biggestSize) { biggestSize = relsize; biggestIngred = istack; permutation = pstack; break; } } } if (biggestIngred == null)//not enough ingreds { return null; } biggestIngred.distributed += permutation.getCount(); assignedIngredients.add(new IngredientDistribution(biggestIngred, permutation)); } return assignedIngredients; }
Example 2
Source File: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 5 votes |
public DistributedIngred findIngred(List<DistributedIngred> ingredStacks, ItemStack pstack) { for (DistributedIngred istack : ingredStacks) { if (InventoryUtils.canStack(pstack, istack.stack)) { return istack; } } return null; }
Example 3
Source File: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 5 votes |
private List<IngredientDistribution> assignIngredients(List<PositionedStack> ingredients, List<DistributedIngred> ingredStacks) { ArrayList<IngredientDistribution> assignedIngredients = new ArrayList<IngredientDistribution>(); for(PositionedStack posstack : ingredients)//assign what we need and have { 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(biggestIngred == null)//not enough ingreds return null; biggestIngred.distributed+=permutation.stackSize; assignedIngredients.add(new IngredientDistribution(biggestIngred, permutation)); } return assignedIngredients; }
Example 4
Source File: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 5 votes |
public DistributedIngred findIngred(List<DistributedIngred> ingredStacks, ItemStack pstack) { for(DistributedIngred istack : ingredStacks) if(InventoryUtils.canStack(pstack, istack.stack)) return istack; return null; }
Example 5
Source File: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 4 votes |
@SuppressWarnings ("unchecked") private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) { for (IngredientDistribution distrib : assignedIngredients) { ItemStack pstack = distrib.permutation; int transferCap = quantity * pstack.getCount(); int transferred = 0; int destSlotIndex = 0; Slot dest = distrib.slots[0]; int slotTransferred = 0; int slotTransferCap = pstack.getMaxStackSize(); for (Slot slot : gui.inventorySlots.inventorySlots) { if (!slot.getHasStack() || !canMoveFrom(slot, gui)) { continue; } ItemStack stack = slot.getStack(); if (!InventoryUtils.canStack(stack, pstack)) { continue; } FastTransferManager.clickSlot(gui, slot.slotNumber); int amount = Math.min(transferCap - transferred, stack.getCount()); 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; } } } }
Example 6
Source File: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 4 votes |
@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() || !canMoveFrom(slot, gui)) 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; } } }