Skip to content

Commit d3af70d

Browse files
Add optional registry utils to TagUtil (#3819)
1 parent c00bc6b commit d3af70d

File tree

1 file changed

+14
-0
lines changed
  • common/src/main/java/com/viaversion/viaversion/util

1 file changed

+14
-0
lines changed

common/src/main/java/com/viaversion/viaversion/util/TagUtil.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,33 @@
2626
public final class TagUtil {
2727

2828
public static ListTag<CompoundTag> getRegistryEntries(final CompoundTag tag, final String key) {
29+
return getRegistryEntries(tag, key, null);
30+
}
31+
32+
public static ListTag<CompoundTag> getRegistryEntries(final CompoundTag tag, final String key, final @Nullable ListTag<CompoundTag> defaultValue) {
2933
CompoundTag registry = tag.getCompoundTag(Key.namespaced(key));
3034
if (registry == null) {
3135
registry = tag.getCompoundTag(Key.stripMinecraftNamespace(key));
36+
if (registry == null) {
37+
return defaultValue;
38+
}
3239
}
3340
return registry.getListTag("value", CompoundTag.class);
3441
}
3542

3643
public static ListTag<CompoundTag> removeRegistryEntries(final CompoundTag tag, final String key) {
44+
return removeRegistryEntries(tag, key, null);
45+
}
46+
47+
public static ListTag<CompoundTag> removeRegistryEntries(final CompoundTag tag, final String key, final @Nullable ListTag<CompoundTag> defaultValue) {
3748
String currentKey = Key.namespaced(key);
3849
CompoundTag registry = tag.getCompoundTag(currentKey);
3950
if (registry == null) {
4051
currentKey = Key.stripMinecraftNamespace(key);
4152
registry = tag.getCompoundTag(currentKey);
53+
if (registry == null) {
54+
return defaultValue;
55+
}
4256
}
4357
tag.remove(currentKey);
4458
return registry.getListTag("value", CompoundTag.class);

0 commit comments

Comments
 (0)