diff --git a/src/mantle/blocks/MantleBlock.java b/src/mantle/blocks/MantleBlock.java index bf00e2b..3b044c7 100644 --- a/src/mantle/blocks/MantleBlock.java +++ b/src/mantle/blocks/MantleBlock.java @@ -2,7 +2,8 @@ package mantle.blocks; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; -import mantle.blocks.iface.IDebuggable; +import mantle.debug.DebugHelper; +import mantle.debug.IDebuggable; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; @@ -28,11 +29,10 @@ public abstract class MantleBlock extends Block { { TileEntity te = world.getBlockTileEntity(x, y, z); if (te instanceof IDebuggable) - { - ((IDebuggable) te).sendDebugToPlayer(player); - } + DebugHelper.handleDebugData(((IDebuggable) te).getDebugInfo(player)); } super.onBlockClicked(world, x, y, z, player); } + } diff --git a/src/mantle/blocks/abstracts/InventoryBlock.java b/src/mantle/blocks/abstracts/InventoryBlock.java index 0c11cc9..083a955 100644 --- a/src/mantle/blocks/abstracts/InventoryBlock.java +++ b/src/mantle/blocks/abstracts/InventoryBlock.java @@ -2,7 +2,8 @@ package mantle.blocks.abstracts; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; -import mantle.blocks.iface.IDebuggable; +import mantle.debug.DebugHelper; +import mantle.debug.IDebuggable; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -203,7 +204,7 @@ public abstract class InventoryBlock extends BlockContainer TileEntity te = world.getBlockTileEntity(x, y, z); if (te instanceof IDebuggable) { - ((IDebuggable) te).sendDebugToPlayer(player); + DebugHelper.handleDebugData(((IDebuggable) te).getDebugInfo(player)); } } diff --git a/src/mantle/blocks/abstracts/InventoryLogic.java b/src/mantle/blocks/abstracts/InventoryLogic.java index 3f3366f..8a3598e 100644 --- a/src/mantle/blocks/abstracts/InventoryLogic.java +++ b/src/mantle/blocks/abstracts/InventoryLogic.java @@ -1,6 +1,7 @@ package mantle.blocks.abstracts; -import mantle.blocks.iface.IDebuggable; +import mantle.debug.DebugData; +import mantle.debug.IDebuggable; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -228,8 +229,10 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I /* IDebuggable */ @Override - public void sendDebugToPlayer(EntityPlayer player) { - player.addChatMessage("[InventoryLogic] invName: "+ invName + ", inventory.length: " + inventory.length + ", stackSizeLimit: " + stackSizeLimit); + public DebugData getDebugInfo(EntityPlayer player) { + String[] strs = new String[1]; + strs[0] = "invName: "+ invName + ", inventory.length: " + inventory.length + ", stackSizeLimit: " + stackSizeLimit; + return new DebugData(player, getClass(), strs); } } diff --git a/src/mantle/blocks/abstracts/MultiServantLogic.java b/src/mantle/blocks/abstracts/MultiServantLogic.java index 322a8b5..35b8fcb 100644 --- a/src/mantle/blocks/abstracts/MultiServantLogic.java +++ b/src/mantle/blocks/abstracts/MultiServantLogic.java @@ -1,6 +1,7 @@ package mantle.blocks.abstracts; -import mantle.blocks.iface.IDebuggable; +import mantle.debug.DebugData; +import mantle.debug.IDebuggable; import mantle.world.CoordTuple; import mantle.blocks.iface.IMasterLogic; import mantle.blocks.iface.IServantLogic; @@ -180,14 +181,15 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb /* IDebuggable */ @Override - public void sendDebugToPlayer(EntityPlayer player) - { - player.addChatMessage("[MultiServantLogic] Location: x" + xCoord + ", y" + yCoord + ", z" + zCoord); + public DebugData getDebugInfo(EntityPlayer player) { + String[] strs = new String[2]; + strs[0] = "Location: x" + xCoord + ", y" + yCoord + ", z" + zCoord; if (hasMaster) { - player.addChatMessage("[MultiServantLogic] masterID: " + masterID + ", masterMeat: " + masterMeat); + strs[1] = "masterID: " + masterID + ", masterMeat: " + masterMeat; } else { - player.addChatMessage("[MultiServantLogic] No active master."); + strs[1] = "No active master."; } + return new DebugData(player, getClass(), strs); } } diff --git a/src/mantle/debug/DebugData.java b/src/mantle/debug/DebugData.java new file mode 100644 index 0000000..d727378 --- /dev/null +++ b/src/mantle/debug/DebugData.java @@ -0,0 +1,23 @@ +package mantle.debug; + +import net.minecraft.entity.player.EntityPlayer; + +/** + * Encapsulation for debug information + * + * @author Sunstrike + */ +public class DebugData { + + public final EntityPlayer player; + public final Class cl; + public final String[] strings; + + public DebugData(EntityPlayer player, Class cl, String[] strings) + { + this.player = player; + this.cl = cl; + this.strings = strings; + } + +} diff --git a/src/mantle/debug/DebugHelper.java b/src/mantle/debug/DebugHelper.java new file mode 100644 index 0000000..a3b1e68 --- /dev/null +++ b/src/mantle/debug/DebugHelper.java @@ -0,0 +1,45 @@ +package mantle.debug; + +import net.minecraft.entity.player.EntityPlayer; + +import static mantle.lib.CoreRepo.*; +import static mantle.lib.CoreConfig.*; + +/** + * IDebuggable helper + * + * @author Sunstrike + */ +public class DebugHelper { + + private DebugHelper() {} //Singleton + + public static void handleDebugData(DebugData data) + { + if (debug_enableChat) + handleChatDebug(data); + if (debug_enableConsole) + handleConsoleDebug(data); + } + + private static void handleChatDebug(DebugData data) + { + EntityPlayer player = data.player; + String prefix = "[" + data.cl.getSimpleName() + "] "; + for (String str : data.strings) + { + player.addChatMessage(prefix + str); + } + } + + private static void handleConsoleDebug(DebugData data) + { + String player = data.player.username; + String prefix = "[" + player + ":" + data.cl.getSimpleName() + "] "; + for (String str : data.strings) + { + logger.info(prefix + str); + } + } + +} diff --git a/src/mantle/blocks/iface/IDebuggable.java b/src/mantle/debug/IDebuggable.java similarity index 79% rename from src/mantle/blocks/iface/IDebuggable.java rename to src/mantle/debug/IDebuggable.java index 86538de..1f78362 100644 --- a/src/mantle/blocks/iface/IDebuggable.java +++ b/src/mantle/debug/IDebuggable.java @@ -1,4 +1,4 @@ -package mantle.blocks.iface; +package mantle.debug; import net.minecraft.entity.player.EntityPlayer; @@ -11,6 +11,6 @@ import net.minecraft.entity.player.EntityPlayer; */ public interface IDebuggable { - public void sendDebugToPlayer(EntityPlayer player); + public DebugData getDebugInfo(EntityPlayer player); } diff --git a/src/mantle/lib/CoreConfig.java b/src/mantle/lib/CoreConfig.java index c172059..8a3c2f2 100644 --- a/src/mantle/lib/CoreConfig.java +++ b/src/mantle/lib/CoreConfig.java @@ -25,11 +25,19 @@ public class CoreConfig silenceEnvChecks = config.get("Environment", "unsupportedLogging", silenceEnvChecks).getBoolean(silenceEnvChecks); + debug_enableConsole = config.get("DebugHelpers", "enableConsole", debug_enableConsole).getBoolean(debug_enableConsole); + debug_enableChat = config.get("DebugHelpers", "enableChat", debug_enableChat).getBoolean(debug_enableChat); + config.save(); logger.info("Configuration load completed."); } // BEGIN CONFIG VARS + // Env Checks public static boolean silenceEnvChecks = false; + // Debug Helpers + public static boolean debug_enableConsole = false; + public static boolean debug_enableChat = false; + }