From 8fb814ef114ac36f026c34e8a6f4633b272a1c63 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 29 May 2024 18:29:21 +0200 Subject: [PATCH] Handle chat and horse container changes --- .../v1_21to1_20_5/Protocol1_21To1_20_5.java | 48 ++++++++++++++++++- .../rewriter/BlockItemPacketRewriter1_21.java | 8 ++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java index ab4bf6c3..c9bf8e1f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java @@ -25,7 +25,9 @@ import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.BlockItemPack import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.EntityPacketRewriter1_21; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.minecraft.item.data.ChatType; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.type.Types; @@ -81,7 +83,6 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol { + translatableRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.TAG)); // Message + + final Holder chatType = wrapper.read(ChatType.TYPE); + if (chatType.isDirect()) { + // Oh well + wrapper.write(Types.VAR_INT, 0); + return; + } + + wrapper.write(Types.VAR_INT, chatType.id()); + }); + registerClientbound(ClientboundPackets1_21.PLAYER_CHAT, wrapper -> { + wrapper.passthrough(Types.UUID); // Sender + wrapper.passthrough(Types.VAR_INT); // Index + wrapper.passthrough(Types.OPTIONAL_SIGNATURE_BYTES); // Signature + wrapper.passthrough(Types.STRING); // Plain content + wrapper.passthrough(Types.LONG); // Timestamp + wrapper.passthrough(Types.LONG); // Salt + + final int lastSeen = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < lastSeen; i++) { + final int index = wrapper.passthrough(Types.VAR_INT); + if (index == 0) { + wrapper.passthrough(Types.SIGNATURE_BYTES); + } + } + + wrapper.passthrough(Types.OPTIONAL_TAG); // Unsigned content + + final int filterMaskType = wrapper.passthrough(Types.VAR_INT); + if (filterMaskType == 2) { + wrapper.passthrough(Types.LONG_ARRAY_PRIMITIVE); // Mask + } + + final Holder chatType = wrapper.read(ChatType.TYPE); + if (chatType.isDirect()) { + // Oh well + wrapper.write(Types.VAR_INT, 0); + return; + } + + wrapper.write(Types.VAR_INT, chatType.id()); + }); + registerClientbound(ClientboundPackets1_21.UPDATE_ATTRIBUTES, wrapper -> { wrapper.passthrough(Types.VAR_INT); // Entity ID diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index c674a924..797d34f3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -81,6 +81,14 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_21.PARTICLE, Types1_20_5.PARTICLE); registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_21.PARTICLE, Types1_20_5.PARTICLE); + protocol.registerClientbound(ClientboundPackets1_21.HORSE_SCREEN_OPEN, wrapper -> { + wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id + + // From columns to size + final int columns = wrapper.read(Types.VAR_INT); + wrapper.write(Types.VAR_INT, columns * 3 + 1); + }); + protocol.registerClientbound(ClientboundPackets1_21.LEVEL_EVENT, wrapper -> { final int event = wrapper.passthrough(Types.INT); wrapper.passthrough(Types.BLOCK_POSITION1_14);