diff --git a/src/common/net/uberkat/obsidian/common/MachineryManager.java b/src/common/net/uberkat/obsidian/common/MachineryManager.java new file mode 100644 index 000000000..99e5ce43e --- /dev/null +++ b/src/common/net/uberkat/obsidian/common/MachineryManager.java @@ -0,0 +1,85 @@ +package net.uberkat.obsidian.common; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.src.*; + +/** + * A simple way of managing all machines -- MachineryManager! Contains an ArrayList of + * basic machines that all machines are added to on placement. + * @author AidanBrady + * + */ +public class MachineryManager +{ + /** The list of machines used */ + public List machines = new ArrayList(); + + /** + * MachineryManager -- the easiest way of managing machines. + */ + public MachineryManager() + { + reset(); + System.out.println("[ObsidianIngots] Successfully initialized Machinery Manager."); + } + + /** + * Register a machine with the manager. + * @param machine - to be added + */ + public void register(TileEntityBasicMachine machine) + { + if(!machines.contains(machine)) + { + machines.add(machine); + } + else { + System.out.println("[ObsidianIngots] Attempted to add machine to manager that already exists."); + } + } + + /** + * Remove a machine from the manager. + * @param machine - to be removed + */ + public void remove(TileEntityBasicMachine machine) + { + if(machines.contains(machine)) + { + machines.remove(machine); + } + else { + System.out.println("[ObsidianIngots] Attempted to remove machine from manager that doesn't exist."); + } + } + + /** + * Grabs a machine from the manager. + * @param world - to be grabbed + * @param x - block coord + * @param y - block coord + * @param z - block coord + * @return machine grabbed from the manager + */ + public TileEntityBasicMachine getMachine(World world, int x, int y, int z) + { + if(machines.contains((TileEntityBasicMachine)world.getBlockTileEntity(x, y, z))) + { + return (TileEntityBasicMachine)world.getBlockTileEntity(x, y, z); + } + else { + System.out.println("[ObsidianIngots] Attempted to grab machine from manager that doesn't exist."); + return null; + } + } + + /** + * Resets the manager -- removing all machines from the ArrayList + */ + public void reset() + { + machines.clear(); + } +} diff --git a/src/common/net/uberkat/obsidian/common/ObsidianIngots.java b/src/common/net/uberkat/obsidian/common/ObsidianIngots.java index 13afaa920..0d3d25ae9 100644 --- a/src/common/net/uberkat/obsidian/common/ObsidianIngots.java +++ b/src/common/net/uberkat/obsidian/common/ObsidianIngots.java @@ -60,7 +60,7 @@ public class ObsidianIngots public static Configuration configuration; /** Obsidian Ingots version number */ - public static Version versionNumber = new Version(4, 2, 1); + public static Version versionNumber = new Version(4, 2, 2); /** The latest version number which is received from the Obsidian Ingots server */ public static String latestVersionNumber; @@ -68,6 +68,9 @@ public class ObsidianIngots /** The recent news which is received from the Obsidian Ingots server */ public static String recentNews; + /** The main MachineryManager instance that is used by all machines */ + public static MachineryManager manager; + /** The IP used to connect to the Obsidian Ingots server */ public static String hostIP = "71.56.58.57"; @@ -982,6 +985,8 @@ public class ObsidianIngots NetworkRegistry.instance().registerGuiHandler(this, new CommonGuiHandler()); //Set the mod's instance instance = this; + //Register the MachineryManager + manager = new MachineryManager(); System.out.println("[ObsidianIngots] Version " + versionNumber + " initializing..."); new ThreadGetData(); proxy.registerRenderInformation(); diff --git a/src/common/net/uberkat/obsidian/common/Version.java b/src/common/net/uberkat/obsidian/common/Version.java index fb5326b39..db32651cf 100644 --- a/src/common/net/uberkat/obsidian/common/Version.java +++ b/src/common/net/uberkat/obsidian/common/Version.java @@ -1,7 +1,7 @@ package net.uberkat.obsidian.common; /** - * Version v1.0.2. Simple version handling for Obsidian Ingots. + * Version v1.0.3. Simple version handling for Obsidian Ingots. * @author AidanBrady * */ @@ -27,6 +27,18 @@ public class Version build = buildNum; } + /** + * Creates a version number with 3 digits from a string, by splitting with the char '.' + * @param version - version number as a String + */ + public Version(String version) + { + String[] numbers = version.split("."); + major = Integer.getInteger(numbers[0]); + minor = Integer.getInteger(numbers[1]); + build = Integer.getInteger(numbers[2]); + } + /** * Resets the version number to "0.0.0." */ @@ -43,14 +55,6 @@ public class Version { return ""; } - else if(major != 0 && minor != 0 && build == 0) - { - return major + "." + minor; - } - else if(major != 0 && minor == 0 && build == 0) - { - return major + "." + minor; - } else { return major + "." + minor + "." + build; }