Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • Author

Its not gonna be crafted tho. Its for an adventure map so mobs are gonna drop em or buy em from villagers

  • Author

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

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

  • Author

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!

  • Author

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!

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.