From d9698edcc278a2fa96390c1aecc0765d7f4dc2c0 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Sat, 13 May 2023 22:42:18 -0400 Subject: [PATCH] Fix smithing tables, but trim recipes are broken. --- .../inventory/InventoryTranslator.java | 2 +- .../SmithingInventoryTranslator.java | 23 +++++----- .../java/JavaUpdateRecipesTranslator.java | 45 ++++++++++++++++++- gradle/libs.versions.toml | 4 +- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java index 7a5a981c6..c61ff13de 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java @@ -92,7 +92,7 @@ public abstract class InventoryTranslator { put(ContainerType.LOOM, new LoomInventoryTranslator()); put(ContainerType.MERCHANT, new MerchantInventoryTranslator()); put(ContainerType.SHULKER_BOX, new ShulkerInventoryTranslator()); - put(ContainerType.SMITHING, new SmithingInventoryTranslator()); // todo: 1.20 smithing + put(ContainerType.SMITHING, new SmithingInventoryTranslator()); put(ContainerType.STONECUTTER, new StonecutterInventoryTranslator()); /* Lectern */ diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/SmithingInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/SmithingInventoryTranslator.java index 243bb48c3..730e4a451 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/SmithingInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/SmithingInventoryTranslator.java @@ -33,15 +33,16 @@ import org.geysermc.geyser.inventory.updater.UIInventoryUpdater; public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslator { public SmithingInventoryTranslator() { - super(3, "minecraft:smithing_table", ContainerType.SMITHING_TABLE, UIInventoryUpdater.INSTANCE); + super(4, "minecraft:smithing_table", ContainerType.SMITHING_TABLE, UIInventoryUpdater.INSTANCE); } @Override public int bedrockSlotToJava(ItemStackRequestSlotData slotInfoData) { return switch (slotInfoData.getContainer()) { - case SMITHING_TABLE_INPUT -> 0; - case SMITHING_TABLE_MATERIAL -> 1; - case SMITHING_TABLE_RESULT, CREATED_OUTPUT -> 2; + case SMITHING_TABLE_TEMPLATE -> 0; + case SMITHING_TABLE_INPUT -> 1; + case SMITHING_TABLE_MATERIAL -> 2; + case SMITHING_TABLE_RESULT, CREATED_OUTPUT -> 3; default -> super.bedrockSlotToJava(slotInfoData); }; } @@ -49,9 +50,10 @@ public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslato @Override public BedrockContainerSlot javaSlotToBedrockContainer(int slot) { return switch (slot) { - case 0 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_INPUT, 51); - case 1 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_MATERIAL, 52); - case 2 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_RESULT, 50); + case 0 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_TEMPLATE, 53); + case 1 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_INPUT, 51); + case 2 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_MATERIAL, 52); + case 3 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_RESULT, 50); default -> super.javaSlotToBedrockContainer(slot); }; } @@ -59,9 +61,10 @@ public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslato @Override public int javaSlotToBedrock(int slot) { return switch (slot) { - case 0 -> 51; - case 1 -> 52; - case 2 -> 50; + case 0 -> 53; + case 1 -> 51; + case 2 -> 52; + case 3 -> 50; default -> super.javaSlotToBedrock(slot); }; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java index a66fe74e7..7fa6ee860 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java @@ -31,6 +31,8 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Recipe; import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType; import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapedRecipeData; import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.SmithingTransformRecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.SmithingTrimRecipeData; import com.github.steveice10.mc.protocol.data.game.recipe.data.StoneCuttingRecipeData; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundUpdateRecipesPacket; import it.unimi.dsi.fastutil.ints.*; @@ -142,7 +144,48 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator { + SmithingTransformRecipeData data = (SmithingTransformRecipeData) recipe.getData(); + ItemData output = ItemTranslator.translateToBedrock(session, data.getResult()); + + for (ItemStack template : data.getTemplate().getOptions()) { + ItemDescriptorWithCount bedrockTemplate = ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, template)); + + for (ItemStack base : data.getBase().getOptions()) { + ItemDescriptorWithCount bedrockBase = ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, base)); + + for (ItemStack addition : data.getAddition().getOptions()) { + ItemDescriptorWithCount bedrockAddition = ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, addition)); + + // Note: vanilla inputs use aux value of Short.MAX_VALUE + craftingDataPacket.getCraftingData().add(org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.SmithingTransformRecipeData.of(recipe.getIdentifier(), + bedrockTemplate, bedrockBase, bedrockAddition, output, "smithing_table", netId++)); + } + } + } + + } + /* + // todo 1.20: BDS sends the trim recipes very concisely using item tag descriptors. this code doesn't result in trim recipes working. + case SMITHING_TRIM -> { + SmithingTrimRecipeData data = (SmithingTrimRecipeData) recipe.getData(); + + for (ItemStack template : data.getTemplate().getOptions()) { + ItemDescriptorWithCount bedrockTemplate = ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, template)); + + for (ItemStack base : data.getBase().getOptions()) { + ItemDescriptorWithCount bedrockBase = ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, base)); + + for (ItemStack addition : data.getAddition().getOptions()) { + ItemDescriptorWithCount bedrockAddition = ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, addition)); + + craftingDataPacket.getCraftingData().add(org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.SmithingTrimRecipeData.of(recipe.getIdentifier(), + bedrockBase, bedrockAddition, bedrockTemplate, "smithing_table", netId++)); + } + } + } + } + */ default -> { List craftingData = recipeTypes.get(recipe.getType()); if (craftingData != null) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fd0528fed..83c1c36e3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,8 +9,8 @@ netty = "4.1.80.Final" guava = "29.0-jre" gson = "2.3.1" # Provided by Spigot 1.8.8 websocket = "1.5.1" -protocol = "3.0.0.Beta1-20230507.200054-78" -protocol-connection = "3.0.0.Beta1-20230507.200054-77" +protocol = "3.0.0.Beta1-20230513.235756-80" +protocol-connection = "3.0.0.Beta1-20230513.235756-79" raknet = "1.0.0.CR1-20230430.211932-7" mcauthlib = "d9d773e" mcprotocollib = "1.20-1-SNAPSHOT"