Posted November 5, 201410 yr OK so to explain quickly what I want to do,I want to add information to items when they are crafted to say who the items owner is (for multiplayer to help prevent item stealing etc). I know how to add info to my own items but would also like it added to vanilla ones as well So I have a crafting handler set up and am trying to add the info but i'm not sure if i'm adding it right to be called (mustn't be if it isn't working). I do however know that the handler works for its other purposes so it is set up right just not the adding info part. so anyone know what i'm doing wrong with it? I'm sure it's something simple. But thanks for any help public class CraftingHandler { @SubscribeEvent public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent event) { List<String> info=new ArrayList<String>(); info.add(event.crafting.getItem().getUnlocalizedName()+ ": owned by " + event.player.getCommandSenderName()); System.out.println(info.get(0)); event.crafting.getItem().addInformation(new ItemStack(event.crafting.getItem()),event.player,info,false); } }
November 5, 201410 yr Use the NBTTagCompound in the ItemStack (ItemStack#stackTagCompound). To add to this: To show info to vanilla items, you need to - create an NBTTagList and storing each line of your info into that list - create a new NBTTagCompound and save that list with the key Lore - get the item's NBTTagCompound (or create a new one) and store the new NBTTagCompound, which contains that list, into that with the key display . If you've created a new one, store the NBT in the item. A note: it defaults to format this in dark purple and italic. If you don't want that, reset the formatting by prepending EnumChatFormatting.RESET to each of your info lines. Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
November 5, 201410 yr Author I am looking a tooltip so when the mouse rolls over it then it would display the owner under the name. But am looking into the NBT compounds now so thanks for the help guys
November 6, 201410 yr For the tooltip itself you'll have to override addInformation I know how to add info to my own items but would also like it added to vanilla ones as well So you see, overriding addInformation is not applicable in this case Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
November 6, 201410 yr If you want to change the tooltip of a vanilla item, you can use the ItemTooltipEvent . BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
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.