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

# Upgrades

Custom Machine upgrades can be made with KubeJS script.

Create a .js file in the `kubejs\server_scripts` folder (ex: custom\_machine\_upgrades.js) and look at the example below to see all the available methods to create a Custom Machine upgrade with KubeJS.

If you're not familiar about custom machine upgrades see [the wiki page](/custom-machinery-1.16/recipes/upgrades.md).

### Creating custom machine upgrade with KubeJS

{% hint style="info" %}
Find all requirement types and targets that can be modified [here](/custom-machinery-1.16/recipes/upgrades/modifiers.md#list-of-properties-that-can-be-modified).
{% endhint %}

```javascript
//Use the 'cm_upgrades' event to register custom machine upgrades.
onEvent('cm_upgrades', event => {

//Create an upgrade from the item you want, ex: vanilla diamond.
//You must also specify the max amount of this upgrade the machine can accept, ex: 64.
//Syntax: event.create(Item.of("item_id"), maxAmount)
event.create(Item.of('minecraft:diamond'), 64)

//Add a machine that can accept this upgrade, you can use this method several times to add differents machines.
//You MUST specify at least one machine or the upgrade will not be created and an error will be thrown.
//Syntax: .machine("machine_id")
.machine("custommachinery:power_crusher")

//You can add a custom tooltip to the machine upgrade item.
.tooltip('Ultra booster MK3')

//Add various requirement modifiers using the methods below.

//Add an addition modifier for all input requirements of type: "requirement_id".
//"target" is for specifying  a specific property of the requirement, ex: "chance" to modify the "chance" property of requirements that have this property.
//chance is a value between 0.0 and 1.0 that define the chance of the modifier to be applied.
.addInput("requirement_id", value)
.addInput("requirement_id", value, "target")
.addInput("requirement_id", value, chance)
.addInput("requirement_id", value, "target", chance)

//Add a multiplication modifier for all input requirements of type: "requirement_id".
//"target" is for specifying  a specific property of the requirement, ex: "chance" to modify the "chance" property of requirements that have this property.
//chance is a value between 0.0 and 1.0 that define the chance of the modifier to be applied.
.mulInput("requirement_id", value)
.mulInput("requirement_id", value, "target")
.mulInput("requirement_id", value, chance)
.mulInput("requirement_id", value, "target", chance)

//Add an addition modifier for all output requirements of type: "requirement_id".
//"target" is for specifying  a specific property of the requirement, ex: "chance" to modify the "chance" property of requirements that have this property.
//chance is a value between 0.0 and 1.0 that define the chance of the modifier to be applied.
.addOutput("requirement_id", value)
.addOutput("requirement_id", value, "target")
.addOutput("requirement_id", value, chance)
.addOutput("requirement_id", value, "target", chance)

//Add a multiplication modifier for all output requirements of type: "requirement_id".
//"target" is for specifying  a specific property of the requirement, ex: "chance" to modify the "chance" property of requirements that have this property.
//chance is a value between 0.0 and 1.0 that define the chance of the modifier to be applied.
.mulOutput("requirement_id", value)
.mulOutput("requirement_id", value, "target")
.mulOutput("requirement_id", value, chance)
.mulOutput("requirement_id", value, "target", chance)
})
```

### Examples

A gold ingot put inside the Power Crusher will double it's energy consumption but also half it's duration time.

```javascript
onEvent('cm_upgrades', event => {
    event.create(Item.of('minecraft:gold_ingot'), 64)
    .machine("custommachinery:power_crusher")
    .mulInput('custommachinery:energy', 2)
    .mulInput('custommachinery:speed', 1.5)
})
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://frinn.gitbook.io/custom-machinery-1.16/mod-integrations/kubejs/upgrades.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
