From 206d93ed1b225755b9e6ae0b2cb12cde7f05dc1c Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 2 Jan 2022 06:58:11 +0100 Subject: [PATCH] Revert "fix declare shaped packet reader (#572)" This reverts commit d94d07bead3c99658ec86da3cebc051f9ec1b729. --- .../server/play/DeclareRecipesPacket.java | 23 +++---------------- .../java/network/PacketWriteReadTest.java | 22 ++++-------------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java index d5ec38f84..68d10d910 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java @@ -7,7 +7,6 @@ import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.Writeable; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; @@ -84,26 +83,10 @@ public record DeclareRecipesPacket(@NotNull List recipes) implem ingredients = List.copyOf(ingredients); } - private DeclaredShapedCraftingRecipe(DeclaredShapedCraftingRecipe packet) { - this(packet.recipeId, packet.width, packet.height, packet.group, packet.ingredients, packet.result); - } - public DeclaredShapedCraftingRecipe(BinaryReader reader) { - this(read(reader)); - } - - private static DeclaredShapedCraftingRecipe read(BinaryReader reader) { - - String recipeId = reader.readSizedString(); - int width = reader.readVarInt(); - int height = reader.readVarInt(); - String group = reader.readSizedString(); - List ingredients = new ArrayList<>(); - for (int slot = 0; slot < width * height; slot++) { - ingredients.add(new Ingredient(reader)); - } - ItemStack result = reader.readItemStack(); - return new DeclaredShapedCraftingRecipe(recipeId, width, height, group, ingredients, result); + this(reader.readSizedString(), reader.readVarInt(), reader.readVarInt(), + reader.readSizedString(), reader.readVarIntList(Ingredient::new), + reader.readItemStack()); } @Override diff --git a/src/test/java/network/PacketWriteReadTest.java b/src/test/java/network/PacketWriteReadTest.java index 618476e72..d25924ee6 100644 --- a/src/test/java/network/PacketWriteReadTest.java +++ b/src/test/java/network/PacketWriteReadTest.java @@ -84,21 +84,10 @@ public class PacketWriteReadTest { SERVER_PACKETS.add(new DeathCombatEventPacket(5, 5, COMPONENT)); SERVER_PACKETS.add(new DeclareRecipesPacket( List.of(new DeclareRecipesPacket.DeclaredShapelessCraftingRecipe( - "minecraft:sticks", - "sticks", - List.of(new Ingredient(List.of(ItemStack.of(Material.OAK_PLANKS)))), - ItemStack.of(Material.STICK) - ), - new DeclareRecipesPacket.DeclaredShapedCraftingRecipe( - "minecraft:torch", - 1, - 1, - "", - List.of(new Ingredient(List.of(ItemStack.of(Material.COAL))), - new Ingredient(List.of(ItemStack.of(Material.STICK)))), - ItemStack.of(Material.TORCH) - )))); - + "minecraft:sticks", + "sticks", + List.of(new Ingredient(List.of(ItemStack.of(Material.OAK_PLANKS)))), + ItemStack.of(Material.STICK))))); SERVER_PACKETS.add(new DestroyEntitiesPacket(List.of(5, 5, 5))); SERVER_PACKETS.add(new DisconnectPacket(COMPONENT)); SERVER_PACKETS.add(new DisplayScoreboardPacket((byte) 5, "scoreboard")); @@ -153,8 +142,7 @@ public class PacketWriteReadTest { BinaryReader reader = new BinaryReader(writer.toByteArray()); var createdPacket = readerConstructor.newInstance(reader); assertEquals(writeable, createdPacket); - } catch (NoSuchMethodException | InvocationTargetException | InstantiationException - | IllegalAccessException e) { + } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { fail(writeable.toString(), e); } }