Impl ItemMeta#getOrDefault

This commit is contained in:
themode 2021-04-03 15:50:34 +02:00
parent 4741c932a0
commit c8fbf47bd9

View File

@ -95,9 +95,14 @@ public class ItemMeta {
return customModelData;
}
@Contract("_, null -> null; _, !null -> !null")
public <T> T getOrDefault(@NotNull ItemTag<T> tag, @Nullable T defaultValue) {
var nbt = toNBT();
var key = tag.getKey();
if (nbt.containsKey(key)) {
return tag.read(toNBT());
} else {
return defaultValue;
}
}
public <T> @Nullable T get(@NotNull ItemTag<T> tag) {