Skip to content
Lenni0451 edited this page Jan 4, 2023 · 3 revisions

To do anything with items you need to create an ItemRegistry instance and fill it with item data.

Creating an ItemRegistry

To create an ItemRegistry you first need to decied what Object your Item type is and which ItemStack wrapper you want/need to use.
ItemStack wrapper:

Wrapper Description
LegacyItemStack This wrapper implementation contains a dedicated damage as seen in older version of minecraft
ItemStack A wrapper implementation for the 'modern' ItemStack style without a dedicated item damage
ItemRegistry<Integer, LegacyItemStack<Integer>> itemRegistry = new ItemRegistry<>(LegacyItemStack::new);

In the following example Integer is used as the item type and LegacyItemStack<Integer> is used as the ItemStack wrapper.

Adding Item data

To add item data you have to use the ItemRegistry.getMeta() method.
This method returns a ItemMeta instance which holds all the data for the item:

Method Description
types Register ItemTypes like BOOTS, LEGGINGS, CHESTPLATE and HELMET
tags Register ItemTags like armor/tool material and properties like DAMAGABLE
maxCount Set the max stack size of the item
maxDamage Set the max item damage

It is recommended to register all types/tags as they are needed for inventory and recipe handling.

itemRegistry.getMeta(123)
    .types(ItemType.HELMET)
    .tags(ItemTag.DAMAGEABLE, ItemTag.MATERIAL_LEATHER)
    .maxCount(1)
    .maxDamage(321);

Creating an ItemStack

To create an ItemStack you have to use the ItemRegistry.create() methods:

  • create(Integer item)
  • create(Integer item, int count)
  • create(Integer item, int count, int damage)
  • create(Integer item, int count, CompoundTag tag)
  • create(Integer item, int count, int damage, CompoundTag tag) These methods return an ItemStack wrapper of the type you specified.

ItemStack util methods

The ItemStack base contains some util methods:

Method Description
getRepairCost() Get the repair cost of the stack (Nbt: {RepairCost:int})
setRepairCost(int) Set the repair cost of the stack
hasCustomName() Check if the stack has a custom name (Nbt: {display:{Name:string}})
getCustomName() Get the custom name or null if the stack has no name
setCustomName(string) Set the custom name of the stack
removeCustomName() Remove the custom name of the stack

All methods support stacks with a null tag and create it if needed.

Clone this wiki locally