American2050 Posted December 28, 2017 Posted December 28, 2017 I have a question, I have an item that stores a boolean value when the player right clicks it. I notice that the NBT isn't there until the first right click I use on it. I know we have the onCreated method. But it looks like that only gets called when the item is crafted. But not if I'm on Creative Mode and pick it from inventory. Is there anything to do around this to get the NBT created even when the item is picked up on creative mode? Quote
Matryoshika Posted December 28, 2017 Posted December 28, 2017 Override Item::onUpdate. Check if the item has the NBTTag, and if it doesn't, add it. Quote Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
American2050 Posted December 28, 2017 Author Posted December 28, 2017 3 hours ago, diesieben07 said: Please no. Have a method which lazily initializes the NBT tag and only use that method to access the tag. Pseudocode: int getMyTag(stack) { if (stack does not have nbt tag) { add default nbt tag } return nbt tag from stack } But when and where from that method would get called? And sorry for this question, I guess the answer is probably obvious, but... Can an item have NBT data "pre-loaded" like for example on the Creative Tab come already with the NBT on it? Quote
American2050 Posted December 28, 2017 Author Posted December 28, 2017 I believe I didn't explain the problem correctly. For example I call the NBT from "onItemRightClick" and there, if the NBT doesn't exists, it gets created. I'm looking for the NBT to exists right away. That's why I call that from onCreated, but the problem is that onCreated doesn't trigger when I pick the item in creative mode. Sorry if it sounds repetitive, but maybe I didn't explain the problem correctly. PS: I also read NBT from the method that display items description when you hover on them. But that runs only "Client Side" is that good to create the NBT there? Or it needs to be done on a method that runs both server and client side. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.