From af3393345b86193aaf765965792d9962ac8f7413 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 3 Dec 2024 23:27:04 +0100 Subject: [PATCH] make the jei crafting module transfer insert items in the order they appear (but stack if multiple are consecutive) --- .../compat/jei/CraftingModuleTransferHandler.java | 13 +++++-------- .../packets/PacketCraftingModuleTransfer.java | 4 +--- .../prettypipes/packets/PacketGhostSlot.java | 1 + 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java b/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java index 7cde3cf..4ee3cca 100644 --- a/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java +++ b/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java @@ -42,14 +42,11 @@ public class CraftingModuleTransferHandler implements IUniversalRecipeTransferHa continue; var remain = allIngredients.getFirst().copy(); var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs; - for (var stack : toAdd) { - if (ItemEquality.compareItems(stack, remain)) { - var fits = Math.min(stack.getMaxStackSize() - stack.getCount(), remain.getCount()); - stack.grow(fits); - remain.shrink(fits); - if (remain.isEmpty()) - break; - } + var lastAdded = toAdd.isEmpty() ? ItemStack.EMPTY : toAdd.getLast(); + if (ItemEquality.compareItems(lastAdded, remain)) { + var fits = Math.min(lastAdded.getMaxStackSize() - lastAdded.getCount(), remain.getCount()); + lastAdded.grow(fits); + remain.shrink(fits); } if (!remain.isEmpty()) toAdd.add(remain); diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java index c76fc2f..d3a958e 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java @@ -40,9 +40,7 @@ public record PacketCraftingModuleTransfer(List inputs, List contents) { for (var i = 0; i < container.getSlots(); i++) - container.setStackInSlot(i, ItemStack.EMPTY); - for (var stack : contents) - ItemHandlerHelper.insertItem(container, stack, false); + container.setStackInSlot(i, i < contents.size() ? contents.get(i) : ItemStack.EMPTY); } } diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java index ef6b381..a9e51ba 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java @@ -44,6 +44,7 @@ public record PacketGhostSlot(BlockPos pos, List stacks) implements Custo tile.setGhostItems(message.stacks); } + // TODO the crafting module should probably also use a system like this to allow recipes that have multiple options & to also pick the items we have most of (like the terminal does in setGhostItems) public record Entry(Optional> stacks, Optional> tag) { public static final StreamCodec CODEC = StreamCodec.composite(