Rebuild IDebuggable to be config-agnostic, make output configurable.

This commit is contained in:
Sunstrike committed 2013-12-10 01:35:05 +00:00
1 parent 5b54ac0673
commit caa5f6f3bb
8 files changed
+99 -17

No files matched your search

+4 -4
View File
@@ -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);
}
}
@@ -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));
}
}
@@ -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);
}
}
@@ -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);
}
}
+23
View File
@@ -0,0 +1,23 @@
package mantle.debug;
import net.minecraft.entity.player.EntityPlayer;
/**
* Encapsulation for debug information
*
* @author Sunstrike <[email protected]>
*/
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;
}
}
+45
View File
@@ -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 <[email protected]>
*/
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);
}
}
}
@@ -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);
}
+8
View File
@@ -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;
}