Jump to content

Recommended Posts

Posted

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?

Posted
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?

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.