ProtocolLib icon indicating copy to clipboard operation
ProtocolLib copied to clipboard

NBTFactory.readBlockState(block) return null

Open Anarchick opened this issue 4 years ago • 3 comments

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

Anarchick avatar Jul 14 '21 20:07 Anarchick

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

TerraMiner avatar Feb 25 '24 01:02 TerraMiner

This if statement is probably wrong:

if (block != null) return null;

it should be

if (block == null) return null;

lukalt avatar Feb 25 '24 16:02 lukalt

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.

TerraMiner avatar Feb 27 '24 15:02 TerraMiner