Add Block::nbtOrEmpty (#2389)

This commit is contained in:
Samuel 2024-09-10 04:00:51 -04:00 committed by GitHub
parent 7ce047b22e
commit d955f51899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,6 +92,15 @@ public sealed interface Block extends StaticProtocolObject, TagReadable, Blocks
@Contract(pure = true)
@Nullable CompoundBinaryTag nbt();
/**
* Returns an unmodifiable view of the block nbt or an empty compound.
*
* @return the block nbt or an empty compound if not present
*/
default @NotNull CompoundBinaryTag nbtOrEmpty() {
return Objects.requireNonNullElse(nbt(), CompoundBinaryTag.empty());
}
@Contract(pure = true)
default boolean hasNbt() {
return nbt() != null;