62 lines
2.7 KiB
Java
62 lines
2.7 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package net.minecraft.data.recipes;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
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.Holder;
|
|
import net.minecraft.data.recipes.RecipeCategory;
|
|
import net.minecraft.data.recipes.RecipeOutput;
|
|
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;
|
|
import net.minecraft.world.item.equipment.trim.TrimPattern;
|
|
|
|
public class SmithingTrimRecipeBuilder {
|
|
private final RecipeCategory category;
|
|
private final Ingredient template;
|
|
private final Ingredient base;
|
|
private final Ingredient addition;
|
|
private final Holder<TrimPattern> pattern;
|
|
private final Map<String, Criterion<?>> criteria = new LinkedHashMap();
|
|
|
|
public SmithingTrimRecipeBuilder(RecipeCategory category, Ingredient template, Ingredient base, Ingredient addition, Holder<TrimPattern> pattern) {
|
|
this.category = category;
|
|
this.template = template;
|
|
this.base = base;
|
|
this.addition = addition;
|
|
this.pattern = pattern;
|
|
}
|
|
|
|
public static SmithingTrimRecipeBuilder smithingTrim(Ingredient template, Ingredient base, Ingredient addition, Holder<TrimPattern> pattern, RecipeCategory category) {
|
|
return new SmithingTrimRecipeBuilder(category, template, base, addition, pattern);
|
|
}
|
|
|
|
public SmithingTrimRecipeBuilder unlocks(String name, Criterion<?> criterion) {
|
|
this.criteria.put(name, criterion);
|
|
return this;
|
|
}
|
|
|
|
public void save(RecipeOutput output, ResourceKey<Recipe<?>> 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);
|
|
SmithingTrimRecipe recipe = new SmithingTrimRecipe(this.template, this.base, this.addition, this.pattern);
|
|
output.accept(id, recipe, advancement.build(id.identifier().withPrefix("recipes/" + this.category.getFolderName() + "/")));
|
|
}
|
|
|
|
private void ensureValid(ResourceKey<Recipe<?>> id) {
|
|
if (this.criteria.isEmpty()) {
|
|
throw new IllegalStateException("No way of obtaining recipe " + String.valueOf(id.identifier()));
|
|
}
|
|
}
|
|
}
|
|
|