3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Add optional registry utils to TagUtil (#3819)

Dieser Commit ist enthalten in:
EnZaXD 2024-05-02 15:45:19 +02:00 committet von GitHub
Ursprung c00bc6b667
Commit d3af70d76c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -26,19 +26,33 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class TagUtil {
public static ListTag<CompoundTag> getRegistryEntries(final CompoundTag tag, final String key) {
return getRegistryEntries(tag, key, null);
}
public static ListTag<CompoundTag> getRegistryEntries(final CompoundTag tag, final String key, final @Nullable ListTag<CompoundTag> defaultValue) {
CompoundTag registry = tag.getCompoundTag(Key.namespaced(key));
if (registry == null) {
registry = tag.getCompoundTag(Key.stripMinecraftNamespace(key));
if (registry == null) {
return defaultValue;
}
}
return registry.getListTag("value", CompoundTag.class);
}
public static ListTag<CompoundTag> removeRegistryEntries(final CompoundTag tag, final String key) {
return removeRegistryEntries(tag, key, null);
}
public static ListTag<CompoundTag> removeRegistryEntries(final CompoundTag tag, final String key, final @Nullable ListTag<CompoundTag> defaultValue) {
String currentKey = Key.namespaced(key);
CompoundTag registry = tag.getCompoundTag(currentKey);
if (registry == null) {
currentKey = Key.stripMinecraftNamespace(key);
registry = tag.getCompoundTag(currentKey);
if (registry == null) {
return defaultValue;
}
}
tag.remove(currentKey);
return registry.getListTag("value", CompoundTag.class);