Skip to content

Commit

Permalink
added method for recipe ingredient that uses multiple tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Dec 13, 2023
1 parent 3640171 commit f27356a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.latvian.mods.kubejs.item.ItemStackJS;
import dev.latvian.mods.kubejs.item.ingredient.IngredientJS;
import dev.latvian.mods.kubejs.item.ingredient.IngredientStackJS;
import dev.latvian.mods.kubejs.item.ingredient.MatchAnyIngredientJS;
import dev.latvian.mods.kubejs.recipe.RecipeJS;
import dev.latvian.mods.kubejs.util.ListJS;
import dev.latvian.mods.kubejs.util.MapJS;
Expand Down Expand Up @@ -138,7 +139,16 @@ public static JsonElement serializeStack(FluidHolder stack) {

@Override
public @Nullable JsonElement serializeIngredientStack(IngredientStackJS in) {
JsonElement element = in.ingredient.toJson();
JsonElement element;
if (in.ingredient instanceof MatchAnyIngredientJS js){
var object = new JsonObject();
JsonArray array = new JsonArray();
js.ingredients.forEach(i -> array.add(i.toJson()));
object.add("values", array);
element = object;
} else {
element = in.ingredient.toJson();
}
if (element instanceof JsonObject object && in.getCount() > 1){
object.addProperty(in.countKey, in.getCount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ public static RecipeIngredient of(TagKey<Item> tagIn, int count) {
return new RecipeIngredient(new RecipeValue(tagIn, count));
}

@SafeVarargs
public static RecipeIngredient of(int count, TagKey<Item>... tagIn) {
for (TagKey<Item> itemTagKey : tagIn) {
ensureRegisteredTag(itemTagKey.location());
}
return new RecipeIngredient(new MultiValue(Arrays.stream(tagIn).map(t -> new RecipeValue(t, count))));
}

public static RecipeIngredient ofObject(Object object, int amount){
if (object instanceof TagKey tag){
return of(tag, amount);
Expand Down

0 comments on commit f27356a

Please sign in to comment.