# Recipes

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
ServerEvents.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="recipes/biome" %}
[biome](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/biome)
{% endcontent-ref %}

{% content-ref url="recipes/block" %}
[block](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/block)
{% endcontent-ref %}

{% content-ref url="recipes/chemical-mekanism" %}
[chemical-mekanism](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/chemical-mekanism)
{% endcontent-ref %}

{% content-ref url="recipes/command" %}
[command](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/command)
{% endcontent-ref %}

{% content-ref url="recipes/contraption-create" %}
[contraption-create](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/contraption-create)
{% endcontent-ref %}

{% content-ref url="recipes/dimension" %}
[dimension](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/dimension)
{% endcontent-ref %}

{% content-ref url="recipes/drop" %}
[drop](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/drop)
{% endcontent-ref %}

{% content-ref url="recipes/durability" %}
[durability](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/durability)
{% endcontent-ref %}

{% content-ref url="recipes/effect" %}
[effect](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/effect)
{% endcontent-ref %}

{% content-ref url="recipes/energy" %}
[energy](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/energy)
{% endcontent-ref %}

{% content-ref url="recipes/entity" %}
[entity](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/entity)
{% endcontent-ref %}

{% content-ref url="recipes/fluid" %}
[fluid](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/fluid)
{% endcontent-ref %}

{% content-ref url="recipes/fuel" %}
[fuel](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/fuel)
{% endcontent-ref %}

{% content-ref url="recipes/function" %}
[function](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/function)
{% endcontent-ref %}

{% content-ref url="recipes/heat-mekanism" %}
[heat-mekanism](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/heat-mekanism)
{% endcontent-ref %}

{% content-ref url="recipes/item" %}
[item](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/item)
{% endcontent-ref %}

{% content-ref url="recipes/item-transform" %}
[item-transform](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/item-transform)
{% endcontent-ref %}

{% content-ref url="recipes/light" %}
[light](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/light)
{% endcontent-ref %}

{% content-ref url="recipes/loot-table" %}
[loot-table](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/loot-table)
{% endcontent-ref %}

{% content-ref url="recipes/position" %}
[position](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/position)
{% endcontent-ref %}

{% content-ref url="recipes/radiation-mekanism" %}
[radiation-mekanism](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/radiation-mekanism)
{% endcontent-ref %}

{% content-ref url="recipes/redstone" %}
[redstone](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/redstone)
{% endcontent-ref %}

{% content-ref url="recipes/sky" %}
[sky](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/sky)
{% endcontent-ref %}

{% content-ref url="recipes/structure" %}
[structure](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/structure)
{% endcontent-ref %}

{% content-ref url="recipes/time" %}
[time](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/time)
{% endcontent-ref %}

{% content-ref url="recipes/weather" %}
[weather](https://frinn.gitbook.io/custom-machinery-1.19/mod-integrations/kubejs/recipes/weather)
{% 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>

<details>

<summary>Display info</summary>

Specify a custom requirement display info by calling the following method after a requirement :&#x20;

```javascript
.info(info => info
    //Add a new tooltip line
    .tooltip("A new tooltip")
    //This line will be displayed for creative players only
    .tooltip("Creative only", TooltipPredicate.CREATIVE)
    //This line will be displayed for players with F3+H only
    .tooltip("Advanced debug info only", TooltipPredicate.ADVANCED)
    //Use an item as icon
    .item("minecraft:diamond")
    //Use one of these 3 methods to specify a texture as icon
    .texture("texture_path")
    .texture("texture_path", width, height)
    .texture("texture_path", width, height, u, v)
    //Use a sprite as icon
    .sprite("atlas_path", "sprite_id")
)
```

Example : Add a diamond icon with a tooltip

```javascript
.info(info => info.tooltip("This recipe make diamonds").item("minecraft:diamond"))
```

![](https://2254391542-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F40ngT44k0ZSkP7lvRktf%2Fuploads%2Fp7ox4iRSpYacBioszYTC%2Fimage.png?alt=media\&token=e0ed5d15-42aa-4feb-a1b7-6547e947b2d6)

</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()
```

### Custom machine appearance

The following methods allow you to set a custom machine appearance that will be applied on the machine while this recipe is processing.

Each of the following properties are optional, just call those you need.

```javascript
.appearance(builder => builder
        .block('block_id')
        .item('item_id') //Useless
        .ambientSound('sound_id')
        .interactionSound('block_id')
        .light(light_level) //Between 0 and 15
        .color(color_integer) //Only integer color here
        .hardness(hardness) //Can be -1 for unbreakable
        .resistance(resistance)
        .tooltype('tool_type') //Must be a block tag id
        .miningLevel('mining_level') //Must be a block tag id
        .requiresTool(required) //True/False
```

### Custom machine gui

The following method allows you to add or replace some of the machine's gui elements while this recipe is processing.

```javascript
.gui([...])//Replace '...' by your gui elements.
```

Any gui element from CM and its addons can be used here.

When a machine process this recipe, all gui elements defined here will be added to the machine gui.

If a gui element defined here has the same id than another element defined in the machine json then it will replace it.

It is impossible to remove a gui element defined in the machine json, but you can replace it with an [empty gui element](https://frinn.gitbook.io/custom-machinery-1.19/creating-custom-machines/machine-gui/empty-element) instead.

#### Example :&#x20;

Change the position of a slot gui element with id "input1", and replace the gui element with id "texture" by an empty gui element :&#x20;

```javascript
.gui([
    {
        "type": "custommachinery:slot",
        "x": 10,
        "y": 10,
        "id": "input1"
    },
    {
       "type": "custommachinery:empty",
       "id": "texture"
    }
])
```

### 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
ServerEvents.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
ServerEvents.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>
