From 483a336b8aa544028d463414204d7d1be9d86192 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 19 Oct 2021 13:16:46 -0400 Subject: [PATCH] Fix grindstones and looms on 1.17.40 --- connector/pom.xml | 2 +- .../inventory/InventoryTranslator.java | 6 ++++-- .../translators/LoomInventoryTranslator.java | 19 ++++++++++++++++--- .../item/translators/BannerTranslator.java | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 810e99bef..c65e73b51 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -115,7 +115,7 @@ com.github.CloudburstMC.Protocol bedrock-v471 - b71f1c9 + 0bc10c8e compile diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java index b6a00982a..00d2804d3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java @@ -64,7 +64,7 @@ import java.util.*; public abstract class InventoryTranslator { public static final InventoryTranslator PLAYER_INVENTORY_TRANSLATOR = new PlayerInventoryTranslator(); - public static final Map INVENTORY_TRANSLATORS = new HashMap() { + public static final Map INVENTORY_TRANSLATORS = new HashMap<>() { { /* Player Inventory */ put(null, PLAYER_INVENTORY_TRANSLATOR); @@ -395,7 +395,9 @@ public abstract class InventoryTranslator { case CRAFT_RECIPE_AUTO: // Called by villagers case CRAFT_NON_IMPLEMENTED_DEPRECATED: // Tends to be called for UI inventories case CRAFT_RESULTS_DEPRECATED: // Tends to be called for UI inventories - case CRAFT_RECIPE_OPTIONAL: { // Anvils and cartography tables will handle this + case CRAFT_RECIPE_OPTIONAL: // Anvils and cartography tables will handle this + case CRAFT_LOOM: // Looms 1.17.40+ + case CRAFT_REPAIR_AND_DISENCHANT: { // Grindstones 1.17.40+ break; } default: diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java index c6909ec9f..2d67f8de0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java @@ -34,6 +34,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType; import com.nukkitx.protocol.bedrock.data.inventory.ContainerType; import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequest; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftLoomStackRequestActionData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftResultsDeprecatedStackRequestActionData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionType; @@ -118,12 +119,14 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator { @Override public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) { // If the LOOM_MATERIAL slot is not empty, we are crafting a pattern that does not come from an item - return action.getType() == StackRequestActionType.CRAFT_NON_IMPLEMENTED_DEPRECATED && inventory.getItem(2).isEmpty(); + // Remove the CRAFT_NON_IMPLEMENTED_DEPRECATED when 1.17.30 is dropped + return (action.getType() == StackRequestActionType.CRAFT_NON_IMPLEMENTED_DEPRECATED || action.getType() == StackRequestActionType.CRAFT_LOOM) + && inventory.getItem(2).isEmpty(); } @Override public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) { - // TODO: I anticipate this will be changed in the future to use something non-deprecated. Keep an eye out. + StackRequestActionData headerData = request.getActions()[0]; StackRequestActionData data = request.getActions()[1]; if (!(data instanceof CraftResultsDeprecatedStackRequestActionData craftData)) { return rejectRequest(request); @@ -133,8 +136,18 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator { List newBlockEntityTag = craftData.getResultItems()[0].getTag().getList("Patterns", NbtType.COMPOUND); // Get the pattern that the Bedrock client requests - the last pattern in the Patterns list NbtMap pattern = newBlockEntityTag.get(newBlockEntityTag.size() - 1); + String bedrockPattern; + + if (headerData instanceof CraftLoomStackRequestActionData loomData) { + // Prioritize this if on 1.17.40 + // Remove the below if statement when 1.17.30 is dropped + bedrockPattern = loomData.getPatternId(); + } else { + bedrockPattern = pattern.getString("Pattern"); + } + // Get the Java index of this pattern - int index = PATTERN_TO_INDEX.getOrDefault(pattern.getString("Pattern"), -1); + int index = PATTERN_TO_INDEX.getOrDefault(bedrockPattern, -1); if (index == -1) { return rejectRequest(request); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java index 116e703bc..e85426647 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java @@ -145,7 +145,7 @@ public class BannerTranslator extends ItemTranslator { /** * Convert the Bedrock edition banner pattern nbt to Java edition * - * @param pattern Bedorck edition pattern nbt + * @param pattern Bedrock edition pattern nbt * @return The Java edition format pattern nbt */ public static CompoundTag getJavaBannerPattern(NbtMap pattern) {