Custom items

Hi! How can I distinguish one particular item stack from another? What are the ways of recording metadata that will help to identify the item stack (for example, I can use the Lore)? This is necessary to create custom items with their own behavior.

Yes you can use lore. Its all based on the heart of sponge, the Data API.

Itemstack item;
List<Text> lore = item.get(Keys.ITEM_LORE).get();

Here is the itemstack is your item (this also works on ItemSnapshots). After you modify the lore to how you want it. You need to offer it back into the item

List<Text> lore;
ItemStack item;
item.offer(Keys.ITEM_LORE, lore);

With snapshots, you cannot offer, but you can state that the item stack snapshot with a key and data

List<Lore> lore;
ItemStackSnapshot item;
item = item.with(Keys.ITEM_LORE, lore);

The with statement doesnt work in the same as offer as it doesnt apply to that object but instead creates a new object with the changes you applied.

You can read more about items in sponge here

1 Like

Well, I know that. Are there any other ways to identify items besides the Lore?

Yeah. So you can create custom data (i believe gets translated into NBT data) to store any value to anything in vanilla minecraft. pie_flavor did a really good example of how to create custom data for api 7.

And here is the official documentation for it (i personally prefer seeing live code and working it out from there, but it is really good at explaining it)