#RecipeJS equivalent for getOriginalRecipeResult() with multiple results?

52 messages · Page 1 of 1 (latest)

cosmic anchor
#

I'm trying to get the result items from a recipe, but the recipe has multiple resulting items, and getOriginalRecipeResult only returns one item. Is there an equivalent function for multiple items?

winter perchBOT
#

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

opaque yacht
#

i thought it returned an array, am i wrong? have you tried using console.log on the recipe result function?

vivid stump
#

it's pretty much a function built around vanilla recipes, which don't have multiple outputs... you can check outputItems, or parse the json manually

cosmic anchor
#

A normal string would have no single quotes around it in console

cosmic anchor
#

that method returns null

opaque yacht
#

with normal JS and kubejs, parsing JSON in it can use single quotes, but for your case i'm assuming you can just remove the quotes using a function

vivid stump
#

well then you'd have to go by the json anyways.... give me more context on what you're trying to do and what you're trying to parse

opaque yacht
#

i forgot the function to remove parts of a string tohugh

cosmic anchor
#

removing the quotes makes the items strings

#

and strings don't work for making recipes iirc

fair seal
#

You can pass it to Ingredient.of

#

Ingredient.of(recipe.json.get('results'))

opaque yacht
#

i mean, were you doing

console.log(thing)

or

console.log(`${thing}`)
opaque yacht
#

hm

round kraken
cosmic anchor
opaque yacht
#

oh yeah slice

round kraken
#

normal js thing for strings

opaque yacht
#

i don't understand

cosmic anchor
#

using a string method will result in errors

#

and passing in strings doesn't seem to work anyways for recipe creation

opaque yacht
#

us not knowing the errors doesn't help

cosmic anchor
#

It's not a string

#

and I've already tried doing it the way you suggested

#

doesn't work

opaque yacht
#

that's weird

cosmic anchor
#

because the parameters for recipe creation methods actually don't use strings

round kraken
#

do String(thing).slice(1, -1)

cosmic anchor
#

because you passed strings into it by doing .toString()

#

you have to pass in ingredients or items

#

Error occurred while handling event 'recipes': Wrapped java.lang.NullPointerException: Cannot invoke "dev.latvian.mods.kubejs.recipe.RecipeTypeJS.getId()" because "this.type" is null

#

also error

#

although lemme check if that's on me

#

but this one does happen because you turned it to a string iirc

#

also you turned "Item.of()" to "tem.of(" by slicing it

fair seal
#

What are you actually trying to do? and what is your current code?

cosmic anchor
#
    
    event.forEachRecipe({type:"farmersdelight:cutting"}, recipe => {
        let recipeJson = recipe.json;
        let item = recipe.getOriginalRecipeIngredients()[0].getFirst().toString().slice(1,-1);
        
        console.log(item);
        let reciperesults = recipeJson.get("result");
        let parsedResults = [];
        reciperesults.forEach((output) => {
            console.log(output);
                parsedResults.push(Ingredient.of(output.get("item")).toString().slice(1,-1));
        });
        console.log(parsedResults);
        console.log("event.recipes.createCutting(" + parsedResults + ", " + item + ");")
        let r = event.recipes
            .createCutting(parsedResults, item);
        console.log(r);
        console.log(r.json);
    })```
#

current code

fair seal
#

You don't need to parse anything, you can use the json values for recipe creation

event.forEachRecipe({type: 'farmersdelight:cutting'}, recipe => {
        event.recipes.createCutting(recipe.json.get('result'), recipe.json.get('ingredients'))
    })```
#

Doing it like this won't respect the chanced outputs though, so I would actually suggest

    event.forEachRecipe({type: 'farmersdelight:cutting'}, recipe => {
        event.custom({
            type: 'create:cutting',
            ingredients: recipe.json.get('ingredients'),
            results: recipe.json.get('result'),
            processingItem : 50
        })
    })