mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-22 15:39:22 +01:00
make the jei crafting module transfer insert items in the order they appear (but stack if multiple are consecutive)
This commit is contained in:
parent
fb59109d08
commit
af3393345b
3 changed files with 7 additions and 11 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue