From 6dc823223c3131ebdca0d80ad633f9c8d4ad2666 Mon Sep 17 00:00:00 2001 From: Alemiz Date: Thu, 16 May 2024 18:43:34 +0200 Subject: [PATCH] Move this logic to other method --- .../CraftingDataSerializer_v685.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v685/serializer/CraftingDataSerializer_v685.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v685/serializer/CraftingDataSerializer_v685.java index 4be68816a..bff737a9f 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v685/serializer/CraftingDataSerializer_v685.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v685/serializer/CraftingDataSerializer_v685.java @@ -30,7 +30,12 @@ protected ShapelessRecipeData readShapelessRecipe(ByteBuf buffer, BedrockCodecHe UUID uuid = helper.readUuid(buffer); String craftingTag = helper.readString(buffer); int priority = VarInts.readInt(buffer); - RecipeUnlockingRequirement requirement = this.readRequirement(buffer, helper, type); + + RecipeUnlockingRequirement requirement = RecipeUnlockingRequirement.INVALID; + if (type == CraftingDataType.SHAPELESS) { + requirement = this.readRequirement(buffer, helper, type); + } + int networkId = VarInts.readUnsignedInt(buffer); return ShapelessRecipeData.of(type, recipeId, inputs, outputs, uuid, craftingTag, priority, networkId, requirement); } @@ -44,7 +49,10 @@ protected void writeShapelessRecipe(ByteBuf buffer, BedrockCodecHelper helper, S helper.writeUuid(buffer, data.getUuid()); helper.writeString(buffer, data.getTag()); VarInts.writeInt(buffer, data.getPriority()); - this.writeRequirement(buffer, helper, data); + + if (data.getType() == CraftingDataType.SHAPELESS) { + this.writeRequirement(buffer, helper, data); + } VarInts.writeUnsignedInt(buffer, data.getNetId()); } @@ -64,7 +72,12 @@ protected ShapedRecipeData readShapedRecipe(ByteBuf buffer, BedrockCodecHelper h String craftingTag = helper.readString(buffer); int priority = VarInts.readInt(buffer); boolean assumeSymmetry = buffer.readBoolean(); - RecipeUnlockingRequirement requirement = this.readRequirement(buffer, helper, type); + + RecipeUnlockingRequirement requirement = RecipeUnlockingRequirement.INVALID; + if (type == CraftingDataType.SHAPED) { + requirement = this.readRequirement(buffer, helper, type); + } + int networkId = VarInts.readUnsignedInt(buffer); return ShapedRecipeData.of(type, recipeId, width, height, inputs, outputs, uuid, craftingTag, priority, networkId, assumeSymmetry, requirement); } @@ -84,7 +97,11 @@ protected void writeShapedRecipe(ByteBuf buffer, BedrockCodecHelper helper, Shap helper.writeString(buffer, data.getTag()); VarInts.writeInt(buffer, data.getPriority()); buffer.writeBoolean(data.isAssumeSymetry()); - this.writeRequirement(buffer, helper, data); + + if (data.getType() == CraftingDataType.SHAPED) { + this.writeRequirement(buffer, helper, data); + } + VarInts.writeUnsignedInt(buffer, data.getNetId()); }