mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-22 23: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;
|
continue;
|
||||||
var remain = allIngredients.getFirst().copy();
|
var remain = allIngredients.getFirst().copy();
|
||||||
var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs;
|
var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs;
|
||||||
for (var stack : toAdd) {
|
var lastAdded = toAdd.isEmpty() ? ItemStack.EMPTY : toAdd.getLast();
|
||||||
if (ItemEquality.compareItems(stack, remain)) {
|
if (ItemEquality.compareItems(lastAdded, remain)) {
|
||||||
var fits = Math.min(stack.getMaxStackSize() - stack.getCount(), remain.getCount());
|
var fits = Math.min(lastAdded.getMaxStackSize() - lastAdded.getCount(), remain.getCount());
|
||||||
stack.grow(fits);
|
lastAdded.grow(fits);
|
||||||
remain.shrink(fits);
|
remain.shrink(fits);
|
||||||
if (remain.isEmpty())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!remain.isEmpty())
|
if (!remain.isEmpty())
|
||||||
toAdd.add(remain);
|
toAdd.add(remain);
|
||||||
|
|
|
@ -40,9 +40,7 @@ public record PacketCraftingModuleTransfer(List<ItemStack> inputs, List<ItemStac
|
||||||
|
|
||||||
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
||||||
for (var i = 0; i < container.getSlots(); i++)
|
for (var i = 0; i < container.getSlots(); i++)
|
||||||
container.setStackInSlot(i, ItemStack.EMPTY);
|
container.setStackInSlot(i, i < contents.size() ? contents.get(i) : ItemStack.EMPTY);
|
||||||
for (var stack : contents)
|
|
||||||
ItemHandlerHelper.insertItem(container, stack, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ public record PacketGhostSlot(BlockPos pos, List<Entry> stacks) implements Custo
|
||||||
tile.setGhostItems(message.stacks);
|
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 record Entry(Optional<List<ItemStack>> stacks, Optional<TagKey<Item>> tag) {
|
||||||
|
|
||||||
public static final StreamCodec<RegistryFriendlyByteBuf, Entry> CODEC = StreamCodec.composite(
|
public static final StreamCodec<RegistryFriendlyByteBuf, Entry> CODEC = StreamCodec.composite(
|
||||||
|
|
Loading…
Reference in a new issue