#Convert fluid ingredient to Json element?

102 messages · Page 1 of 1 (latest)

wary kite
#

I'm trying to replace one of the ingredients in a recipe with a fluid, but the ingredient JSON array only accept JSON elements. How do I convert {fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4} to a JSON element?

cosmic vaultBOT
#

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

fallow berry
#

isn't that a json element tho?

wary kite
#

it says the choice of method matching argument types is "ambiguous"

#

it wants me to either add a String or a JsonElement

fallow berry
#

well

#

add it as a string

wary kite
#

how do I do that?

fallow berry
#

so like:

`{fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4}`
fallow berry
wary kite
#

bc there's a math expression there

fallow berry
#

well

wary kite
#

FULL_BUCKET_AMOUNT is an integer

fallow berry
#

do you know how to use string templates?

wary kite
#

?

fallow berry
#

basically

#

those are a special kind of string

wary kite
#

also the quotes cancel out

fallow berry
#

wrapped in ` instead of any other quotes

wary kite
#

oh

fallow berry
#

which can contain variables inside of them

#

it's basically string concatinating but it looks better

#

and it also can be used as a normal string

wary kite
#

I'm very confused

#

so if I were to console.log('2+2')

fallow berry
#

no

#

well

#

it would just be '2+2'

wary kite
#

I have an expression in the string

#

do I concatenate it in?

fallow berry
#

and it's wrapped in the wrong quotes

#

it would have to be:

console.log(`${2+2}`)
#

and ⬆️ would result 4

#

although please don't do that

#

either way

#
`{fluid:"kubejs:tomato_sauce_fluid", amount: ${FULL_BUCKET_AMOUNT/4}}`

⬆️ should work

wary kite
#

ok lemme run it

wary kite
#

how do I turn it to a normal string?

fallow berry
wary kite
fallow berry
#

try:

"{fluid:\"kubejs:tomato_sauce_fluid\", amount: "+FULL_BUCKET_AMOUNT/4+"}"
wary kite
#

lemme make sure I saved file

#

@fallow berry same error

fallow berry
#

try .toString()ing it raha

wary kite
#

String.toString()

#

this is getting more and more convoluted

wary kite
#

good news

#

it's now saying it's a different class

lunar gust
#

tried JSON.stringify()?

#

by default

{fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4}
``` is JS, so to convert it to JSON, use 
```js
JSON.stringify({fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4})
wary kite
#

checking rn

wary kite
fallow berry
fallow berry
#

makes sense

lunar gust
#

sometimes .toJson() would also fit

wary kite
#

will try .toJson

#

how do I try it?

#

@lunar gust

#

Intellisense isn't giving me guidance

lunar gust
#

my bad, toJson won't work for your case

#

can you give me fuller code example to try it out?

wary kite
# lunar gust can you give me fuller code example to try it out?
let inputItems = recipe.json.get("ingredients");
for (let i = 0; i < inputItems.size(); i++) {
            
        if (Ingredient.of(inputItems.get(i)).getFirst() == ("farmersdelight:tomato_sauce")) {
                console.log("replacing tomato sauce")
                inputItems.remove(i);
                inputItems.add({fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4});
                break;
}
}```
#

basically it goes through the ingredient list

#

so since this turns cooking pot recipes into create mixing with a fluid output

#

it looks for tomato sauce and replaces it with the fluid version

lunar gust
#

because your tomato sauce was added as a bucket?

wary kite
#

as a fluid

lunar gust
#

you're trying to replace it to fluid

wary kite
#

this ingredient list is used for a create mixing recipe

lunar gust
#

from what

wary kite
#
    event.forEachRecipe({type:"farmersdelight:cooking"}, recipe => {
        let outputItem = recipe.getOriginalRecipeResult().getId().split(":")[1];
        let inputItems = recipe.json.get("ingredients");
        if(outputItem=="cabbage_rolls") return; //too few ingredients to add recipe for

        let containers = {
            "minecraft:glass_bottle": [ "hot_cocoa","apple_cider"],
            "minecraft:pumpkin": ["stuffed_pumpkin_block"],
            "#c:dough": ["dumplings"]
        };

        let container = Object.keys(containers).find(key => containers[key].includes(outputItem)) ?? "minecraft:bowl";
        console.log(inputItems)
        for (let i = 0; i < inputItems.size(); i++) {
            
        if (Ingredient.of(inputItems.get(i)).getFirst() == ("farmersdelight:tomato_sauce")) {
                console.log("replacing tomato sauce")
                inputItems.remove(i);
                inputItems.add({fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4});
                break;
        } else {
            Ingredient.of(inputItems.get(i)).getFirst().getTags().forEach( tag => {
                if(tag=="c:dough") inputItems.remove(i); //removes dough from dumpling recipe
            });
        }
            
        }
        console.log(inputItems)
        event.recipes
            .createMixing({ fluid: "kubejs:" + outputItem + "_fluid", amount: FULL_BUCKET_AMOUNT/4 }, inputItems)
            .heatRequirement("heated")
            .processingTime(100);

        event.recipes
            .createFilling(recipe.getOriginalRecipeResult(), [
            container,
            { fluid: "kubejs:" + outputItem + "_fluid", amount: FULL_BUCKET_AMOUNT/4 },
        ]);
    });  
    
}```
#

this is the full thing

wary kite
#

and I want to replace that ingredient with a fluid

lunar gust
#

I'll try to recreate something like that with vanilla recipe and my custom fluid

#

and see how it goes

wary kite
#

thx

lunar gust
#

give me an event it's listening

#

@wary kite

wary kite
#
})
lunar gust
#

figured, ServerEvents.recipes for me

wary kite
lunar gust
#

1.19 works a lot different, f.e. Ingredient.of() doesn't work at all, but
I was able to simplify this change code a little bit, something like this

const FULL_BUCKET_AMOUNT = 1000;
ServerEvents.recipes (event => {
    event.forEachRecipe({type:"create:mixing"}, recipe => {
        let outputItem = recipe.getOriginalRecipeResult().getId();
        console.log(`debug111: ${outputItem}, test: ${recipe.getOriginalRecipeResult().getId()}`)
        let inputItems = recipe.json.get("ingredients");
        console.log(`debug222: ${inputItems}`)
        // for (let i = 0; i < inputItems.size(); i++) {
        event.replaceInput({ output: outputItem }, "minecraft:redstone", Fluid.of("kubejs:liquid_redstone", 250))
        console.log("debug123: replacing redstone")
        // if (inputItems.get(i) == ("forge:dusts/redstone")) {
                // inputItems.remove(i);
                // inputItems.add({fluid:"kubejs:liquid_redstone", amount: FULL_BUCKET_AMOUNT/4});
        //         break;
        // } 
    });
})

maybe it will work for you, worth trying

aside of that consider checking attached script from example-scripts, this script goes for each recipe and changes bucket of a fluid in recipes to a fluid itself, that's almost exactly what you're trying to do

edgy spearBOT
#

Paste version of container_mixing_to_fluid.js from @lunar gust

lunar gust
#

and the script is also for 1.19.2

wary kite
wary kite
#

I don't know if replaceinput works on recipes that I just made

#

just tested it

#

no work