/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.data.recipes; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementRequirements; import net.minecraft.advancements.AdvancementRewards; import net.minecraft.advancements.Criterion; import net.minecraft.advancements.criterion.RecipeUnlockedTrigger; import net.minecraft.core.HolderGetter; import net.minecraft.data.recipes.RecipeBuilder; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.ShapelessRecipe; import net.minecraft.world.level.ItemLike; import org.jspecify.annotations.Nullable; public class ShapelessRecipeBuilder implements RecipeBuilder { private final HolderGetter items; private final RecipeCategory category; private final ItemStack result; private final List ingredients = new ArrayList(); private final Map> criteria = new LinkedHashMap(); private @Nullable String group; private ShapelessRecipeBuilder(HolderGetter items, RecipeCategory category, ItemStack result) { this.items = items; this.category = category; this.result = result; } public static ShapelessRecipeBuilder shapeless(HolderGetter items, RecipeCategory category, ItemStack result) { return new ShapelessRecipeBuilder(items, category, result); } public static ShapelessRecipeBuilder shapeless(HolderGetter items, RecipeCategory category, ItemLike item) { return ShapelessRecipeBuilder.shapeless(items, category, item, 1); } public static ShapelessRecipeBuilder shapeless(HolderGetter items, RecipeCategory category, ItemLike item, int count) { return new ShapelessRecipeBuilder(items, category, item.asItem().getDefaultInstance().copyWithCount(count)); } public ShapelessRecipeBuilder requires(TagKey tag) { return this.requires(Ingredient.of(this.items.getOrThrow(tag))); } public ShapelessRecipeBuilder requires(ItemLike item) { return this.requires(item, 1); } public ShapelessRecipeBuilder requires(ItemLike item, int count) { for (int i = 0; i < count; ++i) { this.requires(Ingredient.of(item)); } return this; } public ShapelessRecipeBuilder requires(Ingredient ingredient) { return this.requires(ingredient, 1); } public ShapelessRecipeBuilder requires(Ingredient ingredient, int count) { for (int i = 0; i < count; ++i) { this.ingredients.add(ingredient); } return this; } @Override public ShapelessRecipeBuilder unlockedBy(String name, Criterion criterion) { this.criteria.put(name, criterion); return this; } @Override public ShapelessRecipeBuilder group(@Nullable String group) { this.group = group; return this; } @Override public Item getResult() { return this.result.getItem(); } @Override public void save(RecipeOutput output, ResourceKey> id) { this.ensureValid(id); Advancement.Builder advancement = output.advancement().addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(id)).rewards(AdvancementRewards.Builder.recipe(id)).requirements(AdvancementRequirements.Strategy.OR); this.criteria.forEach(advancement::addCriterion); ShapelessRecipe recipe = new ShapelessRecipe(Objects.requireNonNullElse(this.group, ""), RecipeBuilder.determineBookCategory(this.category), this.result, this.ingredients); output.accept(id, recipe, advancement.build(id.identifier().withPrefix("recipes/" + this.category.getFolderName() + "/"))); } private void ensureValid(ResourceKey> id) { if (this.criteria.isEmpty()) { throw new IllegalStateException("No way of obtaining recipe " + String.valueOf(id.identifier())); } } }