make the jei crafting module transfer insert items in the order they appear (but stack if multiple are consecutive)

This commit is contained in:
Ell 2024-12-03 23:27:04 +01:00
parent fb59109d08
commit af3393345b
3 changed files with 7 additions and 11 deletions

View file

@ -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);
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())
break;
}
}
if (!remain.isEmpty())
toAdd.add(remain);

View file

@ -40,9 +40,7 @@ public record PacketCraftingModuleTransfer(List<ItemStack> inputs, List<ItemStac
private static void copy(ItemStackHandler container, List<ItemStack> 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);
}
}

View file

@ -44,6 +44,7 @@ public record PacketGhostSlot(BlockPos pos, List<Entry> 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<List<ItemStack>> stacks, Optional<TagKey<Item>> tag) {
public static final StreamCodec<RegistryFriendlyByteBuf, Entry> CODEC = StreamCodec.composite(