From 4627142700359d70f93f0f6d0d59490ab728f31c Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 14 Jun 2023 19:04:28 +0200 Subject: [PATCH] Emulate "trim_pattern" registry in 1.19.4 -> 1.20 if not present (#557) --- .../Protocol1_19_4To1_20.java | 5 +- .../data/BackwardsMappings.java | 49 ++++++++++++++++++ .../packets/EntityPackets1_20.java | 12 ++++- .../viabackwards/data/trim_pattern-1.19.4.nbt | Bin 0 -> 3112 bytes 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java create mode 100644 common/src/main/resources/assets/viabackwards/data/trim_pattern-1.19.4.nbt diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java index 195d20ac..d9f19a68 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java @@ -18,9 +18,9 @@ package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20; import com.viaversion.viabackwards.api.BackwardsProtocol; -import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.data.BackwardsMappings; import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets.BlockItemPackets1_20; import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets.EntityPackets1_20; import com.viaversion.viaversion.api.connection.UserConnection; @@ -29,14 +29,13 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; -import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import java.util.Arrays; public final class Protocol1_19_4To1_20 extends BackwardsProtocol { - public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.20", "1.19.4", Protocol1_20To1_19_4.class); + public static final BackwardsMappings MAPPINGS = new BackwardsMappings(); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this); private final EntityPackets1_20 entityRewriter = new EntityPackets1_20(this); private final BlockItemPackets1_20 itemRewriter = new BlockItemPackets1_20(this); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java new file mode 100644 index 00000000..a9ae27bc --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java @@ -0,0 +1,49 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2023 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.data; + +import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viaversion.api.minecraft.nbt.BinaryTagIO; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; + +import java.io.IOException; + +public class BackwardsMappings extends com.viaversion.viabackwards.api.data.BackwardsMappings { + + private CompoundTag trimPatternRegistry; + + public BackwardsMappings() { + super("1.20", "1.19.4", Protocol1_20To1_19_4.class); + } + + @Override + protected void loadExtras(CompoundTag data) { + super.loadExtras(data); + + try { + trimPatternRegistry = BinaryTagIO.readInputStream(VBMappingDataLoader.getResource("trim_pattern-1.19.4.nbt")); + } catch (final IOException e) { + e.printStackTrace(); + } + } + + public CompoundTag getTrimPatternRegistry() { + return trimPatternRegistry; + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java index bf62b4ae..f88dc392 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java @@ -165,7 +165,17 @@ public final class EntityPackets1_20 extends EntityRewriter { final CompoundTag registry = wrapper.get(Type.NBT, 0); - final ListTag values = ((CompoundTag) registry.get("minecraft:trim_pattern")).get("value"); + + ListTag values; + // A 1.20 server can't send this element, and the 1.20 client still works, if the element is missing + // on a 1.19.4 client there is an exception, so in case the 1.20 server doesn't send the element we put in an original 1.20 element + if (registry.contains("minecraft:trim_pattern")) { + values = ((CompoundTag) registry.get("minecraft:trim_pattern")).get("value"); + } else { + final CompoundTag trimPatternRegistry = Protocol1_19_4To1_20.MAPPINGS.getTrimPatternRegistry().clone(); + registry.put("minecraft:trim_pattern", trimPatternRegistry); + values = trimPatternRegistry.get("value"); + } for (final Tag entry : values) { final CompoundTag element = ((CompoundTag) entry).get("element"); final StringTag templateItem = element.get("template_item"); diff --git a/common/src/main/resources/assets/viabackwards/data/trim_pattern-1.19.4.nbt b/common/src/main/resources/assets/viabackwards/data/trim_pattern-1.19.4.nbt new file mode 100644 index 0000000000000000000000000000000000000000..39ddae51d9598c28735536622f4482aa4968a53e GIT binary patch literal 3112 zcmb`}U2oeU6b4|{Psd%_PLp=AFZFtDqh0sUSS+Rsl8r4OZS(I7xaM$3Ko#m;B>S8^ zFOWlOLMn2icOxU;dM?;n(ntNECGVS&YR#lrkkcpHZCOnSxi;?#+B0$m@2&@`^f5W& zt$Bge8!527Lq zEvZnp8TlFNR=(-VK}?#8D#dhTJh9Scb^c3V_RwwxoB5wI{99a7s{fJDTL!{MM6fRb z!gij1l%fAY6{Yg;3AsTaIQD@%2(%gC$Q)-c#9`taA4ISb9oWC=JEBf#Zu4^*G^wd0_X8spA&Wd+Tto`h%G9gxb zRi!C@Cw>KQ7!+gQ3VRXU3Q7!He|If1DT2Gp)s$vP-CeFJN)Rg#`$sPQF4XVz+nNve z+onmsd+5(mFl04vJ^v!Z5AFe5QmRkg1GXo^M?_frU`9Q$mw6C<&d`GyYAQ^T65bI(IX<*zrqB0rn^TjS{R>~nE-ze)Rm^VNz5J( jLQxKhAx{{TcYZIfGEu_4FeRlal6zr#q5u)m{I7on6M7j? literal 0 HcmV?d00001