#RecipeJS equivalent for getOriginalRecipeResult() with multiple results?
52 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
i thought it returned an array, am i wrong? have you tried using console.log on the recipe result function?
yes
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
parsing the JSON returns items that are always packaged in these weird single quotes
A normal string would have no single quotes around it in console
recipe isn't integrated with kubejs
that method returns null
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
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
i forgot the function to remove parts of a string tohugh
removing the quotes makes the items strings
and strings don't work for making recipes iirc
i mean, were you doing
console.log(thing)
or
console.log(`${thing}`)
first one
hm
you can use .slice(1, -1) to cut off the first and last character of a string
doesn't throw errors, but still gets packaged in weird single quotes
oh yeah slice
they're not strings
normal js thing for strings
what do you mean they're not strings
i don't understand
using a string method will result in errors
and passing in strings doesn't seem to work anyways for recipe creation
us not knowing the errors doesn't help
Error occurred while handling event 'recipes': TypeError: Cannot find function slice in object "minecraft:brown_mushroom".
It's not a string
and I've already tried doing it the way you suggested
doesn't work
that's weird
because the parameters for recipe creation methods actually don't use strings
do String(thing).slice(1, -1)
recipes still aren't generating
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
What are you actually trying to do? and what is your current code?
create a Create cutting recipe for every Farmer's Delight cutting board recipe
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
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
})
})
It works
tysm