Use FML logging system.

Made some of the ASM code more concise
This commit is contained in:
Chicken-Bones committed 2014-04-28 13:34:20 +10:00
1 parent 5c4b9e0a5b
commit bd1a72e958
13 files changed
+388 -451

No files matched your search

+10 -10
View File
@@ -109,8 +109,8 @@ object ConfigContent
catch
{
case e:Exception =>
System.err.println("Invalid line in microblocks.cfg: "+s)
System.err.println(e.getMessage)
logger.error("Invalid line in microblocks.cfg: "+s)
logger.error(e.getMessage)
}
}
}
@@ -126,7 +126,7 @@ object ConfigContent
if(idMap(i) != null)
{
if(block == Blocks.air)
System.err.println("Warning: Unable to add micro material for block with ID "+i+" as it doesn't exist")
logger.warn("Unable to add micro material for block with ID "+i+" as it doesn't exist")
else
createAndRegister(block, idMap(i))
}
@@ -142,10 +142,10 @@ object ConfigContent
createAndRegister(block, m)
}
catch {
case e:IllegalStateException => System.err.println("Unable to register micro material: "+
case e:IllegalStateException => logger.error("Unable to register micro material: "+
materialKey(block, m)+"\n\t"+e.getMessage)
case e:Exception =>
System.err.println("Unable to register micro material: "+materialKey(block, m))
logger.error("Unable to register micro material: "+materialKey(block, m))
e.printStackTrace()
}
}
@@ -153,14 +153,14 @@ object ConfigContent
}
}
nameMap.foreach(e => System.err.println("Warning: Unable to add micro material for block with unlocalised name "+e._1+" as it doesn't exist"))
nameMap.foreach(e => logger.warn("Unable to add micro material for block with unlocalised name "+e._1+" as it doesn't exist"))
}
def handleIMC(messages:Seq[IMCMessage]) {
messages.filter(_.key == "microMaterial").foreach{msg =>
def error(s:String) {
System.err.println("Invalid microblock IMC message from "+msg.getSender+": "+s)
logger.error("Invalid microblock IMC message from "+msg.getSender+": "+s)
}
if(msg.getMessageType != classOf[ItemStack])
@@ -168,15 +168,15 @@ object ConfigContent
else {
val stack = msg.getItemStackValue
if(Block.blockRegistry.containsId(Item.getIdFromItem(stack.getItem)))
System.err.println("Invalid Block: "+stack.getItem)
error("Invalid Block: "+stack.getItem)
else if(stack.getItemDamage < 0 || stack.getItemDamage >= 16)
System.err.println("Invalid metadata: "+stack.getItemDamage)
error("Invalid metadata: "+stack.getItemDamage)
else {
try {
createAndRegister(Block.getBlockFromItem(stack.getItem), stack.getItemDamage)
}
catch {
case e:IllegalStateException => System.err.println("Unable to register micro material: "+
case e:IllegalStateException => error("Unable to register micro material: "+
materialKey(Block.getBlockFromItem(stack.getItem), stack.getItemDamage)+"\n\t"+e.getMessage)
}
}
@@ -21,7 +21,6 @@ import net.minecraft.block.Block.SoundType
object MicroMaterialRegistry
{
/**
* Interface for defining a micro material
*/
@@ -127,11 +126,11 @@ object MicroMaterialRegistry
throw new IllegalStateException("You must register your materials in the init methods.")
if (typeMap.contains(name)) {
System.err.println("Material with id " + name + " is already registered.")
logger.error("Material with id " + name + " is already registered.")
return
}
System.out.println("Registered micro material: " + name)
logger.info("Registered micro material: " + name)
typeMap.put(name, material)
}
@@ -144,9 +143,9 @@ object MicroMaterialRegistry
throw new IllegalStateException("You must register your materials in the init methods.")
if (typeMap.remove(name).isEmpty)
System.err.println("Material with id " + name + " is was not registered.")
logger.error("Material with id " + name + " is was not registered.")
System.out.println("Replaced micro material: " + name)
logger.info("Replaced micro material: " + name)
typeMap.put(name, material)
}
@@ -215,7 +214,7 @@ object MicroMaterialRegistry
def materialID(name: String) = nameMap.get(name) match {
case Some(v) => v
case None =>
System.err.println("Missing mapping for part with ID: " + name)
logger.error("Missing mapping for part with ID: " + name)
0
}
@@ -12,41 +12,35 @@ import codechicken.microblock.ConfigContent
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent
import scala.collection.JavaConversions._
@Mod(modid = "ForgeMicroblock", acceptedMinecraftVersions = "[1.7.2]",
dependencies="required-after:ForgeMultipart;after:*", modLanguage="scala")
@Mod(modid = "ForgeMicroblock", acceptedMinecraftVersions = "[1.7.2]", dependencies = "required-after:ForgeMultipart;after:*", modLanguage = "scala")
object MicroblockMod
{
@EventHandler
def preInit(event:FMLPreInitializationEvent)
{
MicroblockProxy.preInit()
def preInit(event: FMLPreInitializationEvent) {
MicroblockProxy.preInit(event.getModLog)
DefaultContent.load()
ConfigContent.parse(event.getModConfigurationDirectory)
}
@EventHandler
def init(event:FMLInitializationEvent)
{
def init(event: FMLInitializationEvent) {
MicroblockProxy.init()
ConfigContent.load()
}
@EventHandler
def postInit(event:FMLPostInitializationEvent)
{
def postInit(event: FMLPostInitializationEvent) {
MicroMaterialRegistry.setupIDMap()
MicroblockProxy.postInit()
}
@EventHandler
def beforeServerStart(event:FMLServerAboutToStartEvent)
{
def beforeServerStart(event: FMLServerAboutToStartEvent) {
MicroMaterialRegistry.setupIDMap()
}
@EventHandler
def handleIMC(event:IMCEvent)
{
def handleIMC(event: IMCEvent) {
ConfigContent.handleIMC(event.getMessages)
}
}
@@ -20,9 +20,12 @@ import cpw.mods.fml.common.registry.GameRegistry
import cpw.mods.fml.common.network.NetworkRegistry
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.init.{Blocks, Items}
import org.apache.logging.log4j.Logger
class MicroblockProxy_serverImpl
{
var logger:Logger = _
private var baseID = 24875-1
def nextItemID = {baseID+=1; baseID}
@@ -33,8 +36,9 @@ class MicroblockProxy_serverImpl
var sawDiamond:Item = _
var stoneRod:Item = _
def preInit()
def preInit(logger:Logger)
{
this.logger = logger
itemMicro = new ItemMicroPart
GameRegistry.registerItem(itemMicro, "microblock")
sawStone = createSaw(config, "sawStone", 1)
+8
View File
@@ -0,0 +1,8 @@
package codechicken
import codechicken.microblock.handler.MicroblockProxy
package object microblock
{
def logger = MicroblockProxy.logger
}