Converted a lot of item classes into static objects, fixed exception logging

This commit is contained in:
bdew committed 2014-04-23 13:39:51 +03:00
1 parent 472b88c98c
commit f07c9e9a80
20 files changed
+67 -62

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ apply plugin: 'forge'
apply plugin: 'scala'
version = "1.2.0"
ext.bdlibver = "1.3.0.5"
ext.bdlibver = "1.3.0.6"
ext.versuffix = "mc172"
if (project.hasProperty('buildnum')) {
@@ -16,7 +16,7 @@ import _root_.forestry.api.lepidopterology.{EnumButterflyChromosome, IButterflyR
import net.minecraft.command.{CommandException, CommandBase, ICommandSender, WrongUsageException}
import java.util.List
import net.bdew.gendustry.forestry.GeneSampleInfo
import net.bdew.gendustry.config.Items
import net.bdew.gendustry.items.GeneSample
class CommandGiveSample extends CommandBase {
def getCommandName = "givesample"
@@ -58,7 +58,7 @@ class CommandGiveSample extends CommandBase {
if (!isValidAllele(root, chromosome, allele)) throw new CommandException("gendustry.givesample.error.invalid")
val sample = Items.geneSample.newStack(GeneSampleInfo(root, chromosome, allele))
val sample = GeneSample.newStack(GeneSampleInfo(root, chromosome, allele))
val entityitem = player.entityDropItem(sample, 0)
entityitem.delayBeforeCanPickup = 0
@@ -16,7 +16,7 @@ import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.item.Item
import net.minecraftforge.fluids.Fluid
class ItemFluidCan(fluid: Fluid) extends Item() {
class ItemFluidCan(fluid: Fluid) extends Item {
setUnlocalizedName(Gendustry.modId + "." + fluid.getName.toLowerCase + ".can")
@SideOnly(Side.CLIENT)
+3
View File
@@ -36,6 +36,9 @@ object Gendustry {
def logInfo(msg: String, args: Any*) = log.info(msg.format(args: _*))
def logWarn(msg: String, args: Any*) = log.warn(msg.format(args: _*))
def logError(msg: String, args: Any*) = log.error(msg.format(args: _*))
def logWarnException(msg: String, t: Throwable, args: Any*) = log.warn(msg.format(args: _*), t)
def logErrorException(msg: String, t: Throwable, args: Any*) = log.error(msg.format(args: _*), t)
@EventHandler
def preInit(event: FMLPreInitializationEvent) {
@@ -25,8 +25,7 @@ object ExtraBeesProxy {
Class.forName("binnie.extrabees.ExtraBees").getField("serum").get(null).asInstanceOf[Item]
} catch {
case e: Throwable =>
Gendustry.logWarn("Failed to load ExtraBees serum item")
e.printStackTrace()
Gendustry.logWarnException("Failed to load ExtraBees serum item", e)
null
}
else
+1 -1
View File
@@ -12,6 +12,6 @@ package net.bdew.gendustry.config
import net.bdew.lib.config.BlockManager
import net.bdew.gendustry.Gendustry
object Blocks extends BlockManager() {
object Blocks extends BlockManager {
Gendustry.logInfo("Blocks loaded")
}
+1 -1
View File
@@ -17,7 +17,7 @@ import net.bdew.lib.Misc
import cpw.mods.fml.common.registry.GameRegistry
import net.minecraft.item.ItemStack
object Fluids extends FluidManager() {
object Fluids extends FluidManager {
val emptyBucket = new ItemStack(GameRegistry.findItem("minecraft", "bucket"))
val emptyCan = new ItemStack(GameRegistry.findItem("Forestry", "canEmpty"))
+6 -10
View File
@@ -9,27 +9,23 @@
package net.bdew.gendustry.config
import cpw.mods.fml.common.registry.GameRegistry
import net.bdew.gendustry.items.{IndustrialScoop, IndustrialGrafter, GeneTemplate, GeneSample}
import net.bdew.gendustry.machines.apiary.upgrades.ItemApiaryUpgrade
import net.bdew.lib.config.ItemManager
import net.bdew.gendustry.Gendustry
object Items extends ItemManager() {
object Items extends ItemManager {
val labware = regSimpleItem("Labware")
val waste = regSimpleItem("Waste")
val geneSampleBlank = regSimpleItem("GeneSampleBlank")
val geneSample = regItem(new GeneSample())
val geneTemplate = regItem(new GeneTemplate())
regItem(GeneSample)
regItem(GeneTemplate)
val upgradeItem = regItemCls(classOf[ItemApiaryUpgrade], "ApiaryUpgrade")
regItem(ItemApiaryUpgrade)
val grafter = regItemCls(classOf[IndustrialGrafter], "IndustrialGrafter", false)
GameRegistry.registerCustomItemStack("IndustrialGrafter", grafter.stackWithCharge(0))
val scoop = regItemCls(classOf[IndustrialScoop], "IndustrialScoop", false)
GameRegistry.registerCustomItemStack("IndustrialScoop", scoop.stackWithCharge(0))
regItem(IndustrialGrafter)
regItem(IndustrialScoop)
regSimpleItem("MutagenTank")
regSimpleItem("BeeReceptacle")
@@ -14,7 +14,6 @@ import net.minecraft.item.ItemStack
import net.minecraft.inventory.InventoryCrafting
import net.minecraft.world.World
import net.bdew.gendustry.items.{GeneTemplate, GeneSample}
import net.bdew.gendustry.config.Items
class GeneRecipe extends IRecipe {
def matches(inv: InventoryCrafting, world: World): Boolean = getCraftingResult(inv) != null
@@ -23,9 +22,9 @@ class GeneRecipe extends IRecipe {
var samples = Seq.empty[GeneSampleInfo]
for (i <- 0 until 3; j <- 0 until 3) {
val itm = inv.getStackInRowAndColumn(i, j)
if (itm != null && itm.getItem.isInstanceOf[GeneSample] && itm.hasTagCompound)
samples :+= Items.geneSample.getInfo(itm)
else if (itm != null && itm.getItem.isInstanceOf[GeneTemplate] && template == null)
if (itm != null && itm.getItem == GeneSample && itm.hasTagCompound)
samples :+= GeneSample.getInfo(itm)
else if (itm != null && itm.getItem == GeneTemplate && template == null)
template = itm
else if (itm != null)
return null
@@ -33,7 +32,7 @@ class GeneRecipe extends IRecipe {
if (samples.isEmpty || template == null) return null
val out = template.copy()
for (s <- samples) {
if (!Items.geneTemplate.addSample(out, s)) return null
if (!GeneTemplate.addSample(out, s)) return null
}
return out
}
@@ -19,6 +19,7 @@ import java.util.Random
import net.bdew.gendustry.config.{Items, Machines}
import net.minecraft.world.World
import forestry.api.lepidopterology.{EnumFlutterType, IButterflyRoot}
import net.bdew.gendustry.items.GeneTemplate
object GeneticsHelper {
val random = new Random
@@ -169,8 +170,8 @@ object GeneticsHelper {
}
def individualFromTemplate(tpl: ItemStack, pristine: Boolean = false) = {
val root = Items.geneTemplate.getSpecies(tpl)
val samples = Items.geneTemplate.getSamples(tpl)
val root = GeneTemplate.getSpecies(tpl)
val samples = GeneTemplate.getSamples(tpl)
val template = root.getDefaultTemplate
samples.foreach(x => template(x.chromosome) = x.allele)
val individual = root.templateAsIndividual(template)
@@ -189,10 +190,10 @@ object GeneticsHelper {
def templateFromSpeciesUID(uid: String) = {
val root = AlleleManager.alleleRegistry.getAllele(uid).asInstanceOf[IAlleleSpecies].getRoot
val template = root.getTemplate(uid)
val item = new ItemStack(Items.geneTemplate)
val item = new ItemStack(GeneTemplate)
for ((allele, chromosome) <- template.zipWithIndex if allele != null)
Items.geneTemplate.addSample(item, GeneSampleInfo(root, chromosome, allele))
GeneTemplate.addSample(item, GeneSampleInfo(root, chromosome, allele))
item
}
@@ -18,7 +18,7 @@ import net.bdew.gendustry.forestry.GeneSampleInfo
import net.bdew.gendustry.config.Items
import net.bdew.lib.items.SimpleItem
class GeneSample extends SimpleItem("GeneSample") {
object GeneSample extends SimpleItem("GeneSample") {
setMaxStackSize(1)
setContainerItem(Items.geneSampleBlank)
@@ -22,8 +22,9 @@ import forestry.api.apiculture.{IBeeRoot, EnumBeeChromosome}
import forestry.api.arboriculture.{ITreeRoot, EnumTreeChromosome}
import forestry.api.lepidopterology.{IButterflyRoot, EnumButterflyChromosome}
import net.minecraft.util.EnumChatFormatting
import net.bdew.gendustry.Gendustry
class GeneTemplate extends SimpleItem("GeneTemplate") {
object GeneTemplate extends SimpleItem("GeneTemplate") {
setMaxStackSize(1)
val unusedBeeChromosomes = Set(EnumBeeChromosome.HUMIDITY)
@@ -112,7 +113,7 @@ class GeneTemplate extends SimpleItem("GeneTemplate") {
} catch {
case e: Throwable =>
e.printStackTrace()
Gendustry.logWarnException("Exception while generating template tooltip", e)
tip += "Error"
}
} else {
@@ -26,9 +26,11 @@ import net.minecraft.client.renderer.texture.IIconRegister
import cpw.mods.fml.common.Optional
import net.bdew.gendustry.compat.PowerProxy
import net.bdew.gendustry.power.ItemPowered
import net.bdew.lib.items.NamedItem
@Optional.Interface(modid = PowerProxy.IC2_MOD_ID, iface = "ic2.api.item.ISpecialElectricItem")
class IndustrialGrafter extends ItemTool(0, Item.ToolMaterial.IRON, new util.HashSet[Block]) with ItemPowered with IToolGrafter {
object IndustrialGrafter extends ItemTool(0, Item.ToolMaterial.IRON, new util.HashSet[Block]) with NamedItem with ItemPowered with IToolGrafter {
def name = "IndustrialGrafter"
lazy val cfg = Tuning.getSection("Items").getSection("IndustrialGrafter")
lazy val mjPerCharge = cfg.getInt("MjPerCharge")
lazy val maxCharge = cfg.getInt("Charges") * mjPerCharge
@@ -27,9 +27,11 @@ import net.bdew.gendustry.power.ItemPowered
import forestry.api.core.IToolScoop
import net.minecraftforge.common.ForgeHooks
import net.minecraft.block.material.Material
import net.bdew.lib.items.NamedItem
@Optional.Interface(modid = PowerProxy.IC2_MOD_ID, iface = "ic2.api.item.ISpecialElectricItem")
class IndustrialScoop extends ItemTool(0, Item.ToolMaterial.IRON, new util.HashSet[Block]) with ItemPowered with IToolScoop {
object IndustrialScoop extends ItemTool(0, Item.ToolMaterial.IRON, new util.HashSet[Block]) with NamedItem with ItemPowered with IToolScoop {
def name = "IndustrialScoop"
lazy val cfg = Tuning.getSection("Items").getSection("IndustrialScoop")
lazy val mjPerCharge = cfg.getInt("MjPerCharge")
lazy val maxCharge = cfg.getInt("Charges") * mjPerCharge
@@ -19,18 +19,16 @@ import net.minecraft.creativetab.CreativeTabs
import java.util
import net.minecraft.entity.player.EntityPlayer
import net.bdew.lib.Misc
import cpw.mods.fml.common.registry.GameRegistry
import net.bdew.lib.items.NamedItem
class ItemApiaryUpgrade extends Item with IApiaryUpgrade {
val icons = collection.mutable.Map.empty[Int, IIcon]
object ItemApiaryUpgrade extends Item with IApiaryUpgrade with NamedItem {
var icons = Map.empty[Int, IIcon]
def name = "ApiaryUpgrade"
setHasSubtypes(true)
setMaxDamage(-1)
setUnlocalizedName(Gendustry.modId + ".apiary.upgrade")
for ((id, upgrade) <- Upgrades.map)
GameRegistry.registerCustomItemStack("upgrade." + upgrade.name, new ItemStack(this, 1, id))
def formatModifier(f: Float, base: Float) = (if (f > base) "+" else "") + "%.0f".format((f - base) * 100) + "%"
override def addInformation(stack: ItemStack, player: EntityPlayer, list: util.List[_], par4: Boolean) {
@@ -113,8 +111,8 @@ class ItemApiaryUpgrade extends Item with IApiaryUpgrade {
@SideOnly(Side.CLIENT)
override def registerIcons(reg: IIconRegister) {
for ((id, upgrade) <- Upgrades.map) {
icons += id -> reg.registerIcon("%s:upgrades/%s".format(Gendustry.modId, upgrade.name))
}
icons = Upgrades.map.map({
case (id, upgrade) => id -> reg.registerIcon("%s:upgrades/%s".format(Gendustry.modId, upgrade.name))
}).toMap
}
}
@@ -11,7 +11,7 @@ package net.bdew.gendustry.machines.apiary.upgrades
import net.bdew.gendustry.api.ApiaryModifiers
import net.bdew.gendustry.config.TuningLoader._
import net.bdew.gendustry.config.{Items, Tuning}
import net.bdew.gendustry.config.Tuning
import net.bdew.lib.recipes.gencfg.{EntryStr, ConfigSection}
import cpw.mods.fml.common.registry.GameRegistry
import net.minecraft.item.ItemStack
@@ -72,7 +72,7 @@ object Upgrades {
case (pname, v) => sys.error("Unknown upgrade modifier '%s' - %s in upgrade '%s'".format(pname, v, name))
})
map += id -> Upgrade(id, name, max, mods.toSeq)
GameRegistry.registerCustomItemStack("upgrade." + name, new ItemStack(Items.upgradeItem, 1, id))
GameRegistry.registerCustomItemStack("upgrade." + name, new ItemStack(ItemApiaryUpgrade, 1, id))
}
}
}
@@ -17,6 +17,7 @@ import forestry.api.apiculture.{EnumBeeType, IBeeRoot, IBee}
import scala.util.Random
import net.bdew.lib.power.TileItemProcessor
import net.bdew.gendustry.power.TilePowered
import net.bdew.gendustry.items.GeneTemplate
class TileImprinter extends TileItemProcessor with TilePowered {
lazy val cfg = Machines.imprinter
@@ -41,7 +42,7 @@ class TileImprinter extends TileItemProcessor with TilePowered {
val individual = AlleleManager.alleleRegistry.getIndividual(getStackInSlot(slots.inIndividual))
val genome = individual.getGenome.getChromosomes
val root = Items.geneTemplate.getSpecies(getStackInSlot(slots.inTemplate))
val root = GeneTemplate.getSpecies(getStackInSlot(slots.inTemplate))
if (root != individual.getGenome.getSpeciesRoot) return false
@@ -65,7 +66,7 @@ class TileImprinter extends TileItemProcessor with TilePowered {
val primary = genome.map(x => if (x == null) null else x.getPrimaryAllele)
val secondary = genome.map(x => if (x == null) null else x.getSecondaryAllele)
for (x <- Items.geneTemplate.getSamples(getStackInSlot(slots.inTemplate))) {
for (x <- GeneTemplate.getSamples(getStackInSlot(slots.inTemplate))) {
primary(x.chromosome) = x.allele
secondary(x.chromosome) = x.allele
}
@@ -95,13 +96,13 @@ class TileImprinter extends TileItemProcessor with TilePowered {
if (stack == null || stack.getItem == null) return false
slot match {
case slots.inTemplate =>
return (stack.getItem == Items.geneTemplate) &&
(inv(slots.inIndividual) == null || Items.geneTemplate.getSpecies(stack) == AlleleManager.alleleRegistry.getSpeciesRoot(inv(slots.inIndividual)))
return (stack.getItem == GeneTemplate) &&
(inv(slots.inIndividual) == null || GeneTemplate.getSpecies(stack) == AlleleManager.alleleRegistry.getSpeciesRoot(inv(slots.inIndividual)))
case slots.inLabware =>
return stack.getItem == Items.labware
case slots.inIndividual =>
return (AlleleManager.alleleRegistry.getIndividual(stack) != null) &&
(inv(slots.inTemplate) == null || Items.geneTemplate.getSpecies(inv(slots.inTemplate)) == AlleleManager.alleleRegistry.getSpeciesRoot(stack))
(inv(slots.inTemplate) == null || GeneTemplate.getSpecies(inv(slots.inTemplate)) == AlleleManager.alleleRegistry.getSpeciesRoot(stack))
case _ =>
return false
}
@@ -9,7 +9,7 @@
package net.bdew.gendustry.machines.replicator
import net.bdew.gendustry.config.{Fluids, Items, Machines}
import net.bdew.gendustry.config.{Fluids, Machines}
import net.minecraft.item.ItemStack
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
@@ -17,6 +17,7 @@ import net.bdew.lib.data.DataSlotTankRestricted
import net.bdew.lib.power.TileItemProcessor
import net.bdew.gendustry.power.TilePowered
import net.bdew.gendustry.forestry.GeneticsHelper
import net.bdew.gendustry.items.GeneTemplate
class TileReplicator extends TileItemProcessor with TilePowered with IFluidHandler {
lazy val cfg = Machines.replicator
@@ -48,7 +49,7 @@ class TileReplicator extends TileItemProcessor with TilePowered with IFluidHandl
}
override def isItemValidForSlot(slot: Int, itemstack: ItemStack) =
slot == slots.inTemplate && itemstack.getItem == Items.geneTemplate && Items.geneTemplate.isComplete(itemstack)
slot == slots.inTemplate && itemstack.getItem == GeneTemplate && GeneTemplate.isComplete(itemstack)
allowSided = true
override def canExtractItem(slot: Int, item: ItemStack, side: Int) = slot == slots.outIndividual
@@ -17,6 +17,7 @@ import net.bdew.gendustry.forestry.GeneSampleInfo
import net.bdew.lib.power.TileItemProcessor
import net.bdew.gendustry.power.TilePowered
import net.bdew.gendustry.compat.ExtraBeesProxy
import net.bdew.gendustry.items.GeneSample
class TileSampler extends TileItemProcessor with TilePowered {
lazy val cfg = Machines.sampler
@@ -34,7 +35,7 @@ class TileSampler extends TileItemProcessor with TilePowered {
def selectRandomAllele(stack: ItemStack): ItemStack = {
if (cfg.convertEBSerums && ExtraBeesProxy.isSerum(stack)) {
val sample = ExtraBeesProxy.getSerumSample(stack)
if (sample != null) return Items.geneSample.newStack(sample)
if (sample != null) return GeneSample.newStack(sample)
}
val root = AlleleManager.alleleRegistry.getSpeciesRoot(stack)
@@ -48,7 +49,7 @@ class TileSampler extends TileItemProcessor with TilePowered {
val rand = new Random()
val (chr, allele) = alleles(rand.nextInt(alleles.length))
return Items.geneSample.newStack(GeneSampleInfo(root, chr, allele))
return GeneSample.newStack(GeneSampleInfo(root, chr, allele))
}
def canStart =
@@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack
import net.bdew.lib.power.TileItemProcessor
import net.bdew.gendustry.power.TilePowered
import net.bdew.lib.items.IStack
import net.bdew.gendustry.items.{GeneTemplate, GeneSample}
class TileTransposer extends TileItemProcessor with TilePowered {
lazy val cfg = Machines.transposer
@@ -37,11 +38,11 @@ class TileTransposer extends TileItemProcessor with TilePowered {
def tryStart(): Boolean = {
if (canStart) {
val tpl = getStackInSlot(slots.inTemplate)
if (tpl.getItem == Items.geneSample) {
if (tpl.getItem == GeneSample) {
output := tpl.copy()
} else if (tpl.getItem == Items.geneTemplate && Items.geneTemplate.getSamples(tpl) != null) {
} else if (tpl.getItem == GeneTemplate && GeneTemplate.getSamples(tpl) != null) {
output := getStackInSlot(slots.inBlank).copy()
Items.geneTemplate.getSamples(tpl).foreach(Items.geneTemplate.addSample(output, _))
GeneTemplate.getSamples(tpl).foreach(GeneTemplate.addSample(output, _))
} else return false
decrStackSize(slots.inBlank, 1)
@@ -54,13 +55,13 @@ class TileTransposer extends TileItemProcessor with TilePowered {
def isValidInputs(blank: ItemStack, template: ItemStack) = (blank, template) match {
case (IStack(Items.geneSampleBlank), null) => true
case (IStack(Items.geneSampleBlank), IStack(Items.geneSample)) => true
case (null, IStack(Items.geneSample)) => true
case (IStack(Items.geneTemplate), null) => true
case (null, IStack(Items.geneTemplate)) => Items.geneTemplate.getSpecies(template) != null
case (IStack(Items.geneTemplate), IStack(Items.geneTemplate)) =>
val bsp = Items.geneTemplate.getSpecies(blank)
val tsp = Items.geneTemplate.getSpecies(template)
case (IStack(Items.geneSampleBlank), IStack(GeneSample)) => true
case (null, IStack(GeneSample)) => true
case (IStack(GeneTemplate), null) => true
case (null, IStack(GeneTemplate)) => GeneTemplate.getSpecies(template) != null
case (IStack(GeneTemplate), IStack(GeneTemplate)) =>
val bsp = GeneTemplate.getSpecies(blank)
val tsp = GeneTemplate.getSpecies(template)
tsp != null && (bsp == null || bsp == tsp)
case _ => false
}