So in kubejs there is <Ingredient>.tag that returns the tag of a given Ingredient. So Ingredient.of("#minecraft:coals").tag would give you "minecraft:coals". Though if you now add a count to this either through Ingredient.of("10x #minecraft:coals") or Ingredient.of("#minecraft:coals", 10) this will return undefined. Is there anything obvious I'm missing here or is there a better way to get the tag that works with counts? Thanks!
#.tag returns undefined if given an Ingredient with a count > 1
13 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
??xy
The XY problem is when you really want to do X, and you think that Y can achieve X. However, you can't get Y to work, and so ask for help exclusively about Y.
This can lead to a lot of confusion from the people trying to help you, as Y can seem like a very random thing to want to do, and a lot of the time isn't the best way to achieve X anyway.
Its fine to ask about Y, just always include some context about X so you can be put on the right track if Y won't do X well, or there is an easier way to do X.
If you want to know why I need this, there are some stupid mods out there that error with recipe creation if there are given a json as in or output with count (e.g. {item: "minecraft:stone", count: 2} would error) this also is needed as some mods always require the following syntax: {ingredient:{item:"minecraft:coal"},count:2} which doesn't get generated if count is 1. And I'm making functions that handle all of this wierd stuff
OK, so you're wanting KubeJS to generate JSON instead of using a KubeJS custom recipe which already handles JSON?
I'm using custom recipes. I'm creating functions that make it easier creating new recipes, cause event.custom can get pretty long ann my main problem is that some mods want to be different and error if given something generated by kubejs. That's why I need to make workarounds that work always.
for example i've made this piece of code:
function ingredientOfNoCount(item) {
let ingredient = Ingredient.of(item)
let json = item.substring(0, 1)==="#" ? {tag: ingredient.tag} : {item: ingredient.id}
if (ingredient.getNbt()!=null) json["nbt"] = ingredient.getNbt()
if (!isNaN(ingredient.getChance())) json["chance"] = ingredient.getChance()
return json
}```
that's should basically be ingredient.of() and give a json just without the count. Again, this is needed cause SOME MODS don't like the count in thier jsons. Don't ask me why they just don't. the problem now is if someone enters a count and tag as .tag will return undefined. Yes i know i could make another custom function to also hande this. But it is always nicer if there is a kubejs way to do so.
I think I understand, but in that case it's beyond my knowledge. Hopefully someone else on the server will be better able to help you.
ok, thanks anyway.
also, i just noticed this function would generally not work and would rather need to use ingredient.tag!==undefined to detect if it should use tag or item. though this would also error if it's given a count. Aaaahhh help
try maybe .withCount(0).tag
yeah, you're right i can just use .withCount(1) which works as said in the title. And then it isn't saved in the ingredient, so i can get the count. Could have figured that Out myself. Thanks!