From 007c6ca38ad53b2913c49aaff892a62f618ddc11 Mon Sep 17 00:00:00 2001 From: Prospector Date: Sun, 1 Jan 2017 19:32:53 -0800 Subject: [PATCH] Add a use for bauxite and continue the great refactor of 2017 --- src/main/java/techreborn/init/ModRecipes.java | 6 +- .../IndustrialElectrolyzerRecipes.java | 58 +++++++++++++++++++ .../recipes/IndustrialGrinderRecipes.java | 6 +- .../init/recipes/RecipeMethods.java | 21 ++++--- 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 src/main/java/techreborn/init/recipes/IndustrialElectrolyzerRecipes.java diff --git a/src/main/java/techreborn/init/ModRecipes.java b/src/main/java/techreborn/init/ModRecipes.java index eb034d464..78e8e6d0f 100644 --- a/src/main/java/techreborn/init/ModRecipes.java +++ b/src/main/java/techreborn/init/ModRecipes.java @@ -27,10 +27,13 @@ import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.api.recipe.RecyclerRecipe; import techreborn.api.recipe.ScrapboxRecipe; import techreborn.api.recipe.machines.*; -import techreborn.blocks.*; +import techreborn.blocks.BlockMachineFrame; +import techreborn.blocks.BlockOre; +import techreborn.blocks.BlockOre2; import techreborn.compat.CompatManager; import techreborn.config.ConfigTechReborn; import techreborn.init.recipes.CraftingTableRecipes; +import techreborn.init.recipes.IndustrialElectrolyzerRecipes; import techreborn.init.recipes.IndustrialGrinderRecipes; import techreborn.items.*; import techreborn.parts.powerCables.ItemStandaloneCables; @@ -61,6 +64,7 @@ public class ModRecipes { CraftingTableRecipes.init(); IndustrialGrinderRecipes.init(); + IndustrialElectrolyzerRecipes.init(); addGeneralShapedRecipes(); addMachineRecipes(); diff --git a/src/main/java/techreborn/init/recipes/IndustrialElectrolyzerRecipes.java b/src/main/java/techreborn/init/recipes/IndustrialElectrolyzerRecipes.java new file mode 100644 index 000000000..73d7b6b26 --- /dev/null +++ b/src/main/java/techreborn/init/recipes/IndustrialElectrolyzerRecipes.java @@ -0,0 +1,58 @@ +package techreborn.init.recipes; + +import net.minecraft.item.ItemStack; +import reborncore.api.recipe.RecipeHandler; +import techreborn.api.recipe.machines.IndustrialElectrolyzerRecipe; +import techreborn.items.DynamicCell; + +import java.security.InvalidParameterException; + +/** + * Created by Prospector + */ +public class IndustrialElectrolyzerRecipes extends RecipeMethods { + public static void init() { + register(getOre("dustBauxite", 12), 100, 128, getMaterial("aluminum", 8, Type.DUST), getMaterial("titanium", 2, Type.SMALL_DUST), getMaterial("hydrogen", 5, Type.CELL)); + } + + static void register(ItemStack input, int ticks, int euPerTick, ItemStack... outputs) { + ItemStack output1; + ItemStack output2 = null; + ItemStack output3 = null; + ItemStack output4 = null; + + if (outputs.length == 3) { + output1 = outputs[0]; + output2 = outputs[1]; + output3 = outputs[2]; + } else if (outputs.length == 2) { + output1 = outputs[0]; + output2 = outputs[1]; + } else if (outputs.length == 1) { + output1 = outputs[0]; + } else if (outputs.length == 4) { + output1 = outputs[0]; + output2 = outputs[1]; + output3 = outputs[2]; + output4 = outputs[3]; + } else { + throw new InvalidParameterException("Invalid industrial electrolyzer outputs: " + outputs); + } + + int cellCount = 0; + for (ItemStack stack : outputs) { + if (stack.getItem() instanceof DynamicCell) { + cellCount += stack.getCount(); + } + } + + ItemStack cells = null; + if (cellCount > 0) { + if (cellCount > 64) { + throw new InvalidParameterException("Invalid industrial electrolyzer outputs: " + outputs + "(Recipe requires > 64 cells)"); + } + cells = DynamicCell.getEmptyCell(cellCount); + } + RecipeHandler.addRecipe(new IndustrialElectrolyzerRecipe(input, cells, output1, output2, output3, output4, ticks, euPerTick)); + } +} diff --git a/src/main/java/techreborn/init/recipes/IndustrialGrinderRecipes.java b/src/main/java/techreborn/init/recipes/IndustrialGrinderRecipes.java index c5cf34e3d..96e6b9c06 100644 --- a/src/main/java/techreborn/init/recipes/IndustrialGrinderRecipes.java +++ b/src/main/java/techreborn/init/recipes/IndustrialGrinderRecipes.java @@ -5,13 +5,13 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import org.apache.logging.log4j.Level; import reborncore.api.recipe.RecipeHandler; -import techreborn.Core; import techreborn.api.recipe.machines.IndustrialGrinderRecipe; import techreborn.blocks.BlockOre; import techreborn.init.ModFluids; +import java.security.InvalidParameterException; + /** * Created by Prospector */ @@ -171,7 +171,7 @@ public class IndustrialGrinderRecipes extends RecipeMethods { RecipeHandler.addRecipe(new IndustrialGrinderRecipe(output, fluid, inputs[0], inputs[1], inputs[2], inputs[3], ticks, euPerTick)); } else { - Core.logHelper.log(Level.ERROR, "Invalid industrial grinder recipe. Too many or too few inputs."); + throw new InvalidParameterException("Invalid industrial grinder inputs: " + inputs); } } } diff --git a/src/main/java/techreborn/init/recipes/RecipeMethods.java b/src/main/java/techreborn/init/recipes/RecipeMethods.java index c88974f45..bc9dc95cf 100644 --- a/src/main/java/techreborn/init/recipes/RecipeMethods.java +++ b/src/main/java/techreborn/init/recipes/RecipeMethods.java @@ -12,21 +12,20 @@ public abstract class RecipeMethods { static ItemStack getMaterial(String name, int count, Type type) { if (type == Type.DUST) { return ItemDusts.getDustByName(name, count); - } - if (type == Type.SMALL_DUST) { + } else if (type == Type.SMALL_DUST) { return ItemDustsSmall.getSmallDustByName(name, count); - } - if (type == Type.INGOT) { + } else if (type == Type.INGOT) { return ItemIngots.getIngotByName(name, count); - } - if (type == Type.GEM) { + } else if (type == Type.GEM) { return ItemGems.getGemByName(name, count); - } - if (type == Type.PLATE) { + } else if (type == Type.PLATE) { return ItemPlates.getPlateByName(name, count); - } - if (type == Type.NUGGET) { + } else if (type == Type.NUGGET) { return ItemNuggets.getNuggetByName(name, count); + } else if (type == Type.CELL) { + return ItemCells.getCellByName(name, count); + } else { + } return ItemStack.EMPTY; } @@ -53,6 +52,6 @@ public abstract class RecipeMethods { } enum Type { - DUST, SMALL_DUST, INGOT, NUGGET, PLATE, GEM + DUST, SMALL_DUST, INGOT, NUGGET, PLATE, GEM, CELL } }