From 9d3ee288df1c24b48e3491a2e15c809a89d317e1 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 22 Oct 2022 11:25:45 +0200 Subject: [PATCH] Handle chat types --- .../Protocol1_19_1To1_19_3.java | 28 ++- .../packets/EntityPackets1_19_3.java | 201 +++++++++++++----- .../storage/ChatTypeStorage1_19_3.java | 23 ++ .../Protocol1_19To1_19_1.java | 11 +- .../storage/ChatRegistryStorage.java | 2 +- .../storage/ChatRegistryStorage1_19_1.java | 21 ++ .../data/mapping-1.19to1.19.3.json | 1 + 7 files changed, 215 insertions(+), 72 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/storage/ChatTypeStorage1_19_3.java create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/storage/ChatRegistryStorage1_19_1.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java index 6db130c1..2180e785 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java @@ -25,7 +25,9 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.packets.BlockItemPackets1_19_3; import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.packets.EntityPackets1_19_3; import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.ChatSessionStorage; +import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.ChatTypeStorage1_19_3; import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.NonceStorage; +import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ProfileKey; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19Types; @@ -59,7 +61,6 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol { MAPPINGS.load(); entityRewriter.onMappingDataLoaded(); }); + translatableRewriter.registerComponentPacket(ClientboundPackets1_19_3.SYSTEM_CHAT); translatableRewriter.registerComponentPacket(ClientboundPackets1_19_3.ACTIONBAR); translatableRewriter.registerComponentPacket(ClientboundPackets1_19_3.TITLE_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_19_3.TITLE_SUBTITLE); @@ -209,7 +210,7 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol { - //TODO is this fine (probably not)? + //TODO is this fine (probably not)? same for chat_command final int offset = 0; final BitSet acknowledged = new BitSet(20); wrapper.write(Type.VAR_INT, offset); @@ -232,7 +233,6 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol { private static final BitSetType PROFILE_ACTIONS_ENUM_TYPE = new BitSetType(6); - private static final int[] PROFILE_ACTIONS = {0, 2, 4, 5}; // Ignore initialize chat and listed status + private static final int[] PROFILE_ACTIONS = {2, 4, 5}; // Ignore initialize chat and listed status; add player already handled before + private static final int ADD_PLAYER = 0; + private static final int INITIALIZE_CHAT = 1; + private static final int UPDATE_GAMEMODE = 2; + private static final int UPDATE_LISTED = 3; + private static final int UPDATE_LATENCY = 4; + private static final int UPDATE_DISPLAYNAME = 5; public EntityPackets1_19_3(final Protocol1_19_1To1_19_3 protocol) { super(protocol); @@ -64,6 +77,17 @@ public final class EntityPackets1_19_3 extends EntityRewriter { + final ChatTypeStorage1_19_3 chatTypeStorage = wrapper.user().get(ChatTypeStorage1_19_3.class); + chatTypeStorage.clear(); + final CompoundTag registry = wrapper.get(Type.NBT, 0); + final ListTag chatTypes = ((CompoundTag) registry.get("minecraft:chat_type")).get("value"); + for (final Tag chatType : chatTypes) { + final CompoundTag chatTypeCompound = (CompoundTag) chatType; + final NumberTag idTag = chatTypeCompound.get("id"); + chatTypeStorage.addChatType(idTag.asInt(), chatTypeCompound); + } + }); } }); @@ -83,65 +107,80 @@ public final class EntityPackets1_19_3 extends EntityRewriter { final int id = meta.metaType().typeId(); - meta.setMetaType(Types1_19.META_TYPES.byId(id > 2 ? id - 1 : id)); // long added + if (id > 2) { + meta.setMetaType(Types1_19.META_TYPES.byId(id - 1)); // long added + } else if (id != 2) { + meta.setMetaType(Types1_19.META_TYPES.byId(id)); + } }); registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, Types1_19.META_TYPES.particleType, Types1_19.META_TYPES.optionalComponentType); @@ -189,4 +250,34 @@ public final class EntityPackets1_19_3 extends EntityRewriter. + */ +package com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage; + +import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ChatRegistryStorage; + +public final class ChatTypeStorage1_19_3 extends ChatRegistryStorage { +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java index 9569f137..48f8ff70 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java @@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.packets.EntityPackets1_19_1; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ChatRegistryStorage; +import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ChatRegistryStorage1_19_1; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.NonceStorage; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ReceivedMessagesStorage; import com.viaversion.viaversion.api.connection.UserConnection; @@ -101,7 +102,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol { - final ChatRegistryStorage chatTypeStorage = wrapper.user().get(ChatRegistryStorage.class); + final ChatRegistryStorage chatTypeStorage = wrapper.user().get(ChatRegistryStorage1_19_1.class); chatTypeStorage.clear(); final CompoundTag registry = wrapper.get(Type.NBT, 0); @@ -172,7 +173,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol chatTypes = new Int2ObjectOpenHashMap<>(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/storage/ChatRegistryStorage1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/storage/ChatRegistryStorage1_19_1.java new file mode 100644 index 00000000..58b48acc --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/storage/ChatRegistryStorage1_19_1.java @@ -0,0 +1,21 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2022 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_19to1_19_1.storage; + +public final class ChatRegistryStorage1_19_1 extends ChatRegistryStorage { +} diff --git a/common/src/main/resources/assets/viabackwards/data/mapping-1.19to1.19.3.json b/common/src/main/resources/assets/viabackwards/data/mapping-1.19to1.19.3.json index 977f217c..9f0f2433 100644 --- a/common/src/main/resources/assets/viabackwards/data/mapping-1.19to1.19.3.json +++ b/common/src/main/resources/assets/viabackwards/data/mapping-1.19to1.19.3.json @@ -662,6 +662,7 @@ "minecraft:bamboo_mosaic_stairs": "minecraft:birch_stairs[", "minecraft:bamboo_slab": "minecraft:birch_slab[", "minecraft:bamboo_mosaic_slab": "minecraft:birch_slab[", + "minecraft:bamboo_fence": "minecraft:birch_fence[", "minecraft:bamboo_fence_gate": "minecraft:birch_fence_gate[", "minecraft:bamboo_door": "minecraft:birch_door[" },