Move chat registry dumps into nbt files (#3763)

This commit is contained in:
EnZaXD 2024-03-31 15:07:46 +02:00 committed by GitHub
parent abd58399cd
commit 7556f7b8fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 70 deletions

View File

@ -17,13 +17,11 @@
*/
package com.viaversion.viaversion.protocols.protocol1_19_1to1_19;
import com.github.steveice10.opennbt.stringified.SNBT;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Preconditions;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.Via;
@ -39,6 +37,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.data.ChatDecorationResult;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.data.ChatRegistry;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.storage.ChatTypeStorage;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.storage.NonceStorage;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
@ -58,39 +58,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPackets1_19, ClientboundPackets1_19_1, ServerboundPackets1_19, ServerboundPackets1_19_1> {
private static final String CHAT_REGISTRY_SNBT = "{" +
" \"minecraft:chat_type\": {" +
" \"type\": \"minecraft:chat_type\"," +
" \"value\": [" +
" {" +
" \"name\":\"minecraft:chat\"," +
" \"id\":1," +
" \"element\":{" +
" \"chat\":{" +
" \"translation_key\":\"chat.type.text\"," +
" \"parameters\":[" +
" \"sender\"," +
" \"content\"" +
" ]" +
" }," +
" \"narration\":{" +
" \"translation_key\":\"chat.type.text.narrate\"," +
" \"parameters\":[" +
" \"sender\"," +
" \"content\"" +
" ]" +
" }" +
" }" +
" }" +
" ]" +
" }" +
"}";
private static final CompoundTag CHAT_REGISTRY;
static {
CHAT_REGISTRY = SNBT.deserializeCompoundTag(CHAT_REGISTRY_SNBT).getCompoundTag("minecraft:chat_type");
}
public Protocol1_19_1To1_19() {
super(ClientboundPackets1_19.class, ClientboundPackets1_19_1.class, ServerboundPackets1_19.class, ServerboundPackets1_19_1.class);
}
@ -229,7 +196,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
}
// Replace chat types - they won't actually be used
registry.put("minecraft:chat_type", CHAT_REGISTRY.copy());
registry.put("minecraft:chat_type", ChatRegistry.chatRegistry());
});
}
});

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_19_1to1_19;
package com.viaversion.viaversion.protocols.protocol1_19_1to1_19.data;
import com.google.gson.JsonElement;

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 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 <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_19_1to1_19.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.data.MappingDataLoader;
public class ChatRegistry {
private static final CompoundTag chatRegistry;
static {
chatRegistry = MappingDataLoader.INSTANCE.loadNBTFromFile("chat-registry-1.19.1.nbt");
}
public static CompoundTag chatRegistry() {
return chatRegistry.copy();
}
}

View File

@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class MappingData extends MappingDataBase {
private final Int2ObjectMap<CompoundTag> defaultChatTypes = new Int2ObjectOpenHashMap<>();
private CompoundTag chatRegistry;
public MappingData() {
super("1.18", "1.19");
@ -41,9 +42,15 @@ public final class MappingData extends MappingDataBase {
final NumberTag idTag = chatType.getNumberTag("id");
defaultChatTypes.put(idTag.asInt(), chatType);
}
chatRegistry = MappingDataLoader.INSTANCE.loadNBTFromFile("chat-registry-1.19.nbt");
}
public @Nullable CompoundTag chatType(final int id) {
return defaultChatTypes.get(id);
}
public CompoundTag chatRegistry() {
return chatRegistry.copy();
}
}

View File

@ -17,12 +17,10 @@
*/
package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets;
import com.github.steveice10.opennbt.stringified.SNBT;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.collect.Maps;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.Via;
@ -54,36 +52,6 @@ import java.util.Map;
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18, Protocol1_19To1_18_2> {
private static final String CHAT_REGISTRY_SNBT = "{\n" +
" \"minecraft:chat_type\": {\n" +
" \"type\": \"minecraft:chat_type\",\n" +
" \"value\": [\n" +
" {\n" +
" \"name\": \"minecraft:system\",\n" +
" \"id\": 1,\n" +
" \"element\": {\n" +
" \"chat\": {},\n" +
" \"narration\": {\n" +
" \"priority\": \"system\"\n" +
" }\n" +
" }\n" +
" },\n" +
" {\n" +
" \"name\": \"minecraft:game_info\",\n" +
" \"id\": 2,\n" +
" \"element\": {\n" +
" \"overlay\": {}\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
public static final CompoundTag CHAT_REGISTRY;
static {
CHAT_REGISTRY = SNBT.deserializeCompoundTag(CHAT_REGISTRY_SNBT).getCompoundTag("minecraft:chat_type");
}
public EntityPackets(final Protocol1_19To1_18_2 protocol) {
super(protocol);
}
@ -207,7 +175,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
final CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
// Add necessary chat types
tag.put("minecraft:chat_type", CHAT_REGISTRY.copy());
tag.put("minecraft:chat_type", protocol.getMappingData().chatRegistry());
// Cache a whole lot of data
final ListTag<CompoundTag> dimensions = tag.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);