From 159f96ca57c28c055c8898c28a90269d2cebb355 Mon Sep 17 00:00:00 2001 From: kotakotik22 <61428759+kotakotik22@users.noreply.github.com> Date: Mon, 5 Jul 2021 18:30:23 +0200 Subject: [PATCH] Processing recipe generation addon utilities --- .../processing/ProcessingRecipeBuilder.java | 4 +- .../data/recipe/CreateRecipeProvider.java | 2 +- .../data/recipe/ProcessingRecipeGen.java | 43 +++++++++++++------ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeBuilder.java b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeBuilder.java index be0045bae..305d5e06a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeBuilder.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeBuilder.java @@ -230,8 +230,8 @@ public class ProcessingRecipeBuilder> { if (!(recipeType.serializer instanceof ProcessingRecipeSerializer)) throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName); - this.id = Create.asResource(typeName + "/" + recipe.getId() - .getPath()); + this.id = new ResourceLocation(recipe.getId().getNamespace(), + typeName + "/" + recipe.getId().getPath()); this.serializer = (ProcessingRecipeSerializer) recipe.getSerializer(); } diff --git a/src/main/java/com/simibubi/create/foundation/data/recipe/CreateRecipeProvider.java b/src/main/java/com/simibubi/create/foundation/data/recipe/CreateRecipeProvider.java index f3c4c24aa..ba8bd3183 100644 --- a/src/main/java/com/simibubi/create/foundation/data/recipe/CreateRecipeProvider.java +++ b/src/main/java/com/simibubi/create/foundation/data/recipe/CreateRecipeProvider.java @@ -33,7 +33,7 @@ public abstract class CreateRecipeProvider extends RecipeProvider { } @FunctionalInterface - interface GeneratedRecipe { + public interface GeneratedRecipe { void register(Consumer consumer); } diff --git a/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java b/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java index 920d5ef13..58d35e2ab 100644 --- a/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java @@ -17,6 +17,7 @@ import net.minecraft.data.DirectoryCache; import net.minecraft.data.IDataProvider; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.IItemProvider; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.FluidAttributes; public abstract class ProcessingRecipeGen extends CreateRecipeProvider { @@ -37,14 +38,14 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { generators.add(new PressingRecipeGen(gen)); generators.add(new FillingRecipeGen(gen)); generators.add(new EmptyingRecipeGen(gen)); - + gen.addProvider(new IDataProvider() { - + @Override public String getName() { return "Create's Processing Recipes"; } - + @Override public void act(DirectoryCache dc) throws IOException { generators.forEach(g -> { @@ -57,22 +58,22 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { } }); } - + public ProcessingRecipeGen(DataGenerator p_i48262_1_) { super(p_i48262_1_); } - + /** * Create a processing recipe with a single itemstack ingredient, using its id * as the name of the recipe */ - protected > GeneratedRecipe create(Supplier singleIngredient, + protected > GeneratedRecipe create(String namespace, Supplier singleIngredient, UnaryOperator> transform) { ProcessingRecipeSerializer serializer = getSerializer(); GeneratedRecipe generatedRecipe = c -> { IItemProvider iItemProvider = singleIngredient.get(); transform - .apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), Create.asResource(iItemProvider.asItem() + .apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), new ResourceLocation(namespace, iItemProvider.asItem() .getRegistryName() .getPath())).withItemIngredients(Ingredient.fromItems(iItemProvider))) .build(c); @@ -81,22 +82,40 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { return generatedRecipe; } + /** + * Create a processing recipe with a single itemstack ingredient, using its id + * as the name of the recipe + */ + protected > GeneratedRecipe create(Supplier singleIngredient, + UnaryOperator> transform) { + return create(Create.ID, singleIngredient, transform); + } + /** * Create a new processing recipe, with recipe definitions provided by the * function */ - protected > GeneratedRecipe create(String name, - UnaryOperator> transform) { + protected > GeneratedRecipe create(ResourceLocation name, + UnaryOperator> transform) { ProcessingRecipeSerializer serializer = getSerializer(); GeneratedRecipe generatedRecipe = - c -> transform.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), Create.asResource(name))) + c -> transform.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), name)) .build(c); all.add(generatedRecipe); return generatedRecipe; } + /** + * Create a new processing recipe, with recipe definitions provided by the + * function + */ + protected > GeneratedRecipe create(String name, + UnaryOperator> transform) { + return create(Create.asResource(name), transform); + } + @SuppressWarnings("unchecked") - private > ProcessingRecipeSerializer getSerializer() { + protected > ProcessingRecipeSerializer getSerializer() { ProcessingRecipeSerializer serializer = (ProcessingRecipeSerializer) getRecipeType().serializer; return serializer; } @@ -105,7 +124,7 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { public final String getName() { return "Create's Processing Recipes: " + getRecipeType(); } - + protected abstract AllRecipeTypes getRecipeType(); }