Compare commits

...
9 Commits
9 changed files with 133 additions and 10 deletions

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ buildscript {
apply plugin: 'forge'
apply plugin: 'scala'
version = "1.2.0"
version = "1.2.2"
if (project.hasProperty('buildnum')) {
project.version = project.version + '.' + project.buildnum
+2 -1
View File
@@ -26,6 +26,7 @@ object Misc {
def toLocal(s: String) = StatCollector.translateToLocal(s)
def toLocalF(s: String, params: Any*) = StatCollector.translateToLocal(s).format(params: _*)
def hasLocal(s: String) = StatCollector.func_94522_b(s)
def flattenRecipe(pattern: Seq[String], items: Map[Char, AnyRef]) =
pattern ++ items.map {
@@ -54,7 +55,7 @@ object Misc {
def filterType[T](from: Iterable[_], cls: Class[T]) = from.filter(cls.isInstance).asInstanceOf[Iterable[T]]
def getBiomeByName(name: String) = BiomeGenBase.biomeList.find(_.biomeName == name).getOrElse(null)
def getBiomeByName(name: String) = BiomeGenBase.biomeList.find(x => x != null && x.biomeName == name).getOrElse(null)
def haveModVersion(spec: String): Boolean = {
val req = VersionParser.parseVersionReference(spec)
+5
View File
@@ -29,6 +29,11 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1) {
object Color {
def fromRGB(r: Int, g: Int, b: Int, a: Int = 255) = Color(r / 255F, g / 255F, b / 255F, a / 255F)
def fromInt(v: Int) = Color(
((v >> 16) & 0xFF) / 255F,
((v >> 8) & 0xFF) / 255F,
(v & 0xFF) / 255F
)
final val white = Color(1, 1, 1)
final val black = Color(0, 0, 0)
final val red = Color(1, 0, 0)
+20 -1
View File
@@ -10,11 +10,12 @@
package net.bdew.lib.items
import net.minecraft.entity.item.EntityItem
import net.minecraft.item.ItemStack
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.world.World
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.inventory.IInventory
import net.bdew.lib.Misc
import java.util.Random
object ItemUtils {
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
@@ -76,4 +77,22 @@ object ItemUtils {
return stack
}
def findItemInInventory(inv: IInventory, item: Item) =
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
.find({ case (slot, stack) => stack != null && stack.getItem == item })
.map({ case (slot, stack) => slot })
def copyWithRandomSize(template: ItemStack, max: Int, rand: Random) = {
val newSize = rand.nextInt(max)
val newStack = template.copy()
newStack.stackSize =
if (newSize > newStack.getMaxStackSize)
newStack.getMaxStackSize
else if (newSize <= 0)
1
else
newSize
newStack
}
}
@@ -60,10 +60,12 @@ case class ConfigSection(pfx: String = "") extends CfgEntry with Iterable[(Strin
def getIntList(id: String) = getDoubleList(id).map(_.round.toInt).toList
def getFloatList(id: String) = getDoubleList(id).map(_.toFloat).toList
def getColor(id: String) = getFloatList(id) match {
case r :: g :: b :: Nil => Color(r, g, b)
case _ => sys.error("Color definition must be 3 numbers")
}
def getColor(id: String) =
raw(id) match {
case EntryDouble(c) => Color.fromInt(c.toInt)
case EntryNumList(r :: g :: b :: Nil) => Color(r.toFloat, g.toFloat, b.toFloat)
case x => sys.error("Invalid color definition: %s".format(x))
}
}
@@ -13,12 +13,17 @@ import net.bdew.lib.recipes.RecipeParser
trait GenericConfigParser extends RecipeParser {
override def statement = statementCfg | super.statement
def negativeNumber = "-" ~> decimalNumber ^^ { case x => "-" + x }
def signedNumber = decimalNumber | negativeNumber
// Hex variant must come before decimalNumber, otherwise the parser breaks
def signedNumber = (
("0x" ~> "[0-9A-Fa-f]+".r) ^^ { case x => Integer.parseInt(x, 16).toDouble }
| decimalNumber ^^ { case x => x.toDouble }
| ("-" ~> decimalNumber) ^^ { case x => -x.toDouble }
)
def cfgStatementNum = ident ~ "=" ~ signedNumber ^^ { case id ~ eq ~ n => CfgVal(id, EntryDouble(n.toDouble)) }
def cfgStatementStr = ident ~ "=" ~ str ^^ { case id ~ eq ~ s => CfgVal(id, EntryStr(s)) }
def cfgStatementNumList = ident ~ ("=" ~> "{" ~> signedNumber.* <~ "}") ^^ { case id ~ l => CfgVal(id, EntryNumList(l.map(_.toDouble))) }
def cfgStatementNumList = ident ~ ("=" ~> "{" ~> signedNumber.* <~ "}") ^^ { case id ~ l => CfgVal(id, EntryNumList(l)) }
def cfgStatementSub = cfgBlock ^^ { case (id, st) => CfgSub(id, st) }
def cfgStatement = cfgStatementNum | cfgStatementStr | cfgStatementSub | cfgStatementNumList
@@ -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
@@ -0,0 +1,42 @@
/*
* 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.recipes.StackRef
import net.minecraft.item.ItemStack
/**
* Loader mixin for loot lists
*/
trait LootListLoader extends GenericConfigLoader {
def resolveLootList(entry: EntryLootList): List[(Int, ItemStack)] = resolveLootList(entry.list)
def resolveLootList(list: List[(Int, StackRef)]) =
(for ((chance, ref) <- list) yield {
try {
val itemStack = getConcreteStack(ref)
if (itemStack == null) {
log.warning("Unable to resolve %s: null returned".format(ref))
None
} else {
if (itemStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
log.info("meta/damage is unset in %s, defaulting to 0".format(ref))
itemStack.setItemDamage(0)
}
Some((chance, itemStack))
}
} catch {
case e: Throwable =>
log.warning("Unable to resolve %s: %s".format(ref, e.getMessage))
None
}
}).flatten
}
@@ -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
}