> For the complete documentation index, see [llms.txt](https://frinn.gitbook.io/custom-machinery-1.21/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://frinn.gitbook.io/custom-machinery-1.21/mod-integrations/kubejs/recipes/item-transform.md).

# Item transform

Use the item transform requirement in a KubeJS recipe

**Use one of these methods to add an** [**Item transform requirement**](/custom-machinery-1.21/recipes/requirements/item-transform.md) **to the recipe.**

```javascript
.transformItem(input, output)
.transformItem(input, output, inputSlots, outputSlots)
.transformItem(input, output, inputSlots, outputSlots, "transform")
```

* The `input`\` and \``output` param must be a SizedIngredient created using one of the following syntax:&#x20;
  * String syntax : `"diamond"` or `"botania:pure_daisy"` or `"4x mekanism:osmium_ingot"`
  * Tag string syntax : `"#c:stones"` or `"3x #c:stones`
  * &#x20;`Item.of()` KubeJS method : `Item.of("minecraft:diamond", 42, components)`
* The `inputSlot` and `outputSlot` params must be a string or array of strings corresponding to a slot id defined in a custom machine json [Item Component](/custom-machinery-1.21/creating-custom-machines/machine-components/item-component.md) `slot` property.\
  If omitted, the recipe will input/output from/to any available slots.
* The `transform` param must be a string referencing an existing `CustommachineryEvent.transformItem("transform", event ⇒ {})`  \
  See more below.

### Using the transform item event

If the `transform` string param is set in the transform item requirement (from either JSON or KubeJS) you can use a KubeJS event to apply transformations to the output item.

This can be used to change the item, its count and/or its NBT.

```javascript
CustommachineryEvents.transformItem("transform", event => {
  let machine = event.machine
  let recipe = event.context.recipe
  let input = event.input
  let originalOutput = event.originalOutput
  
  //Do your things

  //Use event.cancel() to return early without modifying the output item

  //Return another item stack as output
  //If event.success is never used the recipe will keep its original output
  event.success("3x diamond")
})
```

### Example

```javascript
ServerEvents.recipes(event => {

  event.recipes.custommachinery.custom_machine("custommachinery:power_crusher", 100)
  //Transform any stone into 2 gravels
  .transformItem("#c:stones", "2x gravel"))
  //Transform a stone axe in "input1" slot into an iron axe in either "output1" or "output2" slots
  //The NBT of the stone axe (like enchantments) will be put on the iron axe
  .transformItem("stone_axe", "iron_axe", "input1", ["output1", "output2"])
  //Transform a stone into coal
  //In the event we change the output to be a stack of diamond instead of 1 coal
  .transformItem("stone", "coal", [], [], "diamond")
})

CustommachineryEvents.transformItem("diamond", event => {
  event.success("64x diamond")
})
```
