/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.data.recipes; import java.util.LinkedHashMap; 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.component.DataComponents; 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.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.AbstractCookingRecipe; import net.minecraft.world.item.crafting.BlastingRecipe; import net.minecraft.world.item.crafting.CampfireCookingRecipe; import net.minecraft.world.item.crafting.CookingBookCategory; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.SmeltingRecipe; import net.minecraft.world.item.crafting.SmokingRecipe; import net.minecraft.world.level.ItemLike; import org.jspecify.annotations.Nullable; public class SimpleCookingRecipeBuilder implements RecipeBuilder { private final RecipeCategory category; private final CookingBookCategory bookCategory; private final Item result; private final Ingredient ingredient; private final float experience; private final int cookingTime; private final Map> criteria = new LinkedHashMap(); private @Nullable String group; private final AbstractCookingRecipe.Factory factory; private SimpleCookingRecipeBuilder(RecipeCategory category, CookingBookCategory bookCategory, ItemLike result, Ingredient ingredient, float experience, int cookingTime, AbstractCookingRecipe.Factory factory) { this.category = category; this.bookCategory = bookCategory; this.result = result.asItem(); this.ingredient = ingredient; this.experience = experience; this.cookingTime = cookingTime; this.factory = factory; } public static SimpleCookingRecipeBuilder generic(Ingredient ingredient, RecipeCategory category, ItemLike result, float experience, int cookingTime, RecipeSerializer serializer, AbstractCookingRecipe.Factory factory) { return new SimpleCookingRecipeBuilder(category, SimpleCookingRecipeBuilder.determineRecipeCategory(serializer, result), result, ingredient, experience, cookingTime, factory); } public static SimpleCookingRecipeBuilder campfireCooking(Ingredient ingredient, RecipeCategory category, ItemLike result, float experience, int cookingTime) { return new SimpleCookingRecipeBuilder(category, CookingBookCategory.FOOD, result, ingredient, experience, cookingTime, CampfireCookingRecipe::new); } public static SimpleCookingRecipeBuilder blasting(Ingredient ingredient, RecipeCategory category, ItemLike result, float experience, int cookingTime) { return new SimpleCookingRecipeBuilder(category, SimpleCookingRecipeBuilder.determineBlastingRecipeCategory(result), result, ingredient, experience, cookingTime, BlastingRecipe::new); } public static SimpleCookingRecipeBuilder smelting(Ingredient ingredient, RecipeCategory category, ItemLike result, float experience, int cookingTime) { return new SimpleCookingRecipeBuilder(category, SimpleCookingRecipeBuilder.determineSmeltingRecipeCategory(result), result, ingredient, experience, cookingTime, SmeltingRecipe::new); } public static SimpleCookingRecipeBuilder smoking(Ingredient ingredient, RecipeCategory category, ItemLike result, float experience, int cookingTime) { return new SimpleCookingRecipeBuilder(category, CookingBookCategory.FOOD, result, ingredient, experience, cookingTime, SmokingRecipe::new); } @Override public SimpleCookingRecipeBuilder unlockedBy(String name, Criterion criterion) { this.criteria.put(name, criterion); return this; } @Override public SimpleCookingRecipeBuilder group(@Nullable String group) { this.group = group; return this; } @Override public Item getResult() { return this.result; } @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); Object recipe = this.factory.create(Objects.requireNonNullElse(this.group, ""), this.bookCategory, this.ingredient, new ItemStack(this.result), this.experience, this.cookingTime); output.accept(id, (Recipe)recipe, advancement.build(id.identifier().withPrefix("recipes/" + this.category.getFolderName() + "/"))); } private static CookingBookCategory determineSmeltingRecipeCategory(ItemLike result) { if (result.asItem().components().has(DataComponents.FOOD)) { return CookingBookCategory.FOOD; } if (result.asItem() instanceof BlockItem) { return CookingBookCategory.BLOCKS; } return CookingBookCategory.MISC; } private static CookingBookCategory determineBlastingRecipeCategory(ItemLike result) { if (result.asItem() instanceof BlockItem) { return CookingBookCategory.BLOCKS; } return CookingBookCategory.MISC; } private static CookingBookCategory determineRecipeCategory(RecipeSerializer serializer, ItemLike result) { if (serializer == RecipeSerializer.SMELTING_RECIPE) { return SimpleCookingRecipeBuilder.determineSmeltingRecipeCategory(result); } if (serializer == RecipeSerializer.BLASTING_RECIPE) { return SimpleCookingRecipeBuilder.determineBlastingRecipeCategory(result); } if (serializer == RecipeSerializer.SMOKING_RECIPE || serializer == RecipeSerializer.CAMPFIRE_COOKING_RECIPE) { return CookingBookCategory.FOOD; } throw new IllegalStateException("Unknown cooking recipe type"); } private void ensureValid(ResourceKey> id) { if (this.criteria.isEmpty()) { throw new IllegalStateException("No way of obtaining recipe " + String.valueOf(id.identifier())); } } }