No need to expose tag default value

This commit is contained in:
TheMode 2021-05-17 15:17:53 +02:00
parent 429a14e220
commit 9255adb7ec

View File

@ -21,8 +21,7 @@ public final class Tag<T> {
private final String key; private final String key;
private final Function<NBTCompound, T> readFunction; private final Function<NBTCompound, T> readFunction;
private final BiConsumer<NBTCompound, T> writeConsumer; private final BiConsumer<NBTCompound, T> writeConsumer;
private volatile Supplier<T> defaultValue;
protected volatile Supplier<T> defaultValue;
private Tag(@NotNull String key, private Tag(@NotNull String key,
@NotNull Function<NBTCompound, T> readFunction, @NotNull Function<NBTCompound, T> readFunction,
@ -46,15 +45,12 @@ public final class Tag<T> {
return this; return this;
} }
public @Nullable Supplier<@Nullable T> getDefaultValue() {
return defaultValue;
}
public @Nullable T read(@NotNull NBTCompound nbtCompound) { public @Nullable T read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey(key)) { if (nbtCompound.containsKey(key)) {
return readFunction.apply(nbtCompound); return readFunction.apply(nbtCompound);
} else { } else {
return defaultValue != null ? defaultValue.get() : null; final var supplier = defaultValue;
return supplier != null ? supplier.get() : null;
} }
} }