Skip to content

Static Declaration

Custom Items are declared as MetaItem objects.

You can declare them as static to references to them later.

// provide a custom identifier
new MetaItem.Builder(new Identifier("foo:custom_item")).build()

It is highly recommended to create a such registry to register all your items.

public class ItemRegistry {
@Getter
private static final Registry<MetaItem> ITEMS = new Registry<>(MetaItem.class);
// Registry<>#register passes the MetaItem inputed to its output
public static final MetaItem CUSTOM_ITEM = ITEMS.register(
new MetaItem.Builder(new Identifier("foo:custom_item")).build()
);
}

The MinecraftProject object you created can then register that ITEMS registry directly.

// create a project
MinecraftProject project = new MinecraftProject(NAME, VERSION, ID);
// register the registry and compile
project.register(ItemRegistry.getITEMS());
project.compile(...);

Learn more on the data components page.

new MetaItem.Builder(new Identifier("foo:custom_item"))
.withComponent(VanillaItemComponent.ITEM_MODEL, new Identifier("foo:custom_item"))
.build()