NBTFactory.readBlockState(block) return null
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
got the same problem. itemstack, by the way, is also not converted to NBT compound
This if statement is probably wrong:
if (block != null) return null;
it should be
if (block == null) return null;
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.