# 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](https://frinn.gitbook.io/custom-machinery-1.21/recipes/upgrades).

### Creating custom machine upgrade with KubeJS

```java
//Use the 'cm_upgrades' event to register custom machine upgrades.
CustomMachineryEvents.upgrades(event => {

    //Create the upgrade builder and give it the item that will act as upgrade.
    //Use Item.of("item_id") to create the item.
    event.create(Item item)
    //If maxAmount is not specified the default is 64.
    event.create(Item item, int maxAmount)
    
    //Add a machine or a list of machines that will accept this upgrade, 
    //the machine ID must be "namespace:id" like "custommachinery:my_machine",
    //if the json is located in (my_datapack)/data/custommachinery/machines/my_machine.json
    .machine(String... machineID)
    
    //You can add a custom tooltip to the machine upgrade item.
    .tooltip(String... tooltips)
    //Use Text.of("text here") for more formatting options,
    //See https://kubejs.com/wiki/kubejs/Text/
    .tooltip(Text... tooltips)
    
    //Add a recipe modifier to this upgrade.
    .requirement(CMRecipeModifierBuilder modifier)
    
    //Add a component modifier to this upgrade.
    .component(CMRecipeModifierBuilder modifier)
    
    //Add a core modifier to this upgrade.
    .core(CMCoreModifierBuilder modifier)
})
```

{% content-ref url="upgrades/recipe-modifier" %}
[recipe-modifier](https://frinn.gitbook.io/custom-machinery-1.21/mod-integrations/kubejs/upgrades/recipe-modifier)
{% endcontent-ref %}

{% content-ref url="upgrades/component-modifier" %}
[component-modifier](https://frinn.gitbook.io/custom-machinery-1.21/mod-integrations/kubejs/upgrades/component-modifier)
{% endcontent-ref %}

{% content-ref url="upgrades/core-modifier" %}
[core-modifier](https://frinn.gitbook.io/custom-machinery-1.21/mod-integrations/kubejs/upgrades/core-modifier)
{% endcontent-ref %}

### Examples

A gold ingot put inside the Power Crusher will double it's energy consumption with a maximum of 1000FE but also half it's duration time with a minimum of 100 ticks.

```java
CustomMachineryEvents.upgrades(event => {
    event.create(Item.of('minecraft:gold_ingot'))
        .machine("custommachinery:power_crusher")
        .modifier(CMRecipeModifierBuilder.mulInput('custommachinery:energy', 2).max(1000))
        .modifier(CMRecipeModifierBuilder.mulInput('custommachinery:speed', 1.5).min(100))
})
```


---

# Agent Instructions: 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.21/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.
