diff --git a/src/main/java/com/simibubi/create/AllRecipeTypes.java b/src/main/java/com/simibubi/create/AllRecipeTypes.java index a15eda1e4..ee9ccfb2d 100644 --- a/src/main/java/com/simibubi/create/AllRecipeTypes.java +++ b/src/main/java/com/simibubi/create/AllRecipeTypes.java @@ -21,6 +21,7 @@ import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuild import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer; import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import net.minecraft.inventory.IInventory; import net.minecraft.item.crafting.IRecipe; @@ -32,7 +33,7 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import net.minecraftforge.event.RegistryEvent; -public enum AllRecipeTypes { +public enum AllRecipeTypes implements IRecipeTypeInfo { MECHANICAL_CRAFTING(MechanicalCraftingRecipe.Serializer::new), CONVERSION(ConversionRecipe::new), @@ -78,16 +79,19 @@ public enum AllRecipeTypes { this(processingSerializer(processingFactory)); } + @Override public ResourceLocation getId() { return id; } @SuppressWarnings("unchecked") + @Override public > T getSerializer() { return (T) serializer; } @SuppressWarnings("unchecked") + @Override public > T getType() { return (T) type; } diff --git a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java index 4f7649478..da8730eaa 100644 --- a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java +++ b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java @@ -51,6 +51,7 @@ import com.simibubi.create.content.schematics.block.SchematicannonScreen; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.CRecipes; import com.simibubi.create.foundation.config.ConfigBase.ConfigBool; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; @@ -79,12 +80,6 @@ public class CreateJEI implements IModPlugin { private static final ResourceLocation ID = new ResourceLocation(Create.ID, "jei_plugin"); - @Override - @Nonnull - public ResourceLocation getPluginUid() { - return ID; - } - public IIngredientManager ingredientManager; private final List> allCategories = new ArrayList<>(); private final CreateRecipeCategory @@ -221,6 +216,12 @@ public class CreateJEI implements IModPlugin { return new CategoryBuilder(name, supplier); } + @Override + @Nonnull + public ResourceLocation getPluginUid() { + return ID; + } + @Override public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { registration.addRecipeTransferHandler(new BlueprintTransferHandler(), VanillaRecipeCategoryUid.CRAFTING); @@ -269,7 +270,7 @@ public class CreateJEI implements IModPlugin { pred = Predicates.alwaysTrue(); } - public CategoryBuilder recipes(AllRecipeTypes recipeTypeEntry) { + public CategoryBuilder recipes(IRecipeTypeInfo recipeTypeEntry) { return recipes(recipeTypeEntry::getType); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java index 350a5269a..ec8c290d4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java @@ -1,14 +1,14 @@ package com.simibubi.create.content.contraptions.components.crusher; -import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import net.minecraftforge.items.wrapper.RecipeWrapper; public abstract class AbstractCrushingRecipe extends ProcessingRecipe { - public AbstractCrushingRecipe(AllRecipeTypes recipeType, ProcessingRecipeParams params) { + public AbstractCrushingRecipe(IRecipeTypeInfo recipeType, ProcessingRecipeParams params) { super(recipeType, params); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java index 1260470e8..e4bfa6be3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java @@ -22,7 +22,7 @@ public class CrushingRecipe extends AbstractCrushingRecipe { return ingredients.get(0) .test(inv.getItem(0)); } - + @Override protected int getMaxOutputCount() { return 7; diff --git a/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java index a09fef111..92f4f70a7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java @@ -36,14 +36,14 @@ import net.minecraftforge.items.wrapper.RecipeWrapper; public class SequencedAssemblyRecipe implements IRecipe { - ResourceLocation id; - SequencedAssemblyRecipeSerializer serializer; + protected ResourceLocation id; + protected SequencedAssemblyRecipeSerializer serializer; - Ingredient ingredient; - List> sequence; - int loops; - ProcessingOutput transitionalItem; - List resultPool; + protected Ingredient ingredient; + protected List> sequence; + protected int loops; + protected ProcessingOutput transitionalItem; + protected List resultPool; public SequencedAssemblyRecipe(ResourceLocation recipeId, SequencedAssemblyRecipeSerializer serializer) { this.id = recipeId; diff --git a/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipeBuilder.java b/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipeBuilder.java index abea8424e..df49e6eb6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipeBuilder.java +++ b/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipeBuilder.java @@ -8,12 +8,10 @@ import java.util.function.UnaryOperator; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.simibubi.create.AllRecipeTypes; -import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeFactory; -import com.simibubi.create.foundation.utility.Lang; import net.minecraft.data.IFinishedRecipe; import net.minecraft.item.Item; @@ -92,16 +90,17 @@ public class SequencedAssemblyRecipeBuilder { public static class DataGenResult implements IFinishedRecipe { - private List recipeConditions; - private SequencedAssemblyRecipeSerializer serializer; - private ResourceLocation id; private SequencedAssemblyRecipe recipe; + private List recipeConditions; + private ResourceLocation id; + private SequencedAssemblyRecipeSerializer serializer; public DataGenResult(SequencedAssemblyRecipe recipe, List recipeConditions) { this.recipeConditions = recipeConditions; this.recipe = recipe; - this.id = Create.asResource(Lang.asId(AllRecipeTypes.SEQUENCED_ASSEMBLY.name()) + "/" + recipe.getId() - .getPath()); + recipe.getId(); + this.id = new ResourceLocation(recipe.getId().getNamespace(), + AllRecipeTypes.SEQUENCED_ASSEMBLY.getId().getPath() + "/" + recipe.getId().getPath()); this.serializer = (SequencedAssemblyRecipeSerializer) recipe.getSerializer(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java index d92235e4c..b5eb01f6f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java @@ -10,11 +10,10 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.apache.logging.log4j.Logger; import com.google.gson.JsonObject; -import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams; import com.simibubi.create.foundation.fluid.FluidIngredient; -import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.inventory.IInventory; @@ -42,24 +41,23 @@ public abstract class ProcessingRecipe implements IRecipe< private IRecipeType type; private IRecipeSerializer serializer; - private AllRecipeTypes enumType; + private IRecipeTypeInfo typeInfo; private Supplier forcedResult; - public ProcessingRecipe(AllRecipeTypes recipeType, ProcessingRecipeParams params) { - + public ProcessingRecipe(IRecipeTypeInfo typeInfo, ProcessingRecipeParams params) { this.forcedResult = null; - this.enumType = recipeType; + this.typeInfo = typeInfo; this.processingDuration = params.processingDuration; this.fluidIngredients = params.fluidIngredients; this.fluidResults = params.fluidResults; - this.serializer = recipeType.getSerializer(); + this.serializer = typeInfo.getSerializer(); this.requiredHeat = params.requiredHeat; this.ingredients = params.ingredients; - this.type = recipeType.getType(); + this.type = typeInfo.getType(); this.results = params.results; this.id = params.id; - validate(Lang.asId(recipeType.name())); + validate(typeInfo.getId()); } // Recipe type options: @@ -86,8 +84,8 @@ public abstract class ProcessingRecipe implements IRecipe< // - private void validate(String recipeTypeName) { - String messageHeader = "Your custom " + recipeTypeName + " recipe (" + id.toString() + ")"; + private void validate(ResourceLocation recipeTypeId) { + String messageHeader = "Your custom " + recipeTypeId + " recipe (" + id.toString() + ")"; Logger logger = Create.LOGGER; int ingredientCount = ingredients.size(); int outputCount = results.size(); @@ -185,32 +183,36 @@ public abstract class ProcessingRecipe implements IRecipe< .getStack(); } - @Override - public ResourceLocation getId() { - return id; - } - @Override public boolean isSpecial() { return true; } - @Override - public IRecipeSerializer getSerializer() { - return serializer; - } - // Processing recipes do not show up in the recipe book @Override public String getGroup() { return "processing"; } + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public IRecipeSerializer getSerializer() { + return serializer; + } + @Override public IRecipeType getType() { return type; } + public IRecipeTypeInfo getTypeInfo() { + return typeInfo; + } + // Additional Data added by subtypes public void readAdditional(JsonObject json) {} @@ -221,8 +223,4 @@ public abstract class ProcessingRecipe implements IRecipe< public void writeAdditional(PacketBuffer buffer) {} - public AllRecipeTypes getEnumType() { - return enumType; - } - } 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 e81f6e0f7..19c839295 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 @@ -6,11 +6,10 @@ import java.util.function.Consumer; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.foundation.fluid.FluidHelper; import com.simibubi.create.foundation.fluid.FluidIngredient; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Pair; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import net.minecraft.data.IFinishedRecipe; import net.minecraft.fluid.Fluid; @@ -221,16 +220,16 @@ public class ProcessingRecipeBuilder> { @SuppressWarnings("unchecked") public DataGenResult(S recipe, List recipeConditions) { - this.recipeConditions = recipeConditions; - AllRecipeTypes recipeType = recipe.getEnumType(); - String typeName = Lang.asId(recipeType.name()); this.recipe = recipe; + this.recipeConditions = recipeConditions; + IRecipeTypeInfo recipeType = this.recipe.getTypeInfo(); + ResourceLocation typeId = recipeType.getId(); if (!(recipeType.getSerializer() instanceof ProcessingRecipeSerializer)) - throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName); + throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeId); this.id = new ResourceLocation(recipe.getId().getNamespace(), - typeName + "/" + recipe.getId().getPath()); + typeId.getPath() + "/" + 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 baae5baa3..2e4138cec 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 @@ -20,10 +20,10 @@ import net.minecraftforge.common.Tags; public abstract class CreateRecipeProvider extends RecipeProvider { - final List all = new ArrayList<>(); + protected final List all = new ArrayList<>(); - public CreateRecipeProvider(DataGenerator p_i48262_1_) { - super(p_i48262_1_); + public CreateRecipeProvider(DataGenerator generator) { + super(generator); } @Override @@ -32,16 +32,16 @@ public abstract class CreateRecipeProvider extends RecipeProvider { Create.LOGGER.info(getName() + " registered " + all.size() + " recipe" + (all.size() == 1 ? "" : "s")); } - @FunctionalInterface - public interface GeneratedRecipe { - void register(Consumer consumer); - } - protected GeneratedRecipe register(GeneratedRecipe recipe) { all.add(recipe); return recipe; } + @FunctionalInterface + public interface GeneratedRecipe { + void register(Consumer consumer); + } + protected static class Marker { } 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 07734300d..d9b9f2026 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 @@ -6,11 +6,11 @@ import java.util.List; import java.util.function.Supplier; import java.util.function.UnaryOperator; -import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import net.minecraft.data.DataGenerator; import net.minecraft.data.DirectoryCache; @@ -22,22 +22,22 @@ import net.minecraftforge.fluids.FluidAttributes; public abstract class ProcessingRecipeGen extends CreateRecipeProvider { - protected static List generators = new ArrayList<>(); + protected static final List GENERATORS = new ArrayList<>(); protected static final int BUCKET = FluidAttributes.BUCKET_VOLUME; protected static final int BOTTLE = 250; public static void registerAll(DataGenerator gen) { - generators.add(new CrushingRecipeGen(gen)); - generators.add(new MillingRecipeGen(gen)); - generators.add(new CuttingRecipeGen(gen)); - generators.add(new WashingRecipeGen(gen)); - generators.add(new PolishingRecipeGen(gen)); - generators.add(new DeployingRecipeGen(gen)); - generators.add(new MixingRecipeGen(gen)); - generators.add(new CompactingRecipeGen(gen)); - generators.add(new PressingRecipeGen(gen)); - generators.add(new FillingRecipeGen(gen)); - generators.add(new EmptyingRecipeGen(gen)); + GENERATORS.add(new CrushingRecipeGen(gen)); + GENERATORS.add(new MillingRecipeGen(gen)); + GENERATORS.add(new CuttingRecipeGen(gen)); + GENERATORS.add(new WashingRecipeGen(gen)); + GENERATORS.add(new PolishingRecipeGen(gen)); + GENERATORS.add(new DeployingRecipeGen(gen)); + GENERATORS.add(new MixingRecipeGen(gen)); + GENERATORS.add(new CompactingRecipeGen(gen)); + GENERATORS.add(new PressingRecipeGen(gen)); + GENERATORS.add(new FillingRecipeGen(gen)); + GENERATORS.add(new EmptyingRecipeGen(gen)); gen.addProvider(new IDataProvider() { @@ -48,7 +48,7 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { @Override public void run(DirectoryCache dc) throws IOException { - generators.forEach(g -> { + GENERATORS.forEach(g -> { try { g.run(dc); } catch (IOException e) { @@ -59,8 +59,8 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { }); } - public ProcessingRecipeGen(DataGenerator p_i48262_1_) { - super(p_i48262_1_); + public ProcessingRecipeGen(DataGenerator generator) { + super(generator); } /** @@ -86,7 +86,7 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { * Create a processing recipe with a single itemstack ingredient, using its id * as the name of the recipe */ - protected > GeneratedRecipe create(Supplier singleIngredient, + > GeneratedRecipe create(Supplier singleIngredient, UnaryOperator> transform) { return create(Create.ID, singleIngredient, transform); } @@ -109,21 +109,20 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider { * Create a new processing recipe, with recipe definitions provided by the * function */ - protected > GeneratedRecipe create(String name, + > GeneratedRecipe create(String name, UnaryOperator> transform) { return create(Create.asResource(name), transform); } - protected > ProcessingRecipeSerializer getSerializer() { - ProcessingRecipeSerializer serializer = getRecipeType().getSerializer(); - return serializer; + protected abstract IRecipeTypeInfo getRecipeType(); + + protected > ProcessingRecipeSerializer getSerializer() { + return getRecipeType().getSerializer(); } @Override - public final String getName() { - return "Create's Processing Recipes: " + getRecipeType(); + public String getName() { + return "Create's Processing Recipes: " + getRecipeType().getId().getPath(); } - protected abstract AllRecipeTypes getRecipeType(); - } diff --git a/src/main/java/com/simibubi/create/foundation/utility/recipe/IRecipeTypeInfo.java b/src/main/java/com/simibubi/create/foundation/utility/recipe/IRecipeTypeInfo.java new file mode 100644 index 000000000..bf347471f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/recipe/IRecipeTypeInfo.java @@ -0,0 +1,15 @@ +package com.simibubi.create.foundation.utility.recipe; + +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.item.crafting.IRecipeType; +import net.minecraft.util.ResourceLocation; + +public interface IRecipeTypeInfo { + + ResourceLocation getId(); + + > T getSerializer(); + + > T getType(); + +}