From f534e1b3b6fc5e7017050e5d71edfccb9674e01d Mon Sep 17 00:00:00 2001 From: Johannes Lohrer Date: Sun, 19 Apr 2015 20:50:13 +0200 Subject: [PATCH] made additional outputs a sequence to allow additional machines so these commits should basically close #760 --- .../integration/gregtech/RecipeRegistry.scala | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/main/scala/li/cil/oc/integration/gregtech/RecipeRegistry.scala b/src/main/scala/li/cil/oc/integration/gregtech/RecipeRegistry.scala index d5808e2ca..bfd69d8ec 100644 --- a/src/main/scala/li/cil/oc/integration/gregtech/RecipeRegistry.scala +++ b/src/main/scala/li/cil/oc/integration/gregtech/RecipeRegistry.scala @@ -13,7 +13,7 @@ import scala.collection.convert.WrapAsScala._ object RecipeRegistry { - def getGTRecipesWithEU(output: ItemStack, recipe: Config): (Array[ItemStack], Option[Array[ItemStack]], Option[FluidStack], Option[FluidStack], Option[ItemStack], Int, Int) = { + def getGTRecipesWithEU(output: ItemStack, recipe: Config): (Array[ItemStack], Option[Array[ItemStack]], Option[FluidStack], Option[FluidStack], Seq[ItemStack], Int, Int) = { val inputs = (recipe.getValue("input").unwrapped() match { case list: util.List[AnyRef]@unchecked => list.map(Recipes.parseIngredient) @@ -55,11 +55,34 @@ object RecipeRegistry { val eu = recipe.getInt("eu") val duration = recipe.getInt("time") + var additionalOutput = Seq.empty[ItemStack] + if(recipe.hasPath("additionalOutput")) + { + additionalOutput = (recipe.getValue("additionalOutput").unwrapped() match { + case list: util.List[AnyRef]@unchecked => list.map(Recipes.parseIngredient) + case other => Seq(Recipes.parseIngredient(other)) + }) map { + case stack: ItemStack => stack + case name: String => val ores = OreDictionary.getOres(name) + if(ores.size()>0) + ores.get(0) + else + null + case other => throw new RecipeException(s"Invalid ingredient type: $other.") + } + + val outputCount = recipe.getIntList("outputCount") + if (outputCount.size() != additionalOutput.size) { + throw new RecipeException(s"Outputs and output count mismatch: ${additionalOutput.size} != ${outputCount.size}.") + } + (additionalOutput, outputCount).zipped.foreach((stack, count) => if (stack != null && count > 0) stack.stackSize = stack.getMaxStackSize min count) + } - //TODO add output - val additionalOutput: Option[ItemStack] = None (inputs, inputCount).zipped.foreach((stacks, count) => stacks.foreach(stack => if (stack != null && count > 0) stack.stackSize = stack.getMaxStackSize min count)) + + + inputs.padTo(2, null) val input = inputs.head (input, Option(inputs.last), inputFluidStack, outputFluidStack, additionalOutput, eu, duration) @@ -113,10 +136,8 @@ object RecipeRegistry { def addGTCutterRecipe(output: ItemStack, recipe: Config) { val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe) var add :ItemStack = null - additionalOutput match{ - case Some(a) => add = a - case _=> - } + if(additionalOutput.size>1) + add = additionalOutput.head for (input1 <- inputs1) { fluidStackIn match { case Some(fluid) => @@ -131,10 +152,9 @@ object RecipeRegistry { def addGTCannerRecipe(output: ItemStack, recipe: Config) { val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe) var add :ItemStack = null - additionalOutput match{ - case Some(a) => add = a - case _=> - } + if(additionalOutput.size>1) + add = additionalOutput.head + for (input1 <- inputs1) { inputs2 match { case Some(inputs2List) => @@ -204,10 +224,8 @@ object RecipeRegistry { def addGTLatheRecipe(output: ItemStack, recipe: Config) { val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe) var add :ItemStack = null - additionalOutput match{ - case Some(a) => add = a - case _=> - } + if(additionalOutput.size>1) + add = additionalOutput.head for (input1 <- inputs1) { gregtech.api.GregTech_API.sRecipeAdder.addLatheRecipe(input1, output, add, duration, eu) }