From 0669f5eb9d5029a8b94ec552171b0837605f7747 Mon Sep 17 00:00:00 2001 From: draknyte1 Date: Fri, 4 Nov 2016 15:23:26 +1000 Subject: $ Cleaned up the entire project. > Much neat, very nices. --- src/Java/gtPlusPlus/core/util/BaseHandler.java | 8 +- src/Java/gtPlusPlus/core/util/ClassUtils.java | 79 +- src/Java/gtPlusPlus/core/util/Log.java | 41 +- src/Java/gtPlusPlus/core/util/LoggingUtils.java | 55 +- src/Java/gtPlusPlus/core/util/Quality.java | 87 +- src/Java/gtPlusPlus/core/util/Utils.java | 711 ++++---- .../gtPlusPlus/core/util/UtilsChatFormatting.java | 266 ++- src/Java/gtPlusPlus/core/util/UtilsRarity.java | 29 +- src/Java/gtPlusPlus/core/util/UtilsText.java | 24 +- .../gtPlusPlus/core/util/array/ArrayUtils.java | 16 +- src/Java/gtPlusPlus/core/util/array/Pair.java | 28 +- src/Java/gtPlusPlus/core/util/array/Triplet.java | 38 +- .../core/util/debug/DEBUG_BLOCK_ShapeSpawner.java | 145 +- .../gtPlusPlus/core/util/debug/DEBUG_INIT.java | 27 +- .../core/util/debug/DEBUG_ITEM_ShapeSpawner.java | 43 +- .../util/debug/DEBUG_MULTIBLOCK_ShapeSpawner.java | 1700 +++++++++++--------- .../core/util/debug/DEBUG_ScreenOverlay.java | 54 +- .../core/util/debug/DEBUG_TimerThread.java | 68 +- .../core/util/debug/UtilityGL11Debug.java | 853 ++++++---- .../gtPlusPlus/core/util/entity/EntityUtils.java | 85 +- src/Java/gtPlusPlus/core/util/fluid/FluidGT6.java | 42 +- .../gtPlusPlus/core/util/fluid/FluidUtils.java | 529 +++--- .../gregtech/recipehandlers/GregtechRecipe.java | 69 +- src/Java/gtPlusPlus/core/util/item/ItemUtils.java | 672 ++++---- .../core/util/materials/MaterialUtils.java | 331 ++-- src/Java/gtPlusPlus/core/util/math/MathUtils.java | 372 +++-- .../core/util/networking/NetworkUtils.java | 42 +- .../util/particles/EntityParticleFXMysterious.java | 19 +- .../gtPlusPlus/core/util/player/PlayerCache.java | 261 +-- .../gtPlusPlus/core/util/player/PlayerUtils.java | 170 +- .../gtPlusPlus/core/util/player/UtilsMining.java | 204 +-- .../gtPlusPlus/core/util/recipe/RecipeUtils.java | 635 +++++--- .../core/util/recipe/shapeless/ShapelessUtils.java | 43 +- .../core/util/reflect/ClientProxyFinder.java | 43 +- .../core/util/reflect/ReflectionUtils.java | 75 +- src/Java/gtPlusPlus/core/util/wrapper/var.java | 116 +- 36 files changed, 4301 insertions(+), 3679 deletions(-) (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 index 63f22f3763..e8fb919ab0 100644 --- a/src/Java/gtPlusPlus/core/util/BaseHandler.java +++ b/src/Java/gtPlusPlus/core/util/BaseHandler.java @@ -2,10 +2,10 @@ package gtPlusPlus.core.util; public abstract class BaseHandler { - public abstract void preInit(); - public abstract void init(); - + public abstract void postInit(); - + + public abstract void preInit(); + } diff --git a/src/Java/gtPlusPlus/core/util/ClassUtils.java b/src/Java/gtPlusPlus/core/util/ClassUtils.java index dfd8ec898b..e58c2f2785 100644 --- a/src/Java/gtPlusPlus/core/util/ClassUtils.java +++ b/src/Java/gtPlusPlus/core/util/ClassUtils.java @@ -4,65 +4,53 @@ 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(String className) { - try { - Class.forName(className); - return true; - } catch (Throwable ex) { - // Class or one of its dependencies is not present... - return false; - } - } - - public static Method getMethodViaReflection(Class lookupClass, String methodName, boolean invoke) throws Exception{ - Class lookup = lookupClass.getClass(); - Method m = lookup.getDeclaredMethod(methodName); - m.setAccessible(true);// Abracadabra - if (invoke){ + 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(String className){ + public static Class getNonPublicClass(final String className) { Class c = null; try { c = Class.forName(className); - } catch (ClassNotFoundException e) { + } + catch (final ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } - //full package name --------^^^^^^^^^^ - //or simpler without Class.forName: - //Class c = package1.A.class; + // full package name --------^^^^^^^^^^ + // or simpler without Class.forName: + // Class c = package1.A.class; - if (null != c){ - //In our case we need to use + if (null != c) { + // In our case we need to use Constructor constructor = null; try { constructor = c.getDeclaredConstructor(); - } catch (NoSuchMethodException | SecurityException e) { + } + 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 + // 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! + // now we need to make this constructor accessible + if (null != constructor) { + constructor.setAccessible(true);// ABRACADABRA! try { - Object o = constructor.newInstance(); + final Object o = constructor.newInstance(); return (Class) o; - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { + } + catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -71,6 +59,21 @@ public class ClassUtils { return null; } - + /* + * @ 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; + } + } } diff --git a/src/Java/gtPlusPlus/core/util/Log.java b/src/Java/gtPlusPlus/core/util/Log.java index ea7076e453..460f8598dc 100644 --- a/src/Java/gtPlusPlus/core/util/Log.java +++ b/src/Java/gtPlusPlus/core/util/Log.java @@ -3,27 +3,22 @@ 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(String msg) - { - LOGGER.warn(msg); - } - - public static void error(String msg) - { - LOGGER.error(msg); - } - - public static void info(String msg) - { - LOGGER.info(msg); - } - - public static void debug(String msg) - { - LOGGER.debug(msg); - } +public final class Log { + public static final Logger LOGGER = LogManager.getLogger("MiscUtils"); + + public static void debug(final String msg) { + Log.LOGGER.debug(msg); + } + + public static void error(final String msg) { + Log.LOGGER.error(msg); + } + + public static void info(final String msg) { + Log.LOGGER.info(msg); + } + + public static void warn(final String msg) { + Log.LOGGER.warn(msg); + } } diff --git a/src/Java/gtPlusPlus/core/util/LoggingUtils.java b/src/Java/gtPlusPlus/core/util/LoggingUtils.java index 607771bc8e..ffae71c40d 100644 --- a/src/Java/gtPlusPlus/core/util/LoggingUtils.java +++ b/src/Java/gtPlusPlus/core/util/LoggingUtils.java @@ -5,47 +5,48 @@ import java.util.Date; public class LoggingUtils { - public static void profileLog(Object o){ - try { + public static boolean logCurrentSystemTime(final String message) { + final Date date = new Date(System.currentTimeMillis()); + try { + LoggingUtils.profileLog(message + " | " + date.toString()); + return true; + } + catch (final Throwable r) { + return false; + } + + } + + public static void profileLog(final Object o) { + try { String content; - File file = new File("GregtechTimingsTC.txt"); + final File file = new File("GregtechTimingsTC.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); - FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - BufferedWriter bw = new BufferedWriter(fw); + 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){ + } + if (o instanceof String) { content = (String) o; - } - else { - content = o.toString(); - } - FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - BufferedWriter bw = new BufferedWriter(fw); + } + 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 (IOException e) { + } + catch (final IOException e) { System.out.println("Data logging failed."); } - } - - public static boolean logCurrentSystemTime(String message){ - Date date = new Date(System.currentTimeMillis()); - try { - profileLog(message+" | "+date.toString()); - return true; - } - catch (Throwable r) { - return false; - } - } - + } diff --git a/src/Java/gtPlusPlus/core/util/Quality.java b/src/Java/gtPlusPlus/core/util/Quality.java index 1ce29c7a58..50d1b9fc90 100644 --- a/src/Java/gtPlusPlus/core/util/Quality.java +++ b/src/Java/gtPlusPlus/core/util/Quality.java @@ -4,56 +4,65 @@ 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) - { + + 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); + + 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; + } + } + private String LOOT; + + private EnumChatFormatting COLOUR; + + private Quality(final String lootTier, final EnumChatFormatting tooltipColour) { this.LOOT = lootTier; this.COLOUR = tooltipColour; } - public String getQuality() { - return LOOT; + public String formatted() { + return this.COLOUR + this.LOOT; } - - protected EnumChatFormatting getColour(){ - return COLOUR; - } - - public String formatted(){ - return this.COLOUR+this.LOOT; + + protected EnumChatFormatting getColour() { + return this.COLOUR; } - - public static Quality getRandomQuality(){ - 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; + + public String getQuality() { + return this.LOOT; } } - - diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index 03d3d68044..e65e0f2ea9 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -31,207 +31,274 @@ import net.minecraftforge.oredict.OreDictionary; public class Utils { - public static final int WILDCARD_VALUE = Short.MAX_VALUE; - - public static final boolean isServer(){ - return FMLCommonHandler.instance().getEffectiveSide().isServer(); - } - static class ShortTimerTask extends TimerTask { @Override public void run() { Utils.LOG_WARNING("Timer expired."); } } - - public static boolean isModUpToDate(){ - - if (CORE.MASTER_VERSION.equals(CORE.VERSION.toLowerCase())){ - return true; - } + + public static final int WILDCARD_VALUE = Short.MAX_VALUE; + + private static short cellID = 15; + + public static Integer appenedHexNotationToInteger(final int hexAsStringOrInt) { + final String hexChar = "0x"; + String result; + Utils.LOG_INFO(String.valueOf(hexAsStringOrInt)); + result = hexChar + String.valueOf(hexAsStringOrInt); + return Integer.getInteger(result); + } + + public static String appenedHexNotationToString(final Object hexAsStringOrInt) { + final String hexChar = "0x"; + String result; + if (hexAsStringOrInt.getClass() == String.class) { + + if (((String) hexAsStringOrInt).length() != 6) { + final String temp = Utils.leftPadWithZeroes((String) hexAsStringOrInt, 6); + result = temp; + } + result = hexChar + hexAsStringOrInt; + return result; + } + else if (hexAsStringOrInt.getClass() == Integer.class) { + ; + if (((String) hexAsStringOrInt).length() != 6) { + final String temp = Utils.leftPadWithZeroes((String) hexAsStringOrInt, 6); + result = temp; + } + result = hexChar + String.valueOf(hexAsStringOrInt); + return result; + } + else { + return null; + } + } + + public static String byteToHex(final byte b) { + final int i = b & 0xFF; + return Integer.toHexString(i); + } + + public static String checkCorrectMiningToolForBlock(final Block currentBlock, final World currentWorld) { + String correctTool = ""; + if (!currentWorld.isRemote) { + try { + correctTool = currentBlock.getHarvestTool(0); + Utils.LOG_WARNING(correctTool); + + } + catch (final NullPointerException e) { + + } + } + + return correctTool; + } + + public static boolean containsMatch(final boolean strict, final ItemStack[] inputs, final ItemStack... targets) { + for (final ItemStack input : inputs) { + for (final ItemStack target : targets) { + if (Utils.itemMatches(target, input, strict)) { + return true; + } + } + } return false; } - - public static TC_AspectStack getTcAspectStack (TC_Aspects aspect, long size){ - return getTcAspectStack(aspect.name(), (int) size); + + public static List convertArrayListToList(final ArrayList sourceArray) { + final List targetList = new ArrayList(Arrays.asList(sourceArray)); + return targetList; + } + + public static List convertArrayToFixedSizeList(final Object[] sourceArray) { + final List targetList = Arrays.asList(sourceArray); + return targetList; + } + + public static List convertArrayToList(final Object[] sourceArray) { + final List targetList = new ArrayList(Arrays.asList(sourceArray)); + return targetList; + } + + public static Object[] convertListToArray(final List sourceList) { + final Object[] targetArray = sourceList.toArray(new Object[sourceList.size()]); + return targetArray; + } + + public static ItemStack createInternalNameAndFluidCell(final String s) { + Utils.LOG_WARNING("1"); + final InternalName yourName = EnumHelper.addEnum(InternalName.class, s, new Class[0], new Object[0]); + Utils.LOG_WARNING("2 " + yourName.name()); + final ItemCell item = (ItemCell) Ic2Items.cell.getItem(); + Utils.LOG_WARNING("3 " + item.getUnlocalizedName()); + try { + Utils.LOG_WARNING("4"); + final Class clz = item.getClass(); + Utils.LOG_WARNING("5 " + clz.getSimpleName()); + final Method methode = clz.getDeclaredMethod("addCell", int.class, InternalName.class, Block[].class); + Utils.LOG_WARNING("6 " + methode.getName()); + methode.setAccessible(true); + Utils.LOG_WARNING("7 " + methode.isAccessible()); + final ItemStack temp = (ItemStack) methode.invoke(item, Utils.cellID++, yourName, new Block[0]); + Utils.LOG_INFO("Successfully created " + temp.getDisplayName() + "s."); + FluidContainerRegistry.registerFluidContainer(FluidUtils.getFluidStack(s.toLowerCase(), 0), temp.copy(), + Ic2Items.cell.copy()); + ItemUtils.addItemToOreDictionary(temp.copy(), "cell" + s); + return temp; + } + catch (final Exception e) { + e.printStackTrace(); + } + return null; + } + + public static boolean doesEntryExistAlreadyInOreDictionary(final String OreDictName) { + if (OreDictionary.getOres(OreDictName).size() != 0) { + return true; + } + return false; } - - public static TC_AspectStack getTcAspectStack (String aspect, long size){ - return getTcAspectStack(aspect, (int) size); + + public static ToolMaterial generateMaterialFromGT(final Materials gtMaterial) { + final String name = gtMaterial.name(); + final int harvestLevel = gtMaterial.mToolQuality; + final int durability = gtMaterial.mDurability; + final float damage = gtMaterial.mToolQuality; + final int efficiency = (int) gtMaterial.mToolSpeed; + final int enchantability = gtMaterial.mEnchantmentToolsLevel; + final ToolMaterial temp = EnumHelper.addToolMaterial(name, harvestLevel, durability, efficiency, damage, + enchantability); + return temp; + } - public static TC_AspectStack getTcAspectStack (TC_Aspects aspect, int size){ - return getTcAspectStack(aspect.name(), size); + /** + * Returns a Liquid Stack with given amount of IC2Steam. + */ + public static FluidStack getIC2Steam(final long aAmount) { + return FluidRegistry.getFluidStack("ic2steam", (int) aAmount); } - - public static TC_AspectStack getTcAspectStack (String aspect, int size){ + + public static TC_AspectStack getTcAspectStack(final String aspect, final int size) { TC_AspectStack returnValue = null; - if (aspect.toUpperCase() == "COGNITIO"){ - //Adds in Compat for older GT Versions which Misspell aspects. + if (aspect.toUpperCase() == "COGNITIO") { + // Adds in Compat for older GT Versions which Misspell aspects. try { - if (EnumUtils.isValidEnum(TC_Aspects.class, "COGNITIO")){ - Utils.LOG_WARNING("TC Aspect found - "+aspect); + if (EnumUtils.isValidEnum(TC_Aspects.class, "COGNITIO")) { + Utils.LOG_WARNING("TC Aspect found - " + aspect); returnValue = new TC_AspectStack(TC_Aspects.valueOf("COGNITIO"), size); } else { - Utils.LOG_INFO("Fallback TC Aspect found - "+aspect+" - PLEASE UPDATE GREGTECH TO A NEWER VERSION TO REMOVE THIS MESSAGE - THIS IS NOT AN ERROR"); + Utils.LOG_INFO("Fallback TC Aspect found - " + aspect + + " - PLEASE UPDATE GREGTECH TO A NEWER VERSION TO REMOVE THIS MESSAGE - THIS IS NOT AN ERROR"); returnValue = new TC_AspectStack(TC_Aspects.valueOf("COGNITO"), size); - } - } catch (NoSuchFieldError r){ + } + } + catch (final NoSuchFieldError r) { Utils.LOG_INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); } } - else if (aspect.toUpperCase() == "EXANIMUS"){ - //Adds in Compat for older GT Versions which Misspell aspects. + else if (aspect.toUpperCase() == "EXANIMUS") { + // Adds in Compat for older GT Versions which Misspell aspects. try { - if (EnumUtils.isValidEnum(TC_Aspects.class, "EXANIMUS")){ - Utils.LOG_WARNING("TC Aspect found - "+aspect); + if (EnumUtils.isValidEnum(TC_Aspects.class, "EXANIMUS")) { + Utils.LOG_WARNING("TC Aspect found - " + aspect); returnValue = new TC_AspectStack(TC_Aspects.valueOf("EXANIMUS"), size); } else { - Utils.LOG_INFO("Fallback TC Aspect found - "+aspect+" - PLEASE UPDATE GREGTECH TO A NEWER VERSION TO REMOVE THIS MESSAGE - THIS IS NOT AN ERROR"); + Utils.LOG_INFO("Fallback TC Aspect found - " + aspect + + " - PLEASE UPDATE GREGTECH TO A NEWER VERSION TO REMOVE THIS MESSAGE - THIS IS NOT AN ERROR"); returnValue = new TC_AspectStack(TC_Aspects.valueOf("EXAMINIS"), size); - } - } catch (NoSuchFieldError r){ + } + } + catch (final NoSuchFieldError r) { Utils.LOG_INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); } - - + } - else if (aspect.toUpperCase() == "PRAECANTATIO"){ - //Adds in Compat for older GT Versions which Misspell aspects. + else if (aspect.toUpperCase() == "PRAECANTATIO") { + // Adds in Compat for older GT Versions which Misspell aspects. try { - if (EnumUtils.isValidEnum(TC_Aspects.class, "PRAECANTATIO")){ - Utils.LOG_WARNING("TC Aspect found - "+aspect); + if (EnumUtils.isValidEnum(TC_Aspects.class, "PRAECANTATIO")) { + Utils.LOG_WARNING("TC Aspect found - " + aspect); returnValue = new TC_AspectStack(TC_Aspects.valueOf("PRAECANTATIO"), size); } else { - Utils.LOG_INFO("Fallback TC Aspect found - "+aspect+" - PLEASE UPDATE GREGTECH TO A NEWER VERSION TO REMOVE THIS MESSAGE - THIS IS NOT AN ERROR"); + Utils.LOG_INFO("Fallback TC Aspect found - " + aspect + + " - PLEASE UPDATE GREGTECH TO A NEWER VERSION TO REMOVE THIS MESSAGE - THIS IS NOT AN ERROR"); returnValue = new TC_AspectStack(TC_Aspects.valueOf("PRAECANTIO"), size); - } - } catch (NoSuchFieldError r){ + } + } + catch (final NoSuchFieldError r) { Utils.LOG_INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); - } + } } else { - Utils.LOG_WARNING("TC Aspect found - "+aspect); + Utils.LOG_WARNING("TC Aspect found - " + aspect); returnValue = new TC_AspectStack(TC_Aspects.valueOf(aspect), size); } return returnValue; } - public static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets) - { - for (ItemStack input : inputs) - { - for (ItemStack target : targets) - { - if (itemMatches(target, input, strict)) - { - return true; - } - } - } - return false; - } - - public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict) - { - if (input == null || target == null) - { - return false; - } - return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage())); - } - - //Non-Dev Comments - public static void LOG_INFO(String s){ - //if (CORE.DEBUG){ - FMLLog.info("GT++: "+s); - //} - } - - //Developer Comments - public static void LOG_WARNING(String s){ - if (CORE.DEBUG){ - FMLLog.warning("GT++: "+s); - } - } + /* + * public static void recipeBuilderBlock(ItemStack slot_1, ItemStack slot_2, + * ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, + * ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Block resultBlock){ + * GameRegistry.addRecipe(new ItemStack(resultBlock), new Object[] {"ABC", + * "DEF", "GHI", 'A',slot_1,'B',slot_2,'C',slot_3, + * 'D',slot_4,'E',slot_5,'F',slot_6, 'G',slot_7,'H',slot_8,'I',slot_9 }); } + */ - //Errors - public static void LOG_ERROR(String s){ - if (CORE.DEBUG){ - FMLLog.severe("GT++: "+s); - } + public static TC_AspectStack getTcAspectStack(final String aspect, final long size) { + return Utils.getTcAspectStack(aspect, (int) size); } - //Developer Logger - public static void LOG_SPECIFIC_WARNING(String whatToLog, String msg, int line){ - if (CORE.DEBUG){ - FMLLog.warning("GT++ |"+line+"| "+whatToLog+" | "+msg); - } + public static TC_AspectStack getTcAspectStack(final TC_Aspects aspect, final int size) { + return Utils.getTcAspectStack(aspect.name(), size); } - public static void paintBox(Graphics g, int MinA, int MinB, int MaxA, int MaxB){ - g.drawRect (MinA, MinB, MaxA, MaxB); + public static TC_AspectStack getTcAspectStack(final TC_Aspects aspect, final long size) { + return Utils.getTcAspectStack(aspect.name(), (int) size); } /** - * Returns if that Liquid is IC2Steam. + * + * @param colourInt + * e.g. 0XFFFFFF + * @return Colour */ - public static boolean isIC2Steam(FluidStack aFluid) { - if (aFluid == null) return false; - return aFluid.isFluidEqual(getIC2Steam(1)); + public static Color hex2Rgb(final int colourInt) { + return Color.decode(String.valueOf(colourInt)); } /** - * Returns a Liquid Stack with given amount of IC2Steam. + * + * @param colourStr + * e.g. "#FFFFFF" + * @return */ - public static FluidStack getIC2Steam(long aAmount) { - return FluidRegistry.getFluidStack("ic2steam", (int)aAmount); - } - - - - /*public static void recipeBuilderBlock(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Block resultBlock){ - GameRegistry.addRecipe(new ItemStack(resultBlock), - new Object[] {"ABC", "DEF", "GHI", - 'A',slot_1,'B',slot_2,'C',slot_3, - 'D',slot_4,'E',slot_5,'F',slot_6, - 'G',slot_7,'H',slot_8,'I',slot_9 - }); - }*/ - - public static String checkCorrectMiningToolForBlock(Block currentBlock, World currentWorld){ - String correctTool = ""; - if (!currentWorld.isRemote){ - try { - correctTool = currentBlock.getHarvestTool(0); - Utils.LOG_WARNING(correctTool); - - } catch (NullPointerException e){ - - } - } - - return correctTool; + public static Color hex2Rgb(final String colorStr) { + return new Color(Integer.valueOf(colorStr.substring(1, 3), 16), Integer.valueOf(colorStr.substring(3, 5), 16), + Integer.valueOf(colorStr.substring(5, 7), 16)); } /** - * - * @param colourStr e.g. "#FFFFFF" + * + * @param colourStr + * e.g. "#FFFFFF" * @return String - formatted "rgb(0,0,0)" */ - public static String hex2RgbFormatted(String hexString) { - Color c = new Color( - Integer.valueOf(hexString.substring(1, 3), 16), - Integer.valueOf(hexString.substring(3, 5), 16), - Integer.valueOf(hexString.substring(5, 7), 16)); + public static String hex2RgbFormatted(final String hexString) { + final Color c = new Color(Integer.valueOf(hexString.substring(1, 3), 16), + Integer.valueOf(hexString.substring(3, 5), 16), Integer.valueOf(hexString.substring(5, 7), 16)); - StringBuffer sb = new StringBuffer(); + final StringBuffer sb = new StringBuffer(); sb.append("rgb("); sb.append(c.getRed()); sb.append(","); @@ -241,256 +308,162 @@ public class Utils { sb.append(")"); return sb.toString(); } - - /** - * - * @param colourStr e.g. "#FFFFFF" - * @return - */ - public static Color hex2Rgb(String colorStr) { - return new Color( - Integer.valueOf( colorStr.substring( 1, 3 ), 16 ), - Integer.valueOf( colorStr.substring( 3, 5 ), 16 ), - Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) ); - } - - /** - * - * @param colourInt e.g. 0XFFFFFF - * @return Colour - */ - public static Color hex2Rgb(int colourInt) { - return Color.decode(String.valueOf(colourInt)); - } - + /** - * - * @param colourInt e.g. 0XFFFFFF + * + * @param colourInt + * e.g. 0XFFFFFF * @return short[] */ - public static short[] hex2RgbShort(int colourInt) { - Color rgb = Color.decode(String.valueOf(colourInt)); - short[] rgba = {(short) rgb.getRed(), (short) rgb.getGreen(), (short) rgb.getBlue(), (short) rgb.getAlpha()}; + public static short[] hex2RgbShort(final int colourInt) { + final Color rgb = Color.decode(String.valueOf(colourInt)); + final short[] rgba = { + (short) rgb.getRed(), (short) rgb.getGreen(), (short) rgb.getBlue(), (short) rgb.getAlpha() + }; return rgba; } - public static Timer ShortTimer(int seconds) { - Timer timer; - timer = new Timer(); - timer.schedule(new ShortTimerTask(), seconds * 1000); - return timer; - } - - public static String byteToHex(byte b) { - int i = b & 0xFF; - return Integer.toHexString(i); + /* + * Original Code by Chandana Napagoda - + * https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator. + * html + */ + public static Map hexColourGenerator(final int colorCount) { + final int maxColorValue = 16777215; + // this is decimal value of the "FFFFFF" + final int devidedvalue = maxColorValue / colorCount; + int countValue = 0; + final HashMap hexColorMap = new HashMap(); + for (int a = 0; a < colorCount && maxColorValue >= countValue; a++) { + if (a != 0) { + countValue += devidedvalue; + hexColorMap.put(a, Integer.toHexString(0x10000 | countValue).substring(1).toUpperCase()); + } + else { + hexColorMap.put(a, Integer.toHexString(0x10000 | countValue).substring(1).toUpperCase()); + } + } + return hexColorMap; } - public static Object[] convertListToArray(List sourceList) { - Object[] targetArray = sourceList.toArray(new Object[sourceList.size()]); - return targetArray; + /* + * Original Code by Chandana Napagoda - + * https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator. + * html + */ + public static Map hexColourGeneratorRandom(final int colorCount) { + final HashMap hexColorMap = new HashMap(); + for (int a = 0; a < colorCount; a++) { + String code = "" + (int) (Math.random() * 256); + code = code + code + code; + final int i = Integer.parseInt(code); + hexColorMap.put(a, Integer.toHexString(0x1000000 | i).substring(1).toUpperCase()); + Utils.LOG_INFO("" + Integer.toHexString(0x1000000 | i).substring(1).toUpperCase()); + } + return hexColorMap; } - public static List convertArrayToFixedSizeList(Object[] sourceArray) { - List targetList = Arrays.asList(sourceArray); - return targetList; + public static boolean invertBoolean(final boolean booleans) { + if (booleans == true) { + return false; + } + return true; } - public static List convertArrayToList(Object[] sourceArray) { - List targetList = new ArrayList(Arrays.asList(sourceArray)); - return targetList; - } - - public static List convertArrayListToList(ArrayList sourceArray) { - List targetList = new ArrayList(Arrays.asList(sourceArray)); - return targetList; + /** + * Returns if that Liquid is IC2Steam. + */ + public static boolean isIC2Steam(final FluidStack aFluid) { + if (aFluid == null) { + return false; + } + return aFluid.isFluidEqual(Utils.getIC2Steam(1)); } - public static void spawnCustomParticle(Entity entity){ - GTplusplus.proxy.generateMysteriousParticles(entity); - } + public static boolean isModUpToDate() { - public static void spawnFX(World world, int x, int y, int z, String particleName, Object particleName2){ - if (!world.isRemote){ - if (particleName2 == null || particleName2.equals("")){ - particleName2 = particleName; - } - int l = MathUtils.randInt(0, 4); - double d0 = (double)((float)x + 0.5F); - double d1 = (double)((float)y + 0.7F); - double d2 = (double)((float)z + 0.5F); - double d3 = 0.2199999988079071D; - double d4 = 0.27000001072883606D; - - if (l == 1) - { - world.spawnParticle(particleName, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D); - } - else if (l == 2) - { - world.spawnParticle((String) particleName2, d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D); - } - else if (l == 3) - { - world.spawnParticle(particleName, d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D); - } - else if (l == 4) - { - world.spawnParticle((String) particleName2, d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D); - } - else - { - world.spawnParticle(particleName, d0, d1, d2, 0.0D, 0.0D, 0.0D); - if (particleName2 != null){ - world.spawnParticle((String) particleName2, d0, d1, d2, 0.0D, 0.0D, 0.0D); - } - } + if (CORE.MASTER_VERSION.equals(CORE.VERSION.toLowerCase())) { + return true; } + return false; } - public static int rgbtoHexValue(int r, int g, int b){ - if (r > 255 || g > 255 || b > 255 || r < 0 || g < 0 || b < 0){ - return 0; - } - Color c = new Color(r,g,b); - String temp = Integer.toHexString( c.getRGB() & 0xFFFFFF ).toUpperCase(); + public static final boolean isServer() { + return FMLCommonHandler.instance().getEffectiveSide().isServer(); + } - //System.out.println( "hex: " + Integer.toHexString( c.getRGB() & 0xFFFFFF ) + " hex value:"+temp); - temp = Utils.appenedHexNotationToString(String.valueOf(temp)); - Utils.LOG_WARNING("Made "+temp+" - Hopefully it's not a mess."); - Utils.LOG_WARNING("It will decode into "+Integer.decode(temp)+"."); - return Integer.decode(temp); + public static boolean itemMatches(final ItemStack target, final ItemStack input, final boolean strict) { + if (input == null || target == null) { + return false; + } + return target.getItem() == input.getItem() && (target.getItemDamage() == Utils.WILDCARD_VALUE && !strict + || target.getItemDamage() == input.getItemDamage()); } /* * http://javadevnotes.com/java-left-pad-string-with-zeros-examples */ - public static String leftPadWithZeroes(String originalString, int length) { - StringBuilder sb = new StringBuilder(); + public static String leftPadWithZeroes(final String originalString, final int length) { + final StringBuilder sb = new StringBuilder(); while (sb.length() + originalString.length() < length) { sb.append('0'); } sb.append(originalString); - String paddedString = sb.toString(); + final String paddedString = sb.toString(); return paddedString; } - /* - * Original Code by Chandana Napagoda - https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator.html - */ - public static Map hexColourGenerator(int colorCount){ - int maxColorValue = 16777215; - // this is decimal value of the "FFFFFF" - int devidedvalue = maxColorValue/colorCount; - int countValue = 0; - HashMap hexColorMap = new HashMap(); - for(int a=0; a < colorCount && maxColorValue >= countValue ; a++){ - if(a != 0){ - countValue+=devidedvalue; - hexColorMap.put(a,Integer.toHexString( 0x10000 | countValue).substring(1).toUpperCase()); - } - else { - hexColorMap.put(a,Integer.toHexString( 0x10000 | countValue).substring(1).toUpperCase()); - } + // Errors + public static void LOG_ERROR(final String s) { + if (CORE.DEBUG) { + FMLLog.severe("GT++: " + s); } - return hexColorMap; } - /* - * Original Code by Chandana Napagoda - https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator.html - */ - public static Map hexColourGeneratorRandom(int colorCount){ - HashMap hexColorMap = new HashMap(); - for(int a=0;a < colorCount; a++){ - String code = ""+(int)(Math.random()*256); - code = code+code+code; - int i = Integer.parseInt(code); - hexColorMap.put(a,Integer.toHexString( 0x1000000 | i).substring(1).toUpperCase()); - Utils.LOG_INFO(""+Integer.toHexString( 0x1000000 | i).substring(1).toUpperCase()); - } - return hexColorMap; + // Non-Dev Comments + public static void LOG_INFO(final String s) { + // if (CORE.DEBUG){ + FMLLog.info("GT++: " + s); + // } } - public static String appenedHexNotationToString(Object hexAsStringOrInt){ - String hexChar = "0x"; - String result; - if (hexAsStringOrInt.getClass() == String.class){ - - if (((String) hexAsStringOrInt).length() != 6){ - String temp = leftPadWithZeroes((String) hexAsStringOrInt, 6); - result = temp; - } - result = hexChar+hexAsStringOrInt; - return result; + // Developer Logger + public static void LOG_SPECIFIC_WARNING(final String whatToLog, final String msg, final int line) { + if (CORE.DEBUG) { + FMLLog.warning("GT++ |" + line + "| " + whatToLog + " | " + msg); } - else if (hexAsStringOrInt.getClass() == Integer.class){ - ; - if (((String) hexAsStringOrInt).length() != 6){ - String temp = leftPadWithZeroes((String) hexAsStringOrInt, 6); - result = temp; - } - result = hexChar+String.valueOf(hexAsStringOrInt); - return result; - } - else { - return null; - } - } - - public static Integer appenedHexNotationToInteger(int hexAsStringOrInt){ - String hexChar = "0x"; - String result; - Utils.LOG_INFO(String.valueOf(hexAsStringOrInt)); - result = hexChar+String.valueOf(hexAsStringOrInt); - return Integer.getInteger(result); } - public static boolean doesEntryExistAlreadyInOreDictionary(String OreDictName){ - if (OreDictionary.getOres(OreDictName).size() != 0) { - return true; + // Developer Comments + public static void LOG_WARNING(final String s) { + if (CORE.DEBUG) { + FMLLog.warning("GT++: " + s); } - return false; } - public static boolean invertBoolean(boolean booleans){ - if (booleans == true){ - return false; - } - return true; + public static void paintBox(final Graphics g, final int MinA, final int MinB, final int MaxA, final int MaxB) { + g.drawRect(MinA, MinB, MaxA, MaxB); } - private static short cellID = 15; - public static ItemStack createInternalNameAndFluidCell(String s){ - Utils.LOG_WARNING("1"); - InternalName yourName = EnumHelper.addEnum(InternalName.class, s, new Class[0], new Object[0]); - Utils.LOG_WARNING("2 "+yourName.name()); - ItemCell item = (ItemCell)Ic2Items.cell.getItem(); - Utils.LOG_WARNING("3 "+item.getUnlocalizedName()); - try - { - Utils.LOG_WARNING("4"); - Class clz = item.getClass(); - Utils.LOG_WARNING("5 "+clz.getSimpleName()); - Method methode = clz.getDeclaredMethod("addCell", int.class, InternalName.class, Block[].class); - Utils.LOG_WARNING("6 "+methode.getName()); - methode.setAccessible(true); - Utils.LOG_WARNING("7 "+methode.isAccessible()); - ItemStack temp = (ItemStack) methode.invoke(item, cellID++, yourName, new Block[0]); - Utils.LOG_INFO("Successfully created "+temp.getDisplayName()+"s."); - FluidContainerRegistry.registerFluidContainer(FluidUtils.getFluidStack(s.toLowerCase(), 0), temp.copy(), Ic2Items.cell.copy()); - ItemUtils.addItemToOreDictionary(temp.copy(), "cell"+s); - return temp; - } - catch(Exception e){ - e.printStackTrace(); + public static int rgbtoHexValue(final int r, final int g, final int b) { + if (r > 255 || g > 255 || b > 255 || r < 0 || g < 0 || b < 0) { + return 0; } - return null; + final Color c = new Color(r, g, b); + String temp = Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase(); + + // System.out.println( "hex: " + Integer.toHexString( c.getRGB() & + // 0xFFFFFF ) + " hex value:"+temp); + temp = Utils.appenedHexNotationToString(String.valueOf(temp)); + Utils.LOG_WARNING("Made " + temp + " - Hopefully it's not a mess."); + Utils.LOG_WARNING("It will decode into " + Integer.decode(temp) + "."); + return Integer.decode(temp); } - - public static String sanitizeString(String input){ + + public static String sanitizeString(final String input) { String temp; String output; - + temp = input.replace(" ", ""); temp = temp.replace("-", ""); temp = temp.replace("_", ""); @@ -505,24 +478,54 @@ public class Utils { temp = temp.replace("[", ""); temp = temp.replace("]", ""); temp = temp.replace(" ", ""); - output = temp; + output = temp; return output; - - } - - public static ToolMaterial generateMaterialFromGT(Materials gtMaterial){ - String name = gtMaterial.name(); - int harvestLevel = gtMaterial.mToolQuality; - int durability = gtMaterial.mDurability; - float damage = gtMaterial.mToolQuality; - int efficiency = (int) gtMaterial.mToolSpeed; - int enchantability = gtMaterial.mEnchantmentToolsLevel; - ToolMaterial temp = EnumHelper.addToolMaterial(name, harvestLevel, durability, efficiency, damage, enchantability); - return temp; - + } + public static Timer ShortTimer(final int seconds) { + Timer timer; + timer = new Timer(); + timer.schedule(new ShortTimerTask(), seconds * 1000); + return timer; + } -} + public static void spawnCustomParticle(final Entity entity) { + GTplusplus.proxy.generateMysteriousParticles(entity); + } + public static void spawnFX(final World world, final int x, final int y, final int z, final String particleName, + Object particleName2) { + if (!world.isRemote) { + if (particleName2 == null || particleName2.equals("")) { + particleName2 = particleName; + } + final int l = MathUtils.randInt(0, 4); + final double d0 = x + 0.5F; + final double d1 = y + 0.7F; + final double d2 = z + 0.5F; + final double d3 = 0.2199999988079071D; + final double d4 = 0.27000001072883606D; + + if (l == 1) { + world.spawnParticle(particleName, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D); + } + else if (l == 2) { + world.spawnParticle((String) particleName2, d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D); + } + else if (l == 3) { + world.spawnParticle(particleName, d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D); + } + else if (l == 4) { + world.spawnParticle((String) particleName2, d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D); + } + else { + world.spawnParticle(particleName, d0, d1, d2, 0.0D, 0.0D, 0.0D); + if (particleName2 != null) { + world.spawnParticle((String) particleName2, d0, d1, d2, 0.0D, 0.0D, 0.0D); + } + } + } + } +} diff --git a/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java b/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java index 51589a1f5d..38fa9eeca9 100644 --- a/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java +++ b/src/Java/gtPlusPlus/core/util/UtilsChatFormatting.java @@ -6,148 +6,126 @@ 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(char p_i1336_3_) - { - this(p_i1336_3_, false); - } - - private UtilsChatFormatting(char p_i1337_3_, 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(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(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(boolean p_96296_0_, boolean p_96296_1_) - { - ArrayList arraylist = new ArrayList(); - UtilsChatFormatting[] aenumchatformatting = values(); - int i = aenumchatformatting.length; - - for (int j = 0; j < i; ++j) - { - UtilsChatFormatting enumchatformatting = aenumchatformatting[j]; - - if ((!enumchatformatting.isColor() || p_96296_0_) && (!enumchatformatting.isFancyStyling() || p_96296_1_)) - { - arraylist.add(enumchatformatting.getFriendlyName()); - } - } - - return arraylist; - } - - static - { - UtilsChatFormatting[] var0 = values(); - int var1 = var0.length; - - for (int var2 = 0; var2 < var1; ++var2) - { - UtilsChatFormatting var3 = var0[var2]; - formattingCodeMapping.put(Character.valueOf(var3.getFormattingCode()), var3); - nameMapping.put(var3.getFriendlyName(), var3); - } - } +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]"); + static { + final UtilsChatFormatting[] var0 = UtilsChatFormatting.values(); + final int var1 = var0.length; + + for (int var2 = 0; var2 < var1; ++var2) { + final UtilsChatFormatting var3 = var0[var2]; + UtilsChatFormatting.formattingCodeMapping.put(Character.valueOf(var3.getFormattingCode()), var3); + UtilsChatFormatting.nameMapping.put(var3.getFriendlyName(), var3); + } + } + /** + * 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 + : UtilsChatFormatting.formattingCodePattern.matcher(p_110646_0_).replaceAll(""); + } + /** + * 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 = UtilsChatFormatting.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; + } + + /** + * 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) UtilsChatFormatting.nameMapping.get(p_96300_0_.toLowerCase()); + } + + /** 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; + } + + /** + * Gets the friendly name of this value. + */ + public String getFriendlyName() { + return this.name().toLowerCase(); + } + + /** + * Checks if typo is a color. + */ + public boolean isColor() { + return !this.fancyStyling && this != RESET; + } + + /** + * False if this is just changing the color or resetting; true otherwise. + */ + public boolean isFancyStyling() { + return this.fancyStyling; + } + + @Override + public String toString() { + return this.controlString; + } } \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/UtilsRarity.java b/src/Java/gtPlusPlus/core/util/UtilsRarity.java index 19339b7717..1eed211613 100644 --- a/src/Java/gtPlusPlus/core/util/UtilsRarity.java +++ b/src/Java/gtPlusPlus/core/util/UtilsRarity.java @@ -2,22 +2,17 @@ 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; +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"); - private UtilsRarity(EnumChatFormatting rarity, String name) - { - this.rarityColor = rarity; - this.rarityName = name; - } + 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 e91fa95e4c..0db7dd35a2 100644 --- a/src/Java/gtPlusPlus/core/util/UtilsText.java +++ b/src/Java/gtPlusPlus/core/util/UtilsText.java @@ -2,31 +2,17 @@ package gtPlusPlus.core.util; public enum UtilsText { - blue('1'), - green('2'), - teal('3'), - maroon('4'), - purple('5'), - orange('6'), - lightGray('7'), - darkGray('8'), - lightBlue('9'), - black('0'), - lime('a'), - aqua('b'), - red('c'), - pink('d'), - yellow('e'), - white('f'); + blue('1'), green('2'), teal('3'), maroon('4'), purple('5'), orange('6'), lightGray('7'), darkGray('8'), lightBlue( + '9'), black('0'), lime('a'), aqua('b'), red('c'), pink('d'), yellow('e'), white('f'); private char colourValue; - private UtilsText (char value) - { + + private UtilsText(final char value) { this.colourValue = value; } public String colour() { - return "§"+colourValue; + return "�" + this.colourValue; } } diff --git a/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java b/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java index ea02aaf1da..0d78c76681 100644 --- a/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java +++ b/src/Java/gtPlusPlus/core/util/array/ArrayUtils.java @@ -4,15 +4,15 @@ import java.util.Arrays; public class ArrayUtils { - public static void expandArray(Object[] someArray, 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; } - private static Object[] addElement(Object[] series, Object newValueToAdd) { - series = Arrays.copyOf(series, series.length + 1); - series[series.length - 1] = newValueToAdd; - return series; + public static void expandArray(final Object[] someArray, final Object newValueToAdd) { + Object[] series = someArray; + series = ArrayUtils.addElement(series, newValueToAdd); } - + } diff --git a/src/Java/gtPlusPlus/core/util/array/Pair.java b/src/Java/gtPlusPlus/core/util/array/Pair.java index 94437e6779..45c6aacc23 100644 --- a/src/Java/gtPlusPlus/core/util/array/Pair.java +++ b/src/Java/gtPlusPlus/core/util/array/Pair.java @@ -1,21 +1,21 @@ package gtPlusPlus.core.util.array; -public class Pair { - - private final K key; - private final V value; - - public Pair(final K key, final V value){ +public class Pair { + + private final K key; + private final V value; + + public Pair(final K key, final V value) { this.key = key; this.value = value; } - - final public K getKey(){ - return key; - } - - final public V getValue(){ - return value; - } + + final public K getKey() { + return this.key; + } + + final public V getValue() { + return this.value; + } } \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/array/Triplet.java b/src/Java/gtPlusPlus/core/util/array/Triplet.java index 07f29ae6c8..7882c2f13a 100644 --- a/src/Java/gtPlusPlus/core/util/array/Triplet.java +++ b/src/Java/gtPlusPlus/core/util/array/Triplet.java @@ -1,27 +1,27 @@ package gtPlusPlus.core.util.array; -public class Triplet { - - private final K key; - private final V value; - private final C count; - - public Triplet(final K key, final V value, final C value2){ +public class Triplet { + + private final K key; + private final V value; + private final C count; + + public Triplet(final K key, final V value, final C value2) { this.key = key; this.value = value; this.count = value2; } - - final public K getKey(){ - return key; - } - - final public V getValue(){ - return value; - } - - final public C getSecondValue(){ - return count; - } + + final public K getKey() { + return this.key; + } + + final public C getSecondValue() { + return this.count; + } + + final public V getValue() { + return this.value; + } } \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/debug/DEBUG_BLOCK_ShapeSpawner.java b/src/Java/gtPlusPlus/core/util/debug/DEBUG_BLOCK_ShapeSpawner.java index 74df9f90ba..1f90697e52 100644 --- a/src/Java/gtPlusPlus/core/util/debug/DEBUG_BLOCK_ShapeSpawner.java +++ b/src/Java/gtPlusPlus/core/util/debug/DEBUG_BLOCK_ShapeSpawner.java @@ -11,95 +11,67 @@ public class DEBUG_BLOCK_ShapeSpawner extends DEBUG_MULTIBLOCK_ShapeSpawner { private static boolean controller; - public DEBUG_BLOCK_ShapeSpawner(int aID, String aName, String aNameRegional) { + public DEBUG_BLOCK_ShapeSpawner(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); } - public DEBUG_BLOCK_ShapeSpawner(String aName) { + public DEBUG_BLOCK_ShapeSpawner(final String aName) { super(aName); } @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new DEBUG_BLOCK_ShapeSpawner(this.mName); - } - - - public String[] getDescription() { - return new String[]{ - "Controller Block for the Testing", - "Create the shapes for Multiblocks.",}; - } - - - @Override - public ITexture[] getTexture(IGregTechTileEntity arg0, byte arg1, - byte arg2, byte arg3, boolean arg4, boolean arg5) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - // TODO Auto-generated method stub - return false; - } + public boolean checkMachine(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { - @Override - public boolean checkRecipe(ItemStack aStack) { - // TODO Auto-generated method stub - return false; - } + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { return false; } - + int stepX = aBaseMetaTileEntity.getXCoord(); - int stepY = aBaseMetaTileEntity.getYCoord(); + final int stepY = aBaseMetaTileEntity.getYCoord(); int stepZ = aBaseMetaTileEntity.getZCoord(); - int temp = 0; + final int temp = 0; - Utils.LOG_INFO("Starting Block located @ "+"[X:"+stepX+"][Y:"+stepY+"][Z:"+stepZ+"]"); + Utils.LOG_INFO("Starting Block located @ " + "[X:" + stepX + "][Y:" + stepY + "][Z:" + stepZ + "]"); - int tAmount = 0; + final int tAmount = 0; switch (xDir) { - case -1: - stepX++; - Utils.LOG_INFO("Modifying stepX + accomodate a "+xDir+" xDir - [X:"+stepX+"][Y:"+stepY+"][Z:"+stepZ+"]"); - break; - - case 1: - stepX--; - Utils.LOG_INFO("Modifying stepX - accomodate a "+xDir+" xDir - [X:"+stepX+"][Y:"+stepY+"][Z:"+stepZ+"]"); - break; + case -1: + stepX++; + Utils.LOG_INFO("Modifying stepX + accomodate a " + xDir + " xDir - [X:" + stepX + "][Y:" + stepY + + "][Z:" + stepZ + "]"); + break; + + case 1: + stepX--; + Utils.LOG_INFO("Modifying stepX - accomodate a " + xDir + " xDir - [X:" + stepX + "][Y:" + stepY + + "][Z:" + stepZ + "]"); + break; } switch (zDir) { - case -1: - stepZ++; - Utils.LOG_INFO("Modifying stepZ + accomodate a "+zDir+" zDir - [X:"+stepX+"][Y:"+stepY+"][Z:"+stepZ+"]"); - break; - - case 1: - stepZ--; - Utils.LOG_INFO("Modifying stepZ - accomodate a "+zDir+" zDir - [X:"+stepX+"][Y:"+stepY+"][Z:"+stepZ+"]"); - break; + case -1: + stepZ++; + Utils.LOG_INFO("Modifying stepZ + accomodate a " + zDir + " zDir - [X:" + stepX + "][Y:" + stepY + + "][Z:" + stepZ + "]"); + break; + + case 1: + stepZ--; + Utils.LOG_INFO("Modifying stepZ - accomodate a " + zDir + " zDir - [X:" + stepX + "][Y:" + stepY + + "][Z:" + stepZ + "]"); + break; } - for (int i = stepX-1; i <= stepX+1; i++){ - for (int j = stepZ-1; j <= stepZ+1; j++){ - for (int h = stepY-1; h <= stepY+1; h++){ - + for (int i = stepX - 1; i <= stepX + 1; i++) { + for (int j = stepZ - 1; j <= stepZ + 1; j++) { + for (int h = stepY - 1; h <= stepY + 1; h++) { - Utils.LOG_INFO("Block Facing - X:"+xDir+" Z:"+zDir); + Utils.LOG_INFO("Block Facing - X:" + xDir + " Z:" + zDir); Utils.LOG_INFO("(h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))"); - Utils.LOG_INFO(" "+(h != 0)+" || "+(((xDir + i != 0)+" || "+(zDir + j != 0))+" && "+((i != 0)+" || "+(j != 0)))); + Utils.LOG_INFO(" " + (h != 0) + " || " + (xDir + i != 0) + " || " + + (zDir + j != 0) + " && " + (i != 0) + " || " + (j != 0)); } } } @@ -107,33 +79,64 @@ public class DEBUG_BLOCK_ShapeSpawner extends DEBUG_MULTIBLOCK_ShapeSpawner { } @Override - public int getMaxEfficiency(ItemStack aStack) { + public boolean checkRecipe(final ItemStack aStack) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int getAmountOfOutputs() { // TODO Auto-generated method stub return 0; } @Override - public int getPollutionPerTick(ItemStack aStack) { + public int getDamageToComponent(final ItemStack aStack) { // TODO Auto-generated method stub return 0; } @Override - public int getDamageToComponent(ItemStack aStack) { + public String[] getDescription() { + return new String[] { + "Controller Block for the Testing", "Create the shapes for Multiblocks.", + }; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { // TODO Auto-generated method stub return 0; } @Override - public int getAmountOfOutputs() { + public int getPollutionPerTick(final ItemStack aStack) { // TODO Auto-generated method stub return 0; } @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { + public ITexture[] getTexture(final IGregTechTileEntity arg0, final byte arg1, final byte arg2, final byte arg3, + final boolean arg4, final boolean arg5) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { // TODO Auto-generated method stub return false; } + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity