From b4b8f857d1a6c9bea207a0c5343afe99be3d6937 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Sun, 22 Sep 2013 00:05:24 -0400 Subject: [PATCH] ReworkedExtraInfoLoading --- src/dark/core/common/blocks/BlockOre.java | 56 ++++++++++--------- src/dark/core/common/blocks/ItemBlockOre.java | 1 - src/dark/core/common/debug/BlockDebug.java | 18 +----- .../common/machines/BlockBasicMachine.java | 3 +- .../core/common/machines/BlockSolarPanel.java | 14 ++--- src/dark/core/common/transmit/BlockWire.java | 4 +- src/dark/core/prefab/IExtraObjectInfo.java | 31 ---------- .../core/prefab/machine/BlockMachine.java | 44 ++++++++++++++- src/dark/core/prefab/machine/BlockMulti.java | 4 +- .../core/registration/ModObjectRegistry.java | 22 +++++--- 10 files changed, 98 insertions(+), 99 deletions(-) delete mode 100644 src/dark/core/prefab/IExtraObjectInfo.java diff --git a/src/dark/core/common/blocks/BlockOre.java b/src/dark/core/common/blocks/BlockOre.java index 1bcde8830..2eb4e6a10 100644 --- a/src/dark/core/common/blocks/BlockOre.java +++ b/src/dark/core/common/blocks/BlockOre.java @@ -8,26 +8,22 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; +import net.minecraft.world.World; import net.minecraftforge.common.Configuration; import net.minecraftforge.oredict.OreDictionary; import universalelectricity.prefab.ore.OreGenReplaceStone; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dark.api.ProcessorRecipes; -import dark.api.ProcessorRecipes.ProcessorType; import dark.core.common.CoreRecipeLoader; import dark.core.common.DarkMain; import dark.core.common.items.EnumMaterial; -import dark.core.common.items.EnumOrePart; -import dark.core.common.items.ItemOreDirv; -import dark.core.prefab.IExtraObjectInfo; +import dark.core.prefab.IExtraInfo.IExtraBlockInfo; import dark.core.prefab.ModPrefab; import dark.core.prefab.helpers.Pair; -public class BlockOre extends Block implements IExtraObjectInfo +public class BlockOre extends Block implements IExtraBlockInfo { Icon[] icons = new Icon[EnumMaterial.values().length]; @@ -73,24 +69,6 @@ public class BlockOre extends Block implements IExtraObjectInfo return Block.stone.getIcon(side, metadata); } - @Override - public void getTileEntities(int blockID, Set>> list) - { - } - - @Override - public boolean hasExtraConfigs() - { - return false; - } - - @Override - public void loadExtraConfigs(Configuration config) - { - // TODO Auto-generated method stub - - } - @Override public void loadOreNames() { @@ -140,4 +118,32 @@ public class BlockOre extends Block implements IExtraObjectInfo return null; } } + + @Override + public boolean hasExtraConfigs() + { + // TODO Auto-generated method stub + return false; + } + + @Override + public void loadExtraConfigs(Configuration config) + { + // TODO Auto-generated method stub + + } + + @Override + public TileEntity createNewTileEntity(World world) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void getTileEntities(int blockID, Set>> list) + { + // TODO Auto-generated method stub + + } } diff --git a/src/dark/core/common/blocks/ItemBlockOre.java b/src/dark/core/common/blocks/ItemBlockOre.java index cbe8969e3..86184fa01 100644 --- a/src/dark/core/common/blocks/ItemBlockOre.java +++ b/src/dark/core/common/blocks/ItemBlockOre.java @@ -4,7 +4,6 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import dark.core.common.DarkMain; import dark.core.common.blocks.BlockOre.OreData; -import dark.core.common.items.EnumMaterial; public class ItemBlockOre extends ItemBlock { diff --git a/src/dark/core/common/debug/BlockDebug.java b/src/dark/core/common/debug/BlockDebug.java index 188b20723..3355a3659 100644 --- a/src/dark/core/common/debug/BlockDebug.java +++ b/src/dark/core/common/debug/BlockDebug.java @@ -15,12 +15,11 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dark.core.common.DMCreativeTab; import dark.core.common.DarkMain; -import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; import dark.core.registration.ModObjectRegistry.BlockBuildData; -public class BlockDebug extends BlockMachine implements IExtraObjectInfo +public class BlockDebug extends BlockMachine { public static float DebugWattOut, DebugWattDemand; @@ -110,18 +109,12 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo list.add(new Pair>(block.name, block.clazz)); } } - - } - - @Override - public boolean hasExtraConfigs() - { - return true; } @Override public void loadExtraConfigs(Configuration config) { + super.loadExtraConfigs(config); for (DebugBlocks block : DebugBlocks.values()) { block.enabled = config.get("Blocks", "Enable" + block.name + "Block", true).getBoolean(true); @@ -129,13 +122,6 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo } - @Override - public void loadOreNames() - { - // TODO Auto-generated method stub - - } - public static enum DebugBlocks { SOURCE("UnlimitedPower", TileEntityInfSupply.class, "infSource"), diff --git a/src/dark/core/common/machines/BlockBasicMachine.java b/src/dark/core/common/machines/BlockBasicMachine.java index e5536c943..5d56e6090 100644 --- a/src/dark/core/common/machines/BlockBasicMachine.java +++ b/src/dark/core/common/machines/BlockBasicMachine.java @@ -16,12 +16,11 @@ import universalelectricity.core.UniversalElectricity; import dark.core.common.CommonProxy; import dark.core.common.DMCreativeTab; import dark.core.common.DarkMain; -import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; import dark.core.registration.ModObjectRegistry.BlockBuildData; -public class BlockBasicMachine extends BlockMachine implements IExtraObjectInfo +public class BlockBasicMachine extends BlockMachine { public BlockBasicMachine() diff --git a/src/dark/core/common/machines/BlockSolarPanel.java b/src/dark/core/common/machines/BlockSolarPanel.java index ff09bc570..e7e16cb7d 100644 --- a/src/dark/core/common/machines/BlockSolarPanel.java +++ b/src/dark/core/common/machines/BlockSolarPanel.java @@ -2,18 +2,19 @@ package dark.core.common.machines; import java.util.Set; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.Configuration; +import net.minecraftforge.oredict.OreDictionary; import universalelectricity.core.UniversalElectricity; import dark.core.client.renders.BlockRenderingHandler; import dark.core.common.DMCreativeTab; -import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; import dark.core.registration.ModObjectRegistry.BlockBuildData; -public class BlockSolarPanel extends BlockMachine implements IExtraObjectInfo +public class BlockSolarPanel extends BlockMachine { public static int tickRate = 10; public static float wattDay = 0.120f; @@ -57,15 +58,10 @@ public class BlockSolarPanel extends BlockMachine implements IExtraObjectInfo } - @Override - public boolean hasExtraConfigs() - { - return true; - } - @Override public void loadExtraConfigs(Configuration config) { + super.loadExtraConfigs(config); tickRate = config.get("settings", "PanelUpdateRate", tickRate).getInt(); wattDay = (float) (config.get("settings", "WattDayLight", 120).getDouble(120) / 1000); wattNight = (float) (config.get("settings", "WattMoonLight", 1).getDouble(1) / 1000); @@ -75,7 +71,7 @@ public class BlockSolarPanel extends BlockMachine implements IExtraObjectInfo @Override public void loadOreNames() { - // TODO Auto-generated method stub + OreDictionary.registerOre("SolarPanel", new ItemStack(this, 1, 0)); } } diff --git a/src/dark/core/common/transmit/BlockWire.java b/src/dark/core/common/transmit/BlockWire.java index cd9f14a32..1c87a3927 100644 --- a/src/dark/core/common/transmit/BlockWire.java +++ b/src/dark/core/common/transmit/BlockWire.java @@ -17,12 +17,11 @@ import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.tile.TileEntityConductor; import dark.core.common.DMCreativeTab; import dark.core.common.DarkMain; -import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; import dark.core.registration.ModObjectRegistry.BlockBuildData; -public class BlockWire extends BlockMachine implements IExtraObjectInfo +public class BlockWire extends BlockMachine { public static float wireResistance = 0.001f; public static float ampMax = 10000f; @@ -239,6 +238,7 @@ public class BlockWire extends BlockMachine implements IExtraObjectInfo @Override public void loadExtraConfigs(Configuration config) { + super.loadExtraConfigs(config); BlockWire.wireResistance = config.get("Settings", "miliOhms", 1, "Resistance of the wire in 1/1000 of an ohm").getInt() / 1000; BlockWire.ampMax = config.get("Settings", "maxAmps", 10000, "Amp limit of the wire").getInt(); diff --git a/src/dark/core/prefab/IExtraObjectInfo.java b/src/dark/core/prefab/IExtraObjectInfo.java deleted file mode 100644 index cf7dbbd16..000000000 --- a/src/dark/core/prefab/IExtraObjectInfo.java +++ /dev/null @@ -1,31 +0,0 @@ -package dark.core.prefab; - -import java.util.Set; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.Configuration; -import dark.core.prefab.helpers.Pair; - -/** Used to handle info about the block that would normally be handled by the mod main class. Use the - * BlockRegistry in order for these methods to be called on load of the mod. - * - * @author DarkGuardsman */ -public interface IExtraObjectInfo -{ - - /** List of all tileEntities this block needs */ - public void getTileEntities(int blockID, Set>> list); - - /** True will cause a config file to be generated for this block */ - public boolean hasExtraConfigs(); - - /** Loads the config file for this block. This is a single config file that is tied to just this - * block alone. Anything can be stored in the config file but its suggested to use it for - * advanced settings for the block/tile. Things like power, update rate, optional features, - * graphics, or crafting cost */ - public void loadExtraConfigs(Configuration config); - - /** Loads the names used to reference this item in a recipe */ - public void loadOreNames(); - -} diff --git a/src/dark/core/prefab/machine/BlockMachine.java b/src/dark/core/prefab/machine/BlockMachine.java index 97d0ad724..35839e3d0 100644 --- a/src/dark/core/prefab/machine/BlockMachine.java +++ b/src/dark/core/prefab/machine/BlockMachine.java @@ -1,25 +1,34 @@ package dark.core.prefab.machine; +import java.util.Set; + import net.minecraft.block.ITileEntityProvider; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; +import net.minecraftforge.common.Configuration; import universalelectricity.prefab.block.BlockTile; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dark.api.parts.INetworkPart; import dark.core.common.DarkMain; +import dark.core.prefab.IExtraInfo.IExtraBlockInfo; import dark.core.prefab.ModPrefab; +import dark.core.prefab.helpers.Pair; import dark.core.registration.ModObjectRegistry.BlockBuildData; /** Basic TileEntity Container class designed to be used by generic machines. It is suggested that * each mod using this create there own basic block extending this to reduce need to input config * file each time - * + * * @author Darkguardsman */ -public abstract class BlockMachine extends BlockTile implements ITileEntityProvider +public abstract class BlockMachine extends BlockTile implements ITileEntityProvider, IExtraBlockInfo { + + public boolean zeroAnimation, zeroSound, zeroRendering; + public BlockMachine(BlockBuildData data) { super(data.config.getBlock(data.blockName, ModPrefab.getNextID()).getInt(), data.blockMaterial); @@ -77,4 +86,35 @@ public abstract class BlockMachine extends BlockTile implements ITileEntityProvi return super.createTileEntity(world, metadata); } + @Override + public void getTileEntities(int blockID, Set>> list) + { + // TODO Auto-generated method stub + + } + + @Override + public boolean hasExtraConfigs() + { + return true; + } + + @Override + public void loadExtraConfigs(Configuration config) + { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) + { + this.zeroAnimation = config.get("Effects--Not_Supported_By_All_Blocks", "disableAnimation", false, "Turns off animations of the block").getBoolean(false); + this.zeroRendering = config.get("Effects--Not_Supported_By_All_Blocks", "disableRender", false, "Turns off the block render replacing it with a normal block").getBoolean(false); + this.zeroSound = config.get("Effects--Not_Supported_By_All_Blocks", "disableSound", false, "Turns of sound of the block for any or its actions").getBoolean(false); + } + } + + @Override + public void loadOreNames() + { + // TODO Auto-generated method stub + + } + } diff --git a/src/dark/core/prefab/machine/BlockMulti.java b/src/dark/core/prefab/machine/BlockMulti.java index 0f239373d..60e820212 100644 --- a/src/dark/core/prefab/machine/BlockMulti.java +++ b/src/dark/core/prefab/machine/BlockMulti.java @@ -17,11 +17,11 @@ import universalelectricity.core.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dark.core.common.DarkMain; -import dark.core.prefab.IExtraObjectInfo; +import dark.core.prefab.IExtraInfo.IExtraBlockInfo; import dark.core.prefab.ModPrefab; import dark.core.prefab.helpers.Pair; -public class BlockMulti extends BlockContainer implements IExtraObjectInfo +public class BlockMulti extends BlockContainer implements IExtraBlockInfo { public String textureName = null; public String channel = ""; diff --git a/src/dark/core/registration/ModObjectRegistry.java b/src/dark/core/registration/ModObjectRegistry.java index 799138917..922d19d6c 100644 --- a/src/dark/core/registration/ModObjectRegistry.java +++ b/src/dark/core/registration/ModObjectRegistry.java @@ -20,7 +20,8 @@ import net.minecraftforge.fluids.FluidRegistry; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameRegistry; import dark.core.common.DarkMain; -import dark.core.prefab.IExtraObjectInfo; +import dark.core.prefab.IExtraInfo; +import dark.core.prefab.IExtraInfo.IExtraBlockInfo; import dark.core.prefab.ModPrefab; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; @@ -197,21 +198,24 @@ public class ModObjectRegistry } } } - if (block instanceof IExtraObjectInfo) + if (block instanceof IExtraInfo) { - if (((IExtraObjectInfo) block).hasExtraConfigs()) + if (((IExtraInfo) block).hasExtraConfigs()) { Configuration extraBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/blocks/" + block.getUnlocalizedName() + ".cfg")); extraBlockConfig.load(); - ((IExtraObjectInfo) block).loadExtraConfigs(extraBlockConfig); + ((IExtraInfo) block).loadExtraConfigs(extraBlockConfig); extraBlockConfig.save(); } - ((IExtraObjectInfo) block).loadOreNames(); - Set>> tileListNew = new HashSet>>(); - ((IExtraObjectInfo) block).getTileEntities(block.blockID, tileListNew); - for (Pair> par : tileListNew) + if (block instanceof IExtraBlockInfo) { - GameRegistry.registerTileEntityWithAlternatives(par.getValue(), par.getKey(), "DM" + par.getKey()); + ((IExtraBlockInfo) block).loadOreNames(); + Set>> tileListNew = new HashSet>>(); + ((IExtraBlockInfo) block).getTileEntities(block.blockID, tileListNew); + for (Pair> par : tileListNew) + { + GameRegistry.registerTileEntityWithAlternatives(par.getValue(), par.getKey(), "DM" + par.getKey()); + } } }