#Script Improvements [Create KubeJS]
22 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Paste version of recipe_tweaks.js from @young pecan
try this example
ServerEvents.recipes(event => {
const freezingRecipe = (inputItems, resultItems) =>
event.custom({
type: 'create_dragons_plus:freezing',
ingredients: inputItems.map(i => { item: i }),
results: resultItems.map(i => { id: i })
})
freezingRecipe(['lava_bucket', 'stone'], ['bucket', 'obsidian'])
})
You have provided no namespace, I doubt that'll pass with a JSON recipe
As here strings remain strings, they aren't implicitly converted into ResourceLocations
And also, if you want to return an object from a shorthand arrow function, the braces need to be wrapped into parenthesis, otherwise JS interpreter will treat the braces as a function body
ServerEvents.recipes(event => {
const freezingRecipe = (inputItems, resultItems) =>
event.custom({
type: 'create_dragons_plus:freezing',
ingredients: inputItems.map(i => ({ item: i })),
results: resultItems.map(i => ({ id: i }))
})
freezingRecipe(['minecraft:lava_bucket', 'minecraft:stone'], ['minecraft:bucket', 'minecraft:obsidian'])
})
You can also do this like this (more verbose, but more readable for future you):
code rewritten - see below
I don't know the exact expected shape of the JSON expected, so take this with a grain of salt
How would I modify this script to allow for multiple outputs (line 18) and tag-based inputs (lines 19 and 20)
Ok, so far "multiple outputs" is solved (outputs are generally item stacks anyway, so it's OK), but "tag-based inputs" is now a challenge
OK, so it's likely that a tag ingredient is represented as {tag: tag} object
ServerEvents.recipes(event => {
const FREEZING_RECIPES = [
{
inputs: ['minecraft:lava_bucket'],
outputs: ['minecraft:bucket', 'minecraft:obsidian'],
},
{
inputs: ['#aether:freezable_pendants'],
outputs: ['aether:ice_pendant'],
},
{
inputs: ['#aether:freezable_rings'],
outputs: ['aether:ice_ring'],
},
{
inputs: ['aether:cold_aercloud'],
outputs: ['aether:blue_aercloud'],
},
{
inputs: ['aether:skyroot_leaves'],
outputs: ['aether:crystal_leaves'],
},
{
inputs: ['aether:music_disc_chinchilla'],
outputs: ['aether:music_disc_high'],
},
{
inputs: ['deep_aether:goldenleaf_berries'],
outputs: ['deep_aether:frozen_goldenleaf_berries'],
},
]
FREEZING_RECIPES.forEach(recipe => {
/** @param {string} itemString */
const toJson = itemString => (itemString.startsWith('#') ? { tag: itemString.slice(1) } : { item: itemString })
event.custom({
type: 'create_dragons_plus:freezing',
ingredients: recipe.inputs.map(toJson),
results: recipe.outputs.map(item => ({ id: item })),
})
})
})
Seems to have worked, except for the lava bucket recipe. That one only returns an empty bucket, not obsidian as well.
There's no error for KubeJS either
So I don't know what's causing the issue
Search for "failed to parse recipe" in latest.log
I don't see anything coming up for the relevant recipe. The only results are random dndesires recipes.
Paste version of latest.log from @young pecan
Hmm, does the freezing recipe even support multiple outputs?
I haven't seen any in the base mod. I'll ask the mod dev I guess
Good call