Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/12.x-1.20' into 13.x-1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java
  • Loading branch information
shedaniel committed Sep 29, 2023
2 parents 84d6904 + 67d12db commit 56aea58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ public static void onInitialize() {
boolean shift = packetByteBuf.readBoolean();
try {
CompoundTag nbt = packetByteBuf.readNbt();
List<InputIngredient<ItemStack>> inputs = readInputs(nbt.getCompound("Inputs"));
int version = nbt.getInt("Version");
if (version != 1) throw new IllegalStateException("Server and client REI protocol version mismatch! Server: 1, Client: " + version);
List<InputIngredient<ItemStack>> inputs = readInputs(nbt.getList("Inputs", Tag.TAG_COMPOUND));
List<SlotAccessor> input = readSlots(container, player, nbt.getList("InputSlots", Tag.TAG_COMPOUND));
List<SlotAccessor> inventory = readSlots(container, player, nbt.getList("InventorySlots", Tag.TAG_COMPOUND));
NewInputSlotCrafter<AbstractContainerMenu, Container> crafter = new NewInputSlotCrafter<>(container, input, inventory, inputs);
Expand Down Expand Up @@ -201,10 +203,11 @@ private static List<SlotAccessor> readSlots(AbstractContainerMenu menu, Player p
return slots;
}

private static List<InputIngredient<ItemStack>> readInputs(CompoundTag tag) {
private static List<InputIngredient<ItemStack>> readInputs(ListTag tag) {
List<InputIngredient<ItemStack>> inputs = new ArrayList<>();
for (Map.Entry<String, Tag> entry : tag.tags.entrySet()) {
InputIngredient<EntryStack<?>> stacks = InputIngredient.of(Integer.parseInt(entry.getKey()), EntryIngredient.read((ListTag) entry.getValue()));
for (Tag t : tag) {
CompoundTag compoundTag = (CompoundTag) t;
InputIngredient<EntryStack<?>> stacks = InputIngredient.of(compoundTag.getInt("Index"), EntryIngredient.read(compoundTag.getList("Ingredient", Tag.TAG_COMPOUND)));
inputs.add(InputIngredient.withType(stacks, VanillaEntryTypes.ITEM));
}
return inputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public TransferHandler.Result handle(TransferHandler.Context context, SimpleTran

private CompoundTag save(TransferHandler.Context context, List<InputIngredient<ItemStack>> inputs, Iterable<SlotAccessor> inputSlots, Iterable<SlotAccessor> inventorySlots) {
CompoundTag tag = new CompoundTag();
tag.putInt("Version", 1);
tag.put("Inputs", saveInputs(inputs));
tag.put("InventorySlots", saveSlots(context,inventorySlots));
tag.put("InputSlots", saveSlots(context, inputSlots));
Expand All @@ -111,10 +112,13 @@ private Tag saveSlots(TransferHandler.Context context, Iterable<SlotAccessor> sl
}

private Tag saveInputs(List<InputIngredient<ItemStack>> inputs) {
CompoundTag tag = new CompoundTag();
ListTag tag = new ListTag();

for (InputIngredient<ItemStack> input : inputs) {
tag.put(String.valueOf(input.getIndex()), EntryIngredients.ofItemStacks(input.get()).saveIngredient());
CompoundTag innerTag = new CompoundTag();
innerTag.put("Ingredient", EntryIngredients.ofItemStacks(input.get()).saveIngredient());
innerTag.putInt("Index", input.getIndex());
tag.add(innerTag);
}

return tag;
Expand Down

0 comments on commit 56aea58

Please sign in to comment.