Skip to content

Commit

Permalink
feat: add more nbt read methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynverxe committed Jul 30, 2023
1 parent 26cb0ac commit 7a34175
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

public interface NBTReadable {
Expand All @@ -18,6 +19,10 @@ public interface NBTReadable {
return new Tag<>(key, found);
}

default <N extends NBT<?>> @NotNull Optional<N> readOptional(@NotNull String key, @NotNull TagType<N> type) {
return Optional.ofNullable(read(key, type));
}

default <N extends NBT<?>> @Nullable N read(@NotNull String key, @NotNull TagType<N> type) {
return type.cast(read(key));
}
Expand All @@ -41,6 +46,10 @@ default <V, T> T parseValue(@NotNull String key, @NotNull TagType<NBT<V>> type,
return found != null ? parser.apply(found) : null;
}

default <V> @NotNull Optional<V> readOptionalValue(@NotNull String key, @NotNull TagType<NBT<V>> type) {
return Optional.ofNullable(readValue(key, type));
}

default @Nullable Number readNumber(@NotNull String key) {
return readValue(key);
}
Expand Down

0 comments on commit 7a34175

Please sign in to comment.