mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 17:28:52 -04:00
Documented GT recipe handlers in recipe set.
Renamed a few things, simplified a few things, scalafied a few things.
This commit is contained in:
parent
b78c446c22
commit
a8389f7056
@ -1,6 +1,34 @@
|
||||
# Do not change this file, it is rewritten each time you start the game.
|
||||
# Instead, use the user.recipes file to edit recipes by redefining them there.
|
||||
|
||||
# Note that there is support for a number of GregTech machines, by using the
|
||||
# appropriate `type` specifier. Available types are:
|
||||
# - gt_alloySmelter : Alloy Smelter Recipe
|
||||
# - gt_assembler : Circuit Assembler Machine
|
||||
# - gt_bender : Plate Bending Machine Recipe
|
||||
# - gt_canner : Canning Machine Recipe
|
||||
# - gt_chemical : Chemical Recipe
|
||||
# - gt_cnc : CNC-Machine Recipe
|
||||
# - gt_cutter : Cutter Recipe
|
||||
# - gt_lathe : Lathe Machine Recipe
|
||||
# - gt_wiremill : Wiremill Recipe
|
||||
#
|
||||
# For these types, there a few more options for inputs and outputs. A full
|
||||
# recipe using all these options would look like this:
|
||||
# name {
|
||||
# type: gt_???
|
||||
# input: ["primaryInput", "possiblyOptionalSecondaryInput"]
|
||||
# count: [1, 2] # would mean 1 of primary, 2 of secondary
|
||||
# output: 2 # size of primary output stack
|
||||
# eu: EU consumed for the operation
|
||||
# time: time it takes to complete the operation, in ticks.
|
||||
# # The following are usually optional.
|
||||
# secondaryOutput: ["secondaryOutput1", "secondaryOutput2"] # Max number depends on machine.
|
||||
# secondaryOutputCount: [2, 2] # Like `count` to `input`.
|
||||
# inputFluid: {name="water", amount="500"}
|
||||
# outputFluid: {name="lava"} # defaults to amount = 1000
|
||||
# }
|
||||
|
||||
include file("hardmode.recipes")
|
||||
|
||||
analyzer {
|
||||
|
@ -83,7 +83,8 @@ class Proxy {
|
||||
|
||||
OpenComputers.log.info("Initializing mod integration.")
|
||||
Mods.init()
|
||||
OpenComputers.log.info("Initializing Recipes.")
|
||||
|
||||
OpenComputers.log.info("Initializing recipes.")
|
||||
Recipes.init()
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package li.cil.oc.common.recipe
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import java.util
|
||||
|
||||
import com.typesafe.config._
|
||||
import cpw.mods.fml.common.Loader
|
||||
@ -14,17 +13,16 @@ import li.cil.oc.common.init.Items
|
||||
import li.cil.oc.common.item.Delegator
|
||||
import li.cil.oc.common.item.SimpleItem
|
||||
import li.cil.oc.common.item.data.PrintData
|
||||
import li.cil.oc.integration.Mods
|
||||
import li.cil.oc.integration.util.NEI
|
||||
import li.cil.oc.util.Color
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemBlock
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.item.crafting.FurnaceRecipes
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.RegistryNamespaced
|
||||
import net.minecraftforge.fluids.{Fluid, FluidRegistry}
|
||||
import net.minecraftforge.fluids.FluidRegistry
|
||||
import net.minecraftforge.fluids.FluidStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import net.minecraftforge.oredict.RecipeSorter
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category
|
||||
@ -37,11 +35,10 @@ object Recipes {
|
||||
val list = mutable.LinkedHashMap.empty[ItemStack, String]
|
||||
val oreDictEntries = mutable.LinkedHashMap.empty[String, ItemStack]
|
||||
var hadErrors = false
|
||||
val recipeMap = mutable.LinkedHashMap.empty[String, (ItemStack, Config) => Unit]
|
||||
val recipeHandlers = mutable.LinkedHashMap.empty[String, (ItemStack, Config) => Unit]
|
||||
|
||||
|
||||
def registerRecipe(name: String, recipe: (ItemStack, Config) => Unit): Unit = {
|
||||
recipeMap += name -> recipe
|
||||
def registerRecipeHandler(name: String, recipe: (ItemStack, Config) => Unit): Unit = {
|
||||
recipeHandlers += name -> recipe
|
||||
}
|
||||
|
||||
def addBlock(instance: Block, name: String, oreDict: String*) = {
|
||||
@ -290,34 +287,22 @@ object Recipes {
|
||||
list.clear()
|
||||
}
|
||||
|
||||
private def addRecipe(output: ItemStack, recipe: Config, name: String) = {
|
||||
|
||||
private def addRecipe(output: ItemStack, recipe: Config, name: String) = try {
|
||||
val recipeType = tryGetType(recipe)
|
||||
try {
|
||||
recipeMap.get(recipeType) match {
|
||||
case Some(x) => x(output, recipe)
|
||||
case _ => OpenComputers.log.error(s"Failed adding $recipeType recipe for '$name', you will not be able to craft this item!")
|
||||
hadErrors = true
|
||||
|
||||
}
|
||||
}
|
||||
catch {
|
||||
case e: RecipeException =>
|
||||
OpenComputers.log.error(s"Failed adding $recipeType recipe for $name, you will not be able to craft this item! The error was: ${e.getMessage}")
|
||||
recipeHandlers.get(recipeType) match {
|
||||
case Some(recipeHandler) => recipeHandler(output, recipe)
|
||||
case _ =>
|
||||
OpenComputers.log.error(s"Failed adding recipe for $name, you will not be able to craft this item. The error was: Invalid recipe type '$recipeType'.")
|
||||
hadErrors = true
|
||||
}
|
||||
}
|
||||
|
||||
def parseFluidIngredient(entry: AnyRef): Option[Fluid] = entry match {
|
||||
case name: String => {
|
||||
if (name == null || name.trim.isEmpty) None
|
||||
else if (FluidRegistry.getFluid(name) != null) Option(FluidRegistry.getFluid(name))
|
||||
else None
|
||||
}
|
||||
case _ => None
|
||||
|
||||
catch {
|
||||
case e: RecipeException =>
|
||||
OpenComputers.log.error(s"Failed adding recipe for $name, you will not be able to craft this item.", e)
|
||||
hadErrors = true
|
||||
}
|
||||
|
||||
def tryGetCount(recipe: Config) = if (recipe.hasPath("output")) recipe.getInt("output") else 1
|
||||
|
||||
def parseIngredient(entry: AnyRef) = entry match {
|
||||
case map: java.util.Map[AnyRef, AnyRef]@unchecked =>
|
||||
@ -366,6 +351,14 @@ object Recipes {
|
||||
case other => throw new RecipeException(s"Invalid ingredient type (not a map or string): $other")
|
||||
}
|
||||
|
||||
def parseFluidIngredient(entry: Config): Option[FluidStack] = {
|
||||
val fluid = FluidRegistry.getFluid(entry.getString("name"))
|
||||
val amount =
|
||||
if (entry.hasPath("amount")) entry.getInt("amount")
|
||||
else 1000
|
||||
Option(new FluidStack(fluid, amount))
|
||||
}
|
||||
|
||||
private def findItem(name: String) = getObjectWithoutFallback(Item.itemRegistry, name).orElse(Item.itemRegistry.find {
|
||||
case item: Item => item.getUnlocalizedName == name || item.getUnlocalizedName == "item." + name
|
||||
case _ => false
|
||||
@ -382,8 +375,6 @@ object Recipes {
|
||||
|
||||
private def tryGetType(recipe: Config) = if (recipe.hasPath("type")) recipe.getString("type") else "shaped"
|
||||
|
||||
def tryGetCount(recipe: Config) = if (recipe.hasPath("output")) recipe.getInt("output") else 1
|
||||
|
||||
private def tryGetId(ingredient: java.util.Map[AnyRef, AnyRef]): Int =
|
||||
if (ingredient.contains("subID")) ingredient.get("subID") match {
|
||||
case id: Number => id.intValue
|
||||
|
@ -156,8 +156,7 @@ object Mods {
|
||||
final val Factorization = "factorization"
|
||||
final val Forestry = "Forestry"
|
||||
final val ForgeMultipart = "ForgeMultipart"
|
||||
final val DeepStorageUnit = "MineFactoryReloaded|DeepStorageUnit"
|
||||
// Doesn't really exist.
|
||||
final val DeepStorageUnit = "MineFactoryReloaded|DeepStorageUnit" // Doesn't really exist.
|
||||
final val Galacticraft = "Galacticraft API"
|
||||
final val GregTech = "gregtech"
|
||||
final val IndustrialCraft2 = "IC2"
|
||||
|
@ -16,6 +16,6 @@ object ModGregtech extends ModProxy {
|
||||
|
||||
Driver.add(new DriverEnergyContainer)
|
||||
|
||||
RecipeRegistry.init()
|
||||
RecipeHandler.init()
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
package li.cil.oc.integration.gregtech
|
||||
|
||||
import java.util
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigValue
|
||||
import li.cil.oc.common.recipe.Recipes
|
||||
import li.cil.oc.common.recipe.Recipes.RecipeException
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.fluids.FluidStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
object RecipeHandler {
|
||||
def init(): Unit = {
|
||||
Recipes.registerRecipeHandler("gt_alloySmelter", addGTAlloySmelterRecipe)
|
||||
Recipes.registerRecipeHandler("gt_assembler", addGTAssemblingMachineRecipe)
|
||||
Recipes.registerRecipeHandler("gt_bender", addGTBenderRecipe)
|
||||
Recipes.registerRecipeHandler("gt_canner", addGTCannerRecipe)
|
||||
Recipes.registerRecipeHandler("gt_chemical", addGTChemicalRecipe)
|
||||
Recipes.registerRecipeHandler("gt_cnc", addGTCNCRecipe)
|
||||
Recipes.registerRecipeHandler("gt_cutter", addGTCutterRecipe)
|
||||
Recipes.registerRecipeHandler("gt_lathe", addGTLatheRecipe)
|
||||
Recipes.registerRecipeHandler("gt_wiremill", addGTWireMillRecipe)
|
||||
}
|
||||
|
||||
def addGTAlloySmelterRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, secondaryInputs, _, _, _, eu, duration) = parseRecipe(output, recipe)
|
||||
secondaryInputs match {
|
||||
case Some(value) =>
|
||||
for (primaryInput <- primaryInputs; secondaryInput <- value) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAlloySmelterRecipe(primaryInput, secondaryInput, output, duration, eu)
|
||||
}
|
||||
case _ =>
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAlloySmelterRecipe(primaryInput, null, output, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTAssemblingMachineRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, secondaryInputs, fluidInput, _, _, eu, duration) = parseRecipe(output, recipe)
|
||||
secondaryInputs match {
|
||||
case Some(value) =>
|
||||
for (primaryInput <- primaryInputs; secondaryInput <- value) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(primaryInput, secondaryInput, fluidInput.orNull, output, duration, eu)
|
||||
}
|
||||
case _ =>
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(primaryInput, null, fluidInput.orNull, output, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTBenderRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, _, _, _, _, eu, duration) = parseRecipe(output, recipe)
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addBenderRecipe(primaryInput, output, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
def addGTCannerRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, secondaryInputs, _, _, secondaryOutputs, eu, duration) = parseRecipe(output, recipe)
|
||||
val secondaryOutput = secondaryOutputs.headOption.orNull
|
||||
secondaryInputs match {
|
||||
case Some(value) =>
|
||||
for (primaryInput <- primaryInputs; secondaryInput <- value) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCannerRecipe(primaryInput, secondaryInput, output, secondaryOutput, duration, eu)
|
||||
}
|
||||
case None =>
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCannerRecipe(primaryInput, null, output, secondaryOutput, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTChemicalRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, secondaryInputs, fluidInput, fluidOutput, _, _, duration) = parseRecipe(output, recipe)
|
||||
secondaryInputs match {
|
||||
case Some(value) =>
|
||||
for (primaryInput <- primaryInputs; secondaryOutput <- value) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(primaryInput, secondaryOutput, fluidInput.orNull, fluidOutput.orNull, output, duration)
|
||||
}
|
||||
case _ =>
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(primaryInput, null, fluidInput.orNull, fluidOutput.orNull, output, duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTCNCRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, _, _, _, _, eu, duration) = parseRecipe(output, recipe)
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCNCRecipe(primaryInput, output, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
def addGTCutterRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, _, fluidInput, _, secondaryOutputs, eu, duration) = parseRecipe(output, recipe)
|
||||
val secondaryOutput = secondaryOutputs.headOption.orNull
|
||||
fluidInput match {
|
||||
case Some(fluid) =>
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCutterRecipe(primaryInput, fluid, output, secondaryOutput, duration, eu)
|
||||
}
|
||||
case _ =>
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCutterRecipe(primaryInput, output, secondaryOutput, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTLatheRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, _, _, _, secondaryOutputs, eu, duration) = parseRecipe(output, recipe)
|
||||
val secondaryOutput = secondaryOutputs.headOption.orNull
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addLatheRecipe(primaryInput, output, secondaryOutput, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
def addGTWireMillRecipe(output: ItemStack, recipe: Config) {
|
||||
val (primaryInputs, _, _, _, _, eu, duration) = parseRecipe(output, recipe)
|
||||
for (primaryInput <- primaryInputs) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addWiremillRecipe(primaryInput, output, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
private def parseRecipe(output: ItemStack, recipe: Config) = {
|
||||
val inputs = parseIngredientList(recipe.getValue("input")).toBuffer
|
||||
output.stackSize = Recipes.tryGetCount(recipe)
|
||||
|
||||
if (inputs.size < 1 || inputs.size > 2) {
|
||||
throw new RecipeException(s"Invalid recipe length: ${inputs.size}, should be 1 or 2.")
|
||||
}
|
||||
|
||||
val inputCount = recipe.getIntList("count")
|
||||
if (inputCount.size() != inputs.size) {
|
||||
throw new RecipeException(s"Mismatched ingredient count: ${inputs.size} != ${inputCount.size}.")
|
||||
}
|
||||
|
||||
(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 outputs =
|
||||
if (recipe.hasPath("secondaryOutput")) {
|
||||
val secondaryOutput = parseIngredientList(recipe.getValue("secondaryOutput")).map(_.headOption)
|
||||
|
||||
val outputCount = recipe.getIntList("secondaryOutputCount")
|
||||
if (outputCount.size() != secondaryOutput.size) {
|
||||
throw new RecipeException(s"Mismatched secondary output count: ${secondaryOutput.size} != ${outputCount.size}.")
|
||||
}
|
||||
|
||||
(secondaryOutput, outputCount).zipped.foreach((stack, count) =>
|
||||
if (count > 0) stack.foreach(s => s.stackSize = s.getMaxStackSize min count))
|
||||
secondaryOutput.collect { case Some(stack) => stack }
|
||||
}
|
||||
else Iterable.empty[ItemStack]
|
||||
|
||||
val inputFluidStack =
|
||||
if (recipe.hasPath("inputFluid")) Recipes.parseFluidIngredient(recipe.getConfig("inputFluid"))
|
||||
else None
|
||||
|
||||
val outputFluidStack =
|
||||
if (recipe.hasPath("outputFluid")) Recipes.parseFluidIngredient(recipe.getConfig("outputFluid"))
|
||||
else None
|
||||
|
||||
val eu = recipe.getInt("eu")
|
||||
val duration = recipe.getInt("time")
|
||||
|
||||
(inputs.head, Option(inputs.last), inputFluidStack, outputFluidStack, outputs, eu, duration)
|
||||
}
|
||||
|
||||
private def parseIngredientList(list: ConfigValue) =
|
||||
(list.unwrapped() match {
|
||||
case list: util.List[AnyRef]@unchecked => list.map(Recipes.parseIngredient)
|
||||
case other => Iterable(Recipes.parseIngredient(other))
|
||||
}) map {
|
||||
case null => Array.empty[ItemStack]
|
||||
case stack: ItemStack => Array(stack)
|
||||
case name: String => Array(OreDictionary.getOres(name): _*)
|
||||
case other => throw new RecipeException(s"Invalid ingredient type: $other.")
|
||||
}
|
||||
}
|
@ -1,253 +0,0 @@
|
||||
package li.cil.oc.integration.gregtech
|
||||
|
||||
import java.util
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import li.cil.oc.common.recipe.Recipes
|
||||
import li.cil.oc.common.recipe.Recipes.RecipeException
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.fluids.FluidStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
object RecipeRegistry {
|
||||
|
||||
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)
|
||||
case other => Seq(Recipes.parseIngredient(other))
|
||||
}) map {
|
||||
case null => Array.empty[ItemStack]
|
||||
case stack: ItemStack => Array(stack)
|
||||
case name: String => Array(OreDictionary.getOres(name): _*)
|
||||
case other => throw new RecipeException(s"Invalid ingredient type: $other.")
|
||||
}
|
||||
output.stackSize = Recipes.tryGetCount(recipe)
|
||||
|
||||
if (inputs.size < 1 || inputs.size > 2) {
|
||||
throw new RecipeException(s"Invalid recipe length: ${inputs.size}, should be 1 or 2.")
|
||||
}
|
||||
|
||||
val inputCount = recipe.getIntList("count")
|
||||
if (inputCount.size() != inputs.size) {
|
||||
throw new RecipeException(s"Ingredient and input count mismatch: ${inputs.size} != ${inputCount.size}.")
|
||||
}
|
||||
|
||||
var inputFluidStack: Option[FluidStack] = None: Option[FluidStack]
|
||||
if (recipe.hasPath("inputLiquid")) Recipes.parseFluidIngredient(recipe.getString("inputLiquid")) match {
|
||||
case Some(fluid) =>
|
||||
var inputFluidAmount = 1000
|
||||
if (recipe.hasPath("inputFluidAmount")) inputFluidAmount = recipe.getInt("inputFluidAmount")
|
||||
inputFluidStack = Option(new FluidStack(fluid, inputFluidAmount))
|
||||
case _ =>
|
||||
}
|
||||
|
||||
var outputFluidStack: Option[FluidStack] = None: Option[FluidStack]
|
||||
if (recipe.hasPath("outputLiquid")) Recipes.parseFluidIngredient(recipe.getString("outputLiquid")) match {
|
||||
case Some(fluid) =>
|
||||
var fluidAmount = 1000
|
||||
if (recipe.hasPath("outputFluidAmount")) fluidAmount = recipe.getInt("outputFluidAmount")
|
||||
outputFluidStack = Option(new FluidStack(fluid, fluidAmount))
|
||||
case _ =>
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
(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)
|
||||
}
|
||||
|
||||
def addGTAlloySmelterRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
for (input1 <- inputs1) {
|
||||
inputs2 match {
|
||||
case Some(inputs2List) =>
|
||||
for (input2 <- inputs2List)
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAlloySmelterRecipe(input1, input2, output, duration, eu)
|
||||
case None =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAlloySmelterRecipe(input1, null, output, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTAssemblingMachineRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
for (input1 <- inputs1) {
|
||||
inputs2 match {
|
||||
case Some(inputs2List) =>
|
||||
for (input2 <- inputs2List)
|
||||
fluidStackIn match {
|
||||
case Some(fluid) =>
|
||||
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(input1, input2, fluid, output, duration, eu)
|
||||
case None =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(input1, input2, output, duration, eu)
|
||||
}
|
||||
|
||||
case None =>
|
||||
fluidStackIn match {
|
||||
case Some(fluid) =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(input1, null, fluid, output, duration, eu)
|
||||
case None =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(input1, null, output, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTBenderRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
for (input1 <- inputs1) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addBenderRecipe(input1, output, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
def addGTCutterRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
var add: ItemStack = null
|
||||
if (additionalOutput.size > 1)
|
||||
add = additionalOutput.head
|
||||
for (input1 <- inputs1) {
|
||||
fluidStackIn match {
|
||||
case Some(fluid) =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCutterRecipe(input1, fluid, output, add, duration, eu)
|
||||
|
||||
case None =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCutterRecipe(input1, output, add, duration, eu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTCannerRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
var add: ItemStack = null
|
||||
if (additionalOutput.size > 1)
|
||||
add = additionalOutput.head
|
||||
|
||||
for (input1 <- inputs1) {
|
||||
inputs2 match {
|
||||
case Some(inputs2List) =>
|
||||
for (input2 <- inputs2List)
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCannerRecipe(input1, input2, output, add, duration, eu)
|
||||
case None =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCannerRecipe(input1, null, output, add, duration, eu)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTChemicalRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
for (input1 <- inputs1) {
|
||||
inputs2 match {
|
||||
case Some(inputs2List) =>
|
||||
for (input2 <- inputs2List)
|
||||
fluidStackIn match {
|
||||
case Some(fluid) =>
|
||||
fluidStackOut match {
|
||||
case Some(fluidOut) =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, input2, fluid, fluidOut, output, duration)
|
||||
|
||||
case _ =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, input2, fluid, null, output, duration)
|
||||
}
|
||||
case None =>
|
||||
fluidStackOut match {
|
||||
case Some(fluidOut) =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, input2, null, fluidOut, output, duration)
|
||||
case _ =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, input2, output, duration)
|
||||
}
|
||||
}
|
||||
|
||||
case None =>
|
||||
fluidStackIn match {
|
||||
case Some(fluid) =>
|
||||
fluidStackOut match {
|
||||
case Some(fluidOut) =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, null, fluid, fluidOut, output, duration)
|
||||
|
||||
case _ =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, null, fluid, null, output, duration)
|
||||
}
|
||||
case None =>
|
||||
fluidStackOut match {
|
||||
case Some(fluidOut) =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, null, null, fluidOut, output, duration)
|
||||
case _ =>
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addChemicalRecipe(input1, null, output, duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addGTCNCRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
for (input1 <- inputs1) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addCNCRecipe(input1, output, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
def addGTLatheRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
var add: ItemStack = null
|
||||
if (additionalOutput.size > 1)
|
||||
add = additionalOutput.head
|
||||
for (input1 <- inputs1) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addLatheRecipe(input1, output, add, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
def addGTWireMillRecipe(output: ItemStack, recipe: Config) {
|
||||
val (inputs1, inputs2, fluidStackIn, fluidStackOut, additionalOutput, eu, duration) = getGTRecipesWithEU(output, recipe)
|
||||
for (input1 <- inputs1) {
|
||||
gregtech.api.GregTech_API.sRecipeAdder.addWiremillRecipe(input1, output, duration, eu)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def init(): Unit = {
|
||||
Recipes.registerRecipe("gt_alloySmelter", addGTAlloySmelterRecipe)
|
||||
Recipes.registerRecipe("gt_assembler", addGTAssemblingMachineRecipe)
|
||||
Recipes.registerRecipe("gt_bender", addGTBenderRecipe)
|
||||
Recipes.registerRecipe("gt_canner", addGTCannerRecipe)
|
||||
Recipes.registerRecipe("gt_chemical", addGTChemicalRecipe)
|
||||
Recipes.registerRecipe("gt_cnc", addGTCNCRecipe)
|
||||
Recipes.registerRecipe("gt_cutter", addGTCutterRecipe)
|
||||
Recipes.registerRecipe("gt_lathe", addGTLatheRecipe)
|
||||
Recipes.registerRecipe("gt_wiremill", addGTWireMillRecipe)
|
||||
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ object ModVanilla extends ModProxy {
|
||||
Driver.add(ConverterNBT)
|
||||
Driver.add(ConverterWorld)
|
||||
Driver.add(ConverterWorldProvider)
|
||||
RecipeRegistry.init()
|
||||
|
||||
RecipeHandler.init()
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package li.cil.oc.integration.vanilla
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import li.cil.oc.common.recipe.ExtendedShapedOreRecipe
|
||||
import li.cil.oc.common.recipe.ExtendedShapelessOreRecipe
|
||||
import li.cil.oc.common.recipe.Recipes
|
||||
import li.cil.oc.common.recipe.Recipes.RecipeException
|
||||
import li.cil.oc.common.recipe.{Recipes, ExtendedShapelessOreRecipe, ExtendedShapedOreRecipe}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.item.crafting.FurnaceRecipes
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
@ -11,7 +13,12 @@ import net.minecraftforge.oredict.OreDictionary
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.collection.mutable
|
||||
|
||||
object RecipeRegistry {
|
||||
object RecipeHandler {
|
||||
def init(): Unit = {
|
||||
Recipes.registerRecipeHandler("shaped", addShapedRecipe)
|
||||
Recipes.registerRecipeHandler("shapeless", addShapelessRecipe)
|
||||
Recipes.registerRecipeHandler("furnace", addFurnaceRecipe)
|
||||
}
|
||||
|
||||
def addShapedRecipe(output: ItemStack, recipe: Config) {
|
||||
val rows = recipe.getList("input").unwrapped().map {
|
||||
@ -24,12 +31,12 @@ object RecipeRegistry {
|
||||
var shape = mutable.ArrayBuffer.empty[String]
|
||||
val input = mutable.ArrayBuffer.empty[AnyRef]
|
||||
for (row <- rows) {
|
||||
val (pattern, ingredients) = row.foldLeft((new StringBuilder, Seq.empty[AnyRef]))((acc, ingredient) => {
|
||||
val (pattern, ingredients) = row.foldLeft((new StringBuilder, Iterable.empty[AnyRef]))((acc, ingredient) => {
|
||||
val (pattern, ingredients) = acc
|
||||
ingredient match {
|
||||
case _@(_: ItemStack | _: String) =>
|
||||
number += 1
|
||||
(pattern.append(('a' + number).toChar), ingredients ++ Seq(Char.box(('a' + number).toChar), ingredient))
|
||||
(pattern.append(('a' + number).toChar), ingredients ++ Iterable(Char.box(('a' + number).toChar), ingredient))
|
||||
case _ => (pattern.append(' '), ingredients)
|
||||
}
|
||||
})
|
||||
@ -67,10 +74,4 @@ object RecipeRegistry {
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
def init(): Unit = {
|
||||
Recipes.registerRecipe("shaped", addShapedRecipe)
|
||||
Recipes.registerRecipe("shapeless", addShapelessRecipe)
|
||||
Recipes.registerRecipe("furnace", addFurnaceRecipe)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user