mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 07:28:19 +01:00
Unnecessary methods
This commit is contained in:
parent
ee5ca9050c
commit
355beac466
@ -29,8 +29,8 @@ public class Tag<T> {
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final Function<NBT, T> readFunction;
|
||||
private final Function<T, NBT> writeFunction;
|
||||
final Function<NBT, T> readFunction;
|
||||
final Function<T, NBT> writeFunction;
|
||||
private final Supplier<T> defaultValue;
|
||||
|
||||
final int index;
|
||||
@ -103,12 +103,15 @@ public class Tag<T> {
|
||||
|
||||
public @Nullable T read(@NotNull NBTCompoundLike nbt) {
|
||||
final String key = this.key;
|
||||
if (key.isEmpty()) {
|
||||
// Special handling for view tag
|
||||
return convertToValue(nbt.toCompound());
|
||||
final NBT readable = key.isEmpty() ? nbt.toCompound() : nbt.get(key);
|
||||
final T result;
|
||||
try {
|
||||
if (readable == null || (result = readFunction.apply(readable)) == null)
|
||||
return createDefault();
|
||||
return result;
|
||||
} catch (ClassCastException e) {
|
||||
return createDefault();
|
||||
}
|
||||
final NBT subTag = nbt.get(key);
|
||||
return convertToValue(subTag);
|
||||
}
|
||||
|
||||
T createDefault() {
|
||||
@ -133,21 +136,6 @@ public class Tag<T> {
|
||||
write(nbtCompound, (T) value);
|
||||
}
|
||||
|
||||
T convertToValue(NBT nbt) {
|
||||
final T result;
|
||||
try {
|
||||
if (nbt == null || (result = readFunction.apply(nbt)) == null)
|
||||
return createDefault();
|
||||
return result;
|
||||
} catch (ClassCastException e) {
|
||||
return createDefault();
|
||||
}
|
||||
}
|
||||
|
||||
NBT convertToNbt(T value) {
|
||||
return writeFunction.apply(value);
|
||||
}
|
||||
|
||||
public static @NotNull Tag<Byte> Byte(@NotNull String key) {
|
||||
return tag(key, NBTByte.class, NBTByte::getValue, NBT::Byte);
|
||||
}
|
||||
|
@ -122,7 +122,11 @@ final class TagHandlerImpl implements TagHandler {
|
||||
}
|
||||
// Value must be parsed from nbt if the tag is different
|
||||
NBT nbt = entry.nbt;
|
||||
if (nbt == null) entry.nbt = nbt = entryTag.convertToNbt(entry.value);
|
||||
return tag.convertToValue(nbt);
|
||||
if (nbt == null) entry.nbt = nbt = (NBT) entryTag.writeFunction.apply(entry.value);
|
||||
try {
|
||||
return tag.readFunction.apply(nbt);
|
||||
} catch (ClassCastException e) {
|
||||
return tag.createDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user