diff --git a/src/main/java/net/minestom/server/instance/block/Block.java b/src/main/java/net/minestom/server/instance/block/Block.java index 00ea534a6..8e234f734 100644 --- a/src/main/java/net/minestom/server/instance/block/Block.java +++ b/src/main/java/net/minestom/server/instance/block/Block.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import java.util.Map; +import java.util.Objects; import java.util.function.BiPredicate; /** @@ -27,10 +28,14 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants { return withProperty(property.getName(), value.toString()); } - @NotNull Block withTag(@NotNull Tag tag, @Nullable T value); - @NotNull Block withNbt(@Nullable NBTCompound compound); + default @NotNull Block withTag(@NotNull Tag tag, @Nullable T value) { + var compound = Objects.requireNonNullElseGet(getNbt(), NBTCompound::new); + tag.write(compound, value); + return withNbt(compound); + } + @NotNull Block withHandler(@Nullable BlockHandler handler); @NotNull String getProperty(@NotNull String property); diff --git a/src/main/java/net/minestom/server/instance/block/BlockTest.java b/src/main/java/net/minestom/server/instance/block/BlockTest.java index 1cd5e2935..8708de7a5 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockTest.java +++ b/src/main/java/net/minestom/server/instance/block/BlockTest.java @@ -41,13 +41,6 @@ class BlockTest implements Block { return Objects.requireNonNull(BlockRegistry.getProperties(this, properties)); } - @Override - public @NotNull Block withTag(@NotNull Tag tag, @Nullable T value) { - var compound = this.compound != null ? this.compound.deepClone() : new NBTCompound(); - tag.write(compound, value); - return new BlockTest(registry, properties, compound, handler); - } - @Override public @NotNull Block withNbt(@Nullable NBTCompound compound) { return new BlockTest(registry, properties, compound, handler);