mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
custom includer to make .recipes extension work
This commit is contained in:
parent
57a5dd3d71
commit
c37d360f08
@ -3,10 +3,10 @@
|
||||
# priority (i.e. included recipes simply replace the current definition for all
|
||||
# already known recipes).
|
||||
|
||||
include "default.recipes"
|
||||
#include "buildcraft.recipes"
|
||||
#include "gregtech.recipes"
|
||||
#include "your_custom.recipes"
|
||||
include file("default.recipes")
|
||||
#include file("buildcraft.recipes")
|
||||
#include file("gregtech.recipes")
|
||||
#include file("your_custom.recipes")
|
||||
|
||||
# You can also specify custom recipes in this file directly. Have a look at the
|
||||
# default.recipes file to get an idea how recipes have to be structured. You'll
|
||||
|
@ -1,15 +1,16 @@
|
||||
package li.cil.oc
|
||||
|
||||
import com.typesafe.config.{Config, ConfigFactory}
|
||||
import com.typesafe.config._
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import java.io.File
|
||||
import java.io.{FileReader, File}
|
||||
import java.util.logging.Level
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.crafting.FurnaceRecipes
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe, ShapedOreRecipe}
|
||||
import org.apache.commons.io.FileUtils
|
||||
import scala.Some
|
||||
import scala.collection.convert.wrapAsScala._
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
@ -24,7 +25,26 @@ object Recipes {
|
||||
if (!userRecipes.exists()) {
|
||||
FileUtils.copyURLToFile(getClass.getResource("/assets/opencomputers/recipes/user.recipes"), userRecipes)
|
||||
}
|
||||
val recipes = ConfigFactory.parseFile(userRecipes)
|
||||
val config = ConfigParseOptions.defaults.
|
||||
setSyntax(ConfigSyntax.CONF).
|
||||
setIncluder(new ConfigIncluder with ConfigIncluderFile {
|
||||
var fallback: ConfigIncluder = _
|
||||
|
||||
def withFallback(fallback: ConfigIncluder) = {
|
||||
this.fallback = fallback
|
||||
this
|
||||
}
|
||||
|
||||
def include(context: ConfigIncludeContext, what: String) = fallback.include(context, what)
|
||||
|
||||
def includeFile(context: ConfigIncludeContext, what: File) = {
|
||||
val in = if (what.isAbsolute) new FileReader(what) else new FileReader(new File(userRecipes.getParentFile, what.getPath))
|
||||
val result = ConfigFactory.parseReader(in)
|
||||
in.close()
|
||||
result.root()
|
||||
}
|
||||
})
|
||||
val recipes = ConfigFactory.parseFile(userRecipes, config)
|
||||
|
||||
// Try to keep this in the same order as the fields in the Items class
|
||||
// to make it easier to match them and check if anything is missing.
|
||||
@ -114,6 +134,9 @@ object Recipes {
|
||||
case other => throw new RecipeException("Invalid recipe type '" + other + "'.")
|
||||
}
|
||||
}
|
||||
else {
|
||||
OpenComputers.log.info("No recipe for '" + name + "', you will not be able to craft this item.")
|
||||
}
|
||||
}
|
||||
catch {
|
||||
case e: RecipeException => OpenComputers.log.warning("Failed adding recipe for '" + name + "', you will not be able to craft this item! The error was: " + e.getMessage)
|
||||
|
Loading…
x
Reference in New Issue
Block a user