Posted March 5, 201312 yr 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
March 5, 201312 yr 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. Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
March 6, 201312 yr Author Its not gonna be crafted tho. Its for an adventure map so mobs are gonna drop em or buy em from villagers
March 6, 201312 yr then it is even easier just use on itemPickup event to detect it. Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
March 6, 201312 yr 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
March 6, 201312 yr 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 Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
March 6, 201312 yr 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!
March 6, 201312 yr you probably forgot to put the @SideOnly part Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
March 6, 201312 yr 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!
March 6, 201312 yr 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.