From b214235c04a8eb50a5111b48fcf895e21f6d63a1 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Fri, 20 Dec 2024 09:21:14 +0100 Subject: [PATCH] Map first float of 1.21.4 custom model data as int for 1.21.3 clients (#942) --- .../com/viaversion/viabackwards/ViaBackwardsConfig.java | 7 +++++++ .../viaversion/viabackwards/api/ViaBackwardsConfig.java | 7 +++++++ .../rewriter/BlockItemPacketRewriter1_21_4.java | 6 ++++++ common/src/main/resources/assets/viabackwards/config.yml | 3 +++ 4 files changed, 23 insertions(+) diff --git a/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java b/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java index 81d626cc..e2db3998 100644 --- a/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java +++ b/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java @@ -37,6 +37,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback private boolean bedrockAtY0; private boolean sculkShriekersToCryingObsidian; private boolean mapDarknessEffect; + private boolean mapCustomModelData; private boolean suppressEmulationWarnings; public ViaBackwardsConfig(File configFile, Logger logger) { @@ -59,6 +60,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback bedrockAtY0 = getBoolean("bedrock-at-y-0", false); sculkShriekersToCryingObsidian = getBoolean("sculk-shriekers-to-crying-obsidian", false); mapDarknessEffect = getBoolean("map-darkness-effect", true); + mapCustomModelData = getBoolean("map-custom-model-data", true); suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false); } @@ -107,6 +109,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback return mapDarknessEffect; } + @Override + public boolean mapCustomModelData() { + return mapCustomModelData; + } + @Override public boolean suppressEmulationWarnings() { return suppressEmulationWarnings; 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 f9cd38a8..deee84ac 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java @@ -85,6 +85,13 @@ public interface ViaBackwardsConfig extends Config { */ boolean mapDarknessEffect(); + /** + * If enabled, 1.21.3 clients will receive the first float of 1.21.4+ custom model data as int. Disable if you handle this change yourself. + * + * @return true if enabled + */ + boolean mapCustomModelData(); + /** * Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+). * diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java index 7c89988f..20204112 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java @@ -22,6 +22,7 @@ import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.IntArrayTag; import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.StringTag; +import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.Protocol1_21_4To1_21_2; import com.viaversion.viaversion.api.connection.UserConnection; @@ -95,6 +96,11 @@ public final class BlockItemPacketRewriter1_21_4 extends BackwardsStructuredItem final CustomModelData1_21_4 modelData = dataContainer.get(StructuredDataKey.CUSTOM_MODEL_DATA1_21_4); if (modelData != null) { saveTag(createCustomTag(item), customModelDataToTag(modelData), "custom_model_data"); + if (ViaBackwards.getConfig().mapCustomModelData() && modelData.floats().length > 0) { + // Put first float as old custom model data as this is the most common replacement + final int data = (int) modelData.floats()[0]; + dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5, data); + } } downgradeItemData(item); diff --git a/common/src/main/resources/assets/viabackwards/config.yml b/common/src/main/resources/assets/viabackwards/config.yml index 92c15d1f..d60e6ca2 100644 --- a/common/src/main/resources/assets/viabackwards/config.yml +++ b/common/src/main/resources/assets/viabackwards/config.yml @@ -31,5 +31,8 @@ sculk-shriekers-to-crying-obsidian: true # Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers. map-darkness-effect: true # +# If enabled, 1.21.3 clients will receive the first float of 1.21.4+ custom model data as int. Disable if you handle this change yourself. +map-custom-model-data: true +# # Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+). suppress-emulation-warnings: false