> For the complete documentation index, see [llms.txt](https://frinn.gitbook.io/custom-machinery-1.18/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.18/mod-integrations/kubejs/recipes.md).

# Recipes

Create machine recipes using KubeJS

Custom Machine recipes can be made with KubeJS.

Create a .js file in the `kubejs/server_scripts/` folder (ex: `custom_machine_recipes.js`).

Then inside the .js file you can use the `recipes` kubejs event to get the custom machine recipe builder, pass it the id of the machine you want to make the recipe for and the duration of the recipe (in ticks).

```javascript
onEvent('recipes', event => {
  //Machine recipe : 
  event.recipes.custommachinery.custom_machine("namespace:machine_id", duration)
  //Add requirements here
  
  //Craft recipe : 
  event.recipes.custommachinery.custom_craft("namespace:machine_id", Item.of("output_item"))
  //Add requirements here
})
```

### Requirements

You can add various requirements on the custom machine recipe builder :&#x20;

{% content-ref url="/pages/xRb2L2RcQ3radS8S5BAX" %}
[Biome](/custom-machinery-1.18/mod-integrations/kubejs/recipes/biome.md)
{% endcontent-ref %}

{% content-ref url="/pages/cLdRMbbU6iUXFsTc4QSM" %}
[Block](/custom-machinery-1.18/mod-integrations/kubejs/recipes/block.md)
{% endcontent-ref %}

{% content-ref url="/pages/ScvrxuxRz6hNrYNC9BW0" %}
[Chemical (Mekanism)](/custom-machinery-1.18/mod-integrations/kubejs/recipes/chemical-mekanism.md)
{% endcontent-ref %}

{% content-ref url="/pages/B7zmLPtLww1C9G3n78qd" %}
[Command](/custom-machinery-1.18/mod-integrations/kubejs/recipes/command.md)
{% endcontent-ref %}

{% content-ref url="/pages/6bzXl93LxiJ68oPeK0KK" %}
[Contraption (Create)](/custom-machinery-1.18/mod-integrations/kubejs/recipes/contraption-create.md)
{% endcontent-ref %}

{% content-ref url="/pages/yOv5wj3ubuPiB5eccZHZ" %}
[Dimension](/custom-machinery-1.18/mod-integrations/kubejs/recipes/dimension.md)
{% endcontent-ref %}

{% content-ref url="/pages/ofzsDIlJUK8PhEjbuIgk" %}
[Drop](/custom-machinery-1.18/mod-integrations/kubejs/recipes/drop.md)
{% endcontent-ref %}

{% content-ref url="/pages/vTU6jXsippxn5tBAw3H2" %}
[Durability](/custom-machinery-1.18/mod-integrations/kubejs/recipes/durability.md)
{% endcontent-ref %}

{% content-ref url="/pages/ctHCgpEIMOnFd1IgSj4s" %}
[Effect](/custom-machinery-1.18/mod-integrations/kubejs/recipes/effect.md)
{% endcontent-ref %}

{% content-ref url="/pages/4xMBwO7tynFDfZUlee4T" %}
[Energy](/custom-machinery-1.18/mod-integrations/kubejs/recipes/energy.md)
{% endcontent-ref %}

{% content-ref url="/pages/WE1QXmItbEQRDet6FEmg" %}
[Entity](/custom-machinery-1.18/mod-integrations/kubejs/recipes/entity.md)
{% endcontent-ref %}

{% content-ref url="/pages/aUl8SGfVs2PsLu5Ol1Fs" %}
[Fluid](/custom-machinery-1.18/mod-integrations/kubejs/recipes/fluid.md)
{% endcontent-ref %}

{% content-ref url="/pages/KjNfi2F3MJ7ylUNf0JaF" %}
[Fuel](/custom-machinery-1.18/mod-integrations/kubejs/recipes/fuel.md)
{% endcontent-ref %}

{% content-ref url="/pages/eLKhBgnYxXmVi5aGebNA" %}
[Function](/custom-machinery-1.18/mod-integrations/kubejs/recipes/function.md)
{% endcontent-ref %}

{% content-ref url="/pages/1jq2dG10h7ytm250qDMP" %}
[Heat (Mekanism)](/custom-machinery-1.18/mod-integrations/kubejs/recipes/heat-mekanism.md)
{% endcontent-ref %}

{% content-ref url="/pages/Uzv6qkzCpsddLUNpmv40" %}
[Item](/custom-machinery-1.18/mod-integrations/kubejs/recipes/item.md)
{% endcontent-ref %}

{% content-ref url="/pages/PST3KoX0pjDuawxLgzni" %}
[Item transform](/custom-machinery-1.18/mod-integrations/kubejs/recipes/item-transform.md)
{% endcontent-ref %}

{% content-ref url="/pages/wx8zmMdi9SxPpdQc6iRK" %}
[Light](/custom-machinery-1.18/mod-integrations/kubejs/recipes/light.md)
{% endcontent-ref %}

{% content-ref url="/pages/quZuSWaXIMj1rDl28rMi" %}
[Loot table](/custom-machinery-1.18/mod-integrations/kubejs/recipes/loot-table.md)
{% endcontent-ref %}

{% content-ref url="/pages/TXIijLhro4XtorhYvPBj" %}
[Position](/custom-machinery-1.18/mod-integrations/kubejs/recipes/position.md)
{% endcontent-ref %}

{% content-ref url="/pages/7DFIU4cH5HC28gVGWcKv" %}
[Radiation (Mekanism)](/custom-machinery-1.18/mod-integrations/kubejs/recipes/radiation-mekanism.md)
{% endcontent-ref %}

{% content-ref url="/pages/iDSU4a8pNuIl5CP0GKo0" %}
[Redstone](/custom-machinery-1.18/mod-integrations/kubejs/recipes/redstone.md)
{% endcontent-ref %}

{% content-ref url="/pages/ZIrxc35OtmuurP8dpk4O" %}
[Sky](/custom-machinery-1.18/mod-integrations/kubejs/recipes/sky.md)
{% endcontent-ref %}

{% content-ref url="/pages/UlO5WTWnHGzWkOpRKKyI" %}
[Structure](/custom-machinery-1.18/mod-integrations/kubejs/recipes/structure.md)
{% endcontent-ref %}

{% content-ref url="/pages/Op8eUWeLBOUnQSSSv2Za" %}
[Time](/custom-machinery-1.18/mod-integrations/kubejs/recipes/time.md)
{% endcontent-ref %}

{% content-ref url="/pages/GIYShj9Qy0YHfUaPwhAg" %}
[Weather](/custom-machinery-1.18/mod-integrations/kubejs/recipes/weather.md)
{% endcontent-ref %}

### Requirements special properties

Some requirements (almost all) have various properties that can change its behavior.

To set these properties you must call one or several of the methods below **immediately after** the desired requirement. The properties will only be applied on the latest added requirement when the method is called.

If the latest added requirement doesn't support the property an error will be logged and nothing will happen (the property will be ignored).

<details>

<summary>Chance</summary>

**Use this method to add a `chance` property to the latest added requirement.**

```javascript
.chance(chance)
```

* The `chance` param must be a double between 0.0 and 1.0 included.

**Supported requirements :**

* Block
* Command
* Drop
* Durability
* Effect
* Energy
* Energy Per Tick
* Entity
* Fluid
* Fluid Per Tick
* Function
* Item

</details>

<details>

<summary>Delay</summary>

**Use this method to set a delay for the requirement action.**

The requirement will only execute its action after the specified delay.

```javascript
.delay(delay)
```

* The `delay` param must be a double between 0.0 and 1.0 excluded. 0 represent the start of the recipe and 1 represent its end.

**Supported requirements :**

* Block
* Command
* Drop
* Effect
* Entity
* Function

</details>

### Priority

Use the method below to set the priority of the recipe.

If this method is called several times only the latest will be used.

If this is called **AFTER** `.jei()` (no need to be immediatly after) this will act as the "jeiPriority" instead, defining the priority of the recipe to show in jei instead of the priority to be checked in the machine.

If no priority is set, the default value : `0` will be used.

```javascript
.priority(priority)
```

* The `priority` param must be an integer value.

### Jei

If the method below is called, all requirements added after that will be added to the `jei` property requirement list.

```javascript
.jei()
```

This action cannot be inverted, you must add all your recipe requirements before calling it.

Requirements added after this method will only be displayed in jei but not executed by the machine. Learn more [here](https://github.com/Frinn38/Custom-Machinery/wiki/Recipes#jei-optional).

### Reset on error

If the method below is called, the recipe will reset the machine instead of erroring when a requirement throw an error.

```javascript
.resetOnError()
```

Note : When the machine is reset its inventory remains the same, but all already consumed inputs are lost.

### Hide in JEI

Call the following method anywhere in your recipe builder to make the recipe hidden in JEI.

The recipe will still work in the machine but won't show in JEI.

```javascript
.hide()
```

### Examples :

<details>

<summary>Example 1</summary>

**A 100 tick recipe that use 5mB of water, 5mB of any fluid with tag lava and 20FE per tick to create a stone.**

```javascript
onEvent('recipes', event => {

  event.recipes.custommachinery.custom_machine("custommachinery:stone_generator", 100)
  .requireFluid(Fluid.of("minecraft:water", 5))
  .requireFluidTag("#minecraft:lava", 5)
  .requireEnergyPerTick(20)
  .produceItem(Item.of("minecraft:stone", 1))
})
```

![example\_recipe\_1](https://github.com/Frinn38/Custom-Machinery/raw/1.16.5/wiki/example_recipe_1.png)

</details>

<details>

<summary>Example 2</summary>

**A 200 tick recipe that use 1 item with tag stone and 20FE per tick to create 1 cobblestone, 1 gravel with 50% chance and 1 sand with 10% chance.**

```javascript
onEvent('recipes', event => {

  event.recipes.custommachinery.custom_machine("custommachinery:power_crusher", 200)
  .requireItemTag("#forge:stone", 1)
  .requireEnergyPerTick(20)
  .produceItem(Item.of("minecraft:cobblestone", 1))
  .produceItem(Item.of("minecraft:gravel", 1)).chance(0.5)
  .produceItem(Item.of("minecraft:sand", 1)).chance(0.1)
})
```

![example\_recipe\_2](https://github.com/Frinn38/Custom-Machinery/raw/1.16.5/wiki/example_recipe_2.png)

</details>
