2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.recipe;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import net.minecraft.client.entity.EntityClientPlayerMP;
|
2023-09-25 00:35:24 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
2025-06-27 16:32:54 +03:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2023-09-25 00:35:24 +02:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
2025-04-24 18:48:40 +03:00
|
|
|
import net.minecraft.inventory.SlotCrafting;
|
2023-09-25 00:35:24 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2025-07-11 17:33:14 +03:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2023-09-25 00:35:24 +02:00
|
|
|
|
|
|
|
|
import codechicken.lib.inventory.InventoryUtils;
|
|
|
|
|
import codechicken.nei.FastTransferManager;
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.NEIClientUtils;
|
2023-09-25 00:35:24 +02:00
|
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
|
import codechicken.nei.api.IOverlayHandler;
|
|
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
public class DefaultOverlayHandler implements IOverlayHandler {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
public static class DistributedIngred {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public DistributedIngred(ItemStack item) {
|
2014-04-29 10:54:20 +10:00
|
|
|
stack = InventoryUtils.copyStack(item, 1);
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
public ItemStack stack;
|
2014-04-29 10:54:20 +10:00
|
|
|
public int invAmount;
|
|
|
|
|
public int distributed;
|
|
|
|
|
public int numSlots;
|
|
|
|
|
public int recipeAmount;
|
2025-06-27 16:32:54 +03:00
|
|
|
public boolean isContainerItem = false;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
public static class IngredientDistribution {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
public IngredientDistribution(DistributedIngred distrib, ItemStack permutation) {
|
2014-04-29 10:54:20 +10:00
|
|
|
this.distrib = distrib;
|
|
|
|
|
this.permutation = permutation;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public DistributedIngred distrib;
|
|
|
|
|
public ItemStack permutation;
|
|
|
|
|
public Slot[] slots;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
public DefaultOverlayHandler(int x, int y) {
|
2014-04-29 10:54:20 +10:00
|
|
|
offsetx = x;
|
|
|
|
|
offsety = y;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
public DefaultOverlayHandler() {
|
2014-04-29 10:54:20 +10:00
|
|
|
this(5, 11);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 12:22:14 +10:00
|
|
|
public int offsetx;
|
|
|
|
|
public int offsety;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2025-04-24 18:48:40 +03:00
|
|
|
public void overlayRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, boolean maxTransfer) {
|
|
|
|
|
transferRecipe(gui, handler, recipeIndex, maxTransfer ? Integer.MAX_VALUE : 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int transferRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, int multiplier) {
|
|
|
|
|
final List<PositionedStack> ingredients = handler.getIngredientStacks(recipeIndex);
|
|
|
|
|
final List<DistributedIngred> ingredStacks = getPermutationIngredients(ingredients);
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (!clearIngredients(gui)) return 0;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
findInventoryQuantities(gui, ingredStacks);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
final List<IngredientDistribution> assignedIngredients = assignIngredients(ingredients, ingredStacks);
|
|
|
|
|
if (assignedIngredients == null) return 0;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
assignIngredSlots(gui, ingredients, assignedIngredients);
|
2025-04-24 18:48:40 +03:00
|
|
|
multiplier = Math.min(multiplier == 0 ? 64 : multiplier, calculateRecipeQuantity(assignedIngredients));
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (multiplier != 0) {
|
|
|
|
|
moveIngredients(gui, assignedIngredients, (int) multiplier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return multiplier;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Override
|
|
|
|
|
public boolean canFillCraftingGrid(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
|
|
|
|
return presenceOverlay(firstGui, handler, recipeIndex).stream().allMatch(state -> state.isPresent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canCraft(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
|
|
|
|
return canFillCraftingGrid(firstGui, handler, recipeIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean craft(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, int multiplier) {
|
|
|
|
|
final EntityClientPlayerMP thePlayer = NEIClientUtils.mc().thePlayer;
|
|
|
|
|
boolean craft = false;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
while (multiplier > 0) {
|
|
|
|
|
final int transfer = transferRecipe(firstGui, recipe, recipeIndex, multiplier);
|
|
|
|
|
|
|
|
|
|
if (transfer <= 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
multiplier -= transfer;
|
|
|
|
|
|
|
|
|
|
for (Slot slot : firstGui.inventorySlots.inventorySlots) {
|
|
|
|
|
if (slot.getHasStack() && slot instanceof SlotCrafting && slot.canTakeStack(thePlayer)) {
|
|
|
|
|
FastTransferManager.clickSlot(firstGui, slot.slotNumber, 0, 1);
|
|
|
|
|
craft = true;
|
|
|
|
|
break;
|
2024-09-07 15:49:46 +03:00
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 17:25:02 +03:00
|
|
|
clearIngredients(firstGui);
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return craft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean clearIngredients(GuiContainer gui) {
|
|
|
|
|
final EntityClientPlayerMP thePlayer = NEIClientUtils.mc().thePlayer;
|
|
|
|
|
|
|
|
|
|
for (Slot slot : gui.inventorySlots.inventorySlots) {
|
|
|
|
|
if (slot.getHasStack() && !canMoveFrom(slot, gui)
|
|
|
|
|
&& !(slot instanceof SlotCrafting)
|
|
|
|
|
&& slot.canTakeStack(thePlayer)) {
|
|
|
|
|
FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
|
|
|
|
|
if (slot.getHasStack()) return false;
|
|
|
|
|
}
|
2024-09-07 15:49:46 +03:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-06-27 16:32:54 +03:00
|
|
|
return dropOffMouseStack(thePlayer, gui);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int multiplier) {
|
2025-06-27 16:32:54 +03:00
|
|
|
final EntityClientPlayerMP thePlayer = NEIClientUtils.mc().thePlayer;
|
|
|
|
|
|
|
|
|
|
for (Slot slot : gui.inventorySlots.inventorySlots) {
|
|
|
|
|
if (slot instanceof SlotCrafting || !slot.getHasStack()
|
|
|
|
|
|| !canMoveFrom(slot, gui)
|
|
|
|
|
|| !slot.canTakeStack(thePlayer))
|
|
|
|
|
continue;
|
|
|
|
|
ItemStack stack = slot.getStack();
|
|
|
|
|
int slotTransferCap = stack.getMaxStackSize();
|
|
|
|
|
|
|
|
|
|
for (IngredientDistribution distrib : assignedIngredients) {
|
|
|
|
|
if (distrib.slots.length == 0 || !slot.getHasStack() || !canStack(distrib.permutation, stack)) continue;
|
|
|
|
|
int transferCap = Math.min(slotTransferCap, multiplier * distrib.permutation.stackSize);
|
|
|
|
|
int stackSize = slot.getStack().stackSize;
|
|
|
|
|
boolean pickup = false;
|
|
|
|
|
|
|
|
|
|
for (Slot dest : distrib.slots) {
|
|
|
|
|
int amount = Math
|
|
|
|
|
.min(transferCap - (dest.getHasStack() ? dest.getStack().stackSize : 0), stackSize);
|
|
|
|
|
|
|
|
|
|
if (stackSize <= amount) {
|
|
|
|
|
|
|
|
|
|
if (!pickup) {
|
|
|
|
|
FastTransferManager.clickSlot(gui, slot.slotNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FastTransferManager.clickSlot(gui, dest.slotNumber);
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
for (int c = 0; c < amount; c++) {
|
|
|
|
|
|
|
|
|
|
if (pickup != (pickup = true)) {
|
|
|
|
|
FastTransferManager.clickSlot(gui, slot.slotNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
|
|
|
|
|
stackSize--;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-27 16:32:54 +03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (thePlayer.inventory.getItemStack() != null) {
|
|
|
|
|
FastTransferManager.clickSlot(gui, slot.slotNumber);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-27 16:32:54 +03:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2025-06-27 16:32:54 +03:00
|
|
|
protected boolean dropOffMouseStack(EntityPlayer entityPlayer, GuiContainer gui) {
|
|
|
|
|
|
|
|
|
|
if (entityPlayer.inventory.getItemStack() == null) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < gui.inventorySlots.inventorySlots.size(); i++) {
|
|
|
|
|
Slot slot = gui.inventorySlots.inventorySlots.get(i);
|
|
|
|
|
|
|
|
|
|
if (slot.inventory == entityPlayer.inventory) {
|
|
|
|
|
ItemStack mouseItem = entityPlayer.inventory.getItemStack();
|
|
|
|
|
ItemStack slotStack = slot.getStack();
|
|
|
|
|
|
|
|
|
|
if (slotStack == null || NEIClientUtils.areStacksSameType(mouseItem, slotStack)) {
|
|
|
|
|
FastTransferManager.clickSlot(gui, i, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entityPlayer.inventory.getItemStack() == null) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entityPlayer.inventory.getItemStack() == null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
private int calculateRecipeQuantity(List<IngredientDistribution> assignedIngredients) {
|
2014-04-29 10:54:20 +10:00
|
|
|
int quantity = Integer.MAX_VALUE;
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
for (IngredientDistribution distrib : assignedIngredients) {
|
2025-06-27 16:32:54 +03:00
|
|
|
final DistributedIngred istack = distrib.distrib;
|
2022-06-24 12:32:13 +01:00
|
|
|
if (istack.numSlots == 0) return 0;
|
|
|
|
|
|
2023-03-30 20:47:33 +01:00
|
|
|
final int maxStackSize = istack.stack.getMaxStackSize();
|
2025-06-27 16:32:54 +03:00
|
|
|
if (maxStackSize == 1 && istack.isContainerItem) {
|
2023-03-30 20:47:33 +01:00
|
|
|
// If non-stackable, fill up as much as possible of the other ingredients
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-06-27 16:32:54 +03:00
|
|
|
|
|
|
|
|
final int allSlots = Math.min(istack.invAmount, istack.numSlots * maxStackSize);
|
|
|
|
|
quantity = Math.min(quantity, allSlots / istack.distributed);
|
2023-03-30 20:47:33 +01:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2023-03-30 20:47:33 +01:00
|
|
|
if (quantity == Integer.MAX_VALUE) {
|
|
|
|
|
// Only possible if all ingredients were non-stackable
|
|
|
|
|
quantity = 1;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return quantity;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingredients,
|
|
|
|
|
List<IngredientDistribution> assignedIngredients) {
|
|
|
|
|
Slot[][] recipeSlots = mapIngredSlots(gui, ingredients); // setup the slot map
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
HashMap<Slot, Integer> distribution = new HashMap<>();
|
|
|
|
|
for (Slot[] recipeSlot : recipeSlots)
|
2022-06-24 12:32:13 +01:00
|
|
|
for (Slot slot : recipeSlot) if (!distribution.containsKey(slot)) distribution.put(slot, -1);
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
HashSet<Slot> avaliableSlots = new HashSet<>(distribution.keySet());
|
|
|
|
|
HashSet<Integer> remainingIngreds = new HashSet<>();
|
|
|
|
|
ArrayList<LinkedList<Slot>> assignedSlots = new ArrayList<>();
|
2022-06-24 12:32:13 +01:00
|
|
|
for (int i = 0; i < ingredients.size(); i++) {
|
2014-04-29 10:54:20 +10:00
|
|
|
remainingIngreds.add(i);
|
2019-12-30 20:19:16 -08:00
|
|
|
assignedSlots.add(new LinkedList<>());
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2024-09-07 15:49:46 +03:00
|
|
|
while (!avaliableSlots.isEmpty() && !remainingIngreds.isEmpty()) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext();) {
|
2014-04-29 10:54:20 +10:00
|
|
|
int i = iterator.next();
|
|
|
|
|
boolean assigned = false;
|
|
|
|
|
DistributedIngred istack = assignedIngredients.get(i).distrib;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
for (Slot slot : recipeSlots[i]) {
|
|
|
|
|
if (avaliableSlots.contains(slot)) {
|
2014-04-29 10:54:20 +10:00
|
|
|
avaliableSlots.remove(slot);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (slot.getHasStack()) continue;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
istack.numSlots++;
|
|
|
|
|
assignedSlots.get(i).add(slot);
|
|
|
|
|
assigned = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2024-09-07 15:49:46 +03:00
|
|
|
if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount) {
|
2014-04-29 10:54:20 +10:00
|
|
|
iterator.remove();
|
2024-09-07 15:49:46 +03:00
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < ingredients.size(); i++)
|
2014-04-29 10:54:20 +10:00
|
|
|
assignedIngredients.get(i).slots = assignedSlots.get(i).toArray(new Slot[0]);
|
|
|
|
|
return recipeSlots;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
private List<IngredientDistribution> assignIngredients(List<PositionedStack> ingredients,
|
|
|
|
|
List<DistributedIngred> ingredStacks) {
|
2019-12-30 20:19:16 -08:00
|
|
|
ArrayList<IngredientDistribution> assignedIngredients = new ArrayList<>();
|
2022-06-24 12:32:13 +01:00
|
|
|
for (PositionedStack posstack : ingredients) // assign what we need and have
|
2014-04-29 10:54:20 +10:00
|
|
|
{
|
|
|
|
|
DistributedIngred biggestIngred = null;
|
|
|
|
|
ItemStack permutation = null;
|
|
|
|
|
int biggestSize = 0;
|
2022-06-24 12:32:13 +01:00
|
|
|
for (ItemStack pstack : posstack.items) {
|
2019-12-30 20:19:16 -08:00
|
|
|
for (DistributedIngred istack : ingredStacks) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!canStack(pstack, istack.stack) || istack.invAmount - istack.distributed < pstack.stackSize
|
|
|
|
|
|| istack.recipeAmount == 0
|
|
|
|
|
|| pstack.stackSize == 0)
|
|
|
|
|
continue;
|
2019-12-30 20:19:16 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
int relsize = (istack.invAmount - istack.invAmount / istack.recipeAmount * istack.distributed)
|
|
|
|
|
/ pstack.stackSize;
|
2019-12-30 20:19:16 -08:00
|
|
|
if (relsize > biggestSize) {
|
2014-04-29 10:54:20 +10:00
|
|
|
biggestSize = relsize;
|
|
|
|
|
biggestIngred = istack;
|
|
|
|
|
permutation = pstack;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (biggestIngred == null) // not enough ingreds
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
biggestIngred.distributed += permutation.stackSize;
|
2014-04-29 10:54:20 +10:00
|
|
|
assignedIngredients.add(new IngredientDistribution(biggestIngred, permutation));
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return assignedIngredients;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
|
2024-09-07 15:49:46 +03:00
|
|
|
for (Slot slot : gui.inventorySlots.inventorySlots) /* work out how much we have to go round */ {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (slot.getHasStack() && canMoveFrom(slot, gui)) {
|
2025-06-27 16:32:54 +03:00
|
|
|
final ItemStack pstack = slot.getStack();
|
|
|
|
|
final DistributedIngred istack = findIngred(ingredStacks, pstack);
|
|
|
|
|
|
|
|
|
|
if (istack != null) {
|
|
|
|
|
istack.invAmount += pstack.stackSize;
|
|
|
|
|
|
|
|
|
|
if (!istack.isContainerItem && pstack.getMaxStackSize() == 1
|
|
|
|
|
&& pstack.getItem().hasContainerItem(pstack)) {
|
2025-07-11 17:33:14 +03:00
|
|
|
final NBTTagCompound tagCompound = pstack.getTagCompound();
|
|
|
|
|
|
|
|
|
|
if (tagCompound != null && tagCompound.hasKey("GT.ToolStats")) {
|
|
|
|
|
istack.isContainerItem = true;
|
|
|
|
|
} else {
|
|
|
|
|
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
|
|
|
|
|
StackInfo.pauseItemDamageSound(true);
|
|
|
|
|
|
|
|
|
|
final ItemStack containerItem = pstack.getItem().getContainerItem(pstack);
|
|
|
|
|
if (containerItem != null) {
|
|
|
|
|
istack.isContainerItem = pstack.getItem() == containerItem.getItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
|
2025-06-27 16:32:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
private List<DistributedIngred> getPermutationIngredients(List<PositionedStack> ingredients) {
|
2019-12-30 20:19:16 -08:00
|
|
|
ArrayList<DistributedIngred> ingredStacks = new ArrayList<>();
|
2022-06-24 12:32:13 +01:00
|
|
|
for (PositionedStack posstack : ingredients) /* work out what we need */ {
|
|
|
|
|
for (ItemStack pstack : posstack.items) {
|
2014-04-29 10:54:20 +10:00
|
|
|
DistributedIngred istack = findIngred(ingredStacks, pstack);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (istack == null) ingredStacks.add(istack = new DistributedIngred(pstack));
|
|
|
|
|
istack.recipeAmount += pstack.stackSize;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ingredStacks;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 12:28:02 +10:00
|
|
|
public boolean canMoveFrom(Slot slot, GuiContainer gui) {
|
2014-08-07 00:18:08 +10:00
|
|
|
return slot.inventory instanceof InventoryPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients) {
|
2014-04-29 10:54:20 +10:00
|
|
|
Slot[][] recipeSlotList = new Slot[ingredients.size()][];
|
2022-06-24 12:32:13 +01:00
|
|
|
for (int i = 0; i < ingredients.size(); i++) /* identify slots */ {
|
2019-12-30 20:19:16 -08:00
|
|
|
LinkedList<Slot> recipeSlots = new LinkedList<>();
|
2014-04-29 10:54:20 +10:00
|
|
|
PositionedStack pstack = ingredients.get(i);
|
2024-09-07 15:49:46 +03:00
|
|
|
for (Slot slot : gui.inventorySlots.inventorySlots) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
|
2014-04-29 10:54:20 +10:00
|
|
|
recipeSlots.add(slot);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
recipeSlotList[i] = recipeSlots.toArray(new Slot[0]);
|
|
|
|
|
}
|
|
|
|
|
return recipeSlotList;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 20:26:01 -07:00
|
|
|
public DistributedIngred findIngred(List<DistributedIngred> ingredStacks, ItemStack pstack) {
|
2025-04-24 18:48:40 +03:00
|
|
|
for (DistributedIngred istack : ingredStacks) if (canStack(istack.stack, pstack)) return istack;
|
2014-04-29 10:54:20 +10:00
|
|
|
return null;
|
|
|
|
|
}
|
2015-11-17 20:49:10 +00:00
|
|
|
|
|
|
|
|
protected boolean canStack(ItemStack stack1, ItemStack stack2) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (stack1 == null || stack2 == null) return true;
|
2025-06-22 18:49:20 +03:00
|
|
|
return NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack1, stack2);
|
2015-11-17 20:49:10 +00:00
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|