Jump to content

Recommended Posts

Posted

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);
  }
}

Posted

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.

Posted

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.

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.