Added a statement to check if an API is present in configs

This commit is contained in:
bdew committed 2014-07-29 16:19:05 +03:00
1 parent 2d799bb797
commit 5a3fa7ef75
3 files changed
+25 -1

No files matched your search

@@ -125,6 +125,16 @@ case class StClassMacro(id: String, cls: String) extends DelayedStatement
*/
case class StIfHaveMod(mod: String, thn: List[Statement], els: List[Statement]) extends Statement
/**
* Conditional block - checks if api is loaded
* Syntax: ifAPI {string} { {statements} } [else { {statements} }]
* Parser: [[net.bdew.lib.recipes.RecipeParser.ifApi]]
* @param mod API modid
* @param thn Statements to run if present
* @param els Statements to run otherwise
*/
case class StIfHaveAPI(mod: String, thn: List[Statement], els: List[Statement]) extends Statement
/**
* Conditional block - checks if mod is loaded
* Can contain only delayed statements
@@ -11,6 +11,7 @@ package net.bdew.lib.recipes
import java.io.Reader
import cpw.mods.fml.common.ModAPIManager
import cpw.mods.fml.common.registry.GameRegistry
import net.bdew.lib.{BdLib, Misc}
import net.minecraft.block.Block
@@ -220,6 +221,15 @@ class RecipeLoader {
processStatementsSafe(els)
}
case StIfHaveAPI(mod, thn, els) =>
if (ModAPIManager.INSTANCE.hasAPI(mod)) {
BdLib.logInfo("ifAPI: %s found", mod)
processStatementsSafe(thn)
} else {
BdLib.logInfo("ifAPI: %s not found", mod)
processStatementsSafe(els)
}
case StClearRecipes(res) =>
BdLib.logInfo("Clearing recipes that produce %s", res)
delayedStatements = delayedStatements.filter({
+5 -1
View File
@@ -82,6 +82,10 @@ class RecipeParser extends JavaTokenParsers {
case mod ~ thn ~ els => new StIfHaveMod(mod, thn, els.getOrElse(List.empty[Statement]))
}
def ifAPI = ("ifAPI" ~> str) ~ ("{" ~> statements <~ "}") ~ ("else" ~> "{" ~> statements <~ "}").? ^^ {
case mod ~ thn ~ els => new StIfHaveAPI(mod, thn, els.getOrElse(List.empty[Statement]))
}
def ifOreDict = ("ifOreDict" ~> str) ~ ("{" ~> delayedStatements <~ "}") ~ ("else" ~> "{" ~> delayedStatements <~ "}").? ^^ {
case id ~ thn ~ els => new StIfHaveOD(id, thn, els.getOrElse(List.empty[DelayedStatement]))
}
@@ -119,7 +123,7 @@ class RecipeParser extends JavaTokenParsers {
| recipeSmelting
)
def statement: Parser[Statement] = delayedStatement | ifMod | clearRecipes
def statement: Parser[Statement] = delayedStatement | ifMod | ifAPI | clearRecipes
def statements = statement.*
def delayedStatements = delayedStatement.*