mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49a2f0baec | ||
|
|
2a995f1c05 | ||
|
|
423351bfee | ||
|
|
0831386798 | ||
|
|
0b45c61c51 | ||
|
|
65aa8a0f66 | ||
|
|
446f2b6e60 |
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ buildscript {
|
|||||||
apply plugin: 'forge'
|
apply plugin: 'forge'
|
||||||
apply plugin: 'scala'
|
apply plugin: 'scala'
|
||||||
|
|
||||||
version = "1.2.1"
|
version = "1.2.2"
|
||||||
|
|
||||||
if (project.hasProperty('buildnum')) {
|
if (project.hasProperty('buildnum')) {
|
||||||
project.version = project.version + '.' + project.buildnum
|
project.version = project.version + '.' + project.buildnum
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ object Misc {
|
|||||||
|
|
||||||
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
||||||
def toLocalF(s: String, params: Any*) = StatCollector.translateToLocal(s).format(params: _*)
|
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]) =
|
def flattenRecipe(pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||||
pattern ++ items.map {
|
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 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 = {
|
def haveModVersion(spec: String): Boolean = {
|
||||||
val req = VersionParser.parseVersionReference(spec)
|
val req = VersionParser.parseVersionReference(spec)
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1) {
|
|||||||
|
|
||||||
object Color {
|
object Color {
|
||||||
def fromRGB(r: Int, g: Int, b: Int, a: Int = 255) = Color(r / 255F, g / 255F, b / 255F, a / 255F)
|
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 white = Color(1, 1, 1)
|
||||||
final val black = Color(0, 0, 0)
|
final val black = Color(0, 0, 0)
|
||||||
final val red = Color(1, 0, 0)
|
final val red = Color(1, 0, 0)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import net.minecraft.world.World
|
|||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.inventory.IInventory
|
import net.minecraft.inventory.IInventory
|
||||||
import net.bdew.lib.Misc
|
import net.bdew.lib.Misc
|
||||||
|
import java.util.Random
|
||||||
|
|
||||||
object ItemUtils {
|
object ItemUtils {
|
||||||
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
||||||
@@ -81,4 +82,17 @@ object ItemUtils {
|
|||||||
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
|
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
|
||||||
.find({ case (slot, stack) => stack != null && stack.getItem == item })
|
.find({ case (slot, stack) => stack != null && stack.getItem == item })
|
||||||
.map({ case (slot, stack) => slot })
|
.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 getIntList(id: String) = getDoubleList(id).map(_.round.toInt).toList
|
||||||
def getFloatList(id: String) = getDoubleList(id).map(_.toFloat).toList
|
def getFloatList(id: String) = getDoubleList(id).map(_.toFloat).toList
|
||||||
|
|
||||||
def getColor(id: String) = getFloatList(id) match {
|
def getColor(id: String) =
|
||||||
case r :: g :: b :: Nil => Color(r, g, b)
|
raw(id) match {
|
||||||
case _ => sys.error("Color definition must be 3 numbers")
|
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 {
|
trait GenericConfigParser extends RecipeParser {
|
||||||
override def statement = statementCfg | super.statement
|
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 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 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 cfgStatementSub = cfgBlock ^^ { case (id, st) => CfgSub(id, st) }
|
||||||
|
|
||||||
def cfgStatement = cfgStatementNum | cfgStatementStr | cfgStatementSub | cfgStatementNumList
|
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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user