mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2025-02-16 11:41:29 +01:00
Add optional registry utils to TagUtil (#3819)
This commit is contained in:
parent
c00bc6b667
commit
d3af70d76c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user