mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-28 02:51:42 +01:00
Handle tag logic inside read/write
This commit is contained in:
parent
0a7b773aa8
commit
1715e55b4d
@ -43,12 +43,20 @@ public class Tag<T> {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T read(@NotNull NBTCompound nbtCompound) {
|
public @Nullable T read(@NotNull NBTCompound nbtCompound) {
|
||||||
return readFunction.apply(nbtCompound);
|
if (nbtCompound.containsKey(key)) {
|
||||||
|
return readFunction.apply(nbtCompound);
|
||||||
|
} else {
|
||||||
|
return defaultValue != null ? defaultValue.get() : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void write(@NotNull NBTCompound nbtCompound, @NotNull T value) {
|
public void write(@NotNull NBTCompound nbtCompound, @Nullable T value) {
|
||||||
this.writeConsumer.accept(nbtCompound, value);
|
if (value != null) {
|
||||||
|
this.writeConsumer.accept(nbtCompound, value);
|
||||||
|
} else {
|
||||||
|
nbtCompound.removeTag(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull Tag<Byte> Byte(@NotNull String key) {
|
public static @NotNull Tag<Byte> Byte(@NotNull String key) {
|
||||||
|
Loading…
Reference in New Issue
Block a user