/* * Decompiled with CFR 0.152. */ package net.minecraft.data.recipes; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; 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.registries.Registries; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.SmithingTransformRecipe; import net.minecraft.world.item.crafting.TransmuteResult; public class SmithingTransformRecipeBuilder { private final Ingredient template; private final Ingredient base; private final Ingredient addition; private final RecipeCategory category; private final Item result; private final Map> criteria = new LinkedHashMap(); public SmithingTransformRecipeBuilder(Ingredient template, Ingredient base, Ingredient addition, RecipeCategory category, Item result) { this.category = category; this.template = template; this.base = base; this.addition = addition; this.result = result; } public static SmithingTransformRecipeBuilder smithing(Ingredient template, Ingredient base, Ingredient addition, RecipeCategory category, Item result) { return new SmithingTransformRecipeBuilder(template, base, addition, category, result); } public SmithingTransformRecipeBuilder unlocks(String name, Criterion criterion) { this.criteria.put(name, criterion); return this; } public void save(RecipeOutput output, String id) { this.save(output, ResourceKey.create(Registries.RECIPE, Identifier.parse(id))); } 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); SmithingTransformRecipe recipe = new SmithingTransformRecipe(Optional.of(this.template), this.base, Optional.of(this.addition), new TransmuteResult(this.result)); 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())); } } }