diff --git a/build.gradle b/build.gradle index e8b0e52..8896b6d 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { apply plugin: 'forge' apply plugin: 'scala' -version = "1.2.1" +version = "1.2.2" if (project.hasProperty('buildnum')) { project.version = project.version + '.' + project.buildnum diff --git a/src/net/bdew/lib/recipes/lootlist/EntryLootList.scala b/src/net/bdew/lib/recipes/lootlist/EntryLootList.scala new file mode 100644 index 0000000..9aa6078 --- /dev/null +++ b/src/net/bdew/lib/recipes/lootlist/EntryLootList.scala @@ -0,0 +1,24 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.lib.recipes.lootlist + +import net.bdew.lib.recipes.StackRef +import net.bdew.lib.recipes.gencfg.CfgEntry + +/** + * Allos definition of random-weighted loot/drop lists in config sections + * @param list List on (chance percent, stack reference) pairs, resolve to + * real ItemStacks with LootListLoader.resolveLootList + */ +case class EntryLootList(list: List[(Int, StackRef)]) extends CfgEntry + + + + diff --git a/src/net/bdew/lib/recipes/lootlist/LootListLoader.scala b/src/net/bdew/lib/recipes/lootlist/LootListLoader.scala new file mode 100644 index 0000000..ed019bd --- /dev/null +++ b/src/net/bdew/lib/recipes/lootlist/LootListLoader.scala @@ -0,0 +1,40 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/bdlib + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt + */ + +package net.bdew.lib.recipes.lootlist + +import net.bdew.lib.recipes.gencfg.GenericConfigLoader +import net.minecraftforge.oredict.OreDictionary +import net.bdew.lib.BdLib + +/** + * Loader mixin for loot lists + */ +trait LootListLoader extends GenericConfigLoader { + def resolveLootList(entry: EntryLootList) = + (for ((chance, ref) <- entry.list) yield { + try { + val itemStack = getConcreteStack(ref) + if (itemStack == null) { + BdLib.logWarn("Unable to resolve %s: null returned", ref) + None + } else { + if (itemStack.getItemDamage == OreDictionary.WILDCARD_VALUE) { + BdLib.logInfo("meta/damage is unset in %s, defaulting to 0", ref) + itemStack.setItemDamage(0) + } + Some((chance, itemStack)) + } + } catch { + case e: Throwable => + BdLib.logWarn("Unable to resolve %s: %s", ref, e.getMessage) + None + } + }).flatten +} diff --git a/src/net/bdew/lib/recipes/lootlist/LootListParser.scala b/src/net/bdew/lib/recipes/lootlist/LootListParser.scala new file mode 100644 index 0000000..545a89d --- /dev/null +++ b/src/net/bdew/lib/recipes/lootlist/LootListParser.scala @@ -0,0 +1,25 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/bdlib + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt + */ + +package net.bdew.lib.recipes.lootlist + +import net.bdew.lib.recipes.gencfg.{CfgVal, GenericConfigParser} + +/** + * Parser mixin for loot lists + * ident: DropsList( + * {chance}% {stackRef} + * ... + * ) + */ +trait LootListParser extends GenericConfigParser { + def dropsEntry = (wholeNumber <~ "%") ~ spec ^^ { case n ~ s => (n.toInt, s) } + def cfgDrops = ident ~ (":" ~> "DropsList" ~> "(" ~> dropsEntry.* <~ ")") ^^ { case id ~ a => CfgVal(id, EntryLootList(a)) } + override def cfgStatement = cfgDrops | super.cfgStatement +}