package net.minecraft.data.recipes; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import net.minecraft.advancements.AdvancementRewards; import net.minecraft.advancements.Criterion; import net.minecraft.advancements.Advancement.Builder; import net.minecraft.advancements.AdvancementRequirements.Strategy; import net.minecraft.advancements.critereon.RecipeUnlockedTrigger; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.SmithingTrimRecipe; public class SmithingTrimRecipeBuilder { private final RecipeCategory category; private final Ingredient template; private final Ingredient base; private final Ingredient addition; private final Map> criteria = new LinkedHashMap(); public SmithingTrimRecipeBuilder(RecipeCategory category, Ingredient template, Ingredient base, Ingredient addition) { this.category = category; this.template = template; this.base = base; this.addition = addition; } public static SmithingTrimRecipeBuilder smithingTrim(Ingredient template, Ingredient base, Ingredient addition, RecipeCategory category) { return new SmithingTrimRecipeBuilder(category, template, base, addition); } public SmithingTrimRecipeBuilder unlocks(String key, Criterion criterion) { this.criteria.put(key, criterion); return this; } public void save(RecipeOutput output, ResourceKey> resourceKey) { this.ensureValid(resourceKey); Builder builder = output.advancement() .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(resourceKey)) .rewards(AdvancementRewards.Builder.recipe(resourceKey)) .requirements(Strategy.OR); this.criteria.forEach(builder::addCriterion); SmithingTrimRecipe smithingTrimRecipe = new SmithingTrimRecipe(Optional.of(this.template), Optional.of(this.base), Optional.of(this.addition)); output.accept(resourceKey, smithingTrimRecipe, builder.build(resourceKey.location().withPrefix("recipes/" + this.category.getFolderName() + "/"))); } private void ensureValid(ResourceKey> recipe) { if (this.criteria.isEmpty()) { throw new IllegalStateException("No way of obtaining recipe " + recipe.location()); } } }