mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-19 03:49:36 +00:00
Updated Recipe Loader for 1.7.2 changes
This commit is contained in:
1 parent
7eefbb1a31
commit
b89d445b17
3 files changed
+32
-25
No files matched your search
@@ -28,31 +28,33 @@ abstract class StackRef
|
||||
case class StackOreDict(id: String) extends StackRef
|
||||
|
||||
/**
|
||||
* Mod item reference [[cpw.mods.fml.common.registry.GameRegistry.findItemStack]]
|
||||
* Syntax: {modID}:{name}
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specModStack]]
|
||||
* Generic Referende
|
||||
* Syntax: S:{modid}:{name}
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specGenericStack]]
|
||||
* @param mod modId of owner mod
|
||||
* @param id name of the stack
|
||||
* @param name name of the stack
|
||||
*/
|
||||
case class StackMod(mod: String, id: String) extends StackRef
|
||||
case class StackGeneric(mod: String, name: String) extends StackRef
|
||||
|
||||
/**
|
||||
* Vanilla block reference
|
||||
* Syntax: B:{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specMcBlock]]
|
||||
* @param name Unlocalized name (without "tile.")
|
||||
* Block reference
|
||||
* Syntax: B:[{modid}:]{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specBlock]]
|
||||
* @param mod modId of owner mod, default is "minecraft"
|
||||
* @param name Registered name
|
||||
* @param meta Metadata / Damage
|
||||
*/
|
||||
case class StackMCBlock(name: String, meta: Int) extends StackRef
|
||||
case class StackBlock(mod: String, name: String, meta: Int) extends StackRef
|
||||
|
||||
/**
|
||||
* Vanilla item reference
|
||||
* Syntax: I:{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specMcItem]]
|
||||
* @param name Unlocalized name (without "item.")
|
||||
* Item reference
|
||||
* Syntax: I:[{modid}:]{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specItem]]
|
||||
* @param mod modId of owner mod, default is "minecraft"
|
||||
* @param name Registered name
|
||||
* @param meta Metadata / Damage
|
||||
*/
|
||||
case class StackMCItem(name: String, meta: Int) extends StackRef
|
||||
case class StackItem(mod: String, name: String, meta: Int) extends StackRef
|
||||
|
||||
/**
|
||||
* Reference to an Item/Block/ItemStack pulic static field
|
||||
|
||||
@@ -159,6 +159,8 @@ class RecipeLoader {
|
||||
case _ => Seq(getConcreteStack(s))
|
||||
}
|
||||
|
||||
def notNull[T](v:T, err: => String) = if (v == null) error(err) else v
|
||||
|
||||
/**
|
||||
* Returns an ItemStack that match a reference
|
||||
* This is the main StackRef resolution method
|
||||
@@ -175,12 +177,12 @@ class RecipeLoader {
|
||||
BdLib.logInfo("Concrete ItemStack for OD entry '%s' -> %s", id, s)
|
||||
return s
|
||||
case StackMacro(ch) => getConcreteStack(currCharMap(ch), cnt)
|
||||
case StackMod(mod, id) =>
|
||||
val i = GameRegistry.findItemStack(mod, id, cnt)
|
||||
if (i == null) error("Item %s:%s not found", mod, id)
|
||||
i
|
||||
case StackMCBlock(id, meta) => new ItemStack(Vanilla.blocks(id), cnt, meta)
|
||||
case StackMCItem(id, meta) => new ItemStack(Vanilla.items(id), cnt, meta)
|
||||
case StackGeneric(mod, id) =>
|
||||
notNull(GameRegistry.findItemStack(mod, id, 1),"Stack not found %s:%s".format(mod, id))
|
||||
case StackBlock(mod, id, meta) =>
|
||||
new ItemStack(notNull(GameRegistry.findBlock(mod, id),"Block not found %s:%s".format(mod, id)), 1, meta)
|
||||
case StackItem(mod, id, meta) =>
|
||||
new ItemStack(notNull(GameRegistry.findItem(mod, id),"Item not found %s:%s".format(mod, id)), 1, meta)
|
||||
case StackReflect(cls, field, meta) => reflectStack(cls, field, meta, cnt)
|
||||
case StackGetter(cls, method, param, meta) => reflectStackGetter(cls, method, param, meta, cnt)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ class RecipeParser extends JavaTokenParsers {
|
||||
// Possible metadata suffix (defaults to wildcard value)
|
||||
def maybeMeta = ("@" ~> int).? ^^ (_.getOrElse(OreDictionary.WILDCARD_VALUE))
|
||||
|
||||
// Possible modid prefix (defaults to minecraft)
|
||||
def maybeModid = (str <~ ":").? ^^ (_.getOrElse("minecraft"))
|
||||
|
||||
// Qualified class name
|
||||
def clsPath = (ident <~ ".").* ~ ident
|
||||
|
||||
@@ -46,9 +49,9 @@ class RecipeParser extends JavaTokenParsers {
|
||||
// === Item references ===
|
||||
|
||||
def specOD = "OD" ~> ":" ~> ident ^^ StackOreDict
|
||||
def specMcBlock = "B" ~> ":" ~> ident ~ maybeMeta ^^ { case b ~ m => StackMCBlock(b, m) }
|
||||
def specMcItem = "I" ~> ":" ~> ident ~ maybeMeta ^^ { case b ~ m => StackMCItem(b, m) }
|
||||
def specModStack = str ~ ":" ~ str ^^ { case m ~ c ~ n => StackMod(m, n) }
|
||||
def specBlock = "B" ~> ":" ~> maybeModid ~ str ~ maybeMeta ^^ { case m ~ n ~ i => StackBlock(m, n, i) }
|
||||
def specItem = "I" ~> ":" ~> maybeModid ~ str ~ maybeMeta ^^ { case m ~ n ~ i => StackItem(m, n, i) }
|
||||
def specGenericStack = "S" ~> ":" ~> str ~ ":" ~ str ^^ { case m ~ c ~ n => StackGeneric(m, n) }
|
||||
def specMacro = "$" ~> recipeChar ^^ StackMacro
|
||||
|
||||
def specReflect = clsPath ~ ("[" ~> ident <~ "]") ~ maybeMeta ^^ {
|
||||
@@ -59,7 +62,7 @@ class RecipeParser extends JavaTokenParsers {
|
||||
case (p ~ cl) ~ n ~ m => StackGetter(p.mkString("."), cl, n, m)
|
||||
}
|
||||
|
||||
def spec = specMcBlock | specMcItem | specOD | specModStack | specGetter | specReflect | specMacro
|
||||
def spec = specBlock | specItem | specOD | specGenericStack | specGetter | specReflect | specMacro
|
||||
|
||||
// Spec with possible number of items
|
||||
def specWithCount = spec ~ ("*" ~> int).?
|
||||
|
||||
Reference in new issue
Block a user