From 02450bd2f79ce4e1205ae977981d05c8261e0d41 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Sat, 11 Jul 2020 16:18:17 +0200 Subject: [PATCH] More recipe Serializer changes - added Interface IExtendedProcessingRecipe supporting requiredHeat, fluid inputs and fluid outputs - set Mixing recipes to use the extended serializer in AllRecipeTypes - removed constructor parameters specifying fluid usage in recipes that do not support fluids (and changed the ConversionRecipe JEI support class back) - cleaned up annotations, ordered AllRecipeType enum values and imports, reformatted recipe code --- .../com/simibubi/create/AllRecipeTypes.java | 36 +++-- .../create/compat/jei/ConversionRecipe.java | 7 +- .../components/crusher/CrushingRecipe.java | 11 +- .../components/fan/SplashingRecipe.java | 8 +- .../components/millstone/MillingRecipe.java | 9 +- .../components/mixer/MixingRecipe.java | 143 +++++++++--------- .../components/press/PressingRecipe.java | 8 +- .../components/saw/CuttingRecipe.java | 8 +- .../processing/ProcessingRecipe.java | 31 ++-- .../ProcessingRecipeSerializer.java | 80 ++++++---- .../tools/SandPaperPolishingRecipe.java | 18 +-- 11 files changed, 174 insertions(+), 185 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllRecipeTypes.java b/src/main/java/com/simibubi/create/AllRecipeTypes.java index 28c52641a..c5d81e469 100644 --- a/src/main/java/com/simibubi/create/AllRecipeTypes.java +++ b/src/main/java/com/simibubi/create/AllRecipeTypes.java @@ -1,7 +1,5 @@ package com.simibubi.create; -import java.util.function.Supplier; - import com.simibubi.create.compat.jei.ConversionRecipe; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCraftingRecipe; import com.simibubi.create.content.contraptions.components.crusher.CrushingRecipe; @@ -12,11 +10,11 @@ import com.simibubi.create.content.contraptions.components.press.PressingRecipe; import com.simibubi.create.content.contraptions.components.saw.CuttingRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer; +import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer.IExtendedRecipeFactory; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer.IRecipeFactory; import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe; import com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperUpgradeRecipe; import com.simibubi.create.foundation.utility.Lang; - import net.minecraft.inventory.IInventory; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipeSerializer; @@ -26,18 +24,20 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.Registry; import net.minecraftforge.event.RegistryEvent; +import java.util.function.Supplier; + public enum AllRecipeTypes { BLOCKZAPPER_UPGRADE(BlockzapperUpgradeRecipe.Serializer::new, IRecipeType.CRAFTING), - MECHANICAL_CRAFTING(MechanicalCraftingRecipe.Serializer::new), - CRUSHING(processingSerializer(CrushingRecipe::new)), - MILLING(processingSerializer(MillingRecipe::new)), - SPLASHING(processingSerializer(SplashingRecipe::new)), - PRESSING(processingSerializer(PressingRecipe::new)), - CUTTING(processingSerializer(CuttingRecipe::new)), - MIXING(processingSerializer(MixingRecipe::new)), - SANDPAPER_POLISHING(processingSerializer(SandPaperPolishingRecipe::new)), CONVERSION(processingSerializer(ConversionRecipe::new)), + CRUSHING(processingSerializer(CrushingRecipe::new)), + CUTTING(processingSerializer(CuttingRecipe::new)), + MECHANICAL_CRAFTING(MechanicalCraftingRecipe.Serializer::new), + MILLING(processingSerializer(MillingRecipe::new)), + MIXING(extendedProcessingSerializer(MixingRecipe::new)), + PRESSING(processingSerializer(PressingRecipe::new)), + SANDPAPER_POLISHING(processingSerializer(SandPaperPolishingRecipe::new)), + SPLASHING(processingSerializer(SplashingRecipe::new)), ; @@ -45,11 +45,6 @@ public enum AllRecipeTypes { public Supplier> supplier; public IRecipeType> type; - @SuppressWarnings("unchecked") - public > T getType() { - return (T) type; - } - AllRecipeTypes(Supplier> supplier) { this(supplier, null); } @@ -87,4 +82,13 @@ public enum AllRecipeTypes { return () -> new ProcessingRecipeSerializer<>(factory); } + private static Supplier> extendedProcessingSerializer( + IExtendedRecipeFactory> factory) { + return () -> new ProcessingRecipeSerializer<>(factory); + } + + @SuppressWarnings("unchecked") + public > T getType() { + return (T) type; + } } diff --git a/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java b/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java index fe21c60d6..4c838bc55 100644 --- a/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java +++ b/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java @@ -3,7 +3,6 @@ package com.simibubi.create.compat.jei; import java.util.Collections; import java.util.List; -import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import com.simibubi.create.AllRecipeTypes; @@ -16,7 +15,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.wrapper.RecipeWrapper; /** @@ -29,8 +27,7 @@ import net.minecraftforge.items.wrapper.RecipeWrapper; public class ConversionRecipe extends ProcessingRecipe { public ConversionRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, @Nullable List fluidIngredients, - @Nullable List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.CONVERSION, id, group, ingredients, results, processingDuration); } @@ -45,7 +42,7 @@ public class ConversionRecipe extends ProcessingRecipe { public ConversionRecipe(ResourceLocation id, List ingredients, List results) { - this(id, "conversions", ingredients, results, -1, null, null); + this(id, "conversions", ingredients, results, -1); } @Override 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 407c0ad3b..5f5ff519c 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 @@ -1,21 +1,20 @@ package com.simibubi.create.content.contraptions.components.crusher; -import java.util.List; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; - import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.wrapper.RecipeWrapper; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; + +@ParametersAreNonnullByDefault public class CrushingRecipe extends AbstractCrushingRecipe { public CrushingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.CRUSHING, id, group, ingredients, results, processingDuration); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java index d873ae952..2ff2c545a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java @@ -1,26 +1,22 @@ package com.simibubi.create.content.contraptions.components.fan; -import java.util.List; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.logistics.InWorldProcessing; import com.simibubi.create.content.logistics.InWorldProcessing.SplashingInv; - import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; @ParametersAreNonnullByDefault public class SplashingRecipe extends ProcessingRecipe { public SplashingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.SPLASHING, id, group, ingredients, results, processingDuration); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillingRecipe.java index 242138934..dae11e3bf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillingRecipe.java @@ -1,25 +1,21 @@ package com.simibubi.create.content.contraptions.components.millstone; -import java.util.List; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.components.crusher.AbstractCrushingRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; - import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.wrapper.RecipeWrapper; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; @ParametersAreNonnullByDefault public class MillingRecipe extends AbstractCrushingRecipe { public MillingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.MILLING, id, group, ingredients, results, processingDuration); } @@ -35,5 +31,4 @@ public class MillingRecipe extends AbstractCrushingRecipe { protected int getMaxOutputCount() { return 4; } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java index adfac18fd..4857f4db6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java @@ -1,20 +1,11 @@ package com.simibubi.create.content.contraptions.components.mixer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; - -import javax.annotation.Nonnull; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.BasinTileEntity.BasinInputInventory; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; - import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.Ingredient; @@ -23,82 +14,86 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; +import javax.annotation.Nonnull; +import java.util.*; + public class MixingRecipe extends ProcessingRecipe { - public MixingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { - super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration); - } + public MixingRecipe(ResourceLocation id, String group, List ingredients, + List results, int processingDuration, List fluidIngredients, + List fluidResults, int requiredHeat) { + super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration, fluidIngredients, + fluidResults, requiredHeat); + } - public MixingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { - super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration, fluidIngredients, - fluidResults); - } + public static MixingRecipe of(IRecipe recipe) { + return new MixingRecipe(recipe.getId(), recipe.getGroup(), ProcessingIngredient.list(recipe.getIngredients()), + Collections.singletonList(new ProcessingOutput(recipe.getRecipeOutput(), 1)), -1, null, null, 0); + } - @Override - protected int getMaxInputCount() { - return 9; - } + @Override + protected int getMaxInputCount() { + return 9; + } - @Override - protected int getMaxOutputCount() { - return 1; - } + @Override + protected int getMaxOutputCount() { + return 1; + } - @Override - protected boolean canHaveCatalysts() { - return true; - } + @Override + protected boolean canHaveCatalysts() { + return true; + } - @Override - public boolean matches(BasinInputInventory inv, @Nonnull World worldIn) { - if (inv.isEmpty()) - return false; + @Override + public boolean matches(BasinInputInventory inv, @Nonnull World worldIn) { + if (inv.isEmpty()) + return false; - NonNullList ingredients = this.getIngredients(); - if (!ingredients.stream() - .allMatch(Ingredient::isSimple)) - return false; + NonNullList ingredients = this.getIngredients(); + if (!ingredients.stream() + .allMatch(Ingredient::isSimple)) + return false; - List remaining = new ArrayList<>(); - for (int slot = 0; slot < inv.getSizeInventory(); ++slot) { - ItemStack itemstack = inv.getStackInSlot(slot); - if (!itemstack.isEmpty()) { - remaining.add(itemstack.copy()); - } - } + List remaining = new ArrayList<>(); + for (int slot = 0; slot < inv.getSizeInventory(); ++slot) { + ItemStack itemstack = inv.getStackInSlot(slot); + if (!itemstack.isEmpty()) { + remaining.add(itemstack.copy()); + } + } - // sort by leniency - List sortedIngredients = new LinkedList<>(ingredients); - sortedIngredients.sort(Comparator.comparingInt(i -> i.getMatchingStacks().length)); - Ingredients: for (Ingredient ingredient : sortedIngredients) { - for (ItemStack stack : remaining) { - if (stack.isEmpty()) - continue; - if (ingredient.test(stack)) { - stack.shrink(1); - continue Ingredients; - } - } - return false; - } - return true; - } + // sort by leniency + List sortedIngredients = new LinkedList<>(ingredients); + sortedIngredients.sort(Comparator.comparingInt(i -> i.getMatchingStacks().length)); + Ingredients: + for (Ingredient ingredient : sortedIngredients) { + for (ItemStack stack : remaining) { + if (stack.isEmpty()) + continue; + if (ingredient.test(stack)) { + stack.shrink(1); + continue Ingredients; + } + } + return false; + } + return true; + } - public static MixingRecipe of(IRecipe recipe) { - return new MixingRecipe(recipe.getId(), recipe.getGroup(), ProcessingIngredient.list(recipe.getIngredients()), - Collections.singletonList(new ProcessingOutput(recipe.getRecipeOutput(), 1)), -1); - } + @Override + protected boolean canHaveFluidIngredient() { + return true; + } - @Override - protected boolean canHaveFluidIngredient() { - return true; - } + @Override + protected boolean canHaveFluidOutput() { + return true; + } - @Override - protected boolean canHaveFluidOutput() { - return true; - } + @Override + protected boolean requiresHeating() { + return this.requiredHeat > 0; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java index a71395bc8..3ff546dd5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java @@ -1,25 +1,21 @@ package com.simibubi.create.content.contraptions.components.press; -import java.util.List; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity.PressingInv; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; - import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; @ParametersAreNonnullByDefault public class PressingRecipe extends ProcessingRecipe { public PressingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.PRESSING, id, group, ingredients, results, processingDuration); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/CuttingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/CuttingRecipe.java index 80d9a377d..12f7bfffc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/CuttingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/CuttingRecipe.java @@ -1,25 +1,21 @@ package com.simibubi.create.content.contraptions.components.saw; -import java.util.List; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; - import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.wrapper.RecipeWrapper; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; @ParametersAreNonnullByDefault public class CuttingRecipe extends ProcessingRecipe { public CuttingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.CUTTING, id, group, ingredients, results, processingDuration); } 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 8d93a2200..8134ee208 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 @@ -1,11 +1,7 @@ package com.simibubi.create.content.contraptions.processing; -import java.util.List; -import java.util.stream.Collectors; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.Create; - import mcp.MethodsReturnNonnullByDefault; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -19,37 +15,31 @@ import net.minecraftforge.fluids.FluidStack; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; +import java.util.stream.Collectors; @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault public abstract class ProcessingRecipe implements IRecipe { protected final List ingredients; - private final List results; - private final IRecipeType type; - private final IRecipeSerializer serializer; protected final ResourceLocation id; protected final String group; protected final int processingDuration; protected final List fluidIngredients; protected final List fluidResults; + protected final int requiredHeat; + private final List results; + private final IRecipeType type; + private final IRecipeSerializer serializer; public ProcessingRecipe(AllRecipeTypes recipeType, ResourceLocation id, String group, List ingredients, List results, int processingDuration) { - this.type = recipeType.type; - this.serializer = recipeType.serializer; - this.id = id; - this.group = group; - this.ingredients = ingredients; - this.results = results; - this.processingDuration = processingDuration; - this.fluidIngredients = null; - this.fluidResults = null; - validate(recipeType); + this(recipeType, id, group, ingredients, results, processingDuration, null, null, 0); } public ProcessingRecipe(AllRecipeTypes recipeType, ResourceLocation id, String group, List ingredients, List results, int processingDuration, - @Nullable List fluidIngredients, @Nullable List fluidResults) { + @Nullable List fluidIngredients, @Nullable List fluidResults, int requiredHeat) { this.type = recipeType.type; this.serializer = recipeType.serializer; this.id = id; @@ -59,6 +49,7 @@ public abstract class ProcessingRecipe implements IRecipe< this.processingDuration = processingDuration; this.fluidIngredients = fluidIngredients; this.fluidResults = fluidResults; + this.requiredHeat = requiredHeat; validate(recipeType); } @@ -167,4 +158,8 @@ public abstract class ProcessingRecipe implements IRecipe< protected boolean canHaveFluidOutput() { return false; } + + protected boolean requiresHeating() { + return false; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java index a07dfb1e2..3c8de24d8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java @@ -1,11 +1,7 @@ package com.simibubi.create.content.contraptions.processing; -import java.util.ArrayList; -import java.util.List; - import com.google.gson.JsonElement; import com.google.gson.JsonObject; - import mcp.MethodsReturnNonnullByDefault; import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemStack; @@ -17,7 +13,10 @@ import net.minecraft.util.registry.Registry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.registries.ForgeRegistries; +import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.ArrayList; +import java.util.List; @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @@ -39,18 +38,11 @@ public class ProcessingRecipeSerializer> for (JsonElement e : JSONUtils.getJsonArray(json, "ingredients")) { JsonObject entry = e.getAsJsonObject(); if (JSONUtils.hasField(entry, "fluid")) { - Fluid fluid = ForgeRegistries.FLUIDS - .getValue(ResourceLocation.tryCreate(JSONUtils.getString(entry.get("fluid"), "fluid"))); - int amount = 1; - if (JSONUtils.hasField((JsonObject) e, "amount")) { - amount = JSONUtils.getInt(entry.get("amount"), "amount"); - } - if (fluid != null && amount > 0) - fluidIngredients.add(new FluidStack(fluid, amount)); + addFluidToList(fluidIngredients, entry); } else { int count = 1; - if (JSONUtils.hasField((JsonObject) e, "count")) { - count = JSONUtils.getInt(entry.get("count"), "count"); + if (JSONUtils.hasField(entry, "count")) { + count = JSONUtils.getInt(entry, "count"); } for (int i = 0; i < count; i++) { ingredients.add(ProcessingIngredient.parse(entry)); @@ -63,20 +55,13 @@ public class ProcessingRecipeSerializer> for (JsonElement e : JSONUtils.getJsonArray(json, "results")) { JsonObject entry = e.getAsJsonObject(); if (JSONUtils.hasField(entry, "fluid")) { - Fluid fluid = ForgeRegistries.FLUIDS - .getValue(ResourceLocation.tryCreate(JSONUtils.getString(entry.get("fluid"), "fluid"))); - int amount = 1; - if (JSONUtils.hasField((JsonObject) e, "amount")) { - amount = JSONUtils.getInt(entry.get("amount"), "amount"); - } - if (fluid != null && amount > 0) - fluidResults.add(new FluidStack(fluid, amount)); + addFluidToList(fluidResults, entry); } else { - String s1 = JSONUtils.getString(entry.get("item"), "item"); - int i = JSONUtils.getInt(entry.get("count"), "count"); + String s1 = JSONUtils.getString(entry, "item"); + int i = JSONUtils.getInt(entry, "count"); float chance = 1; - if (JSONUtils.hasField((JsonObject) e, "chance")) - chance = JSONUtils.getFloat(entry.get("chance"), "chance"); + if (JSONUtils.hasField(entry, "chance")) + chance = JSONUtils.getFloat(entry, "chance"); ItemStack itemstack = new ItemStack(Registry.ITEM.getOrDefault(new ResourceLocation(s1)), i); results.add(new ProcessingOutput(itemstack, chance)); } @@ -86,7 +71,22 @@ public class ProcessingRecipeSerializer> if (JSONUtils.hasField(json, "processingTime")) duration = JSONUtils.getInt(json, "processingTime"); - return this.factory.create(recipeId, s, ingredients, results, duration, fluidIngredients, fluidResults); + int requiredHeat = 0; + if (JSONUtils.hasField(json, "requiredHeat")) + requiredHeat = JSONUtils.getInt(json, "requiredHeat"); + + return this.factory.create(recipeId, s, ingredients, results, duration, fluidIngredients, fluidResults, + requiredHeat); + } + + private void addFluidToList(List fluidStacks, JsonObject entry) { + Fluid fluid = ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryCreate(JSONUtils.getString(entry, "fluid"))); + int amount = 1; + if (JSONUtils.hasField(entry, "amount")) { + amount = JSONUtils.getInt(entry, "amount"); + } + if (fluid != null && amount > 0) + fluidStacks.add(new FluidStack(fluid, amount)); } public T read(ResourceLocation recipeId, PacketBuffer buffer) { @@ -113,8 +113,10 @@ public class ProcessingRecipeSerializer> fluidResults.add(FluidStack.readFromPacket(buffer)); int duration = buffer.readInt(); + int requiredHeat = buffer.readInt(); - return this.factory.create(recipeId, s, ingredients, results, duration, fluidIngredients, fluidResults); + return this.factory.create(recipeId, s, ingredients, results, duration, fluidIngredients, fluidResults, + requiredHeat); } public void write(PacketBuffer buffer, T recipe) { @@ -141,12 +143,30 @@ public class ProcessingRecipeSerializer> } buffer.writeInt(recipe.processingDuration); + buffer.writeInt(recipe.requiredHeat); } public interface IRecipeFactory> { + default T create(ResourceLocation recipeId, String s, List ingredients, + List results, int duration, @Nullable List fluidIngredients, + @Nullable List fluidResults, int requiredHeat) { + return create(recipeId, s, ingredients, results, duration); + } + T create(ResourceLocation recipeId, String s, List ingredients, - List results, int duration, List fluidIngredients, - List fluidResults); + List results, int duration); } + public interface IExtendedRecipeFactory> extends IRecipeFactory { + @Override + T create(ResourceLocation recipeId, String s, List ingredients, + List results, int duration, @Nullable List fluidIngredients, + @Nullable List fluidResults, int requiredHeat); + + @Override + default T create(ResourceLocation recipeId, String s, List ingredients, + List results, int duration) { + throw new IllegalStateException("Incorrect recipe creation function used: " + recipeId); + } + } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java index b65e57c7e..c2a752b41 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java @@ -1,30 +1,26 @@ package com.simibubi.create.content.curiosities.tools; -import java.util.List; - import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe.SandPaperInv; - import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.RecipeWrapper; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; @ParametersAreNonnullByDefault public class SandPaperPolishingRecipe extends ProcessingRecipe { public SandPaperPolishingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration, List fluidIngredients, - List fluidResults) { + List results, int processingDuration) { super(AllRecipeTypes.SANDPAPER_POLISHING, id, group, ingredients, results, processingDuration); } @@ -41,17 +37,17 @@ public class SandPaperPolishingRecipe extends ProcessingRecipe { return stack; } + public static List> getMatchingRecipes(World world, ItemStack stack) { + return world.getRecipeManager() + .getRecipes(AllRecipeTypes.SANDPAPER_POLISHING.getType(), new SandPaperInv(stack), world); + } + @Override public boolean matches(SandPaperInv inv, World worldIn) { return ingredients.get(0) .test(inv.getStackInSlot(0)); } - public static List> getMatchingRecipes(World world, ItemStack stack) { - return world.getRecipeManager() - .getRecipes(AllRecipeTypes.SANDPAPER_POLISHING.getType(), new SandPaperInv(stack), world); - } - @Override protected int getMaxOutputCount() { return 1;