#Script Improvements [Create KubeJS]

22 messages · Page 1 of 1 (latest)

young pecan
#

How would I modify this script to allow for multiple outputs (line 18) and tag-based inputs (lines 19 and 20) as part of this custom recipe? I know it's possible based on the Create KubeJS documentation for custom bulk processing recipes from base Create, but I don't know how to actually make such a recipe from scratch.

graceful scrollBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

tight dustBOT
#

Paste version of recipe_tweaks.js from @young pecan

tardy void
#

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'])
})
lethal spear
#

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 })),
    })
  })
})
young pecan
#

There's no error for KubeJS either

#

So I don't know what's causing the issue

lethal spear
#

Search for "failed to parse recipe" in latest.log

young pecan
tight dustBOT
#

Paste version of latest.log from @young pecan

lethal spear
#

Hmm, does the freezing recipe even support multiple outputs?

young pecan
lethal spear
#

Good call