Skip to content

Commit 6eeb8c2

Browse files
authored
Custom Recipe Modifiers through KubeJS (#3937)
1 parent 4ddae69 commit 6eeb8c2

2 files changed

Lines changed: 101 additions & 3 deletions

File tree

docs/content/Modpacks/Ore-Generation/Bedrock-Fluid-Veins.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ Bedrock Fluid Veins are invisable veins that exist under the bedrock, to find Fl
1414
GTCEuServerEvents.fluidVeins(event => {
1515

1616
event.add('gtceu:custom_bedrock_fluid_vein', vein => {
17-
vein.addSpawnDimension('minecraft:overworld')
18-
vein.fluid(() => Fluid.of('gtceu:custom_fluid').fluid)
17+
vein.dimensions('minecraft:overworld') // (1)
18+
vein.fluid(() => Fluid.of('gtceu:custom_fluid').fluid)
1919
vein.weight(600)
2020
vein.minimumYield(120)
2121
vein.maximumYield(720)
2222
vein.depletionAmount(2)
2323
vein.depletionChance(1)
2424
vein.depletedYield(50)
2525
});
26+
});
2627

27-
```
28+
```
29+
30+
1. Dimension where fluid vein will spawn.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: Custom Recipe Modifiers
3+
---
4+
5+
# Custom Recipe Modifiers / Data Logic
6+
7+
## Adding a Modifier
8+
Custom recipe modifiers in KubeJS are done through a function. For this example, we will make multiblock that requires temperature for recipes, like the EBF does.
9+
```js title="temperature_recipe_modifier.js"
10+
const $GTRecipe = Java.loadClass("com.gregtechceu.gtceu.api.recipe.GTRecipe");
11+
const $MetaMachine = Java.loadClass("com.gregtechceu.gtceu.api.machine.MetaMachine");
12+
13+
function TemperatureModifier(machine, recipe) {
14+
if (!(machine instanceof $MetaMachine)) return ModifierFunction.NULL // (1)
15+
if (!(recipe instanceof $GTRecipe)) return ModifierFunction.NULL
16+
17+
if (!machine instanceof $CoilWorkableElectricMultiblockMachine) {
18+
return $RecipeModifier.nullWrongType($CoilWorkableElectricMultiblockMachine, machine);
19+
} else {
20+
21+
let temp = machine.getCoilType().getCoilTemperature() // (3)
22+
23+
let recipeTemp = recipe.data.getInt("RequiredTemp") // (4)
24+
if (recipeTemp > temp) {
25+
return ModifierFunction.NULL
26+
}
27+
return ModifierFunction.IDENTITY // (2)
28+
}
29+
}
30+
```
31+
32+
1. `ModifierFunction.NULL` Stops recipe.
33+
2. `ModifierFunction.IDENTITY` Starts recipe.
34+
3. Getting the coil temperature, multiblock **must** contain ``.heatingCoils()`` in any of its keys.
35+
4. Checking if coil temperature is high enough.
36+
37+
## Using Modifier
38+
```js title="example_temperature_multiblock.js"
39+
const $CoilWorkableElectricMultiblockMachine = Java.loadClass("com.gregtechceu.gtceu.api.machine.multiblock.CoilWorkableElectricMultiblockMachine");
40+
41+
GTCEuStartupEvents.registry('gtceu:recipe_type', event => {
42+
event.create('example_smelting')
43+
.category('multiblock')
44+
.setMaxIOSize(1, 1, 0, 0)
45+
.setProgressBar(GuiTextures.PROGRESS_BAR_FUSION, FillDirection.LEFT_TO_RIGHT)
46+
.setSound(GTSoundEntries.BATH);
47+
});
48+
49+
GTCEuStartupEvents.registry('gtceu:machine', event => {
50+
51+
GTRecipeTypes.get("example_smelting").addDataInfo((data) => (
52+
`Temperature: ${data.getInt("RequiredTemp")}K` // (4)
53+
)) // (3)
54+
55+
event.create('example_smelter', 'multiblock')
56+
.rotationState(RotationState.NON_Y_AXIS)
57+
.machine((holder) => new $CoilWorkableElectricMultiblockMachine(holder)) // (1)
58+
.recipeType('alchemy')
59+
.recipeModifiers([(machine, recipe) => TemperatureModifier(machine, recipe)]) // (2)
60+
.appearanceBlock(() => Block.getBlock("gtceu:solid_machine_casing"))
61+
.pattern(definition => FactoryBlockPattern.start()
62+
.aisle('###','HHH','###')
63+
.aisle('###','H H','###')
64+
.aisle('#C#','HHH','###')
65+
.where('C', Predicates.controller(Predicates.blocks(definition.get())))
66+
.where('#', Predicates.blocks("gtceu:solid_machine_casing")
67+
.or(Predicates.abilities(PartAbility.IMPORT_ITEMS).setPreviewCount(1))
68+
.or(Predicates.abilities(PartAbility.EXPORT_ITEMS).setPreviewCount(1))
69+
.or(Predicates.abilities(PartAbility.INPUT_ENERGY).setMaxGlobalLimited(1).setPreviewCount(1)))
70+
.where('H', Predicates.heatingCoils())
71+
.where(' ', Predicates.any())
72+
.build())
73+
.workableCasingModel("gtceu:block/casings/solid/machine_casing_solid_steel", "gtceu:block/multiblock/blast_furnace")
74+
})
75+
```
76+
77+
1. Making multiblock **coilMachine**, without it our modifier won't work.
78+
2. Using our modifier.
79+
3. Display our data in EMI.
80+
4. Getting `RequiredTemp` data from our recipe.
81+
82+
## Using our Modifier in a Recipe
83+
To use our modifier in recipe, you need to add data to it.
84+
```js title="example_smelting.js"
85+
ServerEvents.recipes(event => {
86+
event.recipes.gtceu.example_smelting('example:diamondirt')
87+
.itemInputs('minecraft:dirt')
88+
.itemOutputs('gtceu:raw_diamond')
89+
.addData("RequiredTemp", 1000) // (1)
90+
.duration(320)
91+
.EUt(GTValues.VA[GTValues.LV]);
92+
})
93+
```
94+
95+
1. Adding data to our recipe, in this situation - Temperature

0 commit comments

Comments
 (0)