ProtocolLib

3M Downloads

NBTFactory.readBlockState(block) return null

Anarchick opened this issue ยท 3 comments

commented

Describe the bug
Trying to get NBT from a Tile Entity Block return null.

To Reproduce
Steps to reproduce the behavior:

    public static Object toNMSNBTTagCompound(Block block) {
        if (block != null) return null;
        NbtCompound nbt = NbtFactory.readBlockState(block); // null every time
        return (nbt != null) ? nbt.getHandle() : null;
    }

Expected behavior
Get the nms NBT for a tile entity (chest, sign, ...)

Version Info
mc 1.16.5 , protocolLib 4.6.0
https://pastebin.com/QkVXzemJ

Additional context
the class of variable block is CraftBlock

commented

got the same problem. itemstack, by the way, is also not converted to NBT compound

commented

This if statement is probably wrong:

if (block != null) return null;

it should be

if (block == null) return null;

commented

This if statement is probably wrong:

if (block != null) return null;

it should be

if (block == null) return null;

Correctly noted, but the author indicated a comment next to a specific line of code that returns null. I think he debugged it to point to a specific line. In addition, I also always have null, but it is the NbtFactory#readBlockState function that returns it.