Item-NBT-API icon indicating copy to clipboard operation
Item-NBT-API copied to clipboard

Cannot modify BlockState on 1.16.5 / 1.20.4

Open BlackBaroness opened this issue 1 year ago • 4 comments
trafficstars

My code:

val block = player.eyeLocation.block
NBT.modifyPersistentData(block.getState(true)) { nbt ->
   nbt.setInteger("agugu", 1)
}

I also tried to use modify method instead of modifyPersistentData and using snapshot/default BlockState version.

My server:

[17:00:51 INFO]: This server is running Paper version git-Paper-485 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 862299b)
You are running the latest version

I also use the 2.12.3 (latest) version of NBTAPI using relocation.

Error:

[16:58:31 INFO]: [NBTAPI] [NBTAPI] Found Minecraft: v1_20_R3! Trying to find NMS support
[16:58:31 INFO]: [NBTAPI] [NBTAPI] NMS support 'MC1_20_R3' loaded!
[16:58:31 INFO]: [NBTAPI] [NBTAPI] Using the plugin 'NewDynamites' to create a bStats instance!
[16:58:32 WARN]: io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NbtApiException: [?][2.12.3]Exception while getting NBTCompound from TileEntity!
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:274)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTTileEntity.getCompound(NBTTileEntity.java:79)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTCompound.getResolvedObject(NBTCompound.java:100)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTReflectionUtil.getData(NBTReflectionUtil.java:621)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTCompound.hasTag(NBTCompound.java:720)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTTileEntity.getPersistentDataContainer(NBTTileEntity.java:100)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBT.modifyPersistentData(NBT.java:335)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.command.NewDynamitesCommand.test_1(NewDynamitesCommand.kt:17)
<removed>
[16:58:32 WARN]: Caused by: io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NbtApiException: [?][2.12.3]Error while calling the method 'saveWithId()', loaded: true, Enum: TILEENTITY_GET_NBT_1181, Passed Class: null
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:386)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:264)
[16:58:32 WARN]: 	... 56 more
[16:58:32 WARN]: Caused by: java.lang.NullPointerException
[16:58:32 WARN]: 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[16:58:32 WARN]: 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[16:58:32 WARN]: 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[16:58:32 WARN]: 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[16:58:32 WARN]: 	at NewDynamites-all.jar//io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:383)
[16:58:32 WARN]: 	... 57 more

BlackBaroness avatar Apr 17 '24 14:04 BlackBaroness

Also happens on 1.16.5:

[17:11:02 INFO]: [NBTAPI] [NBTAPI] Found Minecraft: v1_16_R3! Trying to find NMS support
[17:11:02 INFO]: [NBTAPI] [NBTAPI] NMS support 'MC1_16_R3' loaded!
[17:11:02 INFO]: [NBTAPI] [NBTAPI] Using the plugin 'NewDynamites' to create a bStats instance!
[17:11:02 WARN]: io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NbtApiException: [?][2.12.3]Exception while getting NBTCompound from TileEntity!
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:274)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTTileEntity.getCompound(NBTTileEntity.java:79)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTCompound.getResolvedObject(NBTCompound.java:100)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTReflectionUtil.getData(NBTReflectionUtil.java:621)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTCompound.hasTag(NBTCompound.java:720)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTTileEntity.getPersistentDataContainer(NBTTileEntity.java:100)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBT.modifyPersistentData(NBT.java:335)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.command.NewDynamitesCommand.test_1(NewDynamitesCommand.kt:17)
<removed>
[17:11:02 WARN]: Caused by: io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NbtApiException: [?][2.12.3]Error while calling the method 'save', loaded: true, Enum: TILEENTITY_GET_NBT, Passed Class: null
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:386)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:267)
[17:11:02 WARN]: 	... 46 more
[17:11:02 WARN]: Caused by: java.lang.NullPointerException
[17:11:02 WARN]: 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[17:11:02 WARN]: 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
[17:11:02 WARN]: 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[17:11:02 WARN]: 	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
[17:11:02 WARN]: 	at io.github.blackbaroness.newdynamites.__relocated__.de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:383)
[17:11:02 WARN]: 	... 47 more
[17:12:20 INFO]: This server is running Paper version git-Paper-794 (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
You are running the latest version

BlackBaroness avatar Apr 17 '24 14:04 BlackBaroness

That only works on BlockEntities. So unless the block is a chest/sign/furnance/shulker etc, this is the correct behavior.

tr7zw avatar Apr 17 '24 17:04 tr7zw

Also noteworthy that on a block entits the provided code will do nothing, as "agugu" is not a vanilla tag.

tr7zw avatar Apr 17 '24 20:04 tr7zw

That only works on BlockEntities. So unless the block is a chest/sign/furnance/shulker etc, this is the correct behavior.

Also noteworthy that on a block entits the provided code will do nothing, as "agugu" is not a vanilla tag.

Understood. Due to how the contract look like, I thought there was an ability to store custom data inside blocks. Maybe the error message should be improved so it won't look as the library bug?

BlackBaroness avatar Apr 19 '24 06:04 BlackBaroness