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

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

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.

  • 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

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

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.