diff --git a/src/com/coremachine/CoreMachine.java b/src/com/coremachine/CoreMachine.java deleted file mode 100644 index 8ef18588c..000000000 --- a/src/com/coremachine/CoreMachine.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.coremachine; - -public class CoreMachine -{ - private static CoreMachine instance; - - public static CoreMachine instance() - { - if (instance == null) - { - instance = new CoreMachine(); - } - return instance; - } -} diff --git a/src/com/dark/BlockFluid.java b/src/com/dark/BlockFluid.java new file mode 100644 index 000000000..5ac387df4 --- /dev/null +++ b/src/com/dark/BlockFluid.java @@ -0,0 +1,51 @@ +package com.dark; + +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.util.Icon; +import net.minecraftforge.common.Configuration; +import net.minecraftforge.fluids.BlockFluidFinite; +import net.minecraftforge.fluids.Fluid; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockFluid extends BlockFluidFinite +{ + Icon flowing; + Icon still; + Fluid fluid; + String prefix = ""; + + public BlockFluid(String prefix, Fluid fluid, Configuration config) + { + this(prefix, DarkCore.getNextID(), fluid, config); + } + + public BlockFluid(String prefix, int id, Fluid fluid, Configuration config) + { + super(config.getBlock("BlockFluid" + fluid.getName(), id).getInt(), fluid, Material.water); + this.fluid = fluid; + if (prefix != null && prefix.contains(":")) + { + this.prefix = prefix; + } + + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IconRegister par1IconRegister) + { + this.flowing = par1IconRegister.registerIcon(prefix + this.getUnlocalizedName().replace("tile.", "") + "_flowing"); + this.still = par1IconRegister.registerIcon(prefix + this.getUnlocalizedName().replace("tile.", "") + "_still"); + fluid.setIcons(still, flowing); + } + + @Override + @SideOnly(Side.CLIENT) + public Icon getIcon(int par1, int par2) + { + return still; + } + +} diff --git a/src/com/dark/ClientRegistryProxy.java b/src/com/dark/ClientRegistryProxy.java new file mode 100644 index 000000000..fe775df51 --- /dev/null +++ b/src/com/dark/ClientRegistryProxy.java @@ -0,0 +1,42 @@ +package com.dark; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.item.ItemBlock; +import net.minecraft.tileentity.TileEntity; + +import com.builtbroken.common.Pair; +import com.dark.IExtraInfo.IExtraBlockInfo; + +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class ClientRegistryProxy extends RegistryProxy +{ + @Override + public void registerBlock(Block block, Class itemClass, String name, String modID) + { + super.registerBlock(block, itemClass, name, modID); + if (block instanceof IExtraBlockInfo) + { + List, TileEntitySpecialRenderer>> set = new ArrayList, TileEntitySpecialRenderer>>(); + ((IExtraBlockInfo) block).getClientTileEntityRenderers(set); + for (Pair, TileEntitySpecialRenderer> par : set) + { + ClientRegistry.bindTileEntitySpecialRenderer(par.left(), par.right()); + } + } + } + + @Override + public void regiserTileEntity(String name, Class clazz) + { + super.regiserTileEntity(name, clazz); + + } +} diff --git a/src/com/dark/DarkCore.java b/src/com/dark/DarkCore.java new file mode 100644 index 000000000..be7e9df38 --- /dev/null +++ b/src/com/dark/DarkCore.java @@ -0,0 +1,66 @@ +package com.dark; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; + +public class DarkCore +{ + private static DarkCore instance; + + public static final String TEXTURE_DIRECTORY = "textures/"; + public static final String BLOCK_DIRECTORY = TEXTURE_DIRECTORY + "blocks/"; + public static final String ITEM_DIRECTORY = TEXTURE_DIRECTORY + "items/"; + public static final String MODEL_DIRECTORY = TEXTURE_DIRECTORY + "models/"; + public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/"; + + /* START IDS */ + public static int BLOCK_ID_PRE = 3100; + public static int ITEM_ID_PREFIX = 13200; + + public static DarkCore instance() + { + if (instance == null) + { + instance = new DarkCore(); + } + return instance; + } + + /** Gets the next unused ID in the block list. Does not prevent config file issues after the file + * has been made */ + public static int getNextID() + { + int id = BLOCK_ID_PRE; + + while (id > 255 && id < (Block.blocksList.length - 1)) + { + Block block = Block.blocksList[id]; + if (block == null) + { + break; + } + id++; + } + BLOCK_ID_PRE = id + 1; + return id; + } + + /** Gets the next unused ID in the item list. Does not prevent config file issues after the file + * has been made */ + public static int getNextItemId() + { + int id = ITEM_ID_PREFIX; + + while (id > 255 && id < (Item.itemsList.length - 1)) + { + Item item = Item.itemsList[id]; + if (item == null) + { + break; + } + id++; + } + ITEM_ID_PREFIX = id + 1; + return id; + } +} diff --git a/src/com/dark/ExternalModHandler.java b/src/com/dark/ExternalModHandler.java new file mode 100644 index 000000000..e3a2b9a9f --- /dev/null +++ b/src/com/dark/ExternalModHandler.java @@ -0,0 +1,65 @@ +package com.dark; + +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.common.Loader; + +/** Handles working with other mod without or without the need of the APIs. + * + * @author DarkGuardsman */ +public class ExternalModHandler +{ + private static boolean init = false; + + /** Calls this to load all external mod settings and handling */ + public static void init() + { + if (!init) + { + for (MOD_ID mod : MOD_ID.values()) + { + mod.loaded = Loader.isModLoaded(mod.modID); + } + } + } + + /** Checks to see if something can run powerless based on mods loaded + * + * @param optional - power system that the device can use + * @return true if free power is to be generated */ + public static boolean runPowerLess() + { + for (MOD_ID mod : MOD_ID.values()) + { + if (mod.validPowerSystem) + { + return false; + } + } + return true; + } + + /** Enum storing MOD_IDs and some general info on mods */ + public static enum MOD_ID + { + BUILCRAFT_MOD("BuildCraft|Core", false), + BUILCRAFT_ENERGY_MOD("BuildCraft|Energy", true), + BUILCRAFT_FACTORY_MOD("BuildCraft|Factory", false), + BUILCRAFT_SILICON_MOD("BuildCraft|Silicon", false), + BUILCRAFT_BUILDERS_MOD("BuildCraft|Builders", false), + BUILCRAFT_TRANSPORT_MOD("BuildCraft|Transport", false), + INDUSTRIALCRAFT_MOD("IC2", true), + MEKANISM_MOD("Mekanism", true); //TODO add mek sub mods + + public final String modID; + public String modNAME; + public boolean loaded; + public boolean validPowerSystem; + + private MOD_ID(String modID, boolean power) + { + this.modID = modID; + this.validPowerSystem = power; + } + } + +} diff --git a/src/com/dark/IExtraInfo.java b/src/com/dark/IExtraInfo.java new file mode 100644 index 000000000..47a03cbb5 --- /dev/null +++ b/src/com/dark/IExtraInfo.java @@ -0,0 +1,56 @@ +package com.dark; + +import java.util.List; +import java.util.Set; + +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.Configuration; + +import com.builtbroken.common.Pair; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** 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 IExtraInfo +{ + + /** 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); + + public static interface IExtraBlockInfo extends IExtraInfo, ITileEntityProvider + { + + /** Loads the names used to reference this item in a recipe */ + public void loadOreNames(); + + /** List of all tileEntities this block needs */ + public void getTileEntities(int blockID, Set>> list); + + @SideOnly(Side.CLIENT) + public void getClientTileEntityRenderers(List, TileEntitySpecialRenderer>> list); + } + + public static interface IExtraTileEntityInfo extends IExtraInfo + { + + } + + public static interface IExtraItemInfo extends IExtraInfo + { + /** Loads the names used to reference this item in a recipe */ + public void loadOreNames(); + } + +} diff --git a/src/com/dark/ModObjectRegistry.java b/src/com/dark/ModObjectRegistry.java new file mode 100644 index 000000000..da8e42dc4 --- /dev/null +++ b/src/com/dark/ModObjectRegistry.java @@ -0,0 +1,210 @@ +package com.dark; + +import java.io.File; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.Configuration; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import com.builtbroken.common.Pair; +import com.dark.IExtraInfo.IExtraBlockInfo; +import com.dark.IExtraInfo.IExtraItemInfo; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.registry.GameRegistry; + +/** 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 HashMap registredBlocks = new HashMap(); + public static HashMap registredItems = new HashMap(); + + @SidedProxy(clientSide = "dark.core.ClientRegistryProxy", serverSide = "dark.core.RegistryProxy") + public static RegistryProxy proxy; + + public static Configuration masterBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/EnabledBlocks.cfg")); + + public static Block createNewBlock(String name, String modID, Class blockClass) + { + return ModObjectRegistry.createNewBlock(name, modID, blockClass, true); + } + + public static Block createNewBlock(String name, String modID, Class blockClass, boolean canDisable) + { + return ModObjectRegistry.createNewBlock(name, modID, blockClass, null, canDisable); + } + + public static Block createNewBlock(String name, String modID, Class blockClass, Class itemClass) + { + return createNewBlock(name, modID, blockClass, itemClass, true); + } + + public static Block createNewBlock(String name, String modID, Class blockClass, Class itemClass, boolean canDisable) + { + Block block = null; + if (blockClass != null && (!canDisable || canDisable && masterBlockConfig.get("Enabled_List", "Enabled_" + name, true).getBoolean(true))) + { + //TODO redesign to catch blockID conflict + try + { + block = blockClass.newInstance(); + } + catch (IllegalArgumentException e) + { + throw e; + } + catch (Exception e) + { + e.printStackTrace(); + } + if (block != null) + { + registredBlocks.put(block, name); + proxy.registerBlock(block, itemClass, name, modID); + ModObjectRegistry.finishCreation(block); + } + } + return block; + } + + public static void finishCreation(Block block) + { + if (block instanceof IExtraInfo) + { + if (((IExtraInfo) block).hasExtraConfigs()) + { + Configuration extraBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/blocks/" + block.getUnlocalizedName() + ".cfg")); + extraBlockConfig.load(); + ((IExtraInfo) block).loadExtraConfigs(extraBlockConfig); + extraBlockConfig.save(); + } + if (block instanceof IExtraBlockInfo) + { + ((IExtraBlockInfo) block).loadOreNames(); + Set>> tileListNew = new HashSet>>(); + ((IExtraBlockInfo) block).getTileEntities(block.blockID, tileListNew); + for (Pair> par : tileListNew) + { + proxy.regiserTileEntity(par.left(), par.right()); + } + } + } + + } + + /** Method to get block via name + * + * @param blockName + * @return Block requested */ + public static Block getBlock(String blockName) + { + for (Entry entry : registredBlocks.entrySet()) + { + String name = entry.getKey().getUnlocalizedName().replace("tile.", ""); + if (name.equalsIgnoreCase(blockName)) + { + return entry.getKey(); + } + } + return null; + } + + /** Method to get block via id + * + * @param blockID + * @return Block requested */ + public static Block getBlock(int blockID) + { + for (Entry entry : registredBlocks.entrySet()) + { + if (entry.getKey().blockID == blockID) + { + return entry.getKey(); + } + } + return null; + } + + public static Block createNewFluidBlock(String modDomainPrefix, Configuration config, Fluid fluid) + { + Block fluidBlock = null; + Fluid fluidActual = null; + if (config != null && fluid != null && config.get("general", "EnableFluid_" + fluid.getName(), true).getBoolean(true) && FluidRegistry.getFluid(fluid.getName()) == null) + { + FluidRegistry.registerFluid(fluid); + fluidActual = FluidRegistry.getFluid(fluid.getName()); + if (fluidActual == null) + { + fluidActual = fluid; + } + + if (fluidActual.getBlockID() == -1 && masterBlockConfig.get("Enabled_List", "Enabled_" + fluid.getName() + "Block", true).getBoolean(true)) + { + fluidBlock = new BlockFluid(modDomainPrefix, fluidActual, config).setUnlocalizedName("tile.Fluid." + fluid.getName()); + proxy.registerBlock(fluidBlock, null, "DMBlockFluid" + fluid.getName(), modDomainPrefix); + } + else + { + fluidBlock = Block.blocksList[fluid.getBlockID()]; + } + } + + return fluidBlock; + } + + /** Creates a new item using reflection as well runs it threw some check to activate any + * interface methods + * + * @param name - name to register the item with + * @param modid - mods that the item comes from + * @param clazz - item class + * @param canDisable - can a user disable this item + * @return the new item */ + public static Item createNewItem(String name, String modid, Class clazz, boolean canDisable) + { + Item item = null; + if (clazz != null && (!canDisable || canDisable && masterBlockConfig.get("Enabled_List", "Enabled_" + name, true).getBoolean(true))) + { + //TODO redesign to catch blockID conflict + try + { + item = clazz.newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + } + if (item != null) + { + registredItems.put(item, name); + GameRegistry.registerItem(item, name, modid); + if (item instanceof IExtraInfo) + { + if (((IExtraInfo) item).hasExtraConfigs()) + { + Configuration extraBlockConfig = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/items/" + item.getUnlocalizedName() + ".cfg")); + extraBlockConfig.load(); + ((IExtraInfo) item).loadExtraConfigs(extraBlockConfig); + extraBlockConfig.save(); + } + if (item instanceof IExtraItemInfo) + { + ((IExtraItemInfo) item).loadOreNames(); + } + } + } + } + return item; + } +} diff --git a/src/com/dark/RegistryProxy.java b/src/com/dark/RegistryProxy.java new file mode 100644 index 000000000..bb0b5953b --- /dev/null +++ b/src/com/dark/RegistryProxy.java @@ -0,0 +1,22 @@ +package com.dark; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.common.registry.GameRegistry; + +public class RegistryProxy +{ + public void registerBlock(Block block, Class itemClass, String name, String modID) + { + if (block != null && name != null) + { + GameRegistry.registerBlock(block, itemClass == null ? ItemBlock.class : itemClass, name, modID); + } + } + + public void regiserTileEntity(String name, Class clazz) + { + GameRegistry.registerTileEntityWithAlternatives(clazz, name, "DM" + name); + } +} diff --git a/src/dark/api/access/AccessGroup.java b/src/com/dark/access/AccessGroup.java similarity index 99% rename from src/dark/api/access/AccessGroup.java rename to src/com/dark/access/AccessGroup.java index 522f7a8d2..4e6566490 100644 --- a/src/dark/api/access/AccessGroup.java +++ b/src/com/dark/access/AccessGroup.java @@ -1,4 +1,4 @@ -package dark.api.access; +package com.dark.access; import java.util.ArrayList; import java.util.List; diff --git a/src/dark/api/access/AccessProfile.java b/src/com/dark/access/AccessProfile.java similarity index 98% rename from src/dark/api/access/AccessProfile.java rename to src/com/dark/access/AccessProfile.java index 4c8922203..200e2e899 100644 --- a/src/dark/api/access/AccessProfile.java +++ b/src/com/dark/access/AccessProfile.java @@ -1,17 +1,19 @@ -package dark.api.access; +package com.dark.access; import java.io.File; import java.util.ArrayList; import java.util.List; +import com.dark.save.IVirtualObject; +import com.dark.save.NBTFileHelper; +import com.dark.save.SaveManager; + + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; -import dark.api.save.IVirtualObject; -import dark.api.save.NBTFileHelper; -import dark.api.save.SaveManager; /** Designed to be used as a container for AccessGroups and AccessUser. If you plan to use this make * sure to use it correctly. This is designed to be saved separate from the world save if marked for diff --git a/src/dark/api/access/AccessUser.java b/src/com/dark/access/AccessUser.java similarity index 98% rename from src/dark/api/access/AccessUser.java rename to src/com/dark/access/AccessUser.java index 19d2f879a..7c0dc7971 100644 --- a/src/dark/api/access/AccessUser.java +++ b/src/com/dark/access/AccessUser.java @@ -1,4 +1,4 @@ -package dark.api.access; +package com.dark.access; import java.util.ArrayList; import java.util.List; diff --git a/src/dark/api/access/GroupRegistry.java b/src/com/dark/access/GroupRegistry.java similarity index 99% rename from src/dark/api/access/GroupRegistry.java rename to src/com/dark/access/GroupRegistry.java index 1b3d217ef..db50a60e7 100644 --- a/src/dark/api/access/GroupRegistry.java +++ b/src/com/dark/access/GroupRegistry.java @@ -1,4 +1,4 @@ -package dark.api.access; +package com.dark.access; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/dark/api/access/IProfileContainer.java b/src/com/dark/access/IProfileContainer.java similarity index 95% rename from src/dark/api/access/IProfileContainer.java rename to src/com/dark/access/IProfileContainer.java index 7a11e4461..382d1a0c4 100644 --- a/src/dark/api/access/IProfileContainer.java +++ b/src/com/dark/access/IProfileContainer.java @@ -1,4 +1,4 @@ -package dark.api.access; +package com.dark.access; /** Applied to tileEntities that contain an access profile that describes how the tile interacts with * users diff --git a/src/dark/api/access/ISpecialAccess.java b/src/com/dark/access/ISpecialAccess.java similarity index 98% rename from src/dark/api/access/ISpecialAccess.java rename to src/com/dark/access/ISpecialAccess.java index e5f7412ff..3b99f91e7 100644 --- a/src/dark/api/access/ISpecialAccess.java +++ b/src/com/dark/access/ISpecialAccess.java @@ -1,4 +1,4 @@ -package dark.api.access; +package com.dark.access; import java.util.List; diff --git a/src/dark/api/access/Nodes.java b/src/com/dark/access/Nodes.java similarity index 99% rename from src/dark/api/access/Nodes.java rename to src/com/dark/access/Nodes.java index 1c6442151..06744afbc 100644 --- a/src/dark/api/access/Nodes.java +++ b/src/com/dark/access/Nodes.java @@ -1,4 +1,4 @@ -package dark.api.access; +package com.dark.access; /** Constants that represent nodes by which machines and entities used in combination with * ISpecialAccess to limit users on what they can do. These nodes should be used in the same way by diff --git a/src/dark/api/save/ISaveObj.java b/src/com/dark/save/ISaveObj.java similarity index 90% rename from src/dark/api/save/ISaveObj.java rename to src/com/dark/save/ISaveObj.java index f32bd4175..36f6c976b 100644 --- a/src/dark/api/save/ISaveObj.java +++ b/src/com/dark/save/ISaveObj.java @@ -1,4 +1,4 @@ -package dark.api.save; +package com.dark.save; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/dark/api/save/IVirtualObject.java b/src/com/dark/save/IVirtualObject.java similarity index 96% rename from src/dark/api/save/IVirtualObject.java rename to src/com/dark/save/IVirtualObject.java index bd1aa7cea..0776ff3ca 100644 --- a/src/dark/api/save/IVirtualObject.java +++ b/src/com/dark/save/IVirtualObject.java @@ -1,4 +1,4 @@ -package dark.api.save; +package com.dark.save; import java.io.File; diff --git a/src/dark/api/save/NBTFileHelper.java b/src/com/dark/save/NBTFileHelper.java similarity index 99% rename from src/dark/api/save/NBTFileHelper.java rename to src/com/dark/save/NBTFileHelper.java index 6d99fd2ae..ee15a7205 100644 --- a/src/dark/api/save/NBTFileHelper.java +++ b/src/com/dark/save/NBTFileHelper.java @@ -1,4 +1,4 @@ -package dark.api.save; +package com.dark.save; import java.io.File; import java.io.FileInputStream; diff --git a/src/dark/api/save/SaveManager.java b/src/com/dark/save/SaveManager.java similarity index 99% rename from src/dark/api/save/SaveManager.java rename to src/com/dark/save/SaveManager.java index cc4930f20..0a04045e0 100644 --- a/src/dark/api/save/SaveManager.java +++ b/src/com/dark/save/SaveManager.java @@ -1,4 +1,4 @@ -package dark.api.save; +package com.dark.save; import java.io.File; import java.util.ArrayList;