mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
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
This commit is contained in:
parent
a73919357b
commit
02450bd2f7
11 changed files with 174 additions and 185 deletions
|
@ -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<IRecipeSerializer<?>> supplier;
|
||||
public IRecipeType<? extends IRecipe<? extends IInventory>> type;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IRecipeType<?>> T getType() {
|
||||
return (T) type;
|
||||
}
|
||||
|
||||
AllRecipeTypes(Supplier<IRecipeSerializer<?>> supplier) {
|
||||
this(supplier, null);
|
||||
}
|
||||
|
@ -87,4 +82,13 @@ public enum AllRecipeTypes {
|
|||
return () -> new ProcessingRecipeSerializer<>(factory);
|
||||
}
|
||||
|
||||
private static Supplier<IRecipeSerializer<?>> extendedProcessingSerializer(
|
||||
IExtendedRecipeFactory<? extends ProcessingRecipe<?>> factory) {
|
||||
return () -> new ProcessingRecipeSerializer<>(factory);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IRecipeType<?>> T getType() {
|
||||
return (T) type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RecipeWrapper> {
|
||||
|
||||
public ConversionRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, @Nullable List<FluidStack> fluidIngredients,
|
||||
@Nullable List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.CONVERSION, id, group, ingredients, results, processingDuration);
|
||||
}
|
||||
|
||||
|
@ -45,7 +42,7 @@ public class ConversionRecipe extends ProcessingRecipe<RecipeWrapper> {
|
|||
|
||||
public ConversionRecipe(ResourceLocation id, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results) {
|
||||
this(id, "conversions", ingredients, results, -1, null, null);
|
||||
this(id, "conversions", ingredients, results, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.CRUSHING, id, group, ingredients, results, processingDuration);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<InWorldProcessing.SplashingInv> {
|
||||
|
||||
public SplashingRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.SPLASHING, id, group, ingredients, results, processingDuration);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,18 +14,21 @@ 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<BasinInputInventory> {
|
||||
|
||||
public MixingRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration);
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults, int requiredHeat) {
|
||||
super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration, fluidIngredients,
|
||||
fluidResults, requiredHeat);
|
||||
}
|
||||
|
||||
public MixingRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> 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
|
||||
|
@ -73,7 +67,8 @@ public class MixingRecipe extends ProcessingRecipe<BasinInputInventory> {
|
|||
// sort by leniency
|
||||
List<Ingredient> sortedIngredients = new LinkedList<>(ingredients);
|
||||
sortedIngredients.sort(Comparator.comparingInt(i -> i.getMatchingStacks().length));
|
||||
Ingredients: for (Ingredient ingredient : sortedIngredients) {
|
||||
Ingredients:
|
||||
for (Ingredient ingredient : sortedIngredients) {
|
||||
for (ItemStack stack : remaining) {
|
||||
if (stack.isEmpty())
|
||||
continue;
|
||||
|
@ -87,11 +82,6 @@ public class MixingRecipe extends ProcessingRecipe<BasinInputInventory> {
|
|||
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;
|
||||
|
@ -101,4 +91,9 @@ public class MixingRecipe extends ProcessingRecipe<BasinInputInventory> {
|
|||
protected boolean canHaveFluidOutput() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean requiresHeating() {
|
||||
return this.requiredHeat > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MechanicalPressTileEntity.PressingInv> {
|
||||
|
||||
public PressingRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.PRESSING, id, group, ingredients, results, processingDuration);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RecipeWrapper> {
|
||||
|
||||
public CuttingRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.CUTTING, id, group, ingredients, results, processingDuration);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T extends IInventory> implements IRecipe<T> {
|
||||
protected final List<ProcessingIngredient> ingredients;
|
||||
private final List<ProcessingOutput> results;
|
||||
private final IRecipeType<?> type;
|
||||
private final IRecipeSerializer<?> serializer;
|
||||
protected final ResourceLocation id;
|
||||
protected final String group;
|
||||
protected final int processingDuration;
|
||||
protected final List<FluidStack> fluidIngredients;
|
||||
protected final List<FluidStack> fluidResults;
|
||||
protected final int requiredHeat;
|
||||
private final List<ProcessingOutput> results;
|
||||
private final IRecipeType<?> type;
|
||||
private final IRecipeSerializer<?> serializer;
|
||||
|
||||
public ProcessingRecipe(AllRecipeTypes recipeType, ResourceLocation id, String group,
|
||||
List<ProcessingIngredient> ingredients, List<ProcessingOutput> 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<ProcessingIngredient> ingredients, List<ProcessingOutput> results, int processingDuration,
|
||||
@Nullable List<FluidStack> fluidIngredients, @Nullable List<FluidStack> fluidResults) {
|
||||
@Nullable List<FluidStack> fluidIngredients, @Nullable List<FluidStack> fluidResults, int requiredHeat) {
|
||||
this.type = recipeType.type;
|
||||
this.serializer = recipeType.serializer;
|
||||
this.id = id;
|
||||
|
@ -59,6 +49,7 @@ public abstract class ProcessingRecipe<T extends IInventory> implements IRecipe<
|
|||
this.processingDuration = processingDuration;
|
||||
this.fluidIngredients = fluidIngredients;
|
||||
this.fluidResults = fluidResults;
|
||||
this.requiredHeat = requiredHeat;
|
||||
validate(recipeType);
|
||||
}
|
||||
|
||||
|
@ -167,4 +158,8 @@ public abstract class ProcessingRecipe<T extends IInventory> implements IRecipe<
|
|||
protected boolean canHaveFluidOutput() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean requiresHeating() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T extends ProcessingRecipe<?>>
|
|||
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<T extends ProcessingRecipe<?>>
|
|||
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<T extends ProcessingRecipe<?>>
|
|||
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<FluidStack> 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<T extends ProcessingRecipe<?>>
|
|||
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<T extends ProcessingRecipe<?>>
|
|||
}
|
||||
|
||||
buffer.writeInt(recipe.processingDuration);
|
||||
buffer.writeInt(recipe.requiredHeat);
|
||||
}
|
||||
|
||||
public interface IRecipeFactory<T extends ProcessingRecipe<?>> {
|
||||
T create(ResourceLocation recipeId, String s, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int duration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults);
|
||||
default T create(ResourceLocation recipeId, String s, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int duration, @Nullable List<FluidStack> fluidIngredients,
|
||||
@Nullable List<FluidStack> fluidResults, int requiredHeat) {
|
||||
return create(recipeId, s, ingredients, results, duration);
|
||||
}
|
||||
|
||||
T create(ResourceLocation recipeId, String s, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int duration);
|
||||
}
|
||||
|
||||
public interface IExtendedRecipeFactory<T extends ProcessingRecipe<?>> extends IRecipeFactory<T> {
|
||||
@Override
|
||||
T create(ResourceLocation recipeId, String s, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int duration, @Nullable List<FluidStack> fluidIngredients,
|
||||
@Nullable List<FluidStack> fluidResults, int requiredHeat);
|
||||
|
||||
@Override
|
||||
default T create(ResourceLocation recipeId, String s, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int duration) {
|
||||
throw new IllegalStateException("Incorrect recipe creation function used: " + recipeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SandPaperInv> {
|
||||
|
||||
public SandPaperPolishingRecipe(ResourceLocation id, String group, List<ProcessingIngredient> ingredients,
|
||||
List<ProcessingOutput> results, int processingDuration, List<FluidStack> fluidIngredients,
|
||||
List<FluidStack> fluidResults) {
|
||||
List<ProcessingOutput> results, int processingDuration) {
|
||||
super(AllRecipeTypes.SANDPAPER_POLISHING, id, group, ingredients, results, processingDuration);
|
||||
}
|
||||
|
||||
|
@ -41,17 +37,17 @@ public class SandPaperPolishingRecipe extends ProcessingRecipe<SandPaperInv> {
|
|||
return stack;
|
||||
}
|
||||
|
||||
public static List<IRecipe<SandPaperInv>> 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<IRecipe<SandPaperInv>> getMatchingRecipes(World world, ItemStack stack) {
|
||||
return world.getRecipeManager()
|
||||
.getRecipes(AllRecipeTypes.SANDPAPER_POLISHING.getType(), new SandPaperInv(stack), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxOutputCount() {
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue