From db345577a206fbe41e6d9e8e4e3096734da81a26 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 26 Oct 2021 11:09:42 +0200 Subject: [PATCH] Fix 1.13.1->1.13 inventory title regression Fixes #375 --- .../viabackwards/ViaBackwardsConfig.java | 7 +++++++ .../viabackwards/api/ViaBackwardsConfig.java | 2 ++ .../data/BackwardsMappings.java | 2 +- .../Protocol1_13To1_13_1.java | 18 +++++++++++++----- .../resources/assets/viabackwards/config.yml | 4 ++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java b/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java index ae08adfe..e32f89ff 100644 --- a/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java +++ b/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java @@ -31,6 +31,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback private boolean addTeamColorToPrefix; private boolean fix1_13FacePlayer; private boolean alwaysShowOriginalMobName; + private boolean fix1_13FormattedInventoryTitles; private boolean handlePingsAsInvAcknowledgements; public ViaBackwardsConfig(File configFile) { @@ -47,6 +48,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback addCustomEnchantsToLore = getBoolean("add-custom-enchants-into-lore", true); addTeamColorToPrefix = getBoolean("add-teamcolor-to-prefix", true); fix1_13FacePlayer = getBoolean("fix-1_13-face-player", false); + fix1_13FormattedInventoryTitles = getBoolean("fix-formatted-inventory-titles", true); alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true); handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false); } @@ -66,6 +68,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback return fix1_13FacePlayer; } + @Override + public boolean fix1_13FormattedInventoryTitle() { + return fix1_13FormattedInventoryTitles; + } + @Override public boolean alwaysShowOriginalMobName() { return alwaysShowOriginalMobName; diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java index 1d8740aa..fdbb0275 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java @@ -40,6 +40,8 @@ public interface ViaBackwardsConfig { */ boolean isFix1_13FacePlayer(); + boolean fix1_13FormattedInventoryTitle(); + /** * Always shows the original mob's name instead of only when hovering over them with the cursor. * diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java index f6ec6097..fb1c2af3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java @@ -60,7 +60,7 @@ public class BackwardsMappings extends com.viaversion.viabackwards.api.data.Back // Has lots of compat layers, so we can't use the default Via method private static void mapIdentifiers(int[] output, JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) { - Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(oldIdentifiers); + Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(oldIdentifiers); for (Map.Entry entry : newIdentifiers.entrySet()) { String key = entry.getValue().getAsString(); int value = newIdentifierMap.getInt(key); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index 6f7e96fc..1a25e950 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -17,6 +17,7 @@ */ package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1; +import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; @@ -109,14 +110,21 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { - JsonElement title = wrapper.read(Type.COMPONENT); + JsonElement title = wrapper.passthrough(Type.COMPONENT); translatableRewriter.processText(title); - // https://bugs.mojang.com/browse/MC-124543 - JsonObject legacyComponent = new JsonObject(); - legacyComponent.addProperty("text", ChatRewriter.jsonToLegacyText(title.toString())); + if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) { + if (title.isJsonObject() && title.getAsJsonObject().size() == 1 + && title.getAsJsonObject().has("translate")) { + // Hotfix simple translatable components from being converted to legacy text + return; + } - wrapper.write(Type.COMPONENT, legacyComponent); + // https://bugs.mojang.com/browse/MC-124543 + JsonObject legacyComponent = new JsonObject(); + legacyComponent.addProperty("text", ChatRewriter.jsonToLegacyText(title.toString())); + wrapper.set(Type.COMPONENT, 0, legacyComponent); + } }); } }); diff --git a/common/src/main/resources/assets/viabackwards/config.yml b/common/src/main/resources/assets/viabackwards/config.yml index 9abbdbb5..b9ce0f60 100644 --- a/common/src/main/resources/assets/viabackwards/config.yml +++ b/common/src/main/resources/assets/viabackwards/config.yml @@ -13,6 +13,10 @@ add-teamcolor-to-prefix: true # Converts the 1.13 face look-at packet for 1.12- players. Requires a bit of extra caching. fix-1_13-face-player: false # +# Fixes 1.13 clients and lower not seeing color or formatting in inventory titles by converting them to legacy text. +# If you have issues with translatable text being displayed wrongly, disable this. +fix-formatted-inventory-titles: true +# # Sends inventory acknowledgement packets to act as a replacement for ping packets for sub 1.17 clients. # This only takes effect for ids in the short range. Useful for anticheat compatibility. handle-pings-as-inv-acknowledgements: false \ No newline at end of file