| 1 | package net.minecraft.data.recipes;
|
| 2 |
|
| 3 | import java.util.Objects;
|
| 4 | import net.minecraft.advancements.triggers.Criterion;
|
| 5 | import net.minecraft.resources.ResourceKey;
|
| 6 | import net.minecraft.world.item.ItemStackTemplate;
|
| 7 | import net.minecraft.world.item.crafting.AbstractCookingRecipe;
|
| 8 | import net.minecraft.world.item.crafting.BlastingRecipe;
|
| 9 | import net.minecraft.world.item.crafting.CampfireCookingRecipe;
|
| 10 | import net.minecraft.world.item.crafting.CookingBookCategory;
|
| 11 | import net.minecraft.world.item.crafting.Ingredient;
|
| 12 | import net.minecraft.world.item.crafting.Recipe;
|
| 13 | import net.minecraft.world.item.crafting.SmeltingRecipe;
|
| 14 | import net.minecraft.world.item.crafting.SmokingRecipe;
|
| 15 | import net.minecraft.world.level.ItemLike;
|
| 16 | import org.jspecify.annotations.Nullable;
|
| 17 |
|
| 18 | public class SimpleCookingRecipeBuilder implements RecipeBuilder {
|
| 19 | private final RecipeCategory craftingCategory;
|
| 20 | private final CookingBookCategory cookingCategory;
|
| 21 | private final ItemStackTemplate result;
|
| 22 | private final Ingredient ingredient;
|
| 23 | private final float experience;
|
| 24 | private final int cookingTime;
|
| 25 | private final RecipeUnlockAdvancementBuilder advancementBuilder = new RecipeUnlockAdvancementBuilder();
|
| 26 | private @Nullable String group;
|
| 27 | private final AbstractCookingRecipe.Factory<?> factory;
|
| 28 |
|
| 29 | private SimpleCookingRecipeBuilder(
|
| 30 | final RecipeCategory craftingCategory,
|
| 31 | final CookingBookCategory cookingCategory,
|
| 32 | final ItemStackTemplate result,
|
| 33 | final Ingredient ingredient,
|
| 34 | final float experience,
|
| 35 | final int cookingTime,
|
| 36 | final AbstractCookingRecipe.Factory<?> factory
|
| 37 | ) {
|
| 38 | this.craftingCategory = craftingCategory;
|
| 39 | this.cookingCategory = cookingCategory;
|
| 40 | this.result = result;
|
| 41 | this.ingredient = ingredient;
|
| 42 | this.experience = experience;
|
| 43 | this.cookingTime = cookingTime;
|
| 44 | this.factory = factory;
|
| 45 | }
|
| 46 |
|
| 47 | private SimpleCookingRecipeBuilder(
|
| 48 | final RecipeCategory craftingCategory,
|
| 49 | final CookingBookCategory cookingCategory,
|
| 50 | final ItemLike result,
|
| 51 | final Ingredient ingredient,
|
| 52 | final float experience,
|
| 53 | final int cookingTime,
|
| 54 | final AbstractCookingRecipe.Factory<?> factory
|
| 55 | ) {
|
| 56 | this(craftingCategory, cookingCategory, new ItemStackTemplate(result.asItem()), ingredient, experience, cookingTime, factory);
|
| 57 | }
|
| 58 |
|
| 59 | public static <T extends AbstractCookingRecipe> SimpleCookingRecipeBuilder generic(
|
| 60 | final Ingredient ingredient,
|
| 61 | final RecipeCategory craftingCategory,
|
| 62 | final CookingBookCategory cookingCategory,
|
| 63 | final ItemLike result,
|
| 64 | final float experience,
|
| 65 | final int cookingTime,
|
| 66 | final AbstractCookingRecipe.Factory<T> factory
|
| 67 | ) {
|
| 68 | return new SimpleCookingRecipeBuilder(craftingCategory, cookingCategory, result, ingredient, experience, cookingTime, factory);
|
| 69 | }
|
| 70 |
|
| 71 | public static SimpleCookingRecipeBuilder campfireCooking(
|
| 72 | final Ingredient ingredient, final RecipeCategory craftingCategory, final ItemLike result, final float experience, final int cookingTime
|
| 73 | ) {
|
| 74 | return new SimpleCookingRecipeBuilder(craftingCategory, CookingBookCategory.FOOD, result, ingredient, experience, cookingTime, CampfireCookingRecipe::new);
|
| 75 | }
|
| 76 |
|
| 77 | public static SimpleCookingRecipeBuilder blasting(
|
| 78 | final Ingredient ingredient,
|
| 79 | final RecipeCategory craftingCategory,
|
| 80 | final CookingBookCategory cookingCategory,
|
| 81 | final ItemLike result,
|
| 82 | final float experience,
|
| 83 | final int cookingTime
|
| 84 | ) {
|
| 85 | return new SimpleCookingRecipeBuilder(craftingCategory, cookingCategory, result, ingredient, experience, cookingTime, BlastingRecipe::new);
|
| 86 | }
|
| 87 |
|
| 88 | public static SimpleCookingRecipeBuilder smelting(
|
| 89 | final Ingredient ingredient,
|
| 90 | final RecipeCategory craftingCategory,
|
| 91 | final CookingBookCategory cookingCategory,
|
| 92 | final ItemLike result,
|
| 93 | final float experience,
|
| 94 | final int cookingTime
|
| 95 | ) {
|
| 96 | return new SimpleCookingRecipeBuilder(craftingCategory, cookingCategory, result, ingredient, experience, cookingTime, SmeltingRecipe::new);
|
| 97 | }
|
| 98 |
|
| 99 | public static SimpleCookingRecipeBuilder smoking(
|
| 100 | final Ingredient ingredient, final RecipeCategory craftingCategory, final ItemLike result, final float experience, final int cookingTime
|
| 101 | ) {
|
| 102 | return new SimpleCookingRecipeBuilder(craftingCategory, CookingBookCategory.FOOD, result, ingredient, experience, cookingTime, SmokingRecipe::new);
|
| 103 | }
|
| 104 |
|
| 105 | public SimpleCookingRecipeBuilder unlockedBy(final String name, final Criterion<?> criterion) {
|
| 106 | this.advancementBuilder.unlockedBy(name, criterion);
|
| 107 | return this;
|
| 108 | }
|
| 109 |
|
| 110 | public SimpleCookingRecipeBuilder group(final @Nullable String group) {
|
| 111 | this.group = group;
|
| 112 | return this;
|
| 113 | }
|
| 114 |
|
| 115 | @Override
|
| 116 | public ResourceKey<Recipe<?>> defaultId() {
|
| 117 | return RecipeBuilder.getDefaultRecipeId(this.result);
|
| 118 | }
|
| 119 |
|
| 120 | @Override
|
| 121 | public void save(final RecipeOutput output, final ResourceKey<Recipe<?>> id) {
|
| 122 | AbstractCookingRecipe recipe = this.factory
|
| 123 | .create(
|
| 124 | RecipeBuilder.createCraftingCommonInfo(true),
|
| 125 | new AbstractCookingRecipe.CookingBookInfo(this.cookingCategory, Objects.requireNonNullElse(this.group, "")),
|
| 126 | this.ingredient,
|
| 127 | this.result,
|
| 128 | this.experience,
|
| 129 | this.cookingTime
|
| 130 | );
|
| 131 | output.accept(id, recipe, this.advancementBuilder.build(output, id, this.craftingCategory));
|
| 132 | }
|
| 133 | }
|
| 134 |
|