/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Lists * com.google.common.collect.Maps * org.jspecify.annotations.Nullable */ package net.minecraft.data.recipes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; 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.ShapedRecipe; import net.minecraft.world.item.crafting.ShapedRecipePattern; import net.minecraft.world.level.ItemLike; import org.jspecify.annotations.Nullable; public class ShapedRecipeBuilder implements RecipeBuilder { private final HolderGetter items; private final RecipeCategory category; private final Item result; private final int count; private final List rows = Lists.newArrayList(); private final Map key = Maps.newLinkedHashMap(); private final Map> criteria = new LinkedHashMap(); private @Nullable String group; private boolean showNotification = true; private ShapedRecipeBuilder(HolderGetter items, RecipeCategory category, ItemLike result, int count) { this.items = items; this.category = category; this.result = result.asItem(); this.count = count; } public static ShapedRecipeBuilder shaped(HolderGetter items, RecipeCategory category, ItemLike item) { return ShapedRecipeBuilder.shaped(items, category, item, 1); } public static ShapedRecipeBuilder shaped(HolderGetter items, RecipeCategory category, ItemLike item, int count) { return new ShapedRecipeBuilder(items, category, item, count); } public ShapedRecipeBuilder define(Character symbol, TagKey tag) { return this.define(symbol, Ingredient.of(this.items.getOrThrow(tag))); } public ShapedRecipeBuilder define(Character symbol, ItemLike item) { return this.define(symbol, Ingredient.of(item)); } public ShapedRecipeBuilder define(Character symbol, Ingredient ingredient) { if (this.key.containsKey(symbol)) { throw new IllegalArgumentException("Symbol '" + symbol + "' is already defined!"); } if (symbol.charValue() == ' ') { throw new IllegalArgumentException("Symbol ' ' (whitespace) is reserved and cannot be defined"); } this.key.put(symbol, ingredient); return this; } public ShapedRecipeBuilder pattern(String row) { if (!this.rows.isEmpty() && row.length() != this.rows.get(0).length()) { throw new IllegalArgumentException("Pattern must be the same width on every line!"); } this.rows.add(row); return this; } @Override public ShapedRecipeBuilder unlockedBy(String name, Criterion criterion) { this.criteria.put(name, criterion); return this; } @Override public ShapedRecipeBuilder group(@Nullable String group) { this.group = group; return this; } public ShapedRecipeBuilder showNotification(boolean showNotification) { this.showNotification = showNotification; return this; } @Override public Item getResult() { return this.result; } @Override public void save(RecipeOutput output, ResourceKey> id) { ShapedRecipePattern pattern = 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); ShapedRecipe recipe = new ShapedRecipe(Objects.requireNonNullElse(this.group, ""), RecipeBuilder.determineBookCategory(this.category), pattern, new ItemStack(this.result, this.count), this.showNotification); output.accept(id, recipe, advancement.build(id.identifier().withPrefix("recipes/" + this.category.getFolderName() + "/"))); } private ShapedRecipePattern ensureValid(ResourceKey> id) { if (this.criteria.isEmpty()) { throw new IllegalStateException("No way of obtaining recipe " + String.valueOf(id.identifier())); } return ShapedRecipePattern.of(this.key, this.rows); } }