Worked on debug block a bit

This commit is contained in:
DarkGuardsman 2013-09-06 00:32:02 -04:00
parent 13815689a2
commit c950f24580

View file

@ -20,24 +20,7 @@ import dark.core.prefab.helpers.Pair;
public class BlockDebug extends BlockMachine implements IExtraObjectInfo public class BlockDebug extends BlockMachine implements IExtraObjectInfo
{ {
Icon load, source, vod, fluid; public static float DebugWattOut, DebugWattDemand;
public static enum debugBlocks
{
INF_POWER("infSource", TileEntityInfSupply.class),
INF_FLUID("infFluid", TileEntityInfFluid.class),
VOID("void", TileEntityVoid.class),
INF_LOAD("infLoad", TileEntityInfLoad.class);
public String name;
public Class<? extends TileEntity> clazz;
private debugBlocks(String name, Class<? extends TileEntity> clazz)
{
this.name = name;
this.clazz = clazz;
}
}
public BlockDebug(int blockID, Configuration config) public BlockDebug(int blockID, Configuration config)
{ {
@ -45,44 +28,36 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo
this.setCreativeTab(CreativeTabs.tabRedstone); this.setCreativeTab(CreativeTabs.tabRedstone);
} }
@SideOnly(Side.CLIENT)
@Override @Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconReg) public void registerIcons(IconRegister iconReg)
{ {
super.registerIcons(iconReg); super.registerIcons(iconReg);
this.source = iconReg.registerIcon(DarkMain.getInstance().PREFIX + "infSource"); for (DebugBlocks block : DebugBlocks.values())
this.load = iconReg.registerIcon(DarkMain.getInstance().PREFIX + "infLoad"); {
this.vod = iconReg.registerIcon(DarkMain.getInstance().PREFIX + "void"); block.icon = iconReg.registerIcon(DarkMain.getInstance().PREFIX + block.getTextureName());
this.fluid = iconReg.registerIcon(DarkMain.getInstance().PREFIX + "infFluid"); }
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta) public Icon getIcon(int side, int meta)
{ {
switch (meta) if (meta < DebugBlocks.values().length)
{ {
case 0: return DebugBlocks.values()[meta].icon;
return this.source;
case 1:
return this.fluid;
case 2:
return this.vod;
case 3:
return this.load;
default:
return this.blockIcon;
} }
return this.blockIcon;
} }
@Override @Override
public TileEntity createTileEntity(World world, int metadata) public TileEntity createTileEntity(World world, int metadata)
{ {
if (metadata < debugBlocks.values().length) if (metadata < DebugBlocks.values().length)
{ {
try try
{ {
return debugBlocks.values()[metadata].clazz.newInstance(); return DebugBlocks.values()[metadata].clazz.newInstance();
} }
catch (Exception e) catch (Exception e)
{ {
@ -95,25 +70,41 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo
@Override @Override
public TileEntity createNewTileEntity(World world) public TileEntity createNewTileEntity(World world)
{ {
// TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) public void onBlockAdded(World world, int x, int y, int z)
{ {
for (int i = 0; i < debugBlocks.values().length; i++) super.onBlockAdded(world, x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (meta >= DebugBlocks.values().length || !DebugBlocks.values()[meta].enabled)
{ {
par3List.add(new ItemStack(par1, 1, i)); world.setBlock(x, y, z, 0);
}
}
@Override
public void getSubBlocks(int blockID, CreativeTabs tab, List creativeTabList)
{
for (DebugBlocks block : DebugBlocks.values())
{
if (block.enabled)
{
creativeTabList.add(new ItemStack(blockID, 1, block.ordinal()));
}
} }
} }
@Override @Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list) public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{ {
for (int i = 0; i < debugBlocks.values().length; i++) for (DebugBlocks block : DebugBlocks.values())
{ {
list.add(new Pair<String, Class<? extends TileEntity>>("DMDebug" + i, debugBlocks.values()[i].clazz)); if (block.enabled)
{
list.add(new Pair<String, Class<? extends TileEntity>>(block.name, block.clazz));
}
} }
} }
@ -121,14 +112,16 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo
@Override @Override
public boolean hasExtraConfigs() public boolean hasExtraConfigs()
{ {
// TODO Auto-generated method stub return true;
return false;
} }
@Override @Override
public void loadExtraConfigs(Configuration config) public void loadExtraConfigs(Configuration config)
{ {
// TODO Auto-generated method stub for (DebugBlocks block : DebugBlocks.values())
{
block.enabled = config.get("Blocks", "Enable" + block.name + "Block", true).getBoolean(true);
}
} }
@ -146,4 +139,38 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo
} }
public static enum DebugBlocks
{
SOURCE("UnlimitedPower", TileEntityInfSupply.class, "infSource"),
FLUID("UnlimitedFluid", TileEntityInfFluid.class, "infFluid"),
VOID("FluidVoid", TileEntityVoid.class, "void"),
LOAD("PowerVampire", TileEntityInfLoad.class, "infLoad");
public Icon icon;
public String name;
public String texture;
public boolean enabled;
Class<? extends TileEntity> clazz;
private DebugBlocks(String name, Class<? extends TileEntity> clazz)
{
this.name = name;
}
private DebugBlocks(String name, Class<? extends TileEntity> clazz, String texture)
{
this(name, clazz);
this.texture = texture;
}
public String getTextureName()
{
if (texture == null || texture.isEmpty())
{
return name;
}
return texture;
}
}
} }