Skip to main content

Item Mutator

Item mutators are a way to define reusable methods for changing items. For example, if we wanted to generate a random item, we could write it in a mutator. This way we could reuse this method or reference it in a data-driven way. For example, we could generate a random item from inside an item recipe:

Item Mutator In Recipe

Usage

Mutators have three major functions:

Can Modify Item Stack

Check whether the mutator can modify the specified item stack.

Modify Item Stack

Modify the item stack.

note

The input item stack may contain items or be empty; it's up to the individual mutator whether they allow either case.

Common reasons to use empty or non-empty item stacks:

  • Empty: You can 'generate' new items using a mutator. (Like in the example above for generating a random item).
  • Non-Empty: You can modify existing items using a mutator. E.g., 'double the item count of the input item stack'.

Estimate Item Stack Modification

Check whether it's possible to modify the item stack and estimate what the results would be. For most mutators, this will need to spawn a new item stack, making it more expensive than just 'Can Modify Item Stack'. It's reserved for when you need an exact check for the mutator's output.

This function has a few restrictions:

  • If changing the item stack's count, you must always return the maximum of your range. For example, if you're producing between 1-3 items, always return an item stack with 3 items.
  • Changing the item definition does not work with crafting components.