Reworked block registration system

Used reflection to create new block instances. This was done to prevent
disabled block from trying to take block IDs without doing a if
statement per block declaration. As well to make it a bit easier all
around to work with the system.
This commit is contained in:
DarkGuardsman 2013-09-20 07:35:52 -04:00
parent b3fef55589
commit a72c06950e
15 changed files with 377 additions and 253 deletions

View file

@ -1,171 +0,0 @@
package dark.core.common;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry;
import dark.core.prefab.IExtraObjectInfo;
import dark.core.prefab.helpers.Pair;
/** Handler to make registering all parts of a block a bit easier
*
* @author DarkGuardsman */
public class BlockRegistry
{
private static Configuration masterBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/EnabledBlocks.cfg"));
private static HashMap<Block, BlockData> blockMap = new HashMap<Block, BlockData>();
/** Adds a block to the mapping to be registered next call */
public static void addBlockToRegister(BlockData data)
{
synchronized (blockMap)
{
if (data != null && data.block != null && !blockMap.containsKey(data.block))
{
blockMap.put(data.block, data);
}
}
}
public static void addBlocks(List<BlockData> data)
{
for (BlockData entry : data)
{
BlockRegistry.addBlockToRegister(entry);
}
}
/** Runs threw the list of entries and then registers all parts */
public static void registerAllBlocks()
{
masterBlockConfig.load();
synchronized (blockMap)
{
HashMap<String, Class<? extends TileEntity>> tileList = new HashMap<String, Class<? extends TileEntity>>();
for (Entry<Block, BlockData> entry : blockMap.entrySet())
{
BlockData blockData = entry.getValue();
Block block = blockData.block;
if (!blockData.allowDisable || blockData.allowDisable && masterBlockConfig.get("EnabledList", "Enable_" + blockData.block.getUnlocalizedName(), true).getBoolean(true))
{
if (blockData.itemBlock != null)
{
GameRegistry.registerBlock(blockData.block, blockData.itemBlock, blockData.modBlockID);
}
else
{
GameRegistry.registerBlock(blockData.block, blockData.modBlockID);
}
if (blockData.block instanceof IExtraObjectInfo)
{
if (((IExtraObjectInfo) block).hasExtraConfigs())
{
Configuration extraBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/blocks/" + block.getUnlocalizedName() + ".cfg"));
extraBlockConfig.load();
((IExtraObjectInfo) block).loadExtraConfigs(extraBlockConfig);
extraBlockConfig.save();
}
((IExtraObjectInfo) block).loadOreNames();
Set<Pair<String, Class<? extends TileEntity>>> tileListNew = new HashSet<Pair<String, Class<? extends TileEntity>>>();
((IExtraObjectInfo) block).getTileEntities(block.blockID, tileListNew);
for (Pair<String, Class<? extends TileEntity>> par : tileListNew)
{
if (!tileList.containsKey(par.getKey()) && !tileList.containsValue(par.getValue()))
{
tileList.put(par.getKey(), par.getValue());
}
else if (par.getValue() != null)
{
System.out.println("BlockRegistry tried to list a tile or tileName that was already listed");
System.out.println("Tile>" + par.getValue().toString() + " | Name>" + par.getKey());
}
}
}
else
{
if (blockData.tiles != null)
{
for (Pair<String, Class<? extends TileEntity>> pr : blockData.tiles)
{
if (!tileList.containsKey(pr.getKey()) && !tileList.containsValue(pr.getValue()))
{
tileList.put(pr.getKey(), pr.getValue());
}
else if (pr.getValue() != null)
{
System.out.println("BlockRegistry tried to list a tile or tileName that was already listed");
System.out.println("Tile>" + pr.getValue().toString() + " | Name>" + pr.getKey());
}
}
}
}
}
}
for (Entry<String, Class<? extends TileEntity>> entry : tileList.entrySet())
{
GameRegistry.registerTileEntity(entry.getValue(), entry.getKey());
}
}
masterBlockConfig.save();
}
/** Used to store info on the block that will later be used to register all parts of the block */
public static class BlockData
{
public Block block;
public Class<? extends ItemBlock> itemBlock;
public String modBlockID;
public Set<Pair<String, Class<? extends TileEntity>>> tiles = new HashSet<Pair<String, Class<? extends TileEntity>>>();
public boolean allowDisable = true;
public BlockData(Block block, String name)
{
this.block = block;
this.modBlockID = name;
}
public BlockData(Block block, Class<? extends ItemBlock> itemBlock, String name)
{
this(block, name);
this.itemBlock = itemBlock;
}
/** Should there be an option to allow the user to disable this block */
public BlockData canDisable(boolean yes)
{
this.allowDisable = yes;
return this;
}
/** Adds a tileEntity to be registered when this block is registered
*
* @param name - mod name for the tileEntity, should be unique
* @param class1 - new instance of the TileEntity to register */
public BlockData addTileEntity(String name, Class<? extends TileEntity> class1)
{
if (name != null && class1 != null)
{
Pair<String, Class<? extends TileEntity>> pair = new Pair<String, Class<? extends TileEntity>>(name, class1);
if (!this.tiles.contains(pair))
{
this.tiles.add(pair);
}
}
return this;
}
public BlockData addTileEntity(Class<? extends TileEntity> class1, String string)
{
return addTileEntity(string, class1);
}
}
}

View file

@ -2,11 +2,11 @@ package dark.core.common;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
@ -33,12 +33,10 @@ import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import dark.api.ProcessorRecipes;
import dark.core.common.BlockRegistry.BlockData;
import dark.core.common.blocks.BlockBasalt;
import dark.core.common.blocks.BlockColorGlass;
import dark.core.common.blocks.BlockColorGlowGlass;
import dark.core.common.blocks.BlockColorSand;
import dark.core.common.blocks.BlockOre;
import dark.core.common.blocks.ItemBlockBasalt;
import dark.core.common.blocks.ItemBlockColored;
import dark.core.common.blocks.ItemBlockOre;
import dark.core.common.debug.BlockDebug;
@ -50,13 +48,13 @@ import dark.core.common.items.ItemParts;
import dark.core.common.items.ItemParts.Parts;
import dark.core.common.items.ItemTools;
import dark.core.common.items.ItemWrench;
import dark.core.common.machines.BlockBasicMachine;
import dark.core.common.transmit.BlockWire;
import dark.core.network.PacketHandler;
import dark.core.prefab.ModPrefab;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.prefab.items.ItemBlockHolder;
import dark.core.prefab.machine.BlockMulti;
import dark.core.prefab.machine.TileEntityMulti;
/** @author HangCow, DarkGuardsman */
@Mod(modid = DarkMain.MOD_ID, name = DarkMain.MOD_NAME, version = DarkMain.VERSION, dependencies = "after:BuildCraft|Energy", useMetadata = true)
@ -128,7 +126,6 @@ public class DarkMain extends ModPrefab
@Override
public void init(FMLInitializationEvent event)
{
BlockRegistry.registerAllBlocks();
ExternalModHandler.init();
super.init(event);
ProcessorRecipes.parseOreNames();
@ -177,9 +174,8 @@ public class DarkMain extends ModPrefab
}
@Override
public List<BlockData> getBlocks()
public void registerObjects()
{
List<BlockData> dataList = new ArrayList<BlockData>();
if (recipeLoader == null)
{
recipeLoader = new CoreRecipeLoader();
@ -187,24 +183,16 @@ public class DarkMain extends ModPrefab
/* CONFIGS */
CONFIGURATION.load();
/* BLOCKS */
blockMulti = new BlockMulti(getNextID()).setChannel(CHANNEL);
CoreRecipeLoader.blockOre = new BlockOre(getNextID());
CoreRecipeLoader.blockWire = new BlockWire(getNextID());
CoreRecipeLoader.blockDebug = new BlockDebug(getNextID());
CoreRecipeLoader.blockStainGlass = new BlockColorGlass(getNextID(), "StainedGlass");
CoreRecipeLoader.blockColorSand = new BlockColorSand(getNextID());
CoreRecipeLoader.blockBasalt = new BlockBasalt(getNextID());
CoreRecipeLoader.blockGlowGlass = new BlockColorGlass(getNextID(), "GlowGlass").setLightOpacity(2).setLightValue(1);
blockMulti = (BlockMulti) ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockMulti.class, false);
basicMachine = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockBasicMachine.class, ItemBlockHolder.class);
CoreRecipeLoader.blockOre = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockOre.class, ItemBlockOre.class);
CoreRecipeLoader.blockWire = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockWire.class, ItemBlockHolder.class);
CoreRecipeLoader.blockDebug = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockDebug.class, ItemBlockHolder.class);
CoreRecipeLoader.blockStainGlass = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockColorGlass.class, ItemBlockColored.class);
CoreRecipeLoader.blockColorSand = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockColorSand.class, ItemBlockColored.class);
CoreRecipeLoader.blockBasalt = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockColorSand.class, ItemBlockColored.class);
CoreRecipeLoader.blockGlowGlass = ModObjectRegistry.createNewBlock(DarkMain.MOD_ID, BlockColorGlowGlass.class, ItemBlockColored.class);
// // Registration ////
dataList.add(new BlockData(CoreRecipeLoader.blockStainGlass, ItemBlockColored.class, "stainGlass"));
dataList.add(new BlockData(CoreRecipeLoader.blockColorSand, ItemBlockColored.class, "stainSand"));
dataList.add(new BlockData(CoreRecipeLoader.blockBasalt, ItemBlockBasalt.class, "extraBlocks"));
dataList.add(new BlockData(CoreRecipeLoader.blockGlowGlass, ItemBlockColored.class, "stainGlowGlass"));
dataList.add(new BlockData(CoreRecipeLoader.blockOre, ItemBlockOre.class, "DMOre"));
dataList.add(new BlockData(CoreRecipeLoader.blockWire, "DMWire"));
dataList.add(new BlockData(CoreRecipeLoader.blockDebug, ItemBlockHolder.class, "DMDebug"));
dataList.add(new BlockData(blockMulti, "DMDMultiBlock").addTileEntity("DMMultiBlock", TileEntityMulti.class).canDisable(false));
/* ITEMS */
CoreRecipeLoader.itemTool = new ItemTools(ITEM_ID_PREFIX++, DarkMain.CONFIGURATION);
@ -228,8 +216,6 @@ public class DarkMain extends ModPrefab
}
CONFIGURATION.save();
/* CONFIG END */
return dataList;
}
@Override
@ -266,4 +252,41 @@ public class DarkMain extends ModPrefab
return "dark";
}
/** Creative tab for generic items and block that don't belong in any other tab */
public static CreativeTabs tabGSMGeneral = new CreativeTabs("AutomationMachines")
{
@Override
public ItemStack getIconItemStack()
{
return new ItemStack(Item.ingotIron, 1, 0);
}
};
/** Creative tab for High tech and industrial based items and blocks that don't belong in any
* other tab */
public static CreativeTabs tabIndustrial = new CreativeTabs("IndustrialMachines")
{
ItemStack tabItemStack = new ItemStack(Item.ingotIron, 1, 0);
@Override
public ItemStack getIconItemStack()
{
if (DarkMain.basicMachine != null)
{
new ItemStack(DarkMain.basicMachine.blockID, 1, 0);
}
return tabItemStack;
}
};
/** Creative tab for general castle and fortress related items and blocks that don't belong in
* any other tab */
public static CreativeTabs tabHydrualic = new CreativeTabs("HydraulicMachines")
{
@Override
public ItemStack getIconItemStack()
{
return new ItemStack(Item.ingotIron, 1, 0);
}
};
}

View file

@ -0,0 +1,226 @@
package dark.core.common;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry;
import dark.core.prefab.IExtraObjectInfo;
import dark.core.prefab.helpers.Pair;
import dark.core.prefab.machine.BlockMachine;
/** Handler to make registering all parts of a mod's objects that are loaded into the game by forge
*
* @author DarkGuardsman */
public class ModObjectRegistry
{
public static Configuration masterBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/EnabledBlocks.cfg"));
public static Block createNewBlock(String modID, Class<? extends Block> blockClass)
{
return ModObjectRegistry.createNewBlock(modID, blockClass, true);
}
public static Block createNewBlock(String modID, Class<? extends Block> blockClass, boolean canDisable)
{
return ModObjectRegistry.createNewBlock(modID, blockClass, null, canDisable);
}
public static Block createNewBlock(String modID, Class<? extends Block> blockClass, Class<? extends ItemBlock> itemClass)
{
return createNewBlock(modID, blockClass, itemClass, true);
}
public static Block createNewBlock(String modID, Class<? extends Block> blockClass, Class<? extends ItemBlock> itemClass, boolean canDisable)
{
Block block = null;
if (blockClass != null && (!canDisable || canDisable && masterBlockConfig.get("Enabled_List", "Enabled_" + block.getUnlocalizedName().replace("tile.", ""), true).getBoolean(true)))
{
try
{
block = blockClass.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
if (block != null)
{
ModObjectRegistry.finishCreation(block, null);
ModObjectRegistry.registerBlock(block, itemClass, block.getUnlocalizedName().replace("tile.", ""), modID);
}
}
return block;
}
public static Block createNewBlock(String modID, BlockBuildData buildData)
{
Block block = null;
Constructor constructor = null;
try
{
if (buildData != null && (!buildData.allowDisable || buildData.allowDisable && masterBlockConfig.get("Enabled_List", "Enabled_" + buildData.blockName, true).getBoolean(true)))
{
try
{
constructor = buildData.blockClass.getConstructor(BlockBuildData.class);
}
catch (Exception x)
{
x.printStackTrace();
}
if (constructor == null)
{
constructor = buildData.blockClass.getConstructor(Integer.class, Material.class);
if (constructor != null)
{
constructor.setAccessible(true);
block = (Block) constructor.newInstance(buildData.config.getBlock(buildData.blockName, DarkMain.getNextID()), buildData.blockMaterial);
}
}
else
{
constructor.setAccessible(true);
block = (Block) constructor.newInstance(buildData);
}
ModObjectRegistry.finishCreation(block, buildData);
ModObjectRegistry.registerBlock(block, buildData.itemBlock, buildData.blockName, modID);
}
}
catch (Exception x)
{
x.printStackTrace();
}
return block;
}
public static void finishCreation(Block block, BlockBuildData data)
{
if (data != null)
{
if (data.tiles != null)
{
for (Pair<String, Class<? extends TileEntity>> par : data.tiles)
{
GameRegistry.registerTileEntityWithAlternatives(par.getValue(), par.getKey(), "DM" + par.getKey());
}
}
}
if (block instanceof IExtraObjectInfo)
{
if (((IExtraObjectInfo) block).hasExtraConfigs())
{
Configuration extraBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/blocks/" + block.getUnlocalizedName() + ".cfg"));
extraBlockConfig.load();
((IExtraObjectInfo) block).loadExtraConfigs(extraBlockConfig);
extraBlockConfig.save();
}
((IExtraObjectInfo) block).loadOreNames();
Set<Pair<String, Class<? extends TileEntity>>> tileListNew = new HashSet<Pair<String, Class<? extends TileEntity>>>();
((IExtraObjectInfo) block).getTileEntities(block.blockID, tileListNew);
for (Pair<String, Class<? extends TileEntity>> par : tileListNew)
{
GameRegistry.registerTileEntityWithAlternatives(par.getValue(), par.getKey(), "DM" + par.getKey());
}
}
}
public static void registerBlock(Block block, Class<? extends ItemBlock> itemClass, String name, String modID)
{
if (block != null && name != null && !name.isEmpty())
{
if (itemClass == null)
{
itemClass = ItemBlock.class;
}
GameRegistry.registerBlock(block, itemClass, name, modID);
}
}
public static class BlockBuildData
{
public Class<? extends BlockMachine> blockClass;
public Class<? extends ItemBlock> itemBlock;
public String blockName;
public Material blockMaterial;
public Configuration config = DarkMain.CONFIGURATION;
public CreativeTabs creativeTab;
public Set<Pair<String, Class<? extends TileEntity>>> tiles = new HashSet<Pair<String, Class<? extends TileEntity>>>();
public boolean allowDisable = true;
public BlockBuildData(Class<? extends Block> blockClass, String name, Material material)
{
this.blockName = name;
this.blockMaterial = material;
}
public BlockBuildData setConfigProvider(Configuration config)
{
if (config != null)
{
this.config = config;
}
return this;
}
public BlockBuildData setCreativeTab(CreativeTabs tab)
{
if (tab != null)
{
this.creativeTab = tab;
}
return this;
}
public BlockBuildData setItemBlock(Class<? extends ItemBlock> itemClass)
{
this.itemBlock = itemClass;
return this;
}
/** Should there be an option to allow the user to disable this block */
public BlockBuildData canDisable(boolean yes)
{
this.allowDisable = yes;
return this;
}
/** Adds a tileEntity to be registered when this block is registered
*
* @param name - mod name for the tileEntity, should be unique
* @param class1 - new instance of the TileEntity to register */
public BlockBuildData addTileEntity(String name, Class<? extends TileEntity> class1)
{
if (name != null && class1 != null)
{
Pair<String, Class<? extends TileEntity>> pair = new Pair<String, Class<? extends TileEntity>>(name, class1);
if (!this.tiles.contains(pair))
{
this.tiles.add(pair);
}
}
return this;
}
public BlockBuildData addTileEntity(Class<? extends TileEntity> class1, String string)
{
return addTileEntity(string, class1);
}
}
}

View file

@ -33,9 +33,9 @@ public class BlockBasalt extends Block
}
public BlockBasalt(int par1)
public BlockBasalt()
{
super(DarkMain.CONFIGURATION.getBlock("basalt", par1).getInt(), Material.rock);
super(DarkMain.CONFIGURATION.getBlock("basalt", DarkMain.getNextID()).getInt(), Material.rock);
this.setCreativeTab(CreativeTabs.tabDecorations);
this.setHardness(2f);
this.setResistance(2f);

View file

@ -12,15 +12,20 @@ import dark.core.prefab.BlockColored;
public class BlockColorGlass extends BlockColored
{
public BlockColorGlass(int id, String name)
public BlockColorGlass(String name)
{
super(name, DarkMain.CONFIGURATION.getBlock(name, id).getInt(), Material.glass);
super(name, DarkMain.CONFIGURATION.getBlock(name, DarkMain.getNextID()).getInt(), Material.glass);
this.setCreativeTab(CreativeTabs.tabDecorations);
this.setHardness(.5f);
this.setResistance(.5f);
this.setStepSound(soundGlassFootstep);
}
public BlockColorGlass()
{
this("StainedGlass");
}
@Override
public int quantityDropped(Random par1Random)
{

View file

@ -0,0 +1,13 @@
package dark.core.common.blocks;
public class BlockColorGlowGlass extends BlockColorGlass
{
public BlockColorGlowGlass()
{
super("GlowGlass");
this.setLightOpacity(2);
this.setLightValue(1);
}
}

View file

@ -12,9 +12,9 @@ import dark.core.prefab.BlockColored;
//TODO fix instant falling sand
public class BlockColorSand extends BlockColored
{
public BlockColorSand(int par1)
public BlockColorSand()
{
super("colorSand", DarkMain.CONFIGURATION.getBlock("colorSand", par1).getInt(), Material.sand);
super("colorSand", DarkMain.CONFIGURATION.getBlock("colorSand", DarkMain.getNextID()).getInt(), Material.sand);
this.setCreativeTab(CreativeTabs.tabDecorations);
this.setHardness(1f);
this.setResistance(.5f);

View file

@ -24,9 +24,9 @@ public class BlockOre extends Block implements IExtraObjectInfo
{
Icon[] icons = new Icon[EnumMeterials.values().length];
public BlockOre(int par1)
public BlockOre()
{
super(DarkMain.CONFIGURATION.getBlock("Ore", par1).getInt(), Material.rock);
super(DarkMain.CONFIGURATION.getBlock("Ore", DarkMain.getNextID()).getInt(), Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setUnlocalizedName(DarkMain.getInstance().PREFIX + "Ore");
}

View file

@ -13,6 +13,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.common.ModObjectRegistry.BlockBuildData;
import dark.core.common.DarkMain;
import dark.core.prefab.IExtraObjectInfo;
import dark.core.prefab.helpers.Pair;
@ -24,8 +25,7 @@ public class BlockDebug extends BlockMachine implements IExtraObjectInfo
public BlockDebug(int blockID)
{
super("DebugBlock", DarkMain.CONFIGURATION, blockID, Material.clay);
this.setCreativeTab(CreativeTabs.tabRedstone);
super(new BlockBuildData(BlockDebug.class, "DebugBlock", Material.clay).setCreativeTab(DarkMain.tabIndustrial));
}
@Override

View file

@ -13,6 +13,7 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import universalelectricity.core.UniversalElectricity;
import dark.core.common.ModObjectRegistry.BlockBuildData;
import dark.core.common.CommonProxy;
import dark.core.common.DarkMain;
import dark.core.prefab.IExtraObjectInfo;
@ -22,10 +23,9 @@ import dark.core.prefab.machine.BlockMachine;
public class BlockBasicMachine extends BlockMachine implements IExtraObjectInfo
{
public BlockBasicMachine(int id)
public BlockBasicMachine()
{
super("BasicMachine", DarkMain.CONFIGURATION, id, UniversalElectricity.machine);
this.setCreativeTab(CreativeTabs.tabDecorations);
super(new BlockBuildData(BlockBasicMachine.class, "BasicMachine", UniversalElectricity.machine).setCreativeTab(DarkMain.tabIndustrial));
this.setStepSound(soundMetalFootstep);
}

View file

@ -1,17 +0,0 @@
package dark.core.common.machines;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.Configuration;
import dark.core.common.DarkMain;
import dark.core.prefab.machine.BlockMachine;
public class BlockGenerator extends BlockMachine
{
public BlockGenerator(String name, Configuration config, int blockID, Material material)
{
super("generator", DarkMain.CONFIGURATION, blockID, material);
// TODO Auto-generated constructor stub
}
}

View file

@ -16,6 +16,7 @@ import net.minecraftforge.common.Configuration;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.TileEntityConductor;
import dark.core.common.ModObjectRegistry.BlockBuildData;
import dark.core.common.DarkMain;
import dark.core.prefab.IExtraObjectInfo;
import dark.core.prefab.helpers.Pair;
@ -29,14 +30,13 @@ public class BlockWire extends BlockMachine implements IExtraObjectInfo
public Vector3 minVector = new Vector3(0.3, 0.3, 0.3);
public Vector3 maxVector = new Vector3(0.7, 0.7, 0.7);
public BlockWire(int blockID)
public BlockWire()
{
super("DMWire", DarkMain.CONFIGURATION, blockID, Material.cloth);
super(new BlockBuildData(BlockWire.class, "DMWire", Material.cloth).setCreativeTab(DarkMain.tabIndustrial));
this.setStepSound(soundClothFootstep);
this.setResistance(0.2F);
this.setHardness(0.1f);
this.setBlockBounds(0.3f, 0.3f, 0.3f, 0.7f, 0.7f, 0.7f);
this.setCreativeTab(CreativeTabs.tabRedstone);
Block.setBurnProperties(this.blockID, 30, 60);
}

View file

@ -1,7 +1,5 @@
package dark.core.prefab;
import java.util.List;
import net.minecraft.block.Block;
import org.modstats.Modstats;
@ -12,8 +10,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.Side;
import dark.core.common.BlockRegistry;
import dark.core.common.BlockRegistry.BlockData;
import dark.core.common.ModObjectRegistry;
public abstract class ModPrefab
{
@ -40,7 +37,7 @@ public abstract class ModPrefab
/** Gets the next unused ID in the block list. Does not prevent config file issues after the file
* has been made */
public int getNextID()
public static int getNextID()
{
int id = BLOCK_ID_PRE;
@ -62,13 +59,15 @@ public abstract class ModPrefab
{
this.loadModMeta();
Modstats.instance().getReporter().registerMod(this);
BlockRegistry.addBlocks(this.getBlocks());
ModObjectRegistry.masterBlockConfig.load();
this.registerObjects();
}
@EventHandler
public void init(FMLInitializationEvent event)
{
ModObjectRegistry.masterBlockConfig.save();
}
@EventHandler
@ -84,8 +83,10 @@ public abstract class ModPrefab
}
/** Grabs a list of all the mods block Data used to register the block, tileEntities, and extra
* configs */
public abstract List<BlockData> getBlocks();
* configs
*
* @return */
public abstract void registerObjects();
/** Loads the settings that tell what this mod is named, about, and other info to the user */
public abstract void loadModMeta();

View file

@ -3,6 +3,7 @@ package dark.core.prefab.machine;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
@ -11,26 +12,28 @@ import universalelectricity.prefab.block.BlockTile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.api.parts.INetworkPart;
import dark.core.common.ModObjectRegistry.BlockBuildData;
import dark.core.common.DarkMain;
/** 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
{
/** @param name - The name the block will use for both the config and translation file
* @param config - configuration reference used to pull blockID from
* @param blockID - Default block id to be used for the config
* @param material - Block material used for tool reference? */
public BlockMachine(String name, Configuration config, int blockID, Material material)
public BlockMachine(BlockBuildData data)
{
super(config.getBlock(name, blockID).getInt(), material);
this.isBlockContainer = true;
this.setUnlocalizedName(name);
super(data.config.getBlock(data.blockName, DarkMain.getNextID()).getInt(), data.blockMaterial);
this.setUnlocalizedName(data.blockName);
if(data.creativeTab != null)
{
this.setCreativeTab(data.creativeTab);
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconReg)

View file

@ -1,31 +1,37 @@
package dark.core.prefab.machine;
import java.util.Random;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import universalelectricity.core.UniversalElectricity;
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.helpers.Pair;
public class BlockMulti extends BlockContainer
public class BlockMulti extends BlockContainer implements IExtraObjectInfo
{
public String textureName = null;
public String channel = "";
public BlockMulti(int id)
public BlockMulti()
{
super(DarkMain.CONFIGURATION.getBlock("MultiBlock", id).getInt(), UniversalElectricity.machine);
super(DarkMain.CONFIGURATION.getBlock("MultiBlock", DarkMain.getNextID()).getInt(), UniversalElectricity.machine);
this.setHardness(0.8F);
this.setUnlocalizedName("multiBlock");
this.setChannel(DarkMain.CHANNEL);
}
public BlockMulti setChannel(String channel)
@ -132,4 +138,39 @@ public class BlockMulti extends BlockContainer
return null;
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
list.add(new Pair<String, Class<? extends TileEntity>>("DMMultiBlock", TileEntityMulti.class));
}
@Override
public boolean hasExtraConfigs()
{
// TODO Auto-generated method stub
return false;
}
@Override
public void loadExtraConfigs(Configuration config)
{
// TODO Auto-generated method stub
}
@Override
public void loadRecipes()
{
// TODO Auto-generated method stub
}
@Override
public void loadOreNames()
{
// TODO Auto-generated method stub
}
}