Minor cleanup changes

- Change AllRecipeTypes to have less repetition and force getter usage
This commit is contained in:
PepperBell 2021-07-16 15:11:28 -07:00
parent 681791a329
commit 1dd7c4bc1e
13 changed files with 94 additions and 77 deletions

View File

@ -17,7 +17,6 @@ import com.simibubi.create.content.contraptions.fluids.actors.FillingRecipe;
import com.simibubi.create.content.contraptions.itemAssembly.SequencedAssemblyRecipeSerializer; import com.simibubi.create.content.contraptions.itemAssembly.SequencedAssemblyRecipeSerializer;
import com.simibubi.create.content.contraptions.processing.BasinRecipe; import com.simibubi.create.content.contraptions.processing.BasinRecipe;
import com.simibubi.create.content.contraptions.processing.EmptyingRecipe; import com.simibubi.create.content.contraptions.processing.EmptyingRecipe;
import com.simibubi.create.content.contraptions.processing.ProcessingRecipe;
import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeFactory; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeFactory;
import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeSerializer;
import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe; import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe;
@ -36,62 +35,56 @@ import net.minecraftforge.event.RegistryEvent;
public enum AllRecipeTypes { public enum AllRecipeTypes {
MECHANICAL_CRAFTING(MechanicalCraftingRecipe.Serializer::new), MECHANICAL_CRAFTING(MechanicalCraftingRecipe.Serializer::new),
CONVERSION(processingSerializer(ConversionRecipe::new)), CONVERSION(ConversionRecipe::new),
CRUSHING(processingSerializer(CrushingRecipe::new)), CRUSHING(CrushingRecipe::new),
CUTTING(processingSerializer(CuttingRecipe::new)), CUTTING(CuttingRecipe::new),
MILLING(processingSerializer(MillingRecipe::new)), MILLING(MillingRecipe::new),
BASIN(processingSerializer(BasinRecipe::new)), BASIN(BasinRecipe::new),
MIXING(processingSerializer(MixingRecipe::new)), MIXING(MixingRecipe::new),
COMPACTING(processingSerializer(CompactingRecipe::new)), COMPACTING(CompactingRecipe::new),
PRESSING(processingSerializer(PressingRecipe::new)), PRESSING(PressingRecipe::new),
SANDPAPER_POLISHING(processingSerializer(SandPaperPolishingRecipe::new)), SANDPAPER_POLISHING(SandPaperPolishingRecipe::new),
SPLASHING(processingSerializer(SplashingRecipe::new)), SPLASHING(SplashingRecipe::new),
DEPLOYING(processingSerializer(DeployerApplicationRecipe::new)), DEPLOYING(DeployerApplicationRecipe::new),
FILLING(processingSerializer(FillingRecipe::new)), FILLING(FillingRecipe::new),
EMPTYING(processingSerializer(EmptyingRecipe::new)), EMPTYING(EmptyingRecipe::new),
SEQUENCED_ASSEMBLY(SequencedAssemblyRecipeSerializer::new), SEQUENCED_ASSEMBLY(SequencedAssemblyRecipeSerializer::new),
; ;
public IRecipeSerializer<?> serializer; private ResourceLocation id;
public Supplier<IRecipeSerializer<?>> supplier; private Supplier<IRecipeSerializer<?>> serializerSupplier;
public IRecipeType<? extends IRecipe<? extends IInventory>> type; private Supplier<IRecipeType<?>> typeSupplier;
private IRecipeSerializer<?> serializer;
private IRecipeType<?> type;
AllRecipeTypes(Supplier<IRecipeSerializer<?>> supplier) { AllRecipeTypes(Supplier<IRecipeSerializer<?>> serializerSupplier, Supplier<IRecipeType<?>> typeSupplier) {
this(supplier, null); this.id = Create.asResource(Lang.asId(name()));
this.serializerSupplier = serializerSupplier;
this.typeSupplier = typeSupplier;
} }
AllRecipeTypes(Supplier<IRecipeSerializer<?>> supplier, AllRecipeTypes(Supplier<IRecipeSerializer<?>> serializerSupplier, IRecipeType<?> existingType) {
IRecipeType<? extends IRecipe<? extends IInventory>> existingType) { this(serializerSupplier, () -> existingType);
this.supplier = supplier;
this.type = existingType;
} }
public static void register(RegistryEvent.Register<IRecipeSerializer<?>> event) { AllRecipeTypes(Supplier<IRecipeSerializer<?>> serializerSupplier) {
ShapedRecipe.setCraftingSize(9, 9); this.id = Create.asResource(Lang.asId(name()));
this.serializerSupplier = serializerSupplier;
for (AllRecipeTypes r : AllRecipeTypes.values()) { this.typeSupplier = () -> simpleType(id);
if (r.type == null)
r.type = customType(Lang.asId(r.name()));
r.serializer = r.supplier.get();
ResourceLocation location = new ResourceLocation(Create.ID, Lang.asId(r.name()));
event.getRegistry()
.register(r.serializer.setRegistryName(location));
}
} }
private static <T extends IRecipe<?>> IRecipeType<T> customType(String id) { AllRecipeTypes(ProcessingRecipeFactory<?> processingFactory) {
return Registry.register(Registry.RECIPE_TYPE, new ResourceLocation(Create.ID, id), new IRecipeType<T>() { this(processingSerializer(processingFactory));
public String toString() {
return Create.ID + ":" + id;
}
});
} }
private static Supplier<IRecipeSerializer<?>> processingSerializer( public ResourceLocation getId() {
ProcessingRecipeFactory<? extends ProcessingRecipe<?>> factory) { return id;
return () -> new ProcessingRecipeSerializer<>(factory); }
@SuppressWarnings("unchecked")
public <T extends IRecipeSerializer<?>> T getSerializer() {
return (T) serializer;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -103,4 +96,30 @@ public enum AllRecipeTypes {
return world.getRecipeManager() return world.getRecipeManager()
.getRecipeFor(getType(), inv, world); .getRecipeFor(getType(), inv, world);
} }
public static void register(RegistryEvent.Register<IRecipeSerializer<?>> event) {
ShapedRecipe.setCraftingSize(9, 9);
for (AllRecipeTypes r : AllRecipeTypes.values()) {
r.serializer = r.serializerSupplier.get();
r.type = r.typeSupplier.get();
r.serializer.setRegistryName(r.id);
event.getRegistry()
.register(r.serializer);
}
}
private static Supplier<IRecipeSerializer<?>> processingSerializer(ProcessingRecipeFactory<?> factory) {
return () -> new ProcessingRecipeSerializer<>(factory);
}
public static <T extends IRecipe<?>> IRecipeType<T> simpleType(ResourceLocation id) {
String stringId = id.toString();
return Registry.register(Registry.RECIPE_TYPE, id, new IRecipeType<T>() {
public String toString() {
return stringId;
}
});
}
} }

View File

@ -241,7 +241,8 @@ public class AllShapes {
} }
public static class Builder { public static class Builder {
VoxelShape shape;
private VoxelShape shape;
public Builder(VoxelShape shape) { public Builder(VoxelShape shape) {
this.shape = shape; this.shape = shape;

View File

@ -179,7 +179,7 @@ public class CreateJEI implements IModPlugin {
deploying = register("deploying", DeployingCategory::new) deploying = register("deploying", DeployingCategory::new)
.recipeList( .recipeList(
() -> DeployerApplicationRecipe.convert(findRecipesByType(AllRecipeTypes.SANDPAPER_POLISHING.type))) () -> DeployerApplicationRecipe.convert(findRecipesByType(AllRecipeTypes.SANDPAPER_POLISHING.getType())))
.recipes(AllRecipeTypes.DEPLOYING) .recipes(AllRecipeTypes.DEPLOYING)
.catalyst(AllBlocks.DEPLOYER::get) .catalyst(AllBlocks.DEPLOYER::get)
.catalyst(AllBlocks.DEPOT::get) .catalyst(AllBlocks.DEPOT::get)
@ -205,7 +205,7 @@ public class CreateJEI implements IModPlugin {
.recipes(r -> r.getSerializer() == IRecipeSerializer.SHAPELESS_RECIPE && r.getIngredients() .recipes(r -> r.getSerializer() == IRecipeSerializer.SHAPELESS_RECIPE && r.getIngredients()
.size() == 1) .size() == 1)
.recipes( .recipes(
r -> (r.getType() == IRecipeType.CRAFTING && r.getType() != AllRecipeTypes.MECHANICAL_CRAFTING.type) r -> (r.getType() == IRecipeType.CRAFTING && r.getType() != AllRecipeTypes.MECHANICAL_CRAFTING.getType())
&& (r instanceof ShapedRecipe)) && (r instanceof ShapedRecipe))
.catalyst(AllBlocks.MECHANICAL_CRAFTER::get) .catalyst(AllBlocks.MECHANICAL_CRAFTER::get)
.enableWhen(c -> c.allowRegularCraftingInCrafter) .enableWhen(c -> c.allowRegularCraftingInCrafter)

View File

@ -33,17 +33,17 @@ public class MechanicalCraftingRecipe extends ShapedRecipe {
@Override @Override
public IRecipeType<?> getType() { public IRecipeType<?> getType() {
return AllRecipeTypes.MECHANICAL_CRAFTING.type; return AllRecipeTypes.MECHANICAL_CRAFTING.getType();
} }
@Override @Override
public boolean isSpecial() { public boolean isSpecial() {
return true; return true;
} }
@Override @Override
public IRecipeSerializer<?> getSerializer() { public IRecipeSerializer<?> getSerializer() {
return AllRecipeTypes.MECHANICAL_CRAFTING.serializer; return AllRecipeTypes.MECHANICAL_CRAFTING.getSerializer();
} }
public static class Serializer extends ShapedRecipe.Serializer { public static class Serializer extends ShapedRecipe.Serializer {
@ -52,7 +52,7 @@ public class MechanicalCraftingRecipe extends ShapedRecipe {
public ShapedRecipe fromJson(ResourceLocation recipeId, JsonObject json) { public ShapedRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
return fromShaped(super.fromJson(recipeId, json)); return fromShaped(super.fromJson(recipeId, json));
} }
@Override @Override
public ShapedRecipe fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) { public ShapedRecipe fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) {
return fromShaped(super.fromNetwork(recipeId, buffer)); return fromShaped(super.fromNetwork(recipeId, buffer));

View File

@ -229,7 +229,7 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity {
return ((r.getSerializer() == IRecipeSerializer.SHAPELESS_RECIPE return ((r.getSerializer() == IRecipeSerializer.SHAPELESS_RECIPE
&& AllConfigs.SERVER.recipes.allowShapelessInMixer.get() && r.getIngredients() && AllConfigs.SERVER.recipes.allowShapelessInMixer.get() && r.getIngredients()
.size() > 1) .size() > 1)
|| r.getType() == AllRecipeTypes.MIXING.type); || r.getType() == AllRecipeTypes.MIXING.getType());
} }
@Override @Override

View File

@ -346,7 +346,7 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity {
@Override @Override
protected <C extends IInventory> boolean matchStaticFilters(IRecipe<C> recipe) { protected <C extends IInventory> boolean matchStaticFilters(IRecipe<C> recipe) {
return (recipe instanceof ICraftingRecipe && canCompress(recipe.getIngredients())) return (recipe instanceof ICraftingRecipe && canCompress(recipe.getIngredients()))
|| recipe.getType() == AllRecipeTypes.COMPACTING.type; || recipe.getType() == AllRecipeTypes.COMPACTING.getType();
} }
@Override @Override

View File

@ -34,7 +34,7 @@ public class SequencedAssemblyRecipeBuilder {
public SequencedAssemblyRecipeBuilder(ResourceLocation id) { public SequencedAssemblyRecipeBuilder(ResourceLocation id) {
recipeConditions = new ArrayList<>(); recipeConditions = new ArrayList<>();
this.recipe = new SequencedAssemblyRecipe(id, this.recipe = new SequencedAssemblyRecipe(id,
(SequencedAssemblyRecipeSerializer) AllRecipeTypes.SEQUENCED_ASSEMBLY.serializer); AllRecipeTypes.SEQUENCED_ASSEMBLY.getSerializer());
} }
public <T extends ProcessingRecipe<?>> SequencedAssemblyRecipeBuilder addStep(ProcessingRecipeFactory<T> factory, public <T extends ProcessingRecipe<?>> SequencedAssemblyRecipeBuilder addStep(ProcessingRecipeFactory<T> factory,

View File

@ -52,10 +52,10 @@ public abstract class ProcessingRecipe<T extends IInventory> implements IRecipe<
this.processingDuration = params.processingDuration; this.processingDuration = params.processingDuration;
this.fluidIngredients = params.fluidIngredients; this.fluidIngredients = params.fluidIngredients;
this.fluidResults = params.fluidResults; this.fluidResults = params.fluidResults;
this.serializer = recipeType.serializer; this.serializer = recipeType.getSerializer();
this.requiredHeat = params.requiredHeat; this.requiredHeat = params.requiredHeat;
this.ingredients = params.ingredients; this.ingredients = params.ingredients;
this.type = recipeType.type; this.type = recipeType.getType();
this.results = params.results; this.results = params.results;
this.id = params.id; this.id = params.id;

View File

@ -192,15 +192,15 @@ public class ProcessingRecipeBuilder<T extends ProcessingRecipe<?>> {
public static class ProcessingRecipeParams { public static class ProcessingRecipeParams {
ResourceLocation id; protected ResourceLocation id;
NonNullList<Ingredient> ingredients; protected NonNullList<Ingredient> ingredients;
NonNullList<ProcessingOutput> results; protected NonNullList<ProcessingOutput> results;
NonNullList<FluidIngredient> fluidIngredients; protected NonNullList<FluidIngredient> fluidIngredients;
NonNullList<FluidStack> fluidResults; protected NonNullList<FluidStack> fluidResults;
int processingDuration; protected int processingDuration;
HeatCondition requiredHeat; protected HeatCondition requiredHeat;
ProcessingRecipeParams(ResourceLocation id) { protected ProcessingRecipeParams(ResourceLocation id) {
this.id = id; this.id = id;
ingredients = NonNullList.create(); ingredients = NonNullList.create();
results = NonNullList.create(); results = NonNullList.create();
@ -226,7 +226,7 @@ public class ProcessingRecipeBuilder<T extends ProcessingRecipe<?>> {
String typeName = Lang.asId(recipeType.name()); String typeName = Lang.asId(recipeType.name());
this.recipe = recipe; this.recipe = recipe;
if (!(recipeType.serializer instanceof ProcessingRecipeSerializer)) if (!(recipeType.getSerializer() instanceof ProcessingRecipeSerializer))
throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName); throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName);
this.id = new ResourceLocation(recipe.getId().getNamespace(), this.id = new ResourceLocation(recipe.getId().getNamespace(),

View File

@ -11,12 +11,12 @@ import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public abstract class PotatoProjectileRenderMode { public interface PotatoProjectileRenderMode {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public abstract void transform(MatrixStack ms, PotatoProjectileEntity entity, float pt); void transform(MatrixStack ms, PotatoProjectileEntity entity, float pt);
public static class Billboard extends PotatoProjectileRenderMode { public static class Billboard implements PotatoProjectileRenderMode {
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
@ -47,7 +47,7 @@ public abstract class PotatoProjectileRenderMode {
} }
} }
public static class TowardMotion extends PotatoProjectileRenderMode { public static class TowardMotion implements PotatoProjectileRenderMode {
private int spriteAngleOffset; private int spriteAngleOffset;
private float spin; private float spin;
@ -72,7 +72,7 @@ public abstract class PotatoProjectileRenderMode {
} }
public static class StuckToEntity extends PotatoProjectileRenderMode { public static class StuckToEntity implements PotatoProjectileRenderMode {
private Vector3d offset; private Vector3d offset;

View File

@ -1,11 +1,11 @@
package com.simibubi.create.foundation.config; package com.simibubi.create.foundation.config;
import com.simibubi.create.foundation.config.ConfigBase.ConfigBool; import com.simibubi.create.foundation.config.ConfigBase.ConfigBool;
import com.simibubi.create.foundation.config.ConfigBase.ConfigEnum; import com.simibubi.create.foundation.config.ConfigBase.ConfigEnum;
import com.simibubi.create.foundation.config.ConfigBase.ConfigFloat; import com.simibubi.create.foundation.config.ConfigBase.ConfigFloat;
import com.simibubi.create.foundation.config.ConfigBase.ConfigGroup; import com.simibubi.create.foundation.config.ConfigBase.ConfigGroup;
import com.simibubi.create.foundation.config.ConfigBase.ConfigInt; import com.simibubi.create.foundation.config.ConfigBase.ConfigInt;
public class CKinetics extends ConfigBase { public class CKinetics extends ConfigBase {
public ConfigBool disableStress = b(false, "disableStress", Comments.disableStress); public ConfigBool disableStress = b(false, "disableStress", Comments.disableStress);

View File

@ -183,7 +183,7 @@ public class MechanicalCraftingRecipeBuilder {
} }
public IRecipeSerializer<?> getType() { public IRecipeSerializer<?> getType() {
return AllRecipeTypes.MECHANICAL_CRAFTING.serializer; return AllRecipeTypes.MECHANICAL_CRAFTING.getSerializer();
} }
public ResourceLocation getId() { public ResourceLocation getId() {

View File

@ -20,8 +20,6 @@ import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidAttributes;
import com.simibubi.create.foundation.data.recipe.CreateRecipeProvider.GeneratedRecipe;
public abstract class ProcessingRecipeGen extends CreateRecipeProvider { public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
protected static List<ProcessingRecipeGen> generators = new ArrayList<>(); protected static List<ProcessingRecipeGen> generators = new ArrayList<>();
@ -116,9 +114,8 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
return create(Create.asResource(name), transform); return create(Create.asResource(name), transform);
} }
@SuppressWarnings("unchecked")
protected <T extends ProcessingRecipe<?>> ProcessingRecipeSerializer<T> getSerializer() { protected <T extends ProcessingRecipe<?>> ProcessingRecipeSerializer<T> getSerializer() {
ProcessingRecipeSerializer<T> serializer = (ProcessingRecipeSerializer<T>) getRecipeType().serializer; ProcessingRecipeSerializer<T> serializer = getRecipeType().getSerializer();
return serializer; return serializer;
} }