Started by
Stitch147
on
Topic category: Help with Minecraft modding (Java Edition)
As the title says, how stable is itemstack NBT? Specifically this would be a number variable.
I have a currency that is currently stored on a player global variable, but I want to change it over to an item NBT variable, so that the item itself holds the currency. I know that entity NBT can be a little unstable, so I was wondering how stable item NBT is - will it hold the data over time from logging in and out, will it work on multiplayer, will it hold data when dropped, or when put into an item frame?
Also, is there a maximum number of NBT's I can add to the item?
Thank you :)
Edited by Stitch147 on Fri, 08/25/2023 - 23:02
Item NBTs should be the most stable NBT holder, I've tried blockstate nbt (and it didn't even save somewhy), entity I didn't try yet but Item works for me (tested up to 8 tags), keeps the data whatever you do with it (next to deleting/crafting/smelting or anything)
Cool! Thank you so much! I've had similar experiences with blockstate not saving as well.
@ModProgrammMiked Block data will not work if block entity is selected, all NBT
will Alwaysshould be infinite.@presidentuni how do i unselect it then?
You can unselect it under the "Block Entity" tab in the block's element.
I'm confused though, the description says block entity needs to be on in order to store NBT data.
@Stitch147 yea ik thats why i asked
maybe he meant deselecting something different idk
After some time playing around with it, it seems you do need it to be a Block Entity to save the data. All my block NBT data so far has been saving properly, and stays when I log out of the world or completely restart the game. I haven't had any issues with data being lost over time either.
In my experience, item and entity NBT are pretty solid, I've been able to use entity NBTs for pathfinding and timers in some (very specific) use cases. Haven't tried block NBT tags, modifying and assigning vanilla ones works fine, but custom ones seem a bit iffier.
is it however possible to change NBT values of an item which is not in anyone's inventory, but floating in the air?
You would need to make a procedure with a local itemstack variable, set the itemstack variable to the itemstack entity, converted into an itemstack. (There should be a conversion function that, when provided with an item entity, converts it to an itemstack.) Then apply the NBT changes to the local itemstack variable, despawn the original item entity, and spawn in a new item with the changes applied.