| 1 | package net.minecraft.data.recipes;
|
| 2 |
|
| 3 | import net.minecraft.advancements.triggers.Criterion;
|
| 4 | import net.minecraft.resources.ResourceKey;
|
| 5 | import net.minecraft.world.item.ItemStackTemplate;
|
| 6 | import net.minecraft.world.item.crafting.Ingredient;
|
| 7 | import net.minecraft.world.item.crafting.Recipe;
|
| 8 | import net.minecraft.world.item.crafting.SingleItemRecipe;
|
| 9 | import net.minecraft.world.item.crafting.StonecutterRecipe;
|
| 10 | import net.minecraft.world.level.ItemLike;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | public class SingleItemRecipeBuilder implements RecipeBuilder {
|
| 14 | private final RecipeCategory category;
|
| 15 | private final ItemStackTemplate result;
|
| 16 | private final Ingredient ingredient;
|
| 17 | private final RecipeUnlockAdvancementBuilder advancementBuilder = new RecipeUnlockAdvancementBuilder();
|
| 18 | private final SingleItemRecipe.Factory<?> factory;
|
| 19 |
|
| 20 | private SingleItemRecipeBuilder(
|
| 21 | final RecipeCategory category, final SingleItemRecipe.Factory<?> factory, final Ingredient ingredient, final ItemStackTemplate result
|
| 22 | ) {
|
| 23 | this.category = category;
|
| 24 | this.result = result;
|
| 25 | this.ingredient = ingredient;
|
| 26 | this.factory = factory;
|
| 27 | }
|
| 28 |
|
| 29 | public SingleItemRecipeBuilder(
|
| 30 | final RecipeCategory category, final SingleItemRecipe.Factory<?> factory, final Ingredient ingredient, final ItemLike result, final int count
|
| 31 | ) {
|
| 32 | this(category, factory, ingredient, new ItemStackTemplate(result.asItem(), count));
|
| 33 | }
|
| 34 |
|
| 35 | public static SingleItemRecipeBuilder stonecutting(final Ingredient ingredient, final RecipeCategory category, final ItemLike result, final int count) {
|
| 36 | return new SingleItemRecipeBuilder(category, StonecutterRecipe::new, ingredient, result, count);
|
| 37 | }
|
| 38 |
|
| 39 | public SingleItemRecipeBuilder unlockedBy(final String name, final Criterion<?> criterion) {
|
| 40 | this.advancementBuilder.unlockedBy(name, criterion);
|
| 41 | return this;
|
| 42 | }
|
| 43 |
|
| 44 | public SingleItemRecipeBuilder group(final @Nullable String group) {
|
| 45 | return this;
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | public ResourceKey<Recipe<?>> defaultId() {
|
| 50 | return RecipeBuilder.getDefaultRecipeId(this.result);
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | public void save(final RecipeOutput output, final ResourceKey<Recipe<?>> id) {
|
| 55 | SingleItemRecipe recipe = this.factory.create(new Recipe.CommonInfo(true), this.ingredient, this.result);
|
| 56 | output.accept(id, recipe, this.advancementBuilder.build(output, id, this.category));
|
| 57 | }
|
| 58 | }
|
| 59 |
|