From a31f885cc73f2c3529ca95c1b52d836b6567df0c Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 2 Jan 2022 06:08:28 +0100 Subject: [PATCH] Fix default tag value on blocks --- .../java/net/minestom/server/instance/block/BlockImpl.java | 2 +- src/test/java/instance/BlockTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/instance/block/BlockImpl.java b/src/main/java/net/minestom/server/instance/block/BlockImpl.java index 4516ecc66..69a505dcf 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockImpl.java +++ b/src/main/java/net/minestom/server/instance/block/BlockImpl.java @@ -128,7 +128,7 @@ record BlockImpl(@NotNull Registry.BlockEntry registry, @Override public @Nullable T getTag(@NotNull Tag tag) { - return nbt != null ? tag.read(nbt) : null; + return tag.read(Objects.requireNonNullElse(nbt, NBTCompound.EMPTY)); } private Map, Block> possibleProperties() { diff --git a/src/test/java/instance/BlockTest.java b/src/test/java/instance/BlockTest.java index 99249ba65..9d16c822e 100644 --- a/src/test/java/instance/BlockTest.java +++ b/src/test/java/instance/BlockTest.java @@ -1,6 +1,7 @@ package instance; import net.minestom.server.instance.block.Block; +import net.minestom.server.tag.Tag; import net.minestom.server.utils.block.BlockUtils; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTCompound; @@ -27,6 +28,9 @@ public class BlockTest { block = block.withNbt(null); assertFalse(block.hasNbt()); assertNull(block.nbt()); + + var value = block.getTag(Tag.String("key").defaultValue("Default")); + assertEquals("Default", value); } @Test