Skip to main content

ItemBuilder

ItemBuilder builds an Item. Create one with ItemBuilder.create(Identifier) and register it through BundleEvents.registry { it.items(...) }.

Creation

MethodReturnsNotes
static create(Identifier id)builderStart a new item.

Properties

MethodNotes
.stacksTo(int count)Maximum stack size.
.fireResistant()Item survives lava and fire.
.properties(UnaryOperator<Item.Properties>)Direct access to Item.Properties.
.component(DataComponentType<T>, T)Set a data component, e.g. DataComponents.RARITY.
.factory(Function<Item.Properties, Item>)Swap the item class.

Callbacks

Each callback is a functional interface; assign it with a Groovy closure.

MethodRuns
.use { level, player, hand -> ... }Right-click while holding. Return an InteractionResult.
.useOn { ... }Right-click on a block.
.inventoryTick { stack, level, owner, slot -> ... }Every tick while in an inventory.
.onUseTick { ... }While the item is being used.
.finishUsingItem { ... }After the player finishes eating or drinking.
.releaseUsing { ... }When the player lets go.
.hurtEnemy { ... } / .postHurtEnemy { ... }When the item hits an entity.
.onCraftedPostProcess { ... }After the item is crafted.

Data generation

MethodNotes
.generateData(boolean)Set false to skip JSON generation.
.tag(ItemTagBuilder) / .tag(Identifier)Add the item to a tag.

Example

def gem = ItemBuilder.create(id("magic_gem"))
.stacksTo(16)
.component(DataComponents.RARITY, Rarity.UNCOMMON)