Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Add NBT tags in item constructor?


aridale
 Share

Recommended Posts

Ive seen lots of posts about NBT and editing during runtime and things like that but I cant find a simple answer to how to add tags when the item is created.

 

I want the item to have certain tags like "lore" tags like youd add with MCEdit or Ingame NBTEdit but I want to set them in the items code.

 

Surely its got to be possible but nothing Ive found works

Link to comment
Share on other sites

nbt is really simple so all you have to do is use NBTTagCompound.setString("whatever") then you can get it with NBTTagCompound.getString("whatever") then just on item crafted check if it is your item then set it with setString then get it in a seperate method and do whatever you need.

Link to comment
Share on other sites

Well then I guess the only other thing to ask is am I doin it right? Cause it doesnt appear to be working.

 

	public void onItemPickup(EntityPlayer entityplayer, ItemStack itemstack) {
	if(itemstack.itemID == this.itemID) {
		NBTTagCompound tag = itemstack.getTagCompound();
		if (tag == null) {
		 tag = new NBTTagCompound();
		 itemstack.setTagCompound(tag);
		}
		tag.setString("Lore", "This is a test!");
	}
}

 

when I give mself the item from the creative inventory it has no extra text under the name. Still doesnt if I drop it and pick it back up

Link to comment
Share on other sites

oh you want to add text underneath well to add text all you have to do is do this

 

@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
{
	par3List.add("Place your subtext here");
}
}

 

P.S. i haven't tested this but it should work.

P.P.S you don't need the onItemPickup part now

Link to comment
Share on other sites

yeah Ive seen that before. The problem is HOW do I use that? Ive tried it a few times now and it just doesnt do anything like the function is never called. So how do I make it actually work?

 

EDIT: Ok wtf? I just added it to my item exact copy/paste from your reply and it works fine. I coulda solved this a week ago but I swear the exact same function didnt work then when I was searching!

Link to comment
Share on other sites

you probably forgot to put the @SideOnly part

thats prolly exactly what it was. None of the other results talkin about it included that. Thanks for helpin me figure it out hopefully this can help anyone else that runs into the same issue!

definitely not a source of the problem. I'm using this code and it's working fine (it has no SideOnly annotation):

    @Override
    public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
        if (info != null) par3List.add(info);
    }

-----

if you'd want to add tags and use them for showing text I'd done it like this (in a real version there would be more checks present):

    public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
        par3List.add(par1ItemStack.getTagCompound().getString("myTitle"));
    }

and NBT would be set in drop event of a monster (if you're generating drops from mobs than you can easily add a tag to generated ItemStack). don't know about trades, haven't done anything with villagers, but I'd expect that you'll be creating your items for them as well.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.