Check both namespaced and implicit key when replacing registry

This commit is contained in:
Nassim Jahnke 2024-05-01 10:28:53 +02:00
parent fa3c933b2f
commit c00bc6b667
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 16 additions and 1 deletions

View File

@ -190,7 +190,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
chatTypeStorage.clear();
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
final ListTag<CompoundTag> chatTypes = TagUtil.getRegistryEntries(registry, "chat_type");
final ListTag<CompoundTag> chatTypes = TagUtil.removeRegistryEntries(registry, "chat_type");
for (final CompoundTag chatType : chatTypes) {
final NumberTag idTag = chatType.getNumberTag("id");
chatTypeStorage.addChatType(idTag.asInt(), chatType);

View File

@ -33,6 +33,21 @@ public final class TagUtil {
return registry.getListTag("value", CompoundTag.class);
}
public static ListTag<CompoundTag> removeRegistryEntries(final CompoundTag tag, final String key) {
String currentKey = Key.namespaced(key);
CompoundTag registry = tag.getCompoundTag(currentKey);
if (registry == null) {
currentKey = Key.stripMinecraftNamespace(key);
registry = tag.getCompoundTag(currentKey);
}
tag.remove(currentKey);
return registry.getListTag("value", CompoundTag.class);
}
public static boolean removeNamespaced(final CompoundTag tag, final String key) {
return tag.remove(Key.namespaced(key)) != null || tag.remove(Key.stripMinecraftNamespace(key)) != null;
}
public static Tag handleDeep(final Tag tag, final TagUpdater consumer) {
return handleDeep(null, tag, consumer);
}