From fbdbb388c369fae549cfde3eed38b536f7461d90 Mon Sep 17 00:00:00 2001 From: Connor-Colenso <52056774+Connor-Colenso@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:03:23 +0100 Subject: Cleaning up (#767) * Kill playerAPI * Gut more events and compat that is now obsolete * Remove commented out code * Remove final modifier from methods * Make more stuff final * Remove slow building ring * Protected -> private in final classes * More cleaning * More cleaning v2 * Purging * Clean DevHelper * Clean DevHelper 2 * delete DevHelper * remove useless IFMLLoadingPlugin.MCVersion annotation from @Mod files * check for obfuscation only once in the IFMLloadingPlugin.injectData * don't instantiate the static class ASMConfig * delete unused and empty implementation of IFMLCallHook * delete empty class * delete ClassesToTransform class that just holds the class names constants * delete unused methods and unsless logging in dummymod container * delete unused transformer ClassTransformer_TT_ThaumicRestorer * spotless * Clean * Clean utils * Build checkpoint * Purge * Stage 2 * Stage 3 * Stage 4 * Stage 5 * Stage 6 * Spotless * Imports * Stage idk * Stage 1 * Fix issue * Spotless * Format numbers --------- Co-authored-by: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Co-authored-by: Connor Colenso --- src/main/java/gtPlusPlus/core/util/Utils.java | 541 ++++----------------- src/main/java/gtPlusPlus/core/util/data/AES.java | 37 +- .../java/gtPlusPlus/core/util/data/ArrayUtils.java | 60 +-- .../java/gtPlusPlus/core/util/data/FileUtils.java | 8 +- .../gtPlusPlus/core/util/data/LocaleUtils.java | 18 +- .../gtPlusPlus/core/util/data/StringUtils.java | 79 +-- .../java/gtPlusPlus/core/util/math/MathUtils.java | 250 +--------- .../core/util/minecraft/EnchantingUtils.java | 63 +-- .../core/util/minecraft/EntityUtils.java | 160 +----- .../gtPlusPlus/core/util/minecraft/FluidUtils.java | 91 +--- .../core/util/minecraft/InventoryUtils.java | 40 +- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 286 +---------- .../gtPlusPlus/core/util/minecraft/LangUtils.java | 28 +- .../core/util/minecraft/MaterialUtils.java | 142 ++---- .../core/util/minecraft/MiningUtils.java | 92 +--- .../core/util/minecraft/ModularArmourUtils.java | 136 +----- .../gtPlusPlus/core/util/minecraft/NBTUtils.java | 396 +-------------- .../core/util/minecraft/PlayerUtils.java | 13 +- .../core/util/minecraft/RecipeUtils.java | 373 +------------- .../core/util/minecraft/ShapelessUtils.java | 1 - .../util/minecraft/gregtech/PollutionUtils.java | 63 +-- .../particles/EntityParticleFXMysterious.java | 15 - .../gtPlusPlus/core/util/player/PlayerCache.java | 43 +- .../core/util/reflect/ReflectionUtils.java | 16 +- 24 files changed, 308 insertions(+), 2643 deletions(-) delete mode 100644 src/main/java/gtPlusPlus/core/util/minecraft/particles/EntityParticleFXMysterious.java (limited to 'src/main/java/gtPlusPlus/core/util') diff --git a/src/main/java/gtPlusPlus/core/util/Utils.java b/src/main/java/gtPlusPlus/core/util/Utils.java index 04c70beae6..df37479533 100644 --- a/src/main/java/gtPlusPlus/core/util/Utils.java +++ b/src/main/java/gtPlusPlus/core/util/Utils.java @@ -1,21 +1,15 @@ package gtPlusPlus.core.util; import java.awt.Color; -import java.awt.Graphics; import java.io.File; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.entity.Entity; -import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -23,31 +17,24 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; -import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.oredict.OreDictionary; import org.apache.commons.lang3.EnumUtils; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.Materials; import gregtech.api.enums.TC_Aspects; import gregtech.api.enums.TC_Aspects.TC_AspectStack; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; -import gtPlusPlus.GTplusplus; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.item.ModItems; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.NBTUtils; @@ -57,24 +44,14 @@ import ic2.core.item.resources.ItemCell; public class Utils { - public static final int WILDCARD_VALUE = Short.MAX_VALUE; - - public static final boolean isServer() { + public static boolean isServer() { return FMLCommonHandler.instance().getEffectiveSide().isServer(); } - public static final boolean isClient() { + public static boolean isClient() { return FMLCommonHandler.instance().getEffectiveSide().isClient(); } - static class ShortTimerTask extends TimerTask { - - @Override - public void run() { - Logger.WARNING("Timer expired."); - } - } - public static TC_AspectStack getTcAspectStack(final TC_Aspects aspect, final long size) { return getTcAspectStack(aspect.name(), (int) size); } @@ -91,7 +68,7 @@ public class Utils { TC_AspectStack returnValue = null; - if (aspect.toUpperCase().equals("COGNITIO")) { + if (aspect.equalsIgnoreCase("COGNITIO")) { // Adds in Compat for older GT Versions which Misspell aspects. try { if (EnumUtils.isValidEnum(TC_Aspects.class, "COGNITIO")) { @@ -106,7 +83,7 @@ public class Utils { } catch (final NoSuchFieldError r) { Logger.INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); } - } else if (aspect.toUpperCase().equals("EXANIMUS")) { + } else if (aspect.equalsIgnoreCase("EXANIMUS")) { // Adds in Compat for older GT Versions which Misspell aspects. try { if (EnumUtils.isValidEnum(TC_Aspects.class, "EXANIMUS")) { @@ -122,7 +99,7 @@ public class Utils { Logger.INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); } - } else if (aspect.toUpperCase().equals("PRAECANTATIO")) { + } else if (aspect.equalsIgnoreCase("PRAECANTATIO")) { // Adds in Compat for older GT Versions which Misspell aspects. try { if (EnumUtils.isValidEnum(TC_Aspects.class, "PRAECANTATIO")) { @@ -145,35 +122,12 @@ public class Utils { return returnValue; } - public static boolean containsMatch(final boolean strict, final ItemStack[] inputs, final ItemStack... targets) { - for (final ItemStack input : inputs) { - for (final ItemStack target : targets) { - if (itemMatches(target, input, strict)) { - return true; - } - } - } - return false; - } - - 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() == WILDCARD_VALUE) && !strict) - || (target.getItemDamage() == input.getItemDamage()))); - } - // Register an event to both busses. public static void registerEvent(Object o) { MinecraftForge.EVENT_BUS.register(o); FMLCommonHandler.instance().bus().register(o); } - 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); - } - // Send a message to all players on the server public static void sendServerMessage(final String translationKey) { sendServerMessage(new ChatComponentText(translationKey)); @@ -201,158 +155,13 @@ public class Utils { 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(final Block currentBlock, final World currentWorld) { - String correctTool = ""; - if (!currentWorld.isRemote) { - try { - correctTool = currentBlock.getHarvestTool(0); - Logger.WARNING(correctTool); - - } catch (final NullPointerException e) { - - } - } - - return correctTool; - } - - /** - * - * @param colourStr e.g. "#FFFFFF" - * @return String - formatted "rgb(0,0,0)" - */ - 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)); - - final StringBuffer sb = new StringBuffer(); - sb.append("rgb("); - sb.append(c.getRed()); - sb.append(","); - sb.append(c.getGreen()); - sb.append(","); - sb.append(c.getBlue()); - sb.append(")"); - return sb.toString(); - } - - /** - * - * @param colourStr e.g. "#FFFFFF" - * @return - */ - 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 colourInt e.g. 0XFFFFFF - * @return Colour - */ - public static Color hex2Rgb(final int colourInt) { - return Color.decode(String.valueOf(colourInt)); - } - - /** - * - * @param colourInt e.g. 0XFFFFFF - * @return short[] - */ - 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(final int seconds) { - Timer timer; - timer = new Timer(); - timer.schedule(new ShortTimerTask(), seconds * 1000); - return timer; - } - - public static String byteToHex(final byte b) { - final int i = b & 0xFF; - return Integer.toHexString(i); - } - - public static Object[] convertListToArray(final List sourceList) { - final Object[] targetArray = sourceList.toArray(new Object[sourceList.size()]); - return targetArray; - } - - 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 List convertArrayListToList(final ArrayList sourceArray) { - final List targetList = new ArrayList(Arrays.asList(sourceArray)); - return targetList; - } - - 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); - } - } - } - } - 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; } final Color c = new Color(r, g, b); String temp = Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase(); - temp = Utils.appenedHexNotationToString(String.valueOf(temp)); - // Logger.WARNING("Made " + temp + " - Hopefully it's not a mess."); - // Logger.WARNING("It will decode into " + Integer.decode(temp) + "."); + temp = Utils.appenedHexNotationToString(temp); return Integer.decode(temp); } @@ -365,41 +174,7 @@ public class Utils { sb.append('0'); } sb.append(originalString); - final String paddedString = sb.toString(); - return paddedString; - } - - public static String padWithZerosRight(final int value, final int length) { - String originalString = String.valueOf(value); - final StringBuilder sb = new StringBuilder(); - while ((sb.length() + originalString.length()) < length) { - sb.append('0'); - } - // sb.append(originalString); - if (sb.length() > 0) originalString = (originalString + sb.toString()); - final String paddedString = sb.toString(); - return originalString; - } - - /* - * 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; + return sb.toString(); } /* @@ -425,17 +200,15 @@ public class Utils { if (((String) hexAsStringOrInt).length() != 6) { final String temp = padWithZerosLefts((String) hexAsStringOrInt, 6); - result = temp; } result = hexChar + hexAsStringOrInt; return result; - } else if (hexAsStringOrInt.getClass() == Integer.class || hexAsStringOrInt.getClass() == int.class) { + } else if (hexAsStringOrInt.getClass() == Integer.class) { String aa = String.valueOf(hexAsStringOrInt); if (aa.length() != 6) { - final String temp = padWithZerosLefts(aa, 6); - result = temp; + result = padWithZerosLefts(aa, 6); } else { - result = hexChar + String.valueOf(hexAsStringOrInt); + result = hexChar + hexAsStringOrInt; } return result; } else { @@ -443,28 +216,6 @@ public class Utils { } } - public static Integer appenedHexNotationToInteger(final int hexAsStringOrInt) { - final String hexChar = "0x"; - String result; - Logger.WARNING(String.valueOf(hexAsStringOrInt)); - result = hexChar + String.valueOf(hexAsStringOrInt); - return Integer.getInteger(result); - } - - public static boolean doesEntryExistAlreadyInOreDictionary(final String OreDictName) { - if (OreDictionary.getOres(OreDictName).size() != 0) { - return true; - } - return false; - } - - public static boolean invertBoolean(final boolean booleans) { - if (booleans == true) { - return false; - } - return true; - } - public static File getMcDir() { if (Utils.isClient()) { if (Minecraft.getMinecraft() != null) { @@ -504,44 +255,46 @@ public class Utils { return null; } - public static String sanitizeString(final String input, final char[] aDontRemove) { + public static String sanitizeString(final String input, final char[] dontRemove) { + + // List of characters to remove + final HashSet toRemoveSet = new HashSet<>(); + Collections.addAll( + toRemoveSet, + ' ', + '-', + '_', + '~', + '?', + '!', + '@', + '#', + '$', + '%', + '^', + '&', + '*', + '(', + ')', + '{', + '}', + '[', + ']'); + + // Remove characters from the toRemoveSet if they are in dontRemove + for (char e : dontRemove) { + toRemoveSet.remove(e); + } - String output; - AutoMap aToRemoveMap = new AutoMap(); - - aToRemoveMap.put(" "); - aToRemoveMap.put("-"); - aToRemoveMap.put("_"); - aToRemoveMap.put("~"); - aToRemoveMap.put("?"); - aToRemoveMap.put("!"); - aToRemoveMap.put("@"); - aToRemoveMap.put("#"); - aToRemoveMap.put("$"); - aToRemoveMap.put("%"); - aToRemoveMap.put("^"); - aToRemoveMap.put("&"); - aToRemoveMap.put("*"); - aToRemoveMap.put("("); - aToRemoveMap.put(")"); - aToRemoveMap.put("{"); - aToRemoveMap.put("}"); - aToRemoveMap.put("["); - aToRemoveMap.put("]"); - aToRemoveMap.put(" "); - - for (String s : aToRemoveMap) { - for (char e : aDontRemove) { - if (s.charAt(0) == e) { - aToRemoveMap.remove("s"); - } + // Construct a sanitized string + StringBuilder sanitized = new StringBuilder(); + for (char c : input.toCharArray()) { + if (!toRemoveSet.contains(c)) { + sanitized.append(c); } } - output = input; - for (String A : aToRemoveMap) { - output = output.replace(A, ""); - } - return output; + + return sanitized.toString(); } public static String sanitizeString(final String input) { @@ -582,174 +335,86 @@ public class Utils { return output; } - public static String[] parseVersion(final String version) { - return parseVersion(version, "//."); - } - - public static String[] parseVersion(final String version, final String delimiter) { - final String[] versionArray = version.split(delimiter); - return versionArray; - } - - public static Versioning compareModVersion(final String currentVersion, final String expectedVersion) { - return compareModVersion(currentVersion, expectedVersion, "//."); - } - - public static Versioning compareModVersion(final String currentVersion, final String expectedVersion, - final String delimiter) { - final String[] a = parseVersion(currentVersion, delimiter); - final String[] b = parseVersion(expectedVersion, delimiter); - final int[] c = new int[a.length]; - final int[] d = new int[b.length]; - for (int r = 0; r < a.length; r++) { - c[r] = Integer.parseInt(a[r]); - } - for (int r = 0; r < b.length; r++) { - d[r] = Integer.parseInt(b[r]); - } - final Versioning[] e = new Versioning[MathUtils.returnLargestNumber(c.length, d.length)]; - for (int r = 0; r < e.length; r++) { - - if (c[r] > d[r]) { - e[r] = Versioning.NEWER; - } else if (c[r] < d[r]) { - e[r] = Versioning.OLDER; - } else if (c[r] == d[r]) { - e[r] = Versioning.EQUAL; - } - } - - for (int r = 0; r < e.length; r++) { - if (e[0] == Versioning.NEWER) { - return Versioning.NEWER; - } else if (e[0] == Versioning.OLDER) { - return Versioning.OLDER; - } else { - if (e[r] == Versioning.OLDER) {} - - return Versioning.NEWER; - } - } - - return null; - } - - public static ToolMaterial generateToolMaterialFromGT(final Materials gtMaterial) { - final String name = Utils.sanitizeString(gtMaterial.mDefaultLocalName); - 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 enum Versioning { - - EQUAL(0), - NEWER(1), - OLDER(-1); - - private final int versioningInfo; - - Versioning(final int versionStatus) { - this.versioningInfo = versionStatus; - } - - public int getTexture() { - return this.versioningInfo; - } - } - public static String addBookTitleLocalization(final String aTitle) { - return GT_LanguageManager.addStringLocalization( - new StringBuilder().append("Book.").append(aTitle).append(".Name").toString(), - aTitle, - !GregTech_API.sPostloadFinished); + return GT_LanguageManager + .addStringLocalization("Book." + aTitle + ".Name", aTitle, !GregTech_API.sPostloadFinished); } public static String[] addBookPagesLocalization(final String aTitle, final String[] aPages) { String[] aLocalizationPages = new String[aPages.length]; for (byte i = 0; i < aPages.length; i = (byte) (i + 1)) { aLocalizationPages[i] = GT_LanguageManager.addStringLocalization( - new StringBuilder().append("Book.").append(aTitle).append(".Page") - .append((i < 10) ? new StringBuilder().append("0").append(i).toString() : Byte.valueOf(i)) - .toString(), + "Book." + aTitle + ".Page" + ((i < 10) ? "0" + i : Byte.valueOf(i)), aPages[i], !GregTech_API.sPostloadFinished); } return aLocalizationPages; } - public static ItemStack getWrittenBook(final ItemStack aBook, final int aID, final String aMapping, - final String aTitle, final String aAuthor, final String[] aPages) { - if (GT_Utility.isStringInvalid(aMapping)) { + public static ItemStack getWrittenBook(ItemStack book, int ID, String mapping, String title, String author, + String[] pages) { + + if (GT_Utility.isStringInvalid(mapping)) { return null; } - ItemStack rStack = CORE.sBookList.get(aMapping); - if (rStack != null) { - return GT_Utility.copyAmount(1L, new Object[] { rStack }); + + ItemStack stack = CORE.sBookList.get(mapping); + if (stack != null) { + return GT_Utility.copyAmount(1L, stack); } - if ((GT_Utility.isStringInvalid(aTitle)) || (GT_Utility.isStringInvalid(aAuthor)) || (aPages.length <= 0)) { + + if (GT_Utility.isStringInvalid(title) || GT_Utility.isStringInvalid(author) || pages.length <= 0) { return null; } - final int vMeta = aID; - rStack = (aBook == null ? new ItemStack(ModItems.itemCustomBook, 1, vMeta) : aBook); - final NBTTagCompound tNBT = new NBTTagCompound(); - String localizationTitle = addBookTitleLocalization(aTitle); - tNBT.setString("title", localizationTitle); - tNBT.setString("author", aAuthor); - final NBTTagList tNBTList = new NBTTagList(); - final String[] aLocalizationPages = addBookPagesLocalization(aTitle, aPages); - for (byte i = 0; i < aPages.length; i = (byte) (i + 1)) { - aPages[i] = aLocalizationPages[i].replaceAll("
", "\n"); + + stack = (book == null) ? new ItemStack(ModItems.itemCustomBook, 1, ID) : book; + + NBTTagCompound NBT = new NBTTagCompound(); + String localizationTitle = addBookTitleLocalization(title); + NBT.setString("title", localizationTitle); + NBT.setString("author", author); + + NBTTagList NBTList = new NBTTagList(); + String[] localizationPages = addBookPagesLocalization(title, pages); + + for (byte i = 0; i < pages.length; i++) { + pages[i] = localizationPages[i].replaceAll("
", "\n"); if (i < 48) { - if (aPages[i].length() < 256) { - tNBTList.appendTag(new NBTTagString(aPages[i])); + if (pages[i].length() < 256) { + NBTList.appendTag(new NBTTagString(pages[i])); } else { - Logger.INFO("WARNING: String for written Book too long! -> " + aPages[i]); - GT_Log.err.println( - new StringBuilder().append("WARNING: String for written Book too long! -> ") - .append(aPages[i])); + Logger.INFO("WARNING: String for written Book too long! -> " + pages[i]); + GT_Log.err.println("WARNING: String for written Book too long! -> " + pages[i]); } } else { - Logger.INFO("WARNING: Too much Pages for written Book! -> " + aTitle); - GT_Log.err.println( - new StringBuilder().append("WARNING: Too much Pages for written Book! -> ").append(aTitle)); + Logger.INFO("WARNING: Too much Pages for written Book! -> " + title); + GT_Log.err.println("WARNING: Too much Pages for written Book! -> " + title); break; } } - tNBTList.appendTag( - new NBTTagString( - new StringBuilder().append("Credits to ").append(aAuthor) - .append(" for writing this Book. This was Book Nr. ").append(aID) - .append(" at its creation. Gotta get 'em all!").toString())); - tNBT.setTag("pages", tNBTList); - rStack.setTagCompound(tNBT); - GT_Log.out.println( - new StringBuilder().append("GT++_Mod: Added Book to Book++ List - Mapping: '").append(aMapping) - .append("' - Name: '").append(aTitle).append("' - Author: '").append(aAuthor).append("'")); - NBTUtils.createIntegerTagCompound(rStack, "stats", "mMeta", vMeta); - CORE.sBookList.put(aMapping, rStack); - Logger.INFO("Creating book: " + aTitle + " by " + aAuthor + ". Using Meta " + vMeta + "."); - return GT_Utility.copy(new Object[] { rStack }); - } - public static long getMillisSince(long aStartTime, long aCurrentTime) { - return (aCurrentTime - aStartTime); - } + String credits = String.format( + "Credits to %s for writing this Book. This was Book Nr. %d at its creation. Gotta get 'em all!", + author, + ID); + NBTList.appendTag(new NBTTagString(credits)); + NBT.setTag("pages", NBTList); - public static byte getTier(long l) { - byte i = -1; - do { - ++i; - if (i >= GT_Values.V.length) { - return i; - } - } while (l > GT_Values.V[i]); - i = (byte) MathUtils.getValueWithinRange(i, 0, 15); - return i; + stack.setTagCompound(NBT); + + String logMessage = String.format( + "GT++_Mod: Added Book to Book++ List - Mapping: '%s' - Name: '%s' - Author: '%s'", + mapping, + title, + author); + GT_Log.out.println(logMessage); + + NBTUtils.createIntegerTagCompound(stack, "stats", "mMeta", ID); + CORE.sBookList.put(mapping, stack); + + Logger.INFO(String.format("Creating book: %s by %s. Using Meta %d.", title, author, ID)); + + return GT_Utility.copy(stack); } + } diff --git a/src/main/java/gtPlusPlus/core/util/data/AES.java b/src/main/java/gtPlusPlus/core/util/data/AES.java index 8f9580c760..aeafea7606 100644 --- a/src/main/java/gtPlusPlus/core/util/data/AES.java +++ b/src/main/java/gtPlusPlus/core/util/data/AES.java @@ -13,7 +13,7 @@ import javax.crypto.spec.SecretKeySpec; public class AES { - private final String secret;; + private final String secret; private final SecretKeySpec secretKey; @@ -33,12 +33,12 @@ public class AES { secretKey = generateKey(key); } - private static final String getHashedString(String aString) { + private static String getHashedString(String aString) { return toHexString(getSHA(aString)); } - private static final byte[] getSHA(String input) { + private static byte[] getSHA(String input) { MessageDigest md; @@ -56,7 +56,7 @@ public class AES { return new byte[] {}; } - private static final String toHexString(byte[] hash) { + private static String toHexString(byte[] hash) { BigInteger number = new BigInteger(1, hash); @@ -70,7 +70,7 @@ public class AES { return hexString.toString(); } - private final byte[] getBytes(String aKey) { + private byte[] getBytes(String aKey) { byte[] aKeyData; @@ -98,42 +98,21 @@ public class AES { return aKeyData; - } catch (NoSuchAlgorithmException e) { + } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - - e.printStackTrace(); } } return new byte[] {}; } - private final SecretKeySpec generateKey(byte[] aKey) { + private SecretKeySpec generateKey(byte[] aKey) { return new SecretKeySpec(aKey, "AES"); } - public String encode(String strToEncrypt) { - - try { - - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); - - cipher.init(Cipher.ENCRYPT_MODE, secretKey); - - return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8"))); - - } catch (Exception e) { - - System.out.println("Error while encrypting: " + e.toString()); - } - - return null; - } - public String decode(String strToDecrypt) { try { @@ -144,7 +123,7 @@ public class AES { return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt))); - } catch (Exception e) { + } catch (Exception ignored) { } diff --git a/src/main/java/gtPlusPlus/core/util/data/ArrayUtils.java b/src/main/java/gtPlusPlus/core/util/data/ArrayUtils.java index 57c75640a6..d5ab990917 100644 --- a/src/main/java/gtPlusPlus/core/util/data/ArrayUtils.java +++ b/src/main/java/gtPlusPlus/core/util/data/ArrayUtils.java @@ -3,15 +3,10 @@ package gtPlusPlus.core.util.data; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import net.minecraft.item.ItemStack; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; - public class ArrayUtils { public static V[] insertElementAtIndex(V[] aArray, int aIndex, V aObjectToInsert) { @@ -27,60 +22,17 @@ public class ArrayUtils { } public static Object[] removeNulls(final Object[] v) { - List list = new ArrayList(Arrays.asList(v)); + List list = new ArrayList<>(Arrays.asList(v)); list.removeAll(Collections.singleton((Object) null)); return list.toArray(new Object[list.size()]); } public static ItemStack[] removeNulls(final ItemStack[] v) { - List list = new ArrayList(Arrays.asList(v)); + List list = new ArrayList<>(Arrays.asList(v)); list.removeAll(Collections.singleton((ItemStack) null)); return list.toArray(new ItemStack[list.size()]); } - @SuppressWarnings("unchecked") - public static Set combineSetData(Set S, Set J) { - Set mData = new HashSet(); - T[] array1 = (T[]) S.toArray(); - Collections.addAll(mData, array1); - T[] array2 = (T[]) J.toArray(); - Collections.addAll(mData, array2); - return mData; - } - - public static AutoMap mergeTwoMaps(AutoMap a, AutoMap b) { - AutoMap c = new AutoMap(); - for (A g : a.values()) { - c.put(g); - } - for (A g : b.values()) { - c.put(g); - } - return c; - } - - public static T[][] rotateArrayClockwise(T[][] mat) { - Logger.INFO("Rotating Array 90' Clockwise"); - try { - final int M = mat.length; - final int N = mat[0].length; - Logger.INFO("Dimension X: " + M); - Logger.INFO("Dimension Z: " + N); - @SuppressWarnings("unchecked") - T[][] ret = (T[][]) new Object[N][M]; - for (int r = 0; r < M; r++) { - for (int c = 0; c < N; c++) { - ret[c][M - 1 - r] = mat[r][c]; - } - } - Logger.INFO("Returning Rotated Array"); - return ret; - } catch (Throwable t) { - t.printStackTrace(); - return null; - } - } - public static String toString(Object[] aArray, String string) { return org.apache.commons.lang3.ArrayUtils.toString(aArray, string); } @@ -89,12 +41,4 @@ public class ArrayUtils { return org.apache.commons.lang3.ArrayUtils.toString(aArray); } - public static Object[] getArrayFromArrayList(ArrayList aArrayList) { - Object[] aGenericArray = new Object[aArrayList.size()]; - int aIndex = 0; - for (T object : aArrayList) { - aGenericArray[aIndex++] = object; - } - return aGenericArray; - } } diff --git a/src/main/java/gtPlusPlus/core/util/data/FileUtils.java b/src/main/java/gtPlusPlus/core/util/data/FileUtils.java index cec639a76c..b2e5d04375 100644 --- a/src/main/java/gtPlusPlus/core/util/data/FileUtils.java +++ b/src/main/java/gtPlusPlus/core/util/data/FileUtils.java @@ -74,7 +74,7 @@ public class FileUtils { } } - public static boolean appendListToFile(File file, List content) { + public static void appendListToFile(File file, List content) { try { long oldSize; long newSize; @@ -88,11 +88,9 @@ public class FileUtils { e.printStackTrace(); } newSize = Files.size(p); - return newSize > oldSize; } } - } catch (IOException e) {} - return false; + } catch (IOException ignored) {} } /** @@ -108,7 +106,7 @@ public class FileUtils { try { return org.apache.commons.io.FileUtils.readLines(file, utf8); } catch (IOException e) { - return new ArrayList(); + return new ArrayList<>(); } } } diff --git a/src/main/java/gtPlusPlus/core/util/data/LocaleUtils.java b/src/main/java/gtPlusPlus/core/util/data/LocaleUtils.java index 00170d2f16..237b97e5b0 100644 --- a/src/main/java/gtPlusPlus/core/util/data/LocaleUtils.java +++ b/src/main/java/gtPlusPlus/core/util/data/LocaleUtils.java @@ -20,7 +20,7 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; public class LocaleUtils { - public static boolean generateFakeLocaleFile() { + public static void generateFakeLocaleFile() { for (ModContainer modcontainer : Loader.instance().getModList()) { if (modcontainer.getModId().toLowerCase().equals(GTPlusPlus.ID)) { String S = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; @@ -28,18 +28,16 @@ public class LocaleUtils { dumpItemsAndBlocksForModContainer(modcontainer); } } - return true; } - public static boolean dumpItemsAndBlocksForModContainer(ModContainer mod) { + public static void 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; + if (C instanceof Item R) { ItemStack IS = ItemUtils.getSimpleStack(R); String modid = ItemUtils.getModId(IS); if (modid.equals(GTPlusPlus.ID) || modid.equals(GTPlusPlusEverglades.ID)) { @@ -49,7 +47,7 @@ public class LocaleUtils { } } - } catch (Throwable T) {} + } catch (Throwable ignored) {} } writeToFile("Dumping Blocks from " + mod.getModId() + "."); for (Object B : GameData.getBlockRegistry()) { @@ -57,8 +55,7 @@ public class LocaleUtils { try { if (B != null) { - if (B instanceof Block) { - Block R = (Block) B; + if (B instanceof Block R) { ItemStack IS = ItemUtils.getSimpleStack(R); String modid = ItemUtils.getModId(IS); if (modid.equals(GTPlusPlus.ID) || modid.equals(GTPlusPlusEverglades.ID)) { @@ -68,10 +65,9 @@ public class LocaleUtils { } } - } catch (Throwable T) {} + } catch (Throwable ignored) {} } - return true; } public static void writeToFile(String S) { @@ -82,6 +78,6 @@ public class LocaleUtils { writer.write(S); writer.newLine(); writer.close(); - } catch (IOException e) {} + } catch (IOException ignored) {} } } diff --git a/src/main/java/gtPlusPlus/core/util/data/StringUtils.java b/src/main/java/gtPlusPlus/core/util/data/StringUtils.java index 76cd82b096..91bbdc2eda 100644 --- a/src/main/java/gtPlusPlus/core/util/data/StringUtils.java +++ b/src/main/java/gtPlusPlus/core/util/data/StringUtils.java @@ -80,41 +80,6 @@ public class StringUtils { return false; } - // Can call this Enum for formatting. - public static enum TextUtils { - - 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 TextUtils(final char value) { - this.colourValue = value; - } - - public String colour() { - return getFormatter() + this.colourValue; - } - - private String getFormatter() { - return "\u00A7"; // Returns ยง. - } - } - public static String firstLetterCaps(String data) { String firstLetter = data.substring(0, 1).toUpperCase(); String restLetters = data.substring(1).toLowerCase(); @@ -125,13 +90,13 @@ public class StringUtils { if (parameterTypes == null || parameterTypes.length == 0) { return "empty/null"; } else { - String aData = ""; + StringBuilder aData = new StringBuilder(); for (V y : parameterTypes) { if (y != null) { - aData += ", " + y.toString(); + aData.append(", ").append(y); } } - return aData; + return aData.toString(); } } @@ -142,7 +107,7 @@ public class StringUtils { * @return - Is this a special character? */ public static boolean isSpecialCharacter(char aChar) { - if (aChar == '"' || aChar == '.' + return aChar == '"' || aChar == '.' || aChar == '$' || aChar == '|' || aChar == '(' @@ -155,14 +120,11 @@ public class StringUtils { || aChar == '?' || aChar == '*' || aChar == '+' - || aChar == '\\') { - return true; - } - return false; + || aChar == '\\'; } public static boolean isEscaped(String aString) { - return aString.substring(0, 1).equals("\\"); + return aString.charAt(0) == '\\'; } public static String splitAndUppercase(String aInput, String aDelim) { @@ -185,7 +147,7 @@ public class StringUtils { if (aSplit == null || aSplit.length == 0) { return aInput; } else { - AutoMap aTemp = new AutoMap(); + AutoMap aTemp = new AutoMap<>(); for (String s : aSplit) { Logger.INFO("Found: " + s); s = s.replace(".", ""); @@ -195,35 +157,16 @@ public class StringUtils { aTemp.put(s); } Logger.INFO("Rebuilding"); - String aReturn = ""; + StringBuilder aReturn = new StringBuilder(); for (String s : aTemp) { - aReturn += s; + aReturn.append(s); Logger.INFO("Step: " + aReturn); } - return aReturn; - } - } - - public static int characterCount(String aString, char aChar) { - return characterCount(aString, "" + aChar); - } - - public static int characterCount(String aString, String aChar) { - int aLength = aString.length(); - int aFound = 0; - if (aLength == 0 || !aString.contains(aChar)) { - return 0; - } else { - for (int index = 0; index < aLength; index++) { - if (aString.substring(index, index + 1).equals(aChar)) { - aFound++; - } - } - return aFound; + return aReturn.toString(); } } public static long uppercaseCount(String aString) { - return aString.chars().filter((c) -> Character.isUpperCase(c)).count(); + return aString.chars().filter(Character::isUpperCase).count(); } } diff --git a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java index 5a04502ae8..f73a1e3384 100644 --- a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java +++ b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java @@ -7,7 +7,6 @@ import java.util.Random; import gregtech.api.enums.GT_Values; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; @@ -37,10 +36,6 @@ public class MathUtils { return rand.nextInt((max - min) + 1) + min; } - public static double getChanceOfXOverYRuns(final double x, final double y) { - return (1 - Math.pow((1 - x), y)); - } - /** * Returns a psuedo-random number between min and max, inclusive. The difference between min and max can be at most * Long.MAX_VALUE - 1. @@ -146,7 +141,6 @@ public class MathUtils { /** * Returns a double. The returned number is d rounded to the nearest d.01. Supports Doubles. * - * @param current Current value. * @return double Rounded value. */ public static double decimalRounding(final double d) { @@ -157,7 +151,6 @@ public class MathUtils { /** * Returns a double. The returned number is d rounded to the nearest d.5. Supports Doubles. * - * @param current Current value. * @return double Rounded value. */ public static double decimalRoundingToWholes(final double d) { @@ -168,51 +161,22 @@ public class MathUtils { /** * Returns a integer. The returned number is d rounded to the nearest flat integer. Supports Doubles as input. * - * @param current Current value. * @return integer Rounded value. */ public static int roundToClosestInt(final double d) { return (int) (Math.round(d * 2) / 2.0); } - public static int roundToClosestMultiple(final double number, final int multiple) { - int result = multiple; - if ((number % multiple) == 0) { - return (int) number; - } - // If not already multiple of given number - if ((number % multiple) != 0) { - final int division = (int) ((number / multiple) + 1); - result = division * multiple; - } - return result; - } - // Smooth Rounding Function /** * Returns a long. The returned number is d rounded to the nearest flat long. Supports Doubles as input. * - * @param current Current value. * @return long Rounded value. */ public static long roundToClosestLong(final double d) { return (long) (Math.round(d * 2) / 2.0); } - /** - * Returns a boolean. The returned boolean is wether or not X evenly fits in to Y. Supports ints. - * - * @param x Value A. - * @param y Value B. Must be greater than min. - * @return boolean Whether or not it divides evenly. - */ - public static boolean divideXintoY(final int x, final int y) { - if ((x % y) == 0) { - return true; - } - return false; - } - /** * Returns a boolean. The returned boolean is based on the odd/eveness of the input. Supports ints. * @@ -237,29 +201,6 @@ public class MathUtils { return (int) decimalRoundingToWholes(f); } - /** - * Returns a hexInteger. The returned number is the hex value of the input. Supports ints. - * - * @param input Current value. - * @return hexInteger. - */ - public static int getHexNumberFromInt(final int input) { - final String result = Integer.toHexString(input); - final int resultINT = Integer.getInteger(result); - return resultINT; - } - - /** - * Returns a hexInteger. The returned value is between min and max. Supports ints. - * - * @param min Minimum value. - * @param max Maximium value. Must be greater than min. - * @return hexInteger between min and max, inclusive. - */ - public static int generateRandomHexValue(final int min, final int max) { - return getHexNumberFromInt(randInt(min, max)); - } - /** * Returns a random hex value. The returned value is between 000000-ffffff. * @@ -278,8 +219,6 @@ public class MathUtils { Logger.WARNING("Operating with " + temp); temp = Utils.appenedHexNotationToString(String.valueOf(temp)); - // Logger.WARNING("Made "+temp+" - Hopefully it's not a mess."); - // Logger.WARNING("It will decode into "+Integer.decode(temp)+"."); return Integer.decode(temp); } @@ -316,21 +255,11 @@ public class MathUtils { return result; } - public static final int getRgbAsHex(final short[] RGBA) { + public static int getRgbAsHex(final short[] RGBA) { final int returnValue = Utils.rgbtoHexValue(RGBA[0], RGBA[1], RGBA[2]); return (returnValue == 0) ? 0 : returnValue; } - public static final int returnLargestNumber(final int a, final int b) { - if (a > b) { - return a; - } else if (a == b) { - return a; - } else { - return b; - } - } - public static byte safeByte(long number) { return number > Byte.MAX_VALUE ? Byte.MAX_VALUE : (byte) number; } @@ -389,15 +318,6 @@ public class MathUtils { return getIntAverage(aNewSet); } - public static float getFloatAverage(AutoMap aDataSet) { - float[] aNewSet = new float[aDataSet.size()]; - for (int u = 0; u < aDataSet.size(); u++) { - float b = getSafeFloat(aDataSet.get(u)); - aNewSet[u] = b; - } - return getFloatAverage(aNewSet); - } - public static long getLongAverage(AutoMap aDataSet) { long[] aNewSet = new long[aDataSet.size()]; for (int u = 0; u < aDataSet.size(); u++) { @@ -407,17 +327,8 @@ public class MathUtils { return getLongAverage(aNewSet); } - public static double getDoubleAverage(AutoMap aDataSet) { - double[] aNewSet = new double[aDataSet.size()]; - for (int u = 0; u < aDataSet.size(); u++) { - double b = getSafeDouble(aDataSet.get(u)); - aNewSet[u] = b; - } - return getDoubleAverage(aNewSet); - } - public static byte getByteAverage(byte[] aDataSet) { - if (aDataSet.length <= 0) { + if (aDataSet.length == 0) { return 0; } int divisor = aDataSet.length; @@ -430,7 +341,7 @@ public class MathUtils { } public static short getShortAverage(short[] aDataSet) { - if (aDataSet.length <= 0) { + if (aDataSet.length == 0) { return 0; } int divisor = aDataSet.length; @@ -446,7 +357,7 @@ public class MathUtils { } public static int getIntAverage(int[] aDataSet) { - if (aDataSet.length <= 0) { + if (aDataSet.length == 0) { return 0; } int divisor = aDataSet.length; @@ -458,21 +369,8 @@ public class MathUtils { return result; } - public static float getFloatAverage(float[] aDataSet) { - if (aDataSet.length <= 0) { - return 0; - } - int divisor = aDataSet.length; - float total = 0; - for (float i : aDataSet) { - total += i; - } - float result = (total / divisor); - return result; - } - public static long getLongAverage(long[] aDataSet) { - if (aDataSet.length <= 0) { + if (aDataSet.length == 0) { return 0; } int divisor = aDataSet.length; @@ -480,21 +378,7 @@ public class MathUtils { for (long i : aDataSet) { total += i; } - long result = (total / divisor); - return result; - } - - public static double getDoubleAverage(double[] aDataSet) { - if (aDataSet.length <= 0) { - return 0; - } - int divisor = aDataSet.length; - double total = 0; - for (double i : aDataSet) { - total += i; - } - double result = (total / divisor); - return result; + return (total / divisor); } public static int howManyPlaces(int aValueForGen) { @@ -529,37 +413,37 @@ public class MathUtils { if ((aNumberType.getClass() == byte.class) || (aNumberType instanceof Byte)) { if (a1 >= Byte.MIN_VALUE && a1 <= Byte.MAX_VALUE) { - String s = "" + a1; + String s = String.valueOf(a1); Byte s1 = Byte.valueOf(s); return (V) s1; } } else if ((aNumberType.getClass() == short.class) || (aNumberType instanceof Short)) { if (a1 >= Short.MIN_VALUE && a1 <= Short.MAX_VALUE) { - String s = "" + a1; + String s = String.valueOf(a1); Short s1 = Short.valueOf(s); return (V) s1; } } else if ((aNumberType.getClass() == int.class) || (aNumberType instanceof Integer)) { if (a1 >= Integer.MIN_VALUE && a1 <= Integer.MAX_VALUE) { - String s = "" + a1; + String s = String.valueOf(a1); Integer s1 = Integer.valueOf(s); return (V) s1; } } else if ((aNumberType.getClass() == long.class) || (aNumberType instanceof Long)) { if (a1 >= Long.MIN_VALUE && a1 <= Long.MAX_VALUE) { - String s = "" + a1; + String s = String.valueOf(a1); Long s1 = Long.valueOf(s); return (V) s1; } } else if ((aNumberType.getClass() == float.class) || (aNumberType instanceof Float)) { if (a2 >= Float.MIN_VALUE && a2 <= Float.MAX_VALUE) { - String s = "" + a1; + String s = String.valueOf(a1); Float s1 = Float.valueOf(s); return (V) s1; } } else if ((aNumberType.getClass() == double.class) || (aNumberType instanceof Double)) { if (a2 >= Double.MIN_VALUE && a2 <= Double.MAX_VALUE) { - String s = "" + a1; + String s = String.valueOf(a1); Double s1 = Double.valueOf(s); return (V) s1; } @@ -571,37 +455,22 @@ public class MathUtils { public static byte getSafeByte(Byte b) { Byte a = safeCast(b); - return a.byteValue(); + return a; } public static short getSafeShort(Short b) { Short a = safeCast(b); - return a.shortValue(); + return a; } public static int getSafeInt(Integer b) { Integer a = safeCast(b); - return a.intValue(); + return a; } public static long getSafeLong(Long b) { Long a = safeCast(b); - return a.longValue(); - } - - public static float getSafeFloat(Float b) { - Float a = safeCast(b); - return a.floatValue(); - } - - public static double getSafeDouble(Double b) { - Double a = safeCast(b); - return a.doubleValue(); - } - - public static long safeCast_IntToLong(int o) { - long i = o; - return i; + return a; } public static int safeCast_LongToInt(long o) { @@ -613,34 +482,6 @@ public class MathUtils { } } - public static short safeCast_IntToShort(int o) { - if (o > Short.MAX_VALUE) { - return Short.MAX_VALUE; - } else { - short i = (short) o; - return i; - } - } - - public static int safeCast_ShortToInt(short o) { - int i = (int) o; - return i; - } - - public static byte safeCast_ShortToByte(short o) { - if (o > Byte.MAX_VALUE) { - return Byte.MAX_VALUE; - } else { - byte i = (byte) o; - return i; - } - } - - public static short safeCast_ByteToshort(byte o) { - short i = (short) o; - return i; - } - /** * Balances a number within a range. * @@ -653,54 +494,6 @@ public class MathUtils { return Math.max(Math.min(aInput, aMax), aMin); } - /** - * Balances a number within a range. - * - * @param aInput - The number to balance - * @param aMin - The minimum bounds - * @param aMax - The maximum bounds - * @return - A Number which will be between the bounds, or a boundary value. - */ - public static Number balance(Number aInput, Number aMin, Number aMax) { - return max(min(aInput, aMax), aMin); - } - - /** - * Balances a number within a range. - * - * @param aInput - The number to balance - * @param aMin - The minimum bounds - * @param aMax - The maximum bounds - * @return - An Integer which will be between the bounds, or a boundary value. - */ - public static int balanceInt(Number aInput, Number aMin, Number aMax) { - return MathUtils - .safeCast_LongToInt((long) balance(max(min(aInput, aMax), aMin), Integer.MIN_VALUE, Integer.MAX_VALUE)); - } - - /** - * Balances a number within a range. - * - * @param aInput - The number to balance - * @param aMin - The minimum bounds - * @param aMax - The maximum bounds - * @return - A Long which will be between the bounds, or a boundary value. - */ - public static long balanceLong(Number aInput, Number aMin, Number aMax) { - return (long) balance(max(min(aInput, aMax), aMin), Long.MIN_VALUE, Long.MAX_VALUE); - } - - public static int getValueWithinRange(int i, int aMin, int aMax) { - int aAmount = Math.max(Math.min(i, aMax), aMin); - return aAmount; - } - - public static Pair splitLongIntoIntegers(long aLong) { - int aIntMaxInLong = (int) Math.min(Integer.MAX_VALUE, Math.floor(aLong / Integer.MAX_VALUE)); - int aRemainder = (int) (aLong - (aIntMaxInLong * Integer.MAX_VALUE)); - return new Pair(aIntMaxInLong, aRemainder); - } - /** * Returns the smaller of two {@code Number}s. That is, the result the argument closer to the value of * {@link Long#MIN_VALUE}. If the arguments have the same value, the result is that same value. @@ -725,17 +518,6 @@ public class MathUtils { return (a.longValue() >= b.longValue()) ? a : b; } - public static long combineTwoIntegersToLong(int a, int b) { - long val = (((long) a) << 32) | (b & 0xffffffffL); - return val; - } - - public static int[] splitLongIntoTwoIntegers(long aNum) { - int a = (int) (aNum >> 32); - int b = (int) aNum; - return new int[] { a, b }; - } - public static String formatNumbers(long aNumber) { return sNumberFormat.format(aNumber); } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java index e3219369e8..9ee99fb132 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java @@ -7,68 +7,6 @@ import gtPlusPlus.api.objects.Logger; 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."); @@ -87,4 +25,5 @@ public class EnchantingUtils { return null; } } + } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/EntityUtils.java index e2922ee642..d236b8fbd7 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/EntityUtils.java @@ -1,17 +1,8 @@ package gtPlusPlus.core.util.minecraft; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; - -import net.minecraft.block.Block; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EnumCreatureAttribute; -import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; @@ -19,15 +10,10 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; -import cpw.mods.fml.common.registry.EntityRegistry; import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.minecraft.AABB; import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.handler.events.EntityDeathHandler; -import gtPlusPlus.core.util.reflect