diff --git a/RebornCore/src/main/java/reborncore/common/crafting/RecipeUtils.java b/RebornCore/src/main/java/reborncore/common/crafting/RecipeUtils.java index 78a3bc134..74b7a7fd9 100644 --- a/RebornCore/src/main/java/reborncore/common/crafting/RecipeUtils.java +++ b/RebornCore/src/main/java/reborncore/common/crafting/RecipeUtils.java @@ -28,6 +28,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.serialization.Dynamic; import com.mojang.serialization.JsonOps; +import net.minecraft.advancement.Advancement; +import net.minecraft.advancement.AdvancementRewards; +import net.minecraft.advancement.CriterionMerger; +import net.minecraft.advancement.criterion.RecipeUnlockedCriterion; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -40,12 +44,14 @@ import net.minecraft.util.JsonHelper; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; import reborncore.common.util.DefaultedListCollector; import reborncore.common.util.serialization.SerializationUtil; import reborncore.mixin.common.AccessorRecipeManager; import java.util.Collection; import java.util.List; +import java.util.Objects; public class RecipeUtils { @SuppressWarnings("unchecked") @@ -82,4 +88,24 @@ public class RecipeUtils { return stack; } + /** + * Adds the following toast/recipe defaults to an advancement builder: + * + * @param builder the advancement task builder to expand + * @param recipeId the ID of the recipe + * @throws NullPointerException If any parameter refers to null. + */ + public static void addToastDefaults(@NotNull Advancement.Task builder, @NotNull Identifier recipeId) { + Objects.requireNonNull(builder); + Objects.requireNonNull(recipeId); + builder.parent(new Identifier("recipes/root")) + .criterion("has_the_recipe", RecipeUnlockedCriterion.create(recipeId)) + .rewards(AdvancementRewards.Builder.recipe(recipeId)) + .criteriaMerger(CriterionMerger.OR); + } + } diff --git a/src/datagen/groovy/techreborn/datagen/recipes/machine/MachineRecipeJsonFactory.groovy b/src/datagen/groovy/techreborn/datagen/recipes/machine/MachineRecipeJsonFactory.groovy index 2a35b19d2..dc8877c75 100644 --- a/src/datagen/groovy/techreborn/datagen/recipes/machine/MachineRecipeJsonFactory.groovy +++ b/src/datagen/groovy/techreborn/datagen/recipes/machine/MachineRecipeJsonFactory.groovy @@ -26,12 +26,8 @@ package techreborn.datagen.recipes.machine import com.google.gson.JsonObject import net.minecraft.advancement.Advancement.Task -import net.minecraft.advancement.AdvancementRewards -import net.minecraft.advancement.CriterionMerger import net.minecraft.advancement.criterion.CriterionConditions -import net.minecraft.advancement.criterion.RecipeUnlockedCriterion import net.minecraft.data.server.recipe.RecipeJsonProvider -import net.minecraft.data.server.recipe.ShapelessRecipeJsonFactory import net.minecraft.item.ItemConvertible import net.minecraft.item.ItemStack import net.minecraft.recipe.RecipeSerializer @@ -41,6 +37,7 @@ import net.minecraft.util.registry.Registry import org.jetbrains.annotations.NotNull import reborncore.common.crafting.RebornRecipe import reborncore.common.crafting.RebornRecipeType +import reborncore.common.crafting.RecipeUtils import reborncore.common.crafting.ingredient.RebornIngredient import java.util.function.Consumer @@ -178,8 +175,7 @@ class MachineRecipeJsonFactory { validate() Identifier recipeId = getIdentifier() Identifier advancementId = new Identifier(recipeId.getNamespace(), "recipes/" + recipeId.getPath()) - // "has the recipe" condition - builder.parent(new Identifier("recipes/root")).criterion("has_the_recipe", RecipeUnlockedCriterion.create(recipeId)).rewards(AdvancementRewards.Builder.recipe(recipeId)).criteriaMerger(CriterionMerger.OR) + RecipeUtils.addToastDefaults(builder, recipeId) exporter.accept(new MachineRecipeJsonProvider(type, createRecipe(recipeId), advancementId, builder)) }