Put the default toast additions into a proper place.

This commit is contained in:
Ayutac 2022-02-10 08:10:56 +01:00
parent b4adfd652c
commit 145ba48e27
2 changed files with 28 additions and 6 deletions

View file

@ -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:
* <ul>
* <li>parent as "recipes/root"</li>
* <li>criterion "has_the_recipe" via OR</li>
* <li>reward: the specified recipe</li>
* </ul>
* @param builder the advancement task builder to expand
* @param recipeId the ID of the recipe
* @throws NullPointerException If any parameter refers to <code>null</code>.
*/
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);
}
}

View file

@ -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<R extends RebornRecipe> {
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<R>(type, createRecipe(recipeId), advancementId, builder))
}