diff --git a/src/dark/core/prefab/helpers/NBTFileHelper.java b/src/dark/core/prefab/helpers/NBTFileHelper.java deleted file mode 100644 index e409380c..00000000 --- a/src/dark/core/prefab/helpers/NBTFileHelper.java +++ /dev/null @@ -1,322 +0,0 @@ -package dark.core.prefab.helpers; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; - -import net.minecraft.client.Minecraft; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagByte; -import net.minecraft.nbt.NBTTagByteArray; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagDouble; -import net.minecraft.nbt.NBTTagFloat; -import net.minecraft.nbt.NBTTagInt; -import net.minecraft.nbt.NBTTagIntArray; -import net.minecraft.nbt.NBTTagLong; -import net.minecraft.nbt.NBTTagShort; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.server.MinecraftServer; -import universalelectricity.core.vector.Vector2; -import universalelectricity.core.vector.Vector3; - -import com.builtbroken.common.science.units.UnitHelper; - -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.FMLLog; - -/** Helper class used to work with minecraft's NBT file system. - * - * @author DarkGuardsman */ -public class NBTFileHelper -{ - /** @param saveDirectory - file - * @param filename - * @param data - * @return */ - public static boolean saveNBTFile(File saveDirectory, String filename, NBTTagCompound data) - { - return saveNBTFile(new File(saveDirectory, filename), data); - } - - /** Saves an NBT file - * - * @param file - exact File - * @param data - nbt data - * @return */ - public static boolean saveNBTFile(File file, NBTTagCompound data) - { - if (file != null && data != null) - { - try - { - File tempFile = new File(file.getAbsoluteFile(), file.getName() + ".tmp"); - - CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile)); - - if (file.exists()) - { - file.delete(); - } - - tempFile.renameTo(file); - - FMLLog.fine("Saved " + file.getName() + " NBT data file successfully."); - return true; - } - catch (Exception e) - { - System.out.println("Failed to save " + file.getName() + ".dat!"); - e.printStackTrace(); - } - } - return false; - } - - /** Uses the default world directory to save the data to file by the given name - * - * @param filename - file name - * @param data - nbt data - * @return true if everything goes well */ - public static boolean saveNBTFile(String filename, NBTTagCompound data) - { - return saveNBTFile(getWorldSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, data); - } - - /** Reads NBT data from the world folder. - * - * @return The NBT data */ - public static NBTTagCompound loadNBTFile(File saveDirectory, String filename) - { - try - { - File file = new File(saveDirectory, filename + ".dat"); - - if (file.exists()) - { - FMLLog.fine("Loaded " + filename + " data."); - return CompressedStreamTools.readCompressed(new FileInputStream(file)); - } - else - { - FMLLog.fine("Created new " + filename + " data."); - return new NBTTagCompound(); - } - } - catch (Exception e) - { - System.out.println("Failed to load " + filename + ".dat!"); - e.printStackTrace(); - return null; - } - } - - /** Loads an NBT file from the current world file - * - * @param filename - name of the file - * @return NBTTagCompound that was stored in the file */ - public static NBTTagCompound loadNBTFile(String filename) - { - return loadNBTFile(getWorldSaveDirectory(MinecraftServer.getServer().getFolderName()), filename); - } - - public static File getWorldSaveDirectory(String worldName) - { - File parent = getBaseDirectory(); - - if (FMLCommonHandler.instance().getSide().isClient()) - { - parent = new File(getBaseDirectory(), "saves" + File.separator); - } - - return new File(parent, worldName + File.separator); - } - - public static File getBaseDirectory() - { - if (FMLCommonHandler.instance().getSide().isClient()) - { - FMLClientHandler.instance().getClient(); - return Minecraft.getMinecraft().mcDataDir; - } - else - { - return new File("."); - } - } - - /** Used to save an object without knowing what the object is exactly. Supports most - * NBTTagCompound save methods including some special cases. Which includes boolean being saves - * as a string so it can be loaded as a boolean from an object save. - * - * @param tag - NBTTagCompound to save the tag too - * @param key - name to save the object as - * @param value - the actual object - * @return the tag when done saving too i */ - public static NBTTagCompound saveObject(NBTTagCompound tag, String key, Object value) - { - if (value instanceof Float) - { - tag.setFloat(key, (Float) value); - } - else if (value instanceof Double) - { - tag.setDouble(key, (Double) value); - } - else if (value instanceof Integer) - { - tag.setInteger(key, (Integer) value); - } - else if (value instanceof String) - { - tag.setString(key, (String) value); - } - else if (value instanceof Short) - { - tag.setShort(key, (Short) value); - } - else if (value instanceof Byte) - { - tag.setByte(key, (Byte) value); - } - else if (value instanceof Long) - { - tag.setLong(key, (Long) value); - } - else if (value instanceof Boolean) - { - tag.setString(key, "NBT:SAVE:BOOLEAN:" + value); - } - else if (value instanceof NBTBase) - { - tag.setTag(key, (NBTBase) value); - } - else if (value instanceof String) - { - tag.setString(key, (String) value); - } - else if (value instanceof byte[]) - { - tag.setByteArray(key, (byte[]) value); - } - else if (value instanceof int[]) - { - tag.setIntArray(key, (int[]) value); - } - else if (value instanceof NBTTagCompound) - { - tag.setCompoundTag(key, (NBTTagCompound) value); - } - else if (value instanceof Vector2) - { - tag.setString(key, "NBT:SAVE:VECTOR:2:" + ((Vector2) value).x + ":" + ((Vector2) value).y); - } - else if (value instanceof Vector3) - { - tag.setString(key, "NBT:SAVE:VECTOR:3:" + ((Vector3) value).x + ":" + ((Vector3) value).y + ":" + ((Vector3) value).z); - } - return tag; - - } - - /** @param key - * @param value - * @return NBTTagCompound that then can be added to save file */ - public static NBTTagCompound saveObject(String key, Object value) - { - return NBTFileHelper.saveObject(new NBTTagCompound(), key, value); - } - - /** Reads an unknown object with a known name from NBT - * - * @param tag - tag to read the value from - * @param key - name of the value - * @param suggestionValue - value to return in case nothing is found - * @return object or suggestionValue if nothing is found */ - public static Object loadObject(NBTTagCompound tag, String key) - { - if (tag != null && key != null) - { - NBTBase saveTag = tag.getTag(key); - if (saveTag instanceof NBTTagFloat) - { - return tag.getFloat(key); - } - else if (saveTag instanceof NBTTagDouble) - { - return tag.getDouble(key); - } - else if (saveTag instanceof NBTTagInt) - { - return tag.getInteger(key); - } - else if (saveTag instanceof NBTTagString) - { - String str = tag.getString(key); - if (str.startsWith("NBT:SAVE:")) - { - str.replaceAll("NBT:SAVE:", ""); - if (str.startsWith("BOOLEAN:")) - { - str.replaceAll("BOOLEAN:", ""); - if (str.equalsIgnoreCase("true")) - { - return true; - } - if (str.equalsIgnoreCase("false")) - { - return false; - } - } - if (str.startsWith("VECTOR:")) - { - str.replaceAll("VECTOR:", ""); - String[] nums = str.split(":"); - if (UnitHelper.tryToParseDouble(nums[0]) == 2) - { - return new Vector2(UnitHelper.tryToParseDouble(nums[1]), UnitHelper.tryToParseDouble(nums[2])); - } - if (UnitHelper.tryToParseDouble(nums[0]) == 3) - { - return new Vector3(UnitHelper.tryToParseDouble(nums[1]), UnitHelper.tryToParseDouble(nums[2]), UnitHelper.tryToParseDouble(nums[3])); - } - } - return null; - } - return str; - } - else if (saveTag instanceof NBTTagShort) - { - return tag.getShort(key); - } - else if (saveTag instanceof NBTTagByte) - { - return tag.getByte(key); - } - else if (saveTag instanceof NBTTagLong) - { - return tag.getLong(key); - } - else if (saveTag instanceof NBTBase) - { - return tag.getTag(key); - } - else if (saveTag instanceof NBTTagByteArray) - { - return tag.getByteArray(key); - } - else if (saveTag instanceof NBTTagIntArray) - { - return tag.getIntArray(key); - } - else if (saveTag instanceof NBTTagCompound) - { - return tag.getCompoundTag(key); - } - } - return null; - } - -} diff --git a/src/dark/core/prefab/helpers/Quaternion.java b/src/dark/core/prefab/helpers/Quaternion.java deleted file mode 100644 index 21216b65..00000000 --- a/src/dark/core/prefab/helpers/Quaternion.java +++ /dev/null @@ -1,180 +0,0 @@ -package dark.core.prefab.helpers; - -import universalelectricity.core.vector.Vector3; - -/** This code is converted from C code to java based off of this tutorial - * http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation - * - * @author DarkGuardsman */ -public class Quaternion -{ - public static final float TOLERANCE = 0.00001f; - float x, y, z, w; - - public Quaternion() - { - this(0, 0, 0, 1); - } - - public Quaternion(float x, float y, float z, float w) - { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - public Quaternion(Vector3 vec, float w) - { - this((float) vec.x, (float) vec.y, (float) vec.z, w); - } - - public void set(Quaternion quaternion) - { - w = quaternion.w; - x = quaternion.x; - y = quaternion.y; - z = quaternion.z; - } - - public void set(float x, float y, float z, float w) - { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - /** Normalizes the Quaternion only if its outside the min errors range */ - public void normalise() - { - // Don't normalize if we don't have to - double mag2 = w * w + x * x + y * y + z * z; - if (Math.abs(mag2) > TOLERANCE && Math.abs(mag2 - 1.0f) > TOLERANCE) - { - float mag = (float) Math.sqrt(mag2); - w /= mag; - x /= mag; - y /= mag; - z /= mag; - } - } - - /** Gets the inverse of this Quaternion */ - public Quaternion getConj() - { - return new Quaternion(-x, -y, -z, w); - } - - public void conj() - { - x = -x; - y = -y; - z = -z; - } - - /** Multiplying q1 with q2 applies the rotation q2 to q1 */ - public Quaternion multi(Quaternion rq) - { - return new Quaternion(w * rq.x + x * rq.w + y * rq.z - z * rq.y, w * rq.y + y * rq.w + z * rq.x - x * rq.z, w * rq.z + z * rq.w + x * rq.y - y * rq.x, w * rq.w - x * rq.x - y * rq.y - z * rq.z); - } - - public void multLocal(Quaternion q) - { - Quaternion temp = this.multi(q); - this.set(temp); - } - - /** Multi a vector against this in other words applying rotation */ - public Vector3 multi(Vector3 vec) - { - Vector3 vn = vec.clone(); - - Quaternion vecQuat = new Quaternion(0, 0, 0, 1), resQuat; - vecQuat.x = (float) vn.x; - vecQuat.y = (float) vn.y; - vecQuat.z = (float) vn.z; - vecQuat.w = 0.0f; - - resQuat = vecQuat.multi(this.getConj()); - resQuat = this.multi(resQuat); - - return new Vector3(resQuat.x, resQuat.y, resQuat.z); - } - - public void FromAxis(Vector3 v, float angle) - { - angle *= 0.5f; - Vector3 vn = v.clone(); - vn.normalize(); - - float sinAngle = (float) Math.sin(angle); - - x = (float) (vn.x * sinAngle); - y = (float) (vn.y * sinAngle); - z = (float) (vn.z * sinAngle); - w = (float) Math.cos(angle); - } - - // Convert from Euler Angles - public void FromEuler(float pitch, float yaw, float roll) - { - // Basically we create 3 Quaternions, one for pitch, one for yaw, one for roll - // and multiply those together. - // the calculation below does the same, just shorter - - float p = (float) (pitch * (Math.PI / 180) / 2.0); - float y = (float) (yaw * (Math.PI / 180) / 2.0); - float r = (float) (roll * (Math.PI / 180) / 2.0); - - float sinp = (float) Math.sin(p); - float siny = (float) Math.sin(y); - float sinr = (float) Math.sin(r); - float cosp = (float) Math.cos(p); - float cosy = (float) Math.cos(y); - float cosr = (float) Math.cos(r); - - x = sinr * cosp * cosy - cosr * sinp * siny; - y = cosr * sinp * cosy + sinr * cosp * siny; - z = cosr * cosp * siny - sinr * sinp * cosy; - w = cosr * cosp * cosy + sinr * sinp * siny; - - normalise(); - } - - /* Convert to Matrix - public Matrix4 getMatrix() - { - float x2 = (float) (x * x); - float y2 = (float) (y * y); - float z2 = (float) (z * z); - float xy = (float) (x * y); - float xz = (float) (x * z); - float yz = (float) (y * z); - float wx = (float) (w * x); - float wy = (float) (w * y); - float wz = (float) (w * z); - - // This calculation would be a lot more complicated for non-unit length quaternions - // Note: The constructor of Matrix4 expects the Matrix in column-major format like expected - // by - // OpenGL - return new Matrix4(1.0f - 2.0f * (y2 + z2), 2.0f * (xy - wz), 2.0f * (xz + wy), 0.0f, 2.0f * (xy + wz), 1.0f - 2.0f * (x2 + z2), 2.0f * (yz - wx), 0.0f, 2.0f * (xz - wy), 2.0f * (yz + wx), 1.0f - 2.0f * (x2 + y2), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); - }*/ - - // Convert to Axis/Angles - public void getAxisAngle(Vector3 axis, float angle) - { - float scale = (float) Math.sqrt(x * x + y * y + z * z); - x = x / scale; - y = y / scale; - z = z / scale; - angle = (float) (Math.acos(w) * 2.0f); - } - - @Override - public String toString() - { - return "<" + x + "x " + y + "y " + z + "z @" + w + ">"; - } -} diff --git a/src/dark/modhelppage/common/HelpPageInfo.java b/src/dark/modhelppage/common/HelpPageInfo.java deleted file mode 100644 index 7d8c14ac..00000000 --- a/src/dark/modhelppage/common/HelpPageInfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package dark.modhelppage.common; - -import cpw.mods.fml.common.registry.ItemData; - -public class HelpPageInfo -{ - private final ItemData data; - private String name; - private String body; - - public HelpPageInfo(ItemData data) - { - this.data = data; - } -} diff --git a/src/dark/modhelppage/common/ModHelpPage.java b/src/dark/modhelppage/common/ModHelpPage.java deleted file mode 100644 index 4358b3ef..00000000 --- a/src/dark/modhelppage/common/ModHelpPage.java +++ /dev/null @@ -1,43 +0,0 @@ -package dark.modhelppage.common; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import cpw.mods.fml.common.registry.GameData; -import cpw.mods.fml.common.registry.ItemData; -import cpw.mods.fml.relauncher.ReflectionHelper; - -public class ModHelpPage -{ - private static HashMap itemMap = new HashMap(); - private static boolean init = false; - - /** Call this to setup mod page helper for the mod - * - * @param modID - mod's id used to track it, and register all xmls too - * @param configFolder - location of the mods config folder for storing player crated xmls */ - public static void init(String modID, String configFolder) - { - if (!init) - { - Map idMap = ReflectionHelper.getPrivateValue(GameData.class, new GameData(), "idMap"); - if (idMap != null) - { - for (Entry entry : idMap.entrySet()) - { - itemMap.put(entry.getValue().getItemType(), new HelpPageInfo(entry.getValue())); - } - } - } - } - - /** Call this to load an xmlFile from within the mod package - * - * @param modID - mod's id used to track it, and register all xmls too - * @param xmlFile - path to the file */ - public static void load(String modID, String xmlFile) - { - - } -} diff --git a/src/dark/modhelppage/common/XMLHelpFileReader.java b/src/dark/modhelppage/common/XMLHelpFileReader.java deleted file mode 100644 index fb13d648..00000000 --- a/src/dark/modhelppage/common/XMLHelpFileReader.java +++ /dev/null @@ -1,66 +0,0 @@ -package dark.modhelppage.common; - -import java.io.File; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class XMLHelpFileReader -{ - - public void loadFromFile(File file) - { - if (file != null) - { - try - { - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - Document doc = dBuilder.parse(file); - doc.getDocumentElement().normalize(); - - System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); - - NodeList nList = doc.getElementsByTagName("Object"); - - System.out.println("----------------------------"); - - for (int temp = 0; temp < nList.getLength(); temp++) - { - - Node nNode = nList.item(temp); - - System.out.println("\nCurrent Element :" + nNode.getNodeName()); - - if (nNode.getNodeType() == Node.ELEMENT_NODE) - { - Element eElement = (Element) nNode; - - String version = eElement.getAttribute("version"); - String type = eElement.getElementsByTagName("type").item(0).getTextContent(); - String name = eElement.getElementsByTagName("itemName").item(0).getTextContent(); - String desciption = eElement.getElementsByTagName("description").item(0).getTextContent(); - String uses = eElement.getElementsByTagName("uses").item(0).getTextContent(); - String tips = eElement.getElementsByTagName("tips").item(0).getTextContent(); - - } - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - - public static class ObjectHelpInformation - { - String name; - - } -}