Custom Machine upgrades can be made with Crafttweaker.
Create a .zs file in the script folder (ex: custom_machine_upgrades.zs) and look at the example below to see all the available methods to create a Custom Machine upgrade with Crafttweaker.
If you're not familiar about custom machine upgrades see the wiki page.
Creating custom machine upgrade with Crafttweaker
//Create the upgrade builder and give it the item that will act as upgrade and the max amount of this upgrade that can be used in a machine.
mods.custommachinery.CMUpgradeBuilder.create(Item item)//If maxAmount is not specified the default is 64.mods.custommachinery.CMUpgradeBuilder.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 component for more formatting options,//See https://docs.blamejared.com/1.18/en/vanilla/api/text/Component.tooltip(Component...tooltips)//Add a modifier to this upgrade.//See below for modifier syntax..modifier(CMRecipeModifierBuilder modifier)//Finish (don't forget the semicolon ';').build();
Making a modifier
See below the various methods used to build a recipe modifier and pass it to the upgrade.
//Import the modifier builder class as a constant for convenience.importmods.custommachinery.CMRecipeModifierBuilder as Builder;//Create a modifier that add/multiply a value to any input/output requirement of the specified type.//requirement must be specified using brackets : <requirementtype:custommachinery:requirement>//Value can be any numerical value.//Pick one of the 6 methods below :Builder.addInput(requirement, value)Builder.mulInput(requirement, value)Builder.expInput(requirement, value)Builder.addOutput(requirement, value)Builder.mulOutput(requirement, value)Builder.expOutput(requirement, value)//All methods below are optional//Specify a target, in case the requirement have several values that can be modified.//Only 1 target can be defined for a modifier, default is none..target(String target)//Specify a chance for this modifier to be applied.//Must be a value between 0 and 1, 0 is never applied and 1 is 100% chance to be applied.//Default is 1..chance(double chance)//Specify the maximum value that can be obtained after applying this modifier.//It can be any numerical value.//Default is POSITIVE_INFINITY..max(double max)//Specify the minimum value that can be obtained after applying this modifier.//It can be any numerical value.//Default is NEGATIVE_INFINITY..min(double max)//Change the tooltip displayed when holding shift while hovering the upgrade item.//Default : a short string that describe the effect of this modifier..tooltip(String tooltip)//Use a component for more formating options..tooltip(Component tooltip)
Zenscript syntax
Find all requirement types and targets that can be modified here.
If not specified the target will be empty and the chance will be 1.0
CTRequirementType is specified with: <requirementtype:namespace:requirement_type_id> ex: <requirementtype:custommachinery:item>
Example
A gold ingot put inside the Power Crusher will double it's energy consumption with a maximum of 1000FE but also half its duration time with a minimum of 100 ticks.
importmods.custommachinery.CMRecipeModifierBuilder as Builder;mods.custommachinery.CMUpgradeBuilder.create(<item:minecraft:gold_ingot>).machine("custommachinery:power_crusher").modifier(Builder.mulInput(<requirementtype:custommachinery:energy>,2).max(1000)).modifier(Builder.mulInput(<requirementtype:custommachinery:speed>,0.5).min(100)).build();