From 24905c16017decae4ee60ce4128b6d26de66baf5 Mon Sep 17 00:00:00 2001 From: Jordan Byrne Date: Thu, 22 Feb 2018 13:55:56 +1000 Subject: % Minor project cleanup. --- src/Java/gtPlusPlus/core/util/BaseHandler.java | 11 - src/Java/gtPlusPlus/core/util/ClassUtils.java | 76 --- src/Java/gtPlusPlus/core/util/Log.java | 24 - src/Java/gtPlusPlus/core/util/LoggingUtils.java | 49 -- src/Java/gtPlusPlus/core/util/PollutionUtils.java | 54 -- src/Java/gtPlusPlus/core/util/Quality.java | 61 -- src/Java/gtPlusPlus/core/util/StringUtils.java | 97 --- src/Java/gtPlusPlus/core/util/SystemUtils.java | 77 --- src/Java/gtPlusPlus/core/util/Utils.java | 7 +- .../gtPlusPlus/core/util/UtilsChatFormatting.java | 129 ---- src/Java/gtPlusPlus/core/util/UtilsRarity.java | 18 - src/Java/gtPlusPlus/core/util/UtilsText.java | 2 +- .../gtPlusPlus/core/util/array/ArrayUtils.java | 34 - src/Java/gtPlusPlus/core/util/data/ArrayUtils.java | 34 + src/Java/gtPlusPlus/core/util/data/EnumUtils.java | 41 ++ .../gtPlusPlus/core/util/data/LocaleUtils.java | 91 +++ .../gtPlusPlus/core/util/data/LoggingUtils.java | 49 ++ .../gtPlusPlus/core/util/data/StringUtils.java | 97 +++ .../gtPlusPlus/core/util/data/UUIDGenerator.java | 451 +++++++++++++ src/Java/gtPlusPlus/core/util/data/UUIDUtils.java | 25 + .../core/util/enchanting/EnchantingUtils.java | 102 --- .../gtPlusPlus/core/util/entity/EntityUtils.java | 113 ---- src/Java/gtPlusPlus/core/util/fluid/FluidGT6.java | 30 - .../gtPlusPlus/core/util/fluid/FluidUtils.java | 551 ---------------- src/Java/gtPlusPlus/core/util/geo/GeoUtils.java | 107 --- .../util/gregtech/material/MaterialBuilder.java | 254 -------- .../gregtech/recipehandlers/GregtechRecipe.java | 74 --- .../gtPlusPlus/core/util/input/KeyboardUtils.java | 23 - .../core/util/inventory/InventoryUtils.java | 60 -- src/Java/gtPlusPlus/core/util/item/ItemUtils.java | 722 --------------------- .../gtPlusPlus/core/util/locale/LocaleUtils.java | 91 --- .../core/util/materials/MaterialUtils.java | 253 -------- .../core/util/minecraft/EnchantingUtils.java | 102 +++ .../core/util/minecraft/EntityUtils.java | 113 ++++ .../gtPlusPlus/core/util/minecraft/FluidUtils.java | 550 ++++++++++++++++ .../core/util/minecraft/InventoryUtils.java | 60 ++ .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 717 ++++++++++++++++++++ .../core/util/minecraft/MaterialUtils.java | 205 ++++++ .../core/util/minecraft/ModularArmourUtils.java | 159 +++++ .../gtPlusPlus/core/util/minecraft/NBTUtils.java | 453 +++++++++++++ .../core/util/minecraft/PlayerUtils.java | 175 +++++ .../core/util/minecraft/RecipeUtils.java | 479 ++++++++++++++ .../core/util/minecraft/ShapelessUtils.java | 55 ++ .../core/util/minecraft/UtilsMining.java | 214 ++++++ .../util/minecraft/gregtech/PollutionUtils.java | 54 ++ .../gregtech/material/MaterialBuilder.java | 254 ++++++++ .../gregtech/recipehandlers/GregtechRecipe.java | 74 +++ .../minecraft/particles/BlockBreakParticles.java | 17 + .../particles/EntityParticleFXMysterious.java | 17 + .../core/util/nbt/ModularArmourUtils.java | 159 ----- src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java | 454 ------------- .../core/util/networking/NetworkUtils.java | 153 ----- .../core/util/particles/BlockBreakParticles.java | 17 - .../util/particles/EntityParticleFXMysterious.java | 17 - .../gtPlusPlus/core/util/player/PlayerUtils.java | 175 ----- .../gtPlusPlus/core/util/player/UtilsMining.java | 214 ------ .../gtPlusPlus/core/util/recipe/RecipeUtils.java | 481 -------------- .../core/util/recipe/shapeless/ShapelessUtils.java | 55 -- .../core/util/reflect/AddGregtechRecipe.java | 4 +- .../core/util/reflect/ReflectionUtils.java | 74 ++- src/Java/gtPlusPlus/core/util/sys/GeoUtils.java | 106 +++ .../gtPlusPlus/core/util/sys/KeyboardUtils.java | 23 + src/Java/gtPlusPlus/core/util/sys/Log.java | 24 + .../gtPlusPlus/core/util/sys/NetworkUtils.java | 153 +++++ src/Java/gtPlusPlus/core/util/sys/SystemUtils.java | 77 +++ .../gtPlusPlus/core/util/uuid/UUIDGenerator.java | 451 ------------- src/Java/gtPlusPlus/core/util/uuid/UUIDUtils.java | 25 - src/Java/gtPlusPlus/core/util/wrapper/var.java | 67 -- 68 files changed, 4947 insertions(+), 5287 deletions(-) delete mode 100644 src/Java/gtPlusPlus/core/util/BaseHandler.java delete mode 100644 src/Java/gtPlusPlus/core/util/ClassUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/Log.java delete mode 100644 src/Java/gtPlusPlus/core/util/LoggingUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/PollutionUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/Quality.java delete mode 100644 src/Java/gtPlusPlus/core/util/StringUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/SystemUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java delete mode 100644 src/Java/gtPlusPlus/core/util/UtilsRarity.java delete mode 100644 src/Java/gtPlusPlus/core/util/array/ArrayUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/data/ArrayUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/data/EnumUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/data/LocaleUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/data/LoggingUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/data/StringUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/data/UUIDGenerator.java create mode 100644 src/Java/gtPlusPlus/core/util/data/UUIDUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/enchanting/EnchantingUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/entity/EntityUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/fluid/FluidGT6.java delete mode 100644 src/Java/gtPlusPlus/core/util/fluid/FluidUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/geo/GeoUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/gregtech/material/MaterialBuilder.java delete mode 100644 src/Java/gtPlusPlus/core/util/gregtech/recipehandlers/GregtechRecipe.java delete mode 100644 src/Java/gtPlusPlus/core/util/input/KeyboardUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/inventory/InventoryUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/item/ItemUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/locale/LocaleUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/materials/MaterialUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/ModularArmourUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/ShapelessUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/UtilsMining.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/gregtech/material/MaterialBuilder.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/particles/BlockBreakParticles.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/particles/EntityParticleFXMysterious.java delete mode 100644 src/Java/gtPlusPlus/core/util/nbt/ModularArmourUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/networking/NetworkUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/particles/BlockBreakParticles.java delete mode 100644 src/Java/gtPlusPlus/core/util/particles/EntityParticleFXMysterious.java delete mode 100644 src/Java/gtPlusPlus/core/util/player/PlayerUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/player/UtilsMining.java delete mode 100644 src/Java/gtPlusPlus/core/util/recipe/RecipeUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/recipe/shapeless/ShapelessUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/sys/GeoUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/sys/KeyboardUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/sys/Log.java create mode 100644 src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java create mode 100644 src/Java/gtPlusPlus/core/util/sys/SystemUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/uuid/UUIDGenerator.java delete mode 100644 src/Java/gtPlusPlus/core/util/uuid/UUIDUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/wrapper/var.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/util/BaseHandler.java b/src/Java/gtPlusPlus/core/util/BaseHandler.java deleted file mode 100644 index 9457dc363f..0000000000 --- a/src/Java/gtPlusPlus/core/util/BaseHandler.java +++ /dev/null @@ -1,11 +0,0 @@ -package gtPlusPlus.core.util; - -public abstract class BaseHandler { - - public abstract void preInit(); - - public abstract void init(); - - public abstract void postInit(); - -} diff --git a/src/Java/gtPlusPlus/core/util/ClassUtils.java b/src/Java/gtPlusPlus/core/util/ClassUtils.java deleted file mode 100644 index 8f55fca299..0000000000 --- a/src/Java/gtPlusPlus/core/util/ClassUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package gtPlusPlus.core.util; - -import java.lang.reflect.*; - -public class ClassUtils { - - /* - * @ if (isPresent("com.optionaldependency.DependencyClass")) { // This - * block will never execute when the dependency is not present // There is - * therefore no more risk of code throwing NoClassDefFoundException. - * executeCodeLinkingToDependency(); } - */ - public static boolean isPresent(final String className) { - try { - Class.forName(className); - return true; - } catch (final Throwable ex) { - // Class or one of its dependencies is not present... - return false; - } - } - - @SuppressWarnings("rawtypes") - public static Method getMethodViaReflection(final Class lookupClass, final String methodName, - final boolean invoke) throws Exception { - final Class lookup = lookupClass.getClass(); - final Method m = lookup.getDeclaredMethod(methodName); - m.setAccessible(true);// Abracadabra - if (invoke) { - m.invoke(lookup);// now its OK - } - return m; - } - - public static Class getNonPublicClass(final String className) { - Class c = null; - try { - c = Class.forName(className); - } catch (final ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // full package name --------^^^^^^^^^^ - // or simpler without Class.forName: - // Class c = package1.A.class; - - if (null != c) { - // In our case we need to use - Constructor constructor = null; - try { - constructor = c.getDeclaredConstructor(); - } catch (NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // note: getConstructor() can return only public constructors - // so we needed to search for any Declared constructor - - // now we need to make this constructor accessible - if (null != constructor) { - constructor.setAccessible(true);// ABRACADABRA! - - try { - final Object o = constructor.newInstance(); - return (Class) o; - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - return null; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/Log.java b/src/Java/gtPlusPlus/core/util/Log.java deleted file mode 100644 index fe06fcb271..0000000000 --- a/src/Java/gtPlusPlus/core/util/Log.java +++ /dev/null @@ -1,24 +0,0 @@ -package gtPlusPlus.core.util; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public final class Log { - public static final Logger LOGGER = LogManager.getLogger("MiscUtils"); - - public static void warn(final String msg) { - LOGGER.warn(msg); - } - - public static void error(final String msg) { - LOGGER.error(msg); - } - - public static void info(final String msg) { - LOGGER.info(msg); - } - - public static void debug(final String msg) { - LOGGER.debug(msg); - } -} diff --git a/src/Java/gtPlusPlus/core/util/LoggingUtils.java b/src/Java/gtPlusPlus/core/util/LoggingUtils.java deleted file mode 100644 index 6aae8e52ec..0000000000 --- a/src/Java/gtPlusPlus/core/util/LoggingUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package gtPlusPlus.core.util; - -import java.io.*; -import java.util.Date; - -public class LoggingUtils { - - public static void profileLog(final Object o) { - try { - String content; - final File file = new File("GregtechTimingsTC.txt"); - // if file doesnt exists, then create it - if (!file.exists()) { - file.createNewFile(); - final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - final BufferedWriter bw = new BufferedWriter(fw); - bw.write("============================================================"); - bw.write(System.lineSeparator()); - bw.close(); - } - if (o instanceof String) { - content = (String) o; - } else { - content = o.toString(); - } - final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - final BufferedWriter bw = new BufferedWriter(fw); - bw.write(content); - bw.write(System.lineSeparator()); - bw.close(); - System.out.println("Data Logged."); - - } catch (final IOException e) { - System.out.println("Data logging failed."); - } - } - - public static boolean logCurrentSystemTime(final String message) { - final Date date = new Date(System.currentTimeMillis()); - try { - profileLog(message + " | " + date.toString()); - return true; - } catch (final Throwable r) { - return false; - } - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/PollutionUtils.java b/src/Java/gtPlusPlus/core/util/PollutionUtils.java deleted file mode 100644 index d68a25a844..0000000000 --- a/src/Java/gtPlusPlus/core/util/PollutionUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -package gtPlusPlus.core.util; - -import java.lang.reflect.*; - -import gregtech.GT_Mod; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.GT_Proxy; -import gtPlusPlus.core.util.reflect.ReflectionUtils; - -public class PollutionUtils { - - public static boolean mPollution() { - try { - GT_Proxy GT_Pollution = GT_Mod.gregtechproxy; - if (GT_Pollution != null) { - Field mPollution = ReflectionUtils.getField(GT_Pollution.getClass(), "mPollution"); - if (mPollution != null) { - return mPollution.getBoolean(GT_Pollution); - } - } - } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {} - return false; - } - - public static boolean addPollution(IGregTechTileEntity te, int pollutionValue) { - try { - Class GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = GT_Pollution.getMethod("addPollution", IGregTechTileEntity.class, int.class); - if (addPollution != null) { - addPollution.invoke(null, te, pollutionValue); - return true; - } - } - } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) {} - return false; - } - - public static int getPollution(IGregTechTileEntity te) { - try { - Class GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = GT_Pollution.getMethod("getPollution", IGregTechTileEntity.class); - if (addPollution != null) { - return (int) addPollution.invoke(null, te); - } - } - } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) {} - return 0; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/Quality.java b/src/Java/gtPlusPlus/core/util/Quality.java deleted file mode 100644 index 3e13409a10..0000000000 --- a/src/Java/gtPlusPlus/core/util/Quality.java +++ /dev/null @@ -1,61 +0,0 @@ -package gtPlusPlus.core.util; - -import gtPlusPlus.core.util.math.MathUtils; -import net.minecraft.util.EnumChatFormatting; - -public enum Quality { - - // Magic Blue - // Rare Yellow - // Set Green - // Unique Gold/Purple - // Trade-off Brown - - POOR("Poor", EnumChatFormatting.GRAY), COMMON("Common", EnumChatFormatting.WHITE), UNCOMMON("Uncommon", - EnumChatFormatting.DARK_GREEN), MAGIC("Magic", EnumChatFormatting.BLUE), RARE("Rare", - EnumChatFormatting.YELLOW), UNIQUE("Unique", EnumChatFormatting.GOLD), ARTIFACT("Artifact", - EnumChatFormatting.AQUA), SET("Set Piece", EnumChatFormatting.GREEN), TRADEOFF("Trade-off", - EnumChatFormatting.DARK_RED), EPIC("Epic", EnumChatFormatting.LIGHT_PURPLE); - - private String LOOT; - private EnumChatFormatting COLOUR; - - private Quality(final String lootTier, final EnumChatFormatting tooltipColour) { - this.LOOT = lootTier; - this.COLOUR = tooltipColour; - } - - public String getQuality() { - return this.LOOT; - } - - protected EnumChatFormatting getColour() { - return this.COLOUR; - } - - public String formatted() { - return this.COLOUR + this.LOOT; - } - - public static Quality getRandomQuality() { - final int lootChance = MathUtils.randInt(0, 100); - if (lootChance <= 10) { - return Quality.POOR; - } else if (lootChance <= 45) { - return Quality.COMMON; - } else if (lootChance <= 65) { - return Quality.UNCOMMON; - } else if (lootChance <= 82) { - return Quality.MAGIC; - } else if (lootChance <= 92) { - return Quality.EPIC; - } else if (lootChance <= 97) { - return Quality.RARE; - } else if (lootChance <= 99) { - return Quality.ARTIFACT; - } else { - return null; - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/StringUtils.java b/src/Java/gtPlusPlus/core/util/StringUtils.java deleted file mode 100644 index a4679d36a1..0000000000 --- a/src/Java/gtPlusPlus/core/util/StringUtils.java +++ /dev/null @@ -1,97 +0,0 @@ -package gtPlusPlus.core.util; - -public class StringUtils { - - public static String superscript(String str) { - str = str.replaceAll("0", "\u2070"); - str = str.replaceAll("1", "\u00B9"); - str = str.replaceAll("2", "\u00B2"); - str = str.replaceAll("3", "\u00B3"); - str = str.replaceAll("4", "\u2074"); - str = str.replaceAll("5", "\u2075"); - str = str.replaceAll("6", "\u2076"); - str = str.replaceAll("7", "\u2077"); - str = str.replaceAll("8", "\u2078"); - str = str.replaceAll("9", "\u2079"); - return str; - } - - public static String subscript(String str) { - str = str.replaceAll("0", "\u2080"); - str = str.replaceAll("1", "\u2081"); - str = str.replaceAll("2", "\u2082"); - str = str.replaceAll("3", "\u2083"); - str = str.replaceAll("4", "\u2084"); - str = str.replaceAll("5", "\u2085"); - str = str.replaceAll("6", "\u2086"); - str = str.replaceAll("7", "\u2087"); - str = str.replaceAll("8", "\u2088"); - str = str.replaceAll("9", "\u2089"); - return str; - } - - public static boolean containsSuperOrSubScript(final String s){ - if (s.contains(StringUtils.superscript("0"))) { - return true; - } - else if (s.contains(StringUtils.superscript("1"))) { - return true; - } - else if (s.contains(StringUtils.superscript("2"))) { - return true; - } - else if (s.contains(StringUtils.superscript("3"))) { - return true; - } - else if (s.contains(StringUtils.superscript("4"))) { - return true; - } - else if (s.contains(StringUtils.superscript("5"))) { - return true; - } - else if (s.contains(StringUtils.superscript("6"))) { - return true; - } - else if (s.contains(StringUtils.superscript("7"))) { - return true; - } - else if (s.contains(StringUtils.superscript("8"))) { - return true; - } - else if (s.contains(StringUtils.superscript("9"))) { - return true; - } - if (s.contains(StringUtils.subscript("0"))) { - return true; - } - else if (s.contains(StringUtils.subscript("1"))) { - return true; - } - else if (s.contains(StringUtils.subscript("2"))) { - return true; - } - else if (s.contains(StringUtils.subscript("3"))) { - return true; - } - else if (s.contains(StringUtils.subscript("4"))) { - return true; - } - else if (s.contains(StringUtils.subscript("5"))) { - return true; - } - else if (s.contains(StringUtils.subscript("6"))) { - return true; - } - else if (s.contains(StringUtils.subscript("7"))) { - return true; - } - else if (s.contains(StringUtils.subscript("8"))) { - return true; - } - else if (s.contains(StringUtils.subscript("9"))) { - return true; - } - return false; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/SystemUtils.java b/src/Java/gtPlusPlus/core/util/SystemUtils.java deleted file mode 100644 index 45fc25caf6..0000000000 --- a/src/Java/gtPlusPlus/core/util/SystemUtils.java +++ /dev/null @@ -1,77 +0,0 @@ -package gtPlusPlus.core.util; - -public class SystemUtils { - - private static OS SystemType; - - public static OS getOS(){ - if (SystemType != null){ - return SystemType; - } - else { - SystemType = getOperatingSystem(); - return SystemType; - } - } - - public static boolean isWindows() { - return (getOSString().indexOf("win") >= 0); - } - - public static boolean isMac() { - return (getOSString().indexOf("mac") >= 0); - } - - public static boolean isUnix() { - return (getOSString().indexOf("nix") >= 0 || getOSString().indexOf("nux") >= 0 || getOSString().indexOf("aix") > 0 ); - } - - public static boolean isSolaris() { - return (getOSString().indexOf("sunos") >= 0); - } - - public static String getOSString(){ - try { - return System.getProperty("os.name").toLowerCase(); - } - catch (Throwable t){ - return "other"; - } - } - - public static OS getOperatingSystem(){ - if (isMac()){ - return OS.MAC; - } - else if (isWindows()){ - return OS.WINDOWS; - } - else if (isUnix()){ - return OS.UNIX; - } - else if (isSolaris()){ - return OS.SOLARIS; - } - else { - return OS.OTHER; - } - } - - public static enum OS { - MAC(1), - WINDOWS(2), - UNIX(3), - SOLARIS(4), - OTHER(0); - - private int mID; - private OS (final int ID){ - this.mID = ID; - } - - public int getID() { - return this.mID; - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index e15f8ba202..bca7f53b0c 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -38,11 +38,12 @@ import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.item.ModItems; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.fluid.FluidUtils; -import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.nbt.NBTUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.core.util.sys.SystemUtils; import ic2.core.Ic2Items; import ic2.core.init.InternalName; import ic2.core.item.resources.ItemCell; diff --git a/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java b/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java deleted file mode 100644 index a7945311d6..0000000000 --- a/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java +++ /dev/null @@ -1,129 +0,0 @@ -package gtPlusPlus.core.util; - -import java.util.*; -import java.util.regex.Pattern; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public enum UtilsChatFormatting { - BLACK('0'), DARK_BLUE('1'), DARK_GREEN('2'), DARK_AQUA('3'), DARK_RED('4'), DARK_PURPLE('5'), GOLD('6'), GRAY( - '7'), DARK_GRAY('8'), BLUE('9'), GREEN('a'), AQUA('b'), RED('c'), LIGHT_PURPLE('d'), YELLOW('e'), WHITE( - 'f'), OBFUSCATED('k', true), BOLD('l', - true), STRIKETHROUGH('m', true), UNDERLINE('n', true), ITALIC('o', true), RESET('r'); - /** - * Maps a formatting code (e.g., 'f') to its corresponding enum value (e.g., - * WHITE). - */ - private static final Map formattingCodeMapping = new HashMap<>(); - /** - * Maps a name (e.g., 'underline') to its corresponding enum value (e.g., - * UNDERLINE). - */ - private static final Map nameMapping = new HashMap<>(); - /** - * Matches formatting codes that indicate that the client should treat the - * following text as bold, recolored, obfuscated, etc. - */ - private static final Pattern formattingCodePattern = Pattern - .compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]"); - /** The formatting code that produces this format. */ - private final char formattingCode; - private final boolean fancyStyling; - /** - * The control string (section sign + formatting code) that can be inserted - * into client-side text to display subsequent text in this format. - */ - private final String controlString; - - private UtilsChatFormatting(final char p_i1336_3_) { - this(p_i1336_3_, false); - } - - private UtilsChatFormatting(final char p_i1337_3_, final boolean p_i1337_4_) { - this.formattingCode = p_i1337_3_; - this.fancyStyling = p_i1337_4_; - this.controlString = "\u00a7" + p_i1337_3_; - } - - /** - * Gets the formatting code that produces this format. - */ - public char getFormattingCode() { - return this.formattingCode; - } - - /** - * False if this is just changing the color or resetting; true otherwise. - */ - public boolean isFancyStyling() { - return this.fancyStyling; - } - - /** - * Checks if typo is a color. - */ - public boolean isColor() { - return !this.fancyStyling && (this != RESET); - } - - /** - * Gets the friendly name of this value. - */ - public String getFriendlyName() { - return this.name().toLowerCase(); - } - - @Override - public String toString() { - return this.controlString; - } - - /** - * Returns a copy of the given string, with formatting codes stripped away. - */ - @SideOnly(Side.CLIENT) - public static String getTextWithoutFormattingCodes(final String p_110646_0_) { - return p_110646_0_ == null ? null : formattingCodePattern.matcher(p_110646_0_).replaceAll(""); - } - - /** - * Gets a value by its friendly name; null if the given name does not map to - * a defined value. - */ - public static UtilsChatFormatting getValueByName(final String p_96300_0_) { - return p_96300_0_ == null ? null : (UtilsChatFormatting) nameMapping.get(p_96300_0_.toLowerCase()); - } - - /** - * Gets all the valid values. Args: @param par0: Whether or not to include - * color values. @param par1: Whether or not to include fancy-styling values - * (anything that isn't a color value or the "reset" value). - */ - public static Collection getValidValues(final boolean p_96296_0_, final boolean p_96296_1_) { - final ArrayList arraylist = new ArrayList<>(); - final UtilsChatFormatting[] aenumchatformatting = values(); - final int i = aenumchatformatting.length; - - for (int j = 0; j < i; ++j) { - final UtilsChatFormatting enumchatformatting = aenumchatformatting[j]; - - if ((!enumchatformatting.isColor() || p_96296_0_) && (!enumchatformatting.isFancyStyling() || p_96296_1_)) { - arraylist.add(enumchatformatting.getFriendlyName()); - } - } - - return arraylist; - } - - static { - final UtilsChatFormatting[] var0 = values(); - final int var1 = var0.length; - - for (int var2 = 0; var2 < var1; ++var2) { - final UtilsChatFormatting var3 = var0[var2]; - formattingCodeMapping.put(Character.valueOf(var3.getFormattingCode()), var3); - nameMapping.put(var3.getFriendlyName(), var3); - } - } -} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/UtilsRarity.java b/src/Java/gtPlusPlus/core/util/UtilsRarity.java deleted file mode 100644 index 54f4ba8c07..0000000000 --- a/src/Java/gtPlusPlus/core/util/UtilsRarity.java +++ /dev/null @@ -1,18 +0,0 @@ -package gtPlusPlus.core.util; - -import net.minecraft.util.EnumChatFormatting; - -public enum UtilsRarity { - T1_poor(EnumChatFormatting.GRAY, "Poor"), T2_normal(EnumChatFormatting.WHITE, "Common"), T3_uncommon( - EnumChatFormatting.GREEN, - "Uncommon"), T4_magic(EnumChatFormatting.BLUE, "Magic"), T5_rare(EnumChatFormatting.LIGHT_PURPLE, - "Rare"), T6_epic(EnumChatFormatting.YELLOW, "Epic"), T8_unique(EnumChatFormatting.GOLD, "Unique"); - - public final EnumChatFormatting rarityColor; - public final String rarityName; - - private UtilsRarity(final EnumChatFormatting rarity, final String name) { - this.rarityColor = rarity; - this.rarityName = name; - } -} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/UtilsText.java b/src/Java/gtPlusPlus/core/util/UtilsText.java index 0db7dd35a2..9896f2be0c 100644 --- a/src/Java/gtPlusPlus/core/util/UtilsText.java +++ b/src/Java/gtPlusPlus/core/util/UtilsText.java @@ -12,7 +12,7 @@ public enum UtilsText { } public String colour() { - return "�" + this.colourValue; + return "§" + this.colourValue; } } diff --git a/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java b/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java deleted file mode 100644 index fbab888cbf..0000000000 --- a/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package gtPlusPlus.core.util.array; - -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class ArrayUtils { - - public static void expandArray(final Object[] someArray, final Object newValueToAdd) { - Object[] series = someArray; - series = addElement(series, newValueToAdd); - } - - private static Object[] addElement(Object[] series, final Object newValueToAdd) { - series = Arrays.copyOf(series, series.length + 1); - series[series.length - 1] = newValueToAdd; - return series; - } - - /*public static Object getMostCommonElement(List list) { - Optional r = list.stream().map(V::getTextureSet).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); - return r.get(); - }*/ - - public static ItemStack[] removeNulls(final ItemStack[] v) { - List list = new ArrayList(Arrays.asList(v)); - list.removeAll(Collections.singleton((ItemStack)null)); - return list.toArray(new ItemStack[list.size()]); - } -} - diff --git a/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java b/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java new file mode 100644 index 0000000000..63ffe63314 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java @@ -0,0 +1,34 @@ +package gtPlusPlus.core.util.data; + +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class ArrayUtils { + + public static void expandArray(final Object[] someArray, final Object newValueToAdd) { + Object[] series = someArray; + series = addElement(series, newValueToAdd); + } + + private static Object[] addElement(Object[] series, final Object newValueToAdd) { + series = Arrays.copyOf(series, series.length + 1); + series[series.length - 1] = newValueToAdd; + return series; + } + + /*public static Object getMostCommonElement(List list) { + Optional r = list.stream().map(V::getTextureSet).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); + return r.get(); + }*/ + + public static ItemStack[] removeNulls(final ItemStack[] v) { + List list = new ArrayList(Arrays.asList(v)); + list.removeAll(Collections.singleton((ItemStack)null)); + return list.toArray(new ItemStack[list.size()]); + } +} + diff --git a/src/Java/gtPlusPlus/core/util/data/EnumUtils.java b/src/Java/gtPlusPlus/core/util/data/EnumUtils.java new file mode 100644 index 0000000000..22ca73be0b --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/EnumUtils.java @@ -0,0 +1,41 @@ +package gtPlusPlus.core.util.data; + +import com.google.common.base.Enums; +import com.google.common.base.Optional; + +public class EnumUtils { + + /** + * Returns the value of an Enum if it exists. + * If value is not found, case-insensitive search will occur. + * If value still not found, an IllegalArgumentException is thrown. + **/ + public static > T getValue(Class enumeration, String name) { + Optional j = Enums.getIfPresent(enumeration, name); + T VALUE = j.get(); + if (j.get() == null) { + VALUE = valueOfIgnoreCase(enumeration, name); + } + return VALUE; + } + + /** + * Finds the value of the given enumeration by name, case-insensitive. + * Throws an IllegalArgumentException if no match is found. + **/ + private static > T valueOfIgnoreCase(Class enumeration, String name) { + + for (T enumValue : enumeration.getEnumConstants()) { + if (enumValue.name().equalsIgnoreCase(name)) { + return enumValue; + } + } + + throw new IllegalArgumentException(String.format( + "There is no value with name '%s' in Enum %s", + name, enumeration.getName() + )); + } + + +} diff --git a/src/Java/gtPlusPlus/core/util/data/LocaleUtils.java b/src/Java/gtPlusPlus/core/util/data/LocaleUtils.java new file mode 100644 index 0000000000..957f7923f8 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/LocaleUtils.java @@ -0,0 +1,91 @@ +package gtPlusPlus.core.util.data; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.registry.GameData; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class LocaleUtils { + + public static boolean GenerateFakeLocaleFile() { + for (ModContainer modcontainer : Loader.instance().getModList()){ + if (modcontainer.getModId().toLowerCase().equals("miscutils")) { + String S = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; + writeToFile(S); + dumpItemsAndBlocksForModContainer(modcontainer); + } + } + return true; + } + + public static boolean dumpItemsAndBlocksForModContainer(ModContainer mod) { + writeToFile("Dumping Items from "+mod.getModId()+"."); + for (Object C : GameData.getItemRegistry()) { + + try { + + if (C != null) { + if (C instanceof Item) { + Item R = (Item) C; + ItemStack IS = ItemUtils.getSimpleStack(R); + String modid = ItemUtils.getModId(IS); + if (modid.equals("miscutils") || modid.equals("ToxicEverglades")) { + String S = "["+modid+"] "+IS.getUnlocalizedName()+".name="; + writeToFile(S); + } + } + } + + } + catch (Throwable T) {} + + } + writeToFile("Dumping Blocks from "+mod.getModId()+"."); + for (Object B : GameData.getBlockRegistry()) { + + try { + + if (B != null) { + if (B instanceof Block) { + Block R = (Block) B; + ItemStack IS = ItemUtils.getSimpleStack(R); + String modid = ItemUtils.getModId(IS); + if (modid.equals("miscutils") || modid.equals("ToxicEverglades")) { + String S = "["+modid+"] "+IS.getUnlocalizedName()+".name="; + writeToFile(S); + } + } + } + + } + catch (Throwable T) {} + + } + + + return true; + } + + public static void writeToFile(String S) { + try { + File F = new File(Utils.getMcDir(), "config/GTplusplus/en_US.lang"); + BufferedWriter writer; + writer = new BufferedWriter(new FileWriter(F, true)); + writer.write(S); + writer.newLine(); + writer.close(); + } + catch (IOException e) {} + } + + +} diff --git a/src/Java/gtPlusPlus/core/util/data/LoggingUtils.java b/src/Java/gtPlusPlus/core/util/data/LoggingUtils.java new file mode 100644 index 0000000000..8415ab32fe --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/LoggingUtils.java @@ -0,0 +1,49 @@ +package gtPlusPlus.core.util.data; + +import java.io.*; +import java.util.Date; + +public class LoggingUtils { + + public static void profileLog(final Object o) { + try { + String content; + final File file = new File("GregtechTimingsTC.txt"); + // if file doesnt exists, then create it + if (!file.exists()) { + file.createNewFile(); + final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + final BufferedWriter bw = new BufferedWriter(fw); + bw.write("============================================================"); + bw.write(System.lineSeparator()); + bw.close(); + } + if (o instanceof String) { + content = (String) o; + } else { + content = o.toString(); + } + final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + final BufferedWriter bw = new BufferedWriter(fw); + bw.write(content); + bw.write(System.lineSeparator()); + bw.close(); + System.out.println("Data Logged."); + + } catch (final IOException e) { + System.out.println("Data logging failed."); + } + } + + public static boolean logCurrentSystemTime(final String message) { + final Date date = new Date(System.currentTimeMillis()); + try { + profileLog(message + " | " + date.toString()); + return true; + } catch (final Throwable r) { + return false; + } + + } + +} diff --git a/src/Java/gtPlusPlus/core/util/data/StringUtils.java b/src/Java/gtPlusPlus/core/util/data/StringUtils.java new file mode 100644 index 0000000000..77b1fc8413 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/StringUtils.java @@ -0,0 +1,97 @@ +package gtPlusPlus.core.util.data; + +public class StringUtils { + + public static String superscript(String str) { + str = str.replaceAll("0", "\u2070"); + str = str.replaceAll("1", "\u00B9"); + str = str.replaceAll("2", "\u00B2"); + str = str.replaceAll("3", "\u00B3"); + str = str.replaceAll("4", "\u2074"); + str = str.replaceAll("5", "\u2075"); + str = str.replaceAll("6", "\u2076"); + str = str.replaceAll("7", "\u2077"); + str = str.replaceAll("8", "\u2078"); + str = str.replaceAll("9", "\u2079"); + return str; + } + + public static String subscript(String str) { + str = str.replaceAll("0", "\u2080"); + str = str.replaceAll("1", "\u2081"); + str = str.replaceAll("2", "\u2082"); + str = str.replaceAll("3", "\u2083"); + str = str.replaceAll("4", "\u2084"); + str = str.replaceAll("5", "\u2085"); + str = str.replaceAll("6", "\u2086"); + str = str.replaceAll("7", "\u2087"); + str = str.replaceAll("8", "\u2088"); + str = str.replaceAll("9", "\u2089"); + return str; + } + + public static boolean containsSuperOrSubScript(final String s){ + if (s.contains(StringUtils.superscript("0"))) { + return true; + } + else if (s.contains(StringUtils.superscript("1"))) { + return true; + } + else if (s.contains(StringUtils.superscript("2"))) { + return true; + } + else if (s.contains(StringUtils.superscript("3"))) { + return true; + } + else if (s.contains(StringUtils.superscript("4"))) { + return true; + } + else if (s.contains(StringUtils.superscript("5"))) { + return true; + } + else if (s.contains(StringUtils.superscript("6"))) { + return true; + } + else if (s.contains(StringUtils.superscript("7"))) { + return true; + } + else if (s.contains(StringUtils.superscript("8"))) { + return true; + } + else if (s.contains(StringUtils.superscript("9"))) { + return true; + } + if (s.contains(StringUtils.subscript("0"))) { + return true; + } + else if (s.contains(StringUtils.subscript("1"))) { + return true; + } + else if (s.contains(StringUtils.subscript("2"))) { + return true; + } + else if (s.contains(StringUtils.subscript("3"))) { + return true; + } + else if (s.contains(StringUtils.subscript("4"))) { + return true; + } + else if (s.contains(StringUtils.subscript("5"))) { + return true; + } + else if (s.contains(StringUtils.subscript("6"))) { + return true; + } + else if (s.contains(StringUtils.subscript("7"))) { + return true; + } + else if (s.contains(StringUtils.subscript("8"))) { + return true; + } + else if (s.contains(StringUtils.subscript("9"))) { + return true; + } + return false; + } + +} diff --git a/src/Java/gtPlusPlus/core/util/data/UUIDGenerator.java b/src/Java/gtPlusPlus/core/util/data/UUIDGenerator.java new file mode 100644 index 0000000000..513468a9f6 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/UUIDGenerator.java @@ -0,0 +1,451 @@ +package gtPlusPlus.core.util.data; + +import java.io.IOException; +import java.net.InetAddress; +import java.util.Random; +import java.util.UUID; + +import gtPlusPlus.api.objects.random.CSPRNG_DO_NOT_USE; + +/** + * + * Implement modified version of Apache's OpenJPA UUID generator. + * This UUID generator is paired with a Blum-Blum-Shub random number generator + * which in itself is seeded by custom SecureRandom. + * + * The UUID generator class has been converted from a static factory to an instanced factory. + * + */ + +//========================================= APACHE BLOCK ========================================= + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * UUID value generator. Type 1 generator is based on the time-based generator + * in the Apache Commons Id project: http://jakarta.apache.org/commons/sandbox + * /id/uuid.html The type 4 generator uses the standard Java UUID generator. + * + * The type 1 code has been vastly simplified and modified to replace the + * ethernet address of the host machine with the IP, since we do not want to + * require native libs and Java cannot access the MAC address directly. + * + * In spirit, implements the IETF UUID draft specification, found here:
+ * http://www1.ics.uci.edu/~ejw/authoring/uuid-guid/draft-leach-uuids-guids-01 + * .txt + * + * @author Abe White, Kevin Sutter + * @since 0.3.3 + */ +public class UUIDGenerator { + + // supported UUID types + public static final int TYPE1 = 1; + public static final int TYPE4 = 4; + // indexes within the uuid array for certain boundaries + private static final byte IDX_TIME_HI = 6; + private static final byte IDX_TYPE = 6; // multiplexed + private static final byte IDX_TIME_MID = 4; + private static final byte IDX_TIME_LO = 0; + private static final byte IDX_TIME_SEQ = 8; + private static final byte IDX_VARIATION = 8; // multiplexed + // indexes and lengths within the timestamp for certain boundaries + private static final byte TS_TIME_LO_IDX = 4; + private static final byte TS_TIME_LO_LEN = 4; + private static final byte TS_TIME_MID_IDX = 2; + private static final byte TS_TIME_MID_LEN = 2; + private static final byte TS_TIME_HI_IDX = 0; + private static final byte TS_TIME_HI_LEN = 2; + // offset to move from 1/1/1970, which is 0-time for Java, to gregorian + // 0-time 10/15/1582, and multiplier to go from 100nsec to msec units + private static final long GREG_OFFSET = 0xB1D069B5400L; + private static final long MILLI_MULT = 10000L; + // type of UUID -- time based + private final static byte TYPE_TIME_BASED = 0x10; + // random number generator used to reduce conflicts with other JVMs, and + // hasher for strings. + private Random RANDOM; + // 4-byte IP address + 2 random bytes to compensate for the fact that + // the MAC address is usually 6 bytes + private byte[] IP; + // counter is initialized to 0 and is incremented for each uuid request + // within the same timestamp window. + private int _counter; + // current timestamp (used to detect multiple uuid requests within same + // timestamp) + private long _currentMillis; + // last used millis time, and a semi-random sequence that gets reset + // when it overflows + private long _lastMillis = 0L; + private static final int MAX_14BIT = 0x3FFF; + private short _seq = 0; + private boolean type1Initialized = false; /* + * Initializer for type 1 UUIDs. Creates random generator and genenerates + * the node portion of the UUID using the IP address. + */ + private synchronized void initializeForType1() { + if (type1Initialized == true) { + return; + } + // note that secure random is very slow the first time + // it is used; consider switching to a standard random + RANDOM = CSPRNG_DO_NOT_USE.generate(); + _seq = (short) RANDOM.nextInt(MAX_14BIT); + + byte[] ip = null; + try { + ip = InetAddress.getLocalHost().getAddress(); + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + IP = new byte[6]; + RANDOM.nextBytes(IP); + //OPENJPA-2055: account for the fact that 'getAddress' + //may return an IPv6 address which is 16 bytes wide. + for( int i = 0 ; i < ip.length; ++i ) { + IP[2+(i%4)] ^= ip[i]; + } + type1Initialized = true; + } + /** + * Return a unique UUID value. + */ + public byte[] next(int type) { + if (type == TYPE4) { + return createType4(); + } + return createType1(); + } + /* + * Creates a type 1 UUID + */ + public byte[] createType1() { + if (type1Initialized == false) { + initializeForType1(); + } + // set ip addr + byte[] uuid = new byte[16]; + System.arraycopy(IP, 0, uuid, 10, IP.length); + // Set time info. Have to do this processing within a synchronized + // block because of the statics... + long now = 0; + synchronized (UUIDGenerator.class) { + // Get the time to use for this uuid. This method has the side + // effect of modifying the clock sequence, as well. + now = getTime(); + // Insert the resulting clock sequence into the uuid + uuid[IDX_TIME_SEQ] = (byte) ((_seq & 0x3F00) >>> 8); + uuid[IDX_VARIATION] |= 0x80; + uuid[IDX_TIME_SEQ+1] = (byte) (_seq & 0xFF); + } + // have to break up time because bytes are spread through uuid + byte[] timeBytes = Bytes.toBytes(now); + // Copy time low + System.arraycopy(timeBytes, TS_TIME_LO_IDX, uuid, IDX_TIME_LO, + TS_TIME_LO_LEN); + // Copy time mid + System.arraycopy(timeBytes, TS_TIME_MID_IDX, uuid, IDX_TIME_MID, + TS_TIME_MID_LEN); + // Copy time hi + System.arraycopy(timeBytes, TS_TIME_HI_IDX, uuid, IDX_TIME_HI, + TS_TIME_HI_LEN); + //Set version (time-based) + uuid[IDX_TYPE] |= TYPE_TIME_BASED; // 0001 0000 + return uuid; + } + /* + * Creates a type 4 UUID + */ + private byte[] createType4() { + UUID type4 = UUID.randomUUID(); + byte[] uuid = new byte[16]; + longToBytes(type4.getMostSignificantBits(), uuid, 0); + longToBytes(type4.getLeastSignificantBits(), uuid, 8); + return uuid; + } + /* + * Converts a long to byte values, setting them in a byte array + * at a given starting position. + */ + private void longToBytes(long longVal, byte[] buf, int sPos) { + sPos += 7; + for(int i = 0; i < 8; i++) + buf[sPos-i] = (byte)(longVal >>> (i * 8)); + } + + /** + * Return the next unique uuid value as a 16-character string. + */ + public String nextString(int type) { + byte[] bytes = next(type); + try { + return new String(bytes, "ISO-8859-1"); + } catch (Exception e) { + return new String(bytes); + } + } + /** + * Return the next unique uuid value as a 32-character hex string. + */ + public String nextHex(int type) { + return Base16Encoder.encode(next(type)); + } + /** + * Get the timestamp to be used for this uuid. Must be called from + * a synchronized block. + * + * @return long timestamp + */ + // package-visibility for testing + private long getTime() { + if (RANDOM == null) + initializeForType1(); + long newTime = getUUIDTime(); + if (newTime <= _lastMillis) { + incrementSequence(); + newTime = getUUIDTime(); + } + _lastMillis = newTime; + return newTime; + } + /** + * Gets the appropriately modified timestamep for the UUID. Must be called + * from a synchronized block. + * + * @return long timestamp in 100ns intervals since the Gregorian change + * offset + */ + private long getUUIDTime() { + if (_currentMillis != System.currentTimeMillis()) { + _currentMillis = System.currentTimeMillis(); + _counter = 0; // reset counter + } + // check to see if we have created too many uuid's for this timestamp + if (_counter + 1 >= MILLI_MULT) { + // Original algorithm threw exception. Seemed like overkill. + // Let's just increment the timestamp instead and start over... + _currentMillis++; + _counter = 0; + } + // calculate time as current millis plus offset times 100 ns ticks + long currentTime = (_currentMillis + GREG_OFFSET) * MILLI_MULT; + // return the uuid time plus the artificial tick counter incremented + return currentTime + _counter++; + } + /** + * Increments the clock sequence for this uuid. Must be called from a + * synchronized block. + */ + private void incrementSequence() { + // increment, but if it's greater than its 14-bits, reset it + if (++_seq > MAX_14BIT) { + _seq = (short) RANDOM.nextInt(MAX_14BIT); // semi-random + } + } + + //Add Dependant classes internally + + /** + * This class came from the Apache Commons Id sandbox project in support + * of the UUIDGenerator implementation. + * + *

Static methods for managing byte arrays (all methods follow Big + * Endian order where most significant bits are in front).

+ */ + public static final class Bytes { + /** + *

Hide constructor in utility class.

+ */ + private Bytes() { + } + /** + * Appends two bytes array into one. + * + * @param a A byte[]. + * @param b A byte[]. + * @return A byte[]. + */ + public static byte[] append(byte[] a, byte[] b) { + byte[] z = new byte[a.length + b.length]; + System.arraycopy(a, 0, z, 0, a.length); + System.arraycopy(b, 0, z, a.length, b.length); + return z; + } + /** + * Returns a 8-byte array built from a long. + * + * @param n The number to convert. + * @return A byte[]. + */ + public static byte[] toBytes(long n) { + return toBytes(n, new byte[8]); + } + /** + * Build a 8-byte array from a long. No check is performed on the + * array length. + * + * @param n The number to convert. + * @param b The array to fill. + * @return A byte[]. + */ + public static byte[] toBytes(long n, byte[] b) { + b[7] = (byte) (n); + n >>>= 8; + b[6] = (byte) (n); + n >>>= 8; + b[5] = (byte) (n); + n >>>= 8; + b[4] = (byte) (n); + n >>>= 8; + b[3] = (byte) (n); + n >>>= 8; + b[2] = (byte) (n); + n >>>= 8; + b[1] = (byte) (n); + n >>>= 8; + b[0] = (byte) (n); + + return b; + } + /** + * Build a long from first 8 bytes of the array. + * + * @param b The byte[] to convert. + * @return A long. + */ + public static long toLong(byte[] b) { + return ((((long) b[7]) & 0xFF) + + ((((long) b[6]) & 0xFF) << 8) + + ((((long) b[5]) & 0xFF) << 16) + + ((((long) b[4]) & 0xFF) << 24) + + ((((long) b[3]) & 0xFF) << 32) + + ((((long) b[2]) & 0xFF) << 40) + + ((((long) b[1]) & 0xFF) << 48) + + ((((long) b[0]) & 0xFF) << 56)); + } + /** + * Compares two byte arrays for equality. + * + * @param a A byte[]. + * @param b A byte[]. + * @return True if the arrays have identical contents. + */ + public static boolean areEqual(byte[] a, byte[] b) { + int aLength = a.length; + if (aLength != b.length) { + return false; + } + for (int i = 0; i < aLength; i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; + } + /** + *

Compares two byte arrays as specified by Comparable. + * + * @param lhs - left hand value in the comparison operation. + * @param rhs - right hand value in the comparison operation. + * @return a negative integer, zero, or a positive integer as + * lhs is less than, equal to, or greater than + * rhs. + */ + public static int compareTo(byte[] lhs, byte[] rhs) { + if (lhs == rhs) { + return 0; + } + if (lhs == null) { + return -1; + } + if (rhs == null) { + return +1; + } + if (lhs.length != rhs.length) { + return ((lhs.length < rhs.length) ? -1 : +1); + } + for (int i = 0; i < lhs.length; i++) { + if (lhs[i] < rhs[i]) { + return -1; + } else if (lhs[i] > rhs[i]) { + return 1; + } + } + return 0; + } + /** + * Build a short from first 2 bytes of the array. + * + * @param b The byte[] to convert. + * @return A short. + */ + public static short toShort(byte[] b) { + return (short) ((b[1] & 0xFF) + ((b[0] & 0xFF) << 8)); + } + } + /** + * Base 16 encoder. + * + * @author Marc Prud'hommeaux + */ + public static final class Base16Encoder { + + private final static char[] HEX = new char[]{ + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + /** + * Convert bytes to a base16 string. + */ + public static String encode(byte[] byteArray) { + StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2); + for (int i = 0; i < byteArray.length; i++) + for (int j = 1; j >= 0; j--) + hexBuffer.append(HEX[(byteArray[i] >> (j * 4)) & 0xF]); + return hexBuffer.toString(); + } + /** + * Convert a base16 string into a byte array. + */ + public static byte[] decode(String s) { + int len = s.length(); + byte[] r = new byte[len / 2]; + for (int i = 0; i < r.length; i++) { + int digit1 = s.charAt(i * 2), digit2 = s.charAt(i * 2 + 1); + if (digit1 >= '0' && digit1 <= '9') + digit1 -= '0'; + else if (digit1 >= 'A' && digit1 <= 'F') + digit1 -= 'A' - 10; + if (digit2 >= '0' && digit2 <= '9') + digit2 -= '0'; + else if (digit2 >= 'A' && digit2 <= 'F') + digit2 -= 'A' - 10; + + r[i] = (byte) ((digit1 << 4) + digit2); + } + return r; + } + } + + + +} + +//========================================= APACHE BLOCK ========================================= + diff --git a/src/Java/gtPlusPlus/core/util/data/UUIDUtils.java b/src/Java/gtPlusPlus/core/util/data/UUIDUtils.java new file mode 100644 index 0000000000..d6b32314b1 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/data/UUIDUtils.java @@ -0,0 +1,25 @@ +package gtPlusPlus.core.util.data; + +import java.nio.ByteBuffer; +import java.util.UUID; + +public class UUIDUtils { + + //UUID Methods below created by https://gist.github.com/jeffjohnson9046 + //https://gist.github.com/jeffjohnson9046/c663dd22bbe6bb0b3f5e + + public static byte[] getBytesFromUUID(UUID uuid) { + ByteBuffer bb = ByteBuffer.wrap(new byte[16]); + bb.putLong(uuid.getMostSignificantBits()); + bb.putLong(uuid.getLeastSignificantBits()); + return bb.array(); + } + + public static UUID getUUIDFromBytes(byte[] bytes) { + ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); + Long high = byteBuffer.getLong(); + Long low = byteBuffer.getLong(); + return new UUID(high, low); + } + +} diff --git a/src/Java/gtPlusPlus/core/util/enchanting/EnchantingUtils.java b/src/Java/gtPlusPlus/core/util/enchanting/EnchantingUtils.java deleted file mode 100644 index 288ca2e2cc..0000000000 --- a/src/Java/gtPlusPlus/core/util/enchanting/EnchantingUtils.java +++ /dev/null @@ -1,102 +0,0 @@ -package gtPlusPlus.core.util.enchanting; - -import gtPlusPlus.api.objects.Logger; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -public class EnchantingUtils { - - - public static final int XP_PER_BOTTLE = 8; - public static final int RATIO = 20; - public static final int LIQUID_PER_XP_BOTTLE = 160; - public static final double RATIO_MOB_ESSENCE_TO_LIQUID_XP = 13.32; - - public static int liquidToXpRatio(final int liquid) { - return liquid / RATIO; - } - - public static int xpToLiquidRatio(final int xp) { - return xp * RATIO; - } - - public static FluidStack getEssenceFromLiquidXp(final int xpAmount){ - if (xpAmount <= 0){ - return null; - } - return getMobEssence((int) (xpAmount*RATIO_MOB_ESSENCE_TO_LIQUID_XP)); - } - - public static FluidStack getLiquidXpFromEssence(final int essenceAmount){ - if (essenceAmount <= 0){ - return null; - } - return getLiquidXP((int) (essenceAmount/RATIO_MOB_ESSENCE_TO_LIQUID_XP)); - } - - public static int getLiquidForLevel(final int level) { - final int xp = getExperienceForLevel(level); - return xpToLiquidRatio(xp); - } - - public static int getLevelForLiquid(final int liquid) { - final int xp = liquidToXpRatio(liquid); - return getLevelForExperience(xp); - } - - public static int getExperienceForLevel(final int level) { - if (level == 0) { - return 0; - } - if ((level > 0) && (level < 16)) { - return level * 17; - } - if ((level > 15) && (level < 31)) { - return (int) (((1.5 * Math.pow(level, 2.0)) - (29.5 * level)) + 360.0); - } - return (int) (((3.5 * Math.pow(level, 2.0)) - (151.5 * level)) + 2220.0); - } - - public static int getXpToNextLevel(final int level) { - final int levelXP = getLevelForExperience(level); - final int nextXP = getExperienceForLevel(level + 1); - return nextXP - levelXP; - } - - public static int getLevelForExperience(final int experience) { - int i; - for (i = 0; getExperienceForLevel(i) <= experience; ++i) { - } - return i - 1; - } - - - - - - - - //Xp Fluids - public static FluidStack getMobEssence(final int amount){ - Logger.WARNING("Trying to get a fluid stack of Mob Essence."); - try { - return FluidRegistry.getFluidStack("mobessence", amount).copy(); - } - catch (final Throwable e){ - return null; - } - - } - - public static FluidStack getLiquidXP(final int amount){ - Logger.WARNING("Trying to get a fluid stack of Liquid XP."); - try { - return FluidRegistry.getFluidStack("xpjuice", amount).copy(); - } - catch (final Throwable e){ - return null; - } - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java b/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java deleted file mode 100644 index 27412d647f..0000000000 --- a/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -package gtPlusPlus.core.util.entity; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import cpw.mods.fml.common.registry.EntityRegistry; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.minecraft.BlockPos; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import ic2.core.IC2Potion; -import ic2.core.item.armor.ItemArmorHazmat; -import net.minecraft.block.Block; -import net.minecraft.entity.*; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.DamageSource; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - -public class EntityUtils { - - public static void setEntityOnFire(final Entity entity, final int length){ - entity.setFire(length); - } - - public static int getFacingDirection(final Entity entity){ - final int d = MathHelper.floor_double((entity.rotationYaw * 4.0F) / 360 + 0.50) & 3; - return d; - } - - @Deprecated - public static Block findBlockUnderEntityNonBoundingBox(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.posY-0.2D - parEntity.yOffset); - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return parEntity.worldObj.getBlock(blockX, blockY, blockZ); - } - - public static Block findBlockUnderEntity(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1; - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return parEntity.worldObj.getBlock(blockX, blockY, blockZ); - } - - public static BlockPos findBlockPosUnderEntity(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1; - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return new BlockPos(blockX, blockY, blockZ); - } - - //TODO - public static void registerEntityToBiomeSpawns(final Class classy, final EnumCreatureType EntityType, final BiomeGenBase baseBiomeGen){ - EntityRegistry.addSpawn(classy, 6, 1, 5, EntityType, baseBiomeGen); //change the values to vary the spawn rarity, biome, etc. - } - - public static boolean applyRadiationDamageToEntity(final int stackSize, final int radiationLevel, final World world, final Entity entityHolding){ - if (!world.isRemote){ - if ((radiationLevel > 0) && (entityHolding instanceof EntityLivingBase)) { - final EntityLivingBase entityLiving = (EntityLivingBase) entityHolding; - if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode){ - if (!ItemArmorHazmat.hasCompleteHazmat(entityLiving) && !GT_Utility.isWearingFullRadioHazmat(entityLiving)) { - int duration; - if (entityLiving.getActivePotionEffect(IC2Potion.radiation) != null){ - //Utils.LOG_INFO("t"); - duration = (radiationLevel*5)+entityLiving.getActivePotionEffect(IC2Potion.radiation).getDuration(); - } - else { - //Utils.LOG_INFO("f"); - duration = radiationLevel*30; - } - //IC2Potion.radiation.applyTo(entityLiving, duration, damage * 15); - GT_Utility.applyRadioactivity(entityLiving, radiationLevel, stackSize); - } - } - } - return true; - } - return false; - } - - - /** - * Static Version of the method used in {@code doFireDamage(entity, int)} to save memory. - */ - private static volatile Method dealFireDamage; - - /** - * Reflective Call to do Fire Damage to an entity (Does not set entity on fire though) - */ - public static boolean doFireDamage(Entity entity, int amount){ - if (dealFireDamage == null){ - try { - dealFireDamage = Entity.class.getDeclaredMethod("dealFireDamage", int.class); - dealFireDamage.setAccessible(true); - } - catch (NoSuchMethodException | SecurityException e) {} - } - else { - try { - dealFireDamage.invoke(entity, amount); - } - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} - } - return false; - } - - public static void doDamage(Entity entity, DamageSource dmg, int i) { - entity.attackEntityFrom(dmg, i); - } - -} diff --git a/src/Java/gtPlusPlus/core/util/fluid/FluidGT6.java b/src/Java/gtPlusPlus/core/util/fluid/FluidGT6.java deleted file mode 100644 index b09c9dd795..0000000000 --- a/src/Java/gtPlusPlus/core/util/fluid/FluidGT6.java +++ /dev/null @@ -1,30 +0,0 @@ -package gtPlusPlus.core.util.fluid; - -import gregtech.api.GregTech_API; -import gtPlusPlus.core.lib.CORE; -import net.minecraftforge.fluids.Fluid; - -public class FluidGT6 extends Fluid implements Runnable -{ - private final short[] mRGBa; - public final String mTextureName; - - public FluidGT6(final String aName, final String aTextureName, final short[] aRGBa) { - super(aName); - this.mRGBa = aRGBa; - this.mTextureName = aTextureName; - if (GregTech_API.sGTBlockIconload != null) { - GregTech_API.sGTBlockIconload.add(this); - } - } - - @Override - public int getColor() { - return (Math.max(0, Math.min(255, this.mRGBa[0])) << 16