#Convert fluid ingredient to Json element?
102 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
isn't that a json element tho?
it says the choice of method matching argument types is "ambiguous"
it wants me to either add a String or a JsonElement
how do I do that?
so like:
`{fluid:"kubejs:tomato_sauce_fluid", amount: FULL_BUCKET_AMOUNT/4}`
do I concatenate the middle in?
what
bc there's a math expression there
well
FULL_BUCKET_AMOUNT is an integer
do you know how to use string templates?
?
also the quotes cancel out
wrapped in ` instead of any other quotes
oh
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
which is a normal string
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
ok lemme run it
void add(java.lang.String)
void add(com.google.gson.JsonElement)```
how do I turn it to a normal string?

is that a good or bad hmmm
try:
"{fluid:\"kubejs:tomato_sauce_fluid\", amount: "+FULL_BUCKET_AMOUNT/4+"}"
just got the same error
lemme make sure I saved file
@fallow berry same error
void add(java.lang.String)
void add(com.google.gson.JsonElement)
good news
it's now saying it's a different class
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})
checking rn
what

a String is not a String
forgot about it
sometimes .toJson() would also fit
same error
will try .toJson
how do I try it?
@lunar gust
Intellisense isn't giving me guidance
my bad, toJson won't work for your case
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
because your tomato sauce was added as a bucket?
as a fluid
you're trying to replace it to fluid
this ingredient list is used for a create mixing recipe
from what
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
currently it's an item
and I want to replace that ingredient with a fluid
I'll try to recreate something like that with vanilla recipe and my custom fluid
and see how it goes
thx
figured, ServerEvents.recipes for me
1.19?
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
Paste version of container_mixing_to_fluid.js from @lunar gust
and the script is also for 1.19.2
completely forgot why I didn't just replaceinput
does that work for you?
I don't know if replaceinput works on recipes that I just made
just tested it
no work
