Can't get NBTCompound from NBTTileEntity
n08i40k opened this issue ยท 14 comments
Code:
public boolean GetNBTTag(Block b) {
NBTTileEntity tent = new NBTTileEntity(b.getState());
NBTCompound comp = tent.getPersistentDataContainer();
return comp.hasKey("break");
}
Errors in console:
[21:10:54 ERROR]: Could not pass event PlayerMoveEvent to BreakingGlasses v1.0-SNAPSHOT
de.tr7zw.nbtapi.NbtApiException: Exception while getting NBTCompound from TileEntity!
at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:235) ~[item-nbt-api-plugin-2.8.0.jar:?]
at de.tr7zw.nbtapi.NBTTileEntity.getCompound(NBTTileEntity.java:36) ~[item-nbt-api-plugin-2.8.0.jar:?]
at de.tr7zw.nbtapi.NBTReflectionUtil.getData(NBTReflectionUtil.java:608) ~[item-nbt-api-plugin-2.8.0.jar:?]
at de.tr7zw.nbtapi.NBTCompound.hasKey(NBTCompound.java:514) ~[item-nbt-api-plugin-2.8.0.jar:?]
at de.tr7zw.nbtapi.NBTTileEntity.getPersistentDataContainer(NBTTileEntity.java:53) ~[item-nbt-api-plugin-2.8.0.jar:?]
at ru.n08i40k.breakingglasses.EventsHandler.GetNBTTag(EventsHandler.java:64) ~[breaking_glasses.jar:?]
at ru.n08i40k.breakingglasses.EventsHandler.PatchBlocks(EventsHandler.java:31) ~[breaking_glasses.jar:?]
at ru.n08i40k.breakingglasses.EventsHandler.onMove(EventsHandler.java:25) ~[breaking_glasses.jar:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor426.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.17.1.jar:git-Airplane-112]
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:76) ~[patched_1.17.1.jar:git-Airplane-112]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.17.1.jar:git-Airplane-112]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:628) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleMovePlayer(ServerGamePacketListenerImpl.java:1482) ~[app:?]
at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.handle(ServerboundMovePlayerPacket.java:114) ~[app:?]
at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos.handle(ServerboundMovePlayerPacket.java:42) ~[app:?]
at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:56) ~[app:?]
at net.minecraft.server.TickTask.run(TickTask.java:18) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:149) ~[app:?]
at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:23) ~[app:?]
at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1426) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.server.MinecraftServer.executeTask(MinecraftServer.java:192) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:122) ~[app:?]
at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1404) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1397) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:132) ~[app:?]
at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1375) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1286) ~[patched_1.17.1.jar:git-Airplane-112]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319) ~[patched_1.17.1.jar:git-Airplane-112]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: de.tr7zw.nbtapi.NbtApiException: Error while calling the method 'save', loaded: true, Enum: TILEENTITY_GET_NBT
at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:164) ~[item-nbt-api-plugin-2.8.0.jar:?]
at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:230) ~[item-nbt-api-plugin-2.8.0.jar:?]
... 29 more
Caused by: java.lang.NullPointerException
at jdk.internal.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:162) ~[item-nbt-api-plugin-2.8.0.jar:?]
at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:230) ~[item-nbt-api-plugin-2.8.0.jar:?]
... 29 more
You can use the NBTBlock
in 1.16.4+. Some noteworthy things about it: The data gets saved to the chunk, it won't get auto removed when the block gets broken/explodes etc and it won't prevent/be moved by pistons. So basically the data gets saved for the XYZ cords, not to the block itself. Other than that, blocks can't/don't have data.
Server version: Airplane version git-Airplane-112 (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT) (Git: a3b010c on HEAD)
Hm that's a weird one. Can you also give the output of the self-check at the beginning?
new NBTBlock(block).setString("foo", "bar");
They work exactly like the persistent data container/items.
At server start it will print some lines about the NMS version, reflection tests, and sanity checks.
[21:27:18 INFO]: [NBTAPI] Loading NBTAPI v2.8.0
[21:27:18 INFO]: [NBTAPI] Injecting custom NBT
[21:27:18 INFO]: [NBTAPI] [NBTAPI] Found Spigot: v1_17_R1! Trying to find NMS support
[21:27:18 INFO]: [NBTAPI] [NBTAPI] NMS support 'MC1_17_R1' loaded!
[21:27:18 INFO]: [NBTAPI] [NBTAPI] Found Gson: class com.google.gson.Gson
[21:27:18 INFO]: [NBTAPI] [NBTAPI] Using the plugin 'BreakingGlasses' to create a bStats instance!
[21:27:18 WARN]: [NBTInjector] [NBTINJECTOR] The NBT-Injector is not compatibel with this Minecraft Version! For 1.16+ please use the persistent storage API.
[21:27:18 INFO]: [NBTAPI] Injected!
[21:27:37 INFO]: [NBTAPI] Enabling NBTAPI v2.8.0
[21:27:37 INFO]: [NBTAPI] Adding listeners...
[21:27:37 INFO]: [NBTAPI] Gson:
[21:27:37 INFO]: [NBTAPI] Checking bindings...
[21:27:37 INFO]: [NBTAPI] All Classes were able to link!
[21:27:37 INFO]: [NBTAPI] All Methods were able to link!
[21:27:37 INFO]: [NBTAPI] Running NBT reflection test...
[21:27:38 INFO]: [NBTAPI] MergeTileSubCompoundTest: Ok
[21:27:38 INFO]: [NBTAPI] StreamTest: Ok
[21:27:38 INFO]: [NBTAPI] TileTest: Ok
[21:27:38 INFO]: [NBTAPI] NBTFileTest: Ok
[21:27:38 INFO]: [NBTAPI] ListTest: Ok
[21:27:38 INFO]: [NBTAPI] GameprofileTest: Ok
[21:27:38 INFO]: [NBTAPI] ItemMergingTest: Ok
[21:27:38 INFO]: [NBTAPI] TypeTest: Ok
[21:27:38 INFO]: [NBTAPI] EqualsTest: Ok
[21:27:38 INFO]: [NBTAPI] TilesCustomNBTPersistentTest: Ok
[21:27:38 INFO]: [NBTAPI] EntityTest: Ok
[21:27:38 INFO]: [NBTAPI] DirectApplyTest: Ok
[21:27:38 INFO]: [NBTAPI] ChunkNBTPersistentTest: Ok
[21:27:38 INFO]: [NBTAPI] ItemConvertionTest: Ok
[21:27:38 INFO]: [NBTAPI] TilesCustomNBTInjectorTest: Ok
[21:27:38 INFO]: [NBTAPI] BlockNBTTest: Ok
[21:27:38 INFO]: [NBTAPI] EntityCustomNbtInjectorTest: Ok
[21:27:38 INFO]: [NBTAPI] EmptyItemTest: Ok
[21:27:38 INFO]: [NBTAPI] SpawnEntityCustomNbtInjectorTest: Ok
[21:27:38 INFO]: [NBTAPI] SubCompoundsTest: Ok
[21:27:38 INFO]: [NBTAPI] RemovingKeys: Ok
[21:27:38 INFO]: [NBTAPI] GetterSetterTest: Ok
[21:27:38 INFO]: [NBTAPI] ForEachTest: Ok
[21:27:38 INFO]: [NBTAPI] WorldDataTest: Ok
[21:27:38 INFO]: [NBTAPI] MergeTest: Ok
[21:27:38 INFO]: [NBTAPI] EntityCustomNbtPersistentTest: Ok
[21:27:38 INFO]: [NBTAPI] IteratorTest: Ok
[21:27:38 INFO]: [NBTAPI] Success! This version of NBT-API is compatible with your server.
Ok other sanity check, is the block a BlockEntity^^? "BreakingGlasses" makes it sound like it could be glass, which is not a TileEntity/BlockEntity.
Oh, really. I am trying to get a glass block NBTCompont. Is it possible to somehow add NBT to the glass block?
https://github.com/tr7zw/Item-NBT-API/blob/master/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTBlock.java
Check your imports/dependencies.