From 7ca7269f61154d87ac6c152ee9c863c1f039b174 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 30 Sep 2023 01:28:28 +0800 Subject: [PATCH] Fix #1492 --- .../me/shedaniel/rei/RoughlyEnoughItemsNetwork.java | 11 +++++++---- .../client/transfer/SimpleTransferHandlerImpl.java | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 5e8e49475..f76efdd65 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -172,7 +172,9 @@ public static void onInitialize() { boolean shift = packetByteBuf.readBoolean(); try { CompoundTag nbt = packetByteBuf.readAnySizeNbt(); - List> 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> inputs = readInputs(nbt.getList("Inputs", Tag.TAG_COMPOUND)); List input = readSlots(container, player, nbt.getList("InputSlots", Tag.TAG_COMPOUND)); List inventory = readSlots(container, player, nbt.getList("InventorySlots", Tag.TAG_COMPOUND)); NewInputSlotCrafter crafter = new NewInputSlotCrafter<>(container, input, inventory, inputs); @@ -201,10 +203,11 @@ private static List readSlots(AbstractContainerMenu menu, Player p return slots; } - private static List> readInputs(CompoundTag tag) { + private static List> readInputs(ListTag tag) { List> inputs = new ArrayList<>(); - for (Map.Entry entry : tag.tags.entrySet()) { - InputIngredient> stacks = InputIngredient.of(Integer.parseInt(entry.getKey()), EntryIngredient.read((ListTag) entry.getValue())); + for (Tag t : tag) { + CompoundTag compoundTag = (CompoundTag) t; + InputIngredient> stacks = InputIngredient.of(compoundTag.getInt("Index"), EntryIngredient.read(compoundTag.getList("Ingredient", Tag.TAG_COMPOUND))); inputs.add(InputIngredient.withType(stacks, VanillaEntryTypes.ITEM)); } return inputs; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/transfer/SimpleTransferHandlerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/transfer/SimpleTransferHandlerImpl.java index ef7d59c79..893562fbe 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/transfer/SimpleTransferHandlerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/transfer/SimpleTransferHandlerImpl.java @@ -94,6 +94,7 @@ public TransferHandler.Result handle(TransferHandler.Context context, SimpleTran private CompoundTag save(TransferHandler.Context context, List> inputs, Iterable inputSlots, Iterable 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)); @@ -111,10 +112,13 @@ private Tag saveSlots(TransferHandler.Context context, Iterable sl } private Tag saveInputs(List> inputs) { - CompoundTag tag = new CompoundTag(); + ListTag tag = new ListTag(); for (InputIngredient 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;