Put the default toast additions into a proper place.
This commit is contained in:
parent
b4adfd652c
commit
145ba48e27
2 changed files with 28 additions and 6 deletions
|
@ -28,6 +28,10 @@ import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.serialization.Dynamic;
|
import com.mojang.serialization.Dynamic;
|
||||||
import com.mojang.serialization.JsonOps;
|
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.inventory.Inventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -40,12 +44,14 @@ import net.minecraft.util.JsonHelper;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import reborncore.common.util.DefaultedListCollector;
|
import reborncore.common.util.DefaultedListCollector;
|
||||||
import reborncore.common.util.serialization.SerializationUtil;
|
import reborncore.common.util.serialization.SerializationUtil;
|
||||||
import reborncore.mixin.common.AccessorRecipeManager;
|
import reborncore.mixin.common.AccessorRecipeManager;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class RecipeUtils {
|
public class RecipeUtils {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -82,4 +88,24 @@ public class RecipeUtils {
|
||||||
return stack;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,8 @@ package techreborn.datagen.recipes.machine
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import net.minecraft.advancement.Advancement.Task
|
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.CriterionConditions
|
||||||
import net.minecraft.advancement.criterion.RecipeUnlockedCriterion
|
|
||||||
import net.minecraft.data.server.recipe.RecipeJsonProvider
|
import net.minecraft.data.server.recipe.RecipeJsonProvider
|
||||||
import net.minecraft.data.server.recipe.ShapelessRecipeJsonFactory
|
|
||||||
import net.minecraft.item.ItemConvertible
|
import net.minecraft.item.ItemConvertible
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.recipe.RecipeSerializer
|
import net.minecraft.recipe.RecipeSerializer
|
||||||
|
@ -41,6 +37,7 @@ import net.minecraft.util.registry.Registry
|
||||||
import org.jetbrains.annotations.NotNull
|
import org.jetbrains.annotations.NotNull
|
||||||
import reborncore.common.crafting.RebornRecipe
|
import reborncore.common.crafting.RebornRecipe
|
||||||
import reborncore.common.crafting.RebornRecipeType
|
import reborncore.common.crafting.RebornRecipeType
|
||||||
|
import reborncore.common.crafting.RecipeUtils
|
||||||
import reborncore.common.crafting.ingredient.RebornIngredient
|
import reborncore.common.crafting.ingredient.RebornIngredient
|
||||||
|
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
|
@ -178,8 +175,7 @@ class MachineRecipeJsonFactory<R extends RebornRecipe> {
|
||||||
validate()
|
validate()
|
||||||
Identifier recipeId = getIdentifier()
|
Identifier recipeId = getIdentifier()
|
||||||
Identifier advancementId = new Identifier(recipeId.getNamespace(), "recipes/" + recipeId.getPath())
|
Identifier advancementId = new Identifier(recipeId.getNamespace(), "recipes/" + recipeId.getPath())
|
||||||
// "has the recipe" condition
|
RecipeUtils.addToastDefaults(builder, recipeId)
|
||||||
builder.parent(new Identifier("recipes/root")).criterion("has_the_recipe", RecipeUnlockedCriterion.create(recipeId)).rewards(AdvancementRewards.Builder.recipe(recipeId)).criteriaMerger(CriterionMerger.OR)
|
|
||||||
exporter.accept(new MachineRecipeJsonProvider<R>(type, createRecipe(recipeId), advancementId, builder))
|
exporter.accept(new MachineRecipeJsonProvider<R>(type, createRecipe(recipeId), advancementId, builder))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue