NBT-API

NBT-API

98.9k Downloads

Failure to obtain NBTCompound for NBTTileEntity

ChenCMD opened this issue ยท 8 comments

commented

environment

Item-NBT-API version: 2.9.2
spigot version: 1.18.2-R0.1-SNAPSHOT (3482-Spigot-42b6152-e87f2e3)

details

When I tried to construct NBTTileEntity with Container class BlockState and perform toString, getCompound, etc., the following exception occurred and I could not get the data.

de.tr7zw.nbtapi.NbtApiException: [Selfchecked]Exception while getting NBTCompound from TileEntity!
       at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:247)
       at de.tr7zw.nbtapi.NBTTileEntity.getCompound(NBTTileEntity.java:36)
       at de.tr7zw.nbtapi.NBTCompound.asNBTString(NBTCompound.java:800)
       at de.tr7zw.nbtapi.NBTCompound.toString(NBTCompound.java:772)
       ~~~~~~omit~~~~~~
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "target" is null
       at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:180)
       at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:237)
       at de.tr7zw.nbtapi.NBTTileEntity.getCompound(NBTTileEntity.java:36)
       at de.tr7zw.nbtapi.NBTCompound.asNBTString(NBTCompound.java:800)
       at de.tr7zw.nbtapi.NBTCompound.toString(NBTCompound.java:772)
       ~~~~~~omit~~~~~~
commented

with Container class BlockState

What kind of block did you pass into the constructor?

commented

I have not tried all of them, but I have checked with Chest and Furnace.

commented

Chest and Furnance should abolutley work, and in your crash report the [Selfchecked] means that the plugin also did try that and it worked. What is your code?

commented

Uh, I was writing some simplified code for this and noticed that there is no support for getting NBTCompound in an asynchronous thread by any chance?

commented

Async does work, but prooobably not on (Block-)Entities.

commented

Hmmm, perhaps that is the reason.
However, this exception is so non-trivial that I wonder if it would be possible to make it a little easier to understand?

commented

Well, it fails in resolving the data(minecraft returns null instead of a tag), therefore getting a nullpointer exception. And yes future versions should have better error handling that explains the issue better.

commented

I will run it on the main thread for now. Thanks again for your prompt support.
(If you are not tracking here for improved error handling, then Close this issue.)