Fix default tag value on blocks

This commit is contained in:
themode 2022-01-02 06:08:28 +01:00 committed by TheMode
parent 204089d53d
commit a31f885cc7
2 changed files with 5 additions and 1 deletions

View File

@ -128,7 +128,7 @@ record BlockImpl(@NotNull Registry.BlockEntry registry,
@Override
public <T> @Nullable T getTag(@NotNull Tag<T> tag) {
return nbt != null ? tag.read(nbt) : null;
return tag.read(Objects.requireNonNullElse(nbt, NBTCompound.EMPTY));
}
private Map<Map<String, String>, Block> possibleProperties() {

View File

@ -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