diff options
author | iouter <62897714+iouter@users.noreply.github.com> | 2022-01-07 12:36:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 12:36:06 +0800 |
commit | 0834d4b8b45a881f36ed5b295ac0fb38df49fa9a (patch) | |
tree | 6fb4a45cf17dd22748148417bc7bb0efb850cea3 /src/Java/gtPlusPlus/core/util | |
parent | ea1439a4195c8f77c45625ea2593a232bf19984e (diff) | |
parent | 9b2e050151ad93170e84321d067d1e9d4ded4ba5 (diff) | |
download | GT5-Unofficial-0834d4b8b45a881f36ed5b295ac0fb38df49fa9a.tar.gz GT5-Unofficial-0834d4b8b45a881f36ed5b295ac0fb38df49fa9a.tar.bz2 GT5-Unofficial-0834d4b8b45a881f36ed5b295ac0fb38df49fa9a.zip |
Merge branch 'GTNewHorizons:master' into master
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
51 files changed, 0 insertions, 12587 deletions
diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java deleted file mode 100644 index 81b23e0b1c..0000000000 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ /dev/null @@ -1,946 +0,0 @@ -package gtPlusPlus.core.util; - -import java.awt.Color; -import java.awt.Graphics; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; - -import javax.xml.bind.DatatypeConverter; - -import org.apache.commons.lang3.EnumUtils; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.registry.EntityRegistry; -import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; -import gregtech.GT_Mod; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; -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.api.objects.data.Pair; -import gtPlusPlus.core.item.ModItems; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.lib.LoadedMods; -import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.FluidUtils; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.minecraft.NBTUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import gtPlusPlus.core.util.sys.SystemUtils; -import gtPlusPlus.plugin.villagers.tile.TileEntityGenericSpawner; -import ic2.core.Ic2Items; -import ic2.core.init.InternalName; -import ic2.core.item.resources.ItemCell; -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; -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; - -public class Utils { - - public static final int WILDCARD_VALUE = Short.MAX_VALUE; - - public static final boolean isServer() { - return FMLCommonHandler.instance().getEffectiveSide().isServer(); - } - - public static final 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); - } - - public static TC_AspectStack getTcAspectStack(final String aspect, final long size) { - return getTcAspectStack(aspect, (int) size); - } - - public static TC_AspectStack getTcAspectStack(final TC_Aspects aspect, final int size) { - return getTcAspectStack(aspect.name(), size); - } - - public static TC_AspectStack getTcAspectStack(final String aspect, final int size) { - - TC_AspectStack returnValue = null; - - if (aspect.toUpperCase().equals("COGNITIO")) { - // Adds in Compat for older GT Versions which Misspell aspects. - try { - if (EnumUtils.isValidEnum(TC_Aspects.class, "COGNITIO")) { - Logger.WARNING("TC Aspect found - " + aspect); - returnValue = new TC_AspectStack(TC_Aspects.valueOf("COGNITIO"), size); - } else { - Logger.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 (final NoSuchFieldError r) { - Logger.INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); - } - } else if (aspect.toUpperCase().equals("EXANIMUS")) { - // Adds in Compat for older GT Versions which Misspell aspects. - try { - if (EnumUtils.isValidEnum(TC_Aspects.class, "EXANIMUS")) { - Logger.WARNING("TC Aspect found - " + aspect); - returnValue = new TC_AspectStack(TC_Aspects.valueOf("EXANIMUS"), size); - } else { - Logger.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 (final NoSuchFieldError r) { - Logger.INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); - } - - } else if (aspect.toUpperCase().equals("PRAECANTATIO")) { - // Adds in Compat for older GT Versions which Misspell aspects. - try { - if (EnumUtils.isValidEnum(TC_Aspects.class, "PRAECANTATIO")) { - Logger.WARNING("TC Aspect found - " + aspect); - returnValue = new TC_AspectStack(TC_Aspects.valueOf("PRAECANTATIO"), size); - } else { - Logger.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 (final NoSuchFieldError r) { - Logger.INFO("Invalid Thaumcraft Aspects - Report this issue to Alkalus"); - } - } else { - Logger.WARNING("TC Aspect found - " + aspect); - returnValue = new TC_AspectStack(TC_Aspects.valueOf(aspect), size); - } - - 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)); - } - - // Send a message to all players on the server - public static void sendServerMessage(final IChatComponent chatComponent) { - MinecraftServer.getServer().getConfigurationManager().sendChatMsg(chatComponent); - } - - /** - * Returns if that Liquid is IC2Steam. - */ - public static boolean isIC2Steam(final FluidStack aFluid) { - if (aFluid == null) { - return false; - } - return aFluid.isFluidEqual(getIC2Steam(1)); - } - - /** - * Returns a Liquid Stack with given amount of IC2Steam. - */ - public static FluidStack getIC2Steam(final 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(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<Object> sourceList) { - final Object[] targetArray = sourceList.toArray(new Object[sourceList.size()]); - return targetArray; - } - - public static List<Object> convertArrayToFixedSizeList(final Object[] sourceArray) { - final List<Object> targetList = Arrays.asList(sourceArray); - return targetList; - } - - public static List<Object> convertArrayToList(final Object[] sourceArray) { - final List<Object> targetList = new ArrayList<>(Arrays.asList(sourceArray)); - return targetList; - } - - public static List<Object> convertArrayListToList(final ArrayList<Object> sourceArray) { - final List<Object> targetList = new ArrayList<Object>(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) + "."); - return Integer.decode(temp); - } - - /* - * http://javadevnotes.com/java-left-pad-string-with-zeros-examples - */ - public static String padWithZerosLefts(final String originalString, final int length) { - final StringBuilder sb = new StringBuilder(); - while ((sb.length() + originalString.length()) < length) { - 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<Integer, String> 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<Integer, String> 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; - } - - /* - * Original Code by Chandana Napagoda - - * https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator. - * html - */ - public static Map<Integer, String> hexColourGeneratorRandom(final int colorCount) { - final HashMap<Integer, String> 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()); - Logger.WARNING("" + Integer.toHexString(0x1000000 | i).substring(1).toUpperCase()); - } - return hexColorMap; - } - - 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 = padWithZerosLefts((String) hexAsStringOrInt, 6); - result = temp; - } - result = hexChar + hexAsStringOrInt; - return result; - } else if (hexAsStringOrInt.getClass() == Integer.class || hexAsStringOrInt.getClass() == int.class) { - String aa = String.valueOf(hexAsStringOrInt); - if (aa.length() != 6) { - final String temp = padWithZerosLefts(aa, 6); - result = temp; - } - else { - result = hexChar + String.valueOf(hexAsStringOrInt); - } - return result; - } else { - return null; - } - } - - 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) { - return Minecraft.getMinecraft().mcDataDir; - } - } - return new File("."); - } - - private static short cellID = 15; - - public static ItemStack createInternalNameAndFluidCell(final String s) { - Logger.WARNING("1"); - final InternalName yourName = EnumHelper.addEnum(InternalName.class, s, new Class[0], new Object[0]); - Logger.WARNING("2 " + yourName.name()); - final ItemCell item = (ItemCell) Ic2Items.cell.getItem(); - Logger.WARNING("3 " + item.getUnlocalizedName()); - try { - Logger.WARNING("4"); - final Class<? extends ItemCell> clz = item.getClass(); - Logger.WARNING("5 " + clz.getSimpleName()); - final Method methode = clz.getDeclaredMethod("addCell", int.class, InternalName.class, Block[].class); - Logger.WARNING("6 " + methode.getName()); - methode.setAccessible(true); - Logger.WARNING("7 " + methode.isAccessible()); - final ItemStack temp = (ItemStack) methode.invoke(item, cellID++, yourName, new Block[0]); - Logger.WARNING("Successfully created " + temp.getDisplayName() + "s."); - FluidContainerRegistry.registerFluidContainer(FluidUtils.getFluidStack(s.toLowerCase(), 1000), temp.copy(), - Ic2Items.cell.copy()); - ItemUtils.addItemToOreDictionary(temp.copy(), "cell" + s); - return temp; - } catch (final Exception e) { - e.printStackTrace(); - } - return null; - } - - public static ItemStack createInternalNameAndFluidCellNoOreDict(final String s) { - Logger.WARNING("1"); - final InternalName yourName = EnumHelper.addEnum(InternalName.class, s, new Class[0], new Object[0]); - Logger.WARNING("2 " + yourName.name()); - final ItemCell item = (ItemCell) Ic2Items.cell.getItem(); - Logger.WARNING("3 " + item.getUnlocalizedName()); - try { - Logger.WARNING("4"); - final Class<? extends ItemCell> clz = item.getClass(); - Logger.WARNING("5 " + clz.getSimpleName()); - final Method methode = clz.getDeclaredMethod("addCell", int.class, InternalName.class, Block[].class); - Logger.WARNING("6 " + methode.getName()); - methode.setAccessible(true); - Logger.WARNING("7 " + methode.isAccessible()); - final ItemStack temp = (ItemStack) methode.invoke(item, cellID++, yourName, new Block[0]); - Logger.WARNING("Successfully created " + temp.getDisplayName() + "s."); - FluidContainerRegistry.registerFluidContainer(FluidUtils.getFluidStack(s.toLowerCase(), 1000), temp.copy(), - Ic2Items.cell.copy()); - // ItemUtils.addItemToOreDictionary(temp.copy(), "cell"+s); - return temp; - } catch (final Exception e) { - e.printStackTrace(); - } - return null; - } - - public static String sanitizeString(final String input, final char[] aDontRemove) { - - String output; - AutoMap<String> aToRemoveMap = new AutoMap<String>(); - - 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"); - } - } - } - output = input; - for (String A : aToRemoveMap) { - output = output.replace(A, ""); - } - return output; - - } - - public static String sanitizeString(final String input) { - String temp; - String output; - - temp = input.replace(" ", ""); - temp = temp.replace("-", ""); - temp = temp.replace("_", ""); - temp = temp.replace("?", ""); - temp = temp.replace("!", ""); - temp = temp.replace("@", ""); - temp = temp.replace("#", ""); - temp = temp.replace("(", ""); - temp = temp.replace(")", ""); - temp = temp.replace("{", ""); - temp = temp.replace("}", ""); - temp = temp.replace("[", ""); - temp = temp.replace("]", ""); - temp = temp.replace(" ", ""); - output = temp; - return output; - - } - - public static String sanitizeStringKeepBrackets(final String input) { - String temp; - String output; - - temp = input.replace(" ", ""); - temp = temp.replace("-", ""); - temp = temp.replace("_", ""); - temp = temp.replace("?", ""); - temp = temp.replace("!", ""); - temp = temp.replace("@", ""); - temp = temp.replace("#", ""); - temp = temp.replace(" ", ""); - output = temp; - 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 static ToolMaterial generateToolMaterial(final Material material) { - final String name = material.getLocalizedName(); - final int harvestLevel = material.vHarvestLevel; - final int durability = (int) material.vDurability; - final float damage = material.vToolQuality; - final int efficiency = material.vToolQuality; - // int enchantability = material.mEnchantmentToolsLevel; - Logger.INFO("ToolMaterial stats for " + material.getLocalizedName() + " | harvestLevel:" + harvestLevel - + " | durability:" + durability + " | toolQuality:" + damage + " | toolSpeed:" + damage); - final ToolMaterial temp = EnumHelper.addToolMaterial(name, harvestLevel, durability, efficiency, damage, 0); - return temp; - - } - - public static enum Versioning { - EQUAL(0), NEWER(1), OLDER(-1); - private final int versioningInfo; - - private Versioning(final int versionStatus) { - this.versioningInfo = versionStatus; - } - - public int getTexture() { - return this.versioningInfo; - } - } - - - 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)) { - return null; - } - ItemStack rStack = CORE.sBookList.get(aMapping); - if (rStack != null) { - return GT_Utility.copyAmount(1L, new Object[] { rStack }); - } - if ((GT_Utility.isStringInvalid(aTitle)) || (GT_Utility.isStringInvalid(aAuthor)) || (aPages.length <= 0)) { - return null; - } - final int vMeta = aID; - rStack = (aBook == null ? new ItemStack(ModItems.itemCustomBook, 1, vMeta) : aBook); - final NBTTagCompound tNBT = new NBTTagCompound(); - tNBT.setString("title", GT_LanguageManager.addStringLocalization( - new StringBuilder().append("Book.").append(aTitle).append(".Name").toString(), aTitle)); - tNBT.setString("author", aAuthor); - final NBTTagList tNBTList = new NBTTagList(); - for (byte i = 0; i < aPages.length; i = (byte) (i + 1)) { - aPages[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(), aPages[i]); - if (i < 48) { - if (aPages[i].length() < 256) { - tNBTList.appendTag(new NBTTagString(aPages[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]).toString()); - } - } 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).toString()); - 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("'").toString()); - 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 }); - } - - @SuppressWarnings({ "unused", "unchecked" }) - public static Pair<Integer, Integer> getGregtechVersion(){ - Pair<Integer, Integer> version; - if (GT_Mod.VERSION == 509){ - Class<GT_Mod> clazz; - try { - - if (LoadedMods.BeyondRealityCore) { - //Safely assume it's Beyond Reality running .28-pre (If it's not, tough shit really?) - return new Pair<Integer, Integer>(9, 28); - } - - clazz = (Class<GT_Mod>) ReflectionUtils.getClass("gregtech.GT_Mod"); - Field mSubversion = ReflectionUtils.getField(clazz, "SUBVERSION"); - if (mSubversion != null){ - int mSub = 0; - mSub = mSubversion.getInt(clazz); - if (mSub != 0){ - version = new Pair<Integer, Integer>(9, mSub); - return version; - } - } - } - catch (Throwable t){ - - } - } - //5.08.33 - else if (GT_Mod.VERSION == 508){ - version = new Pair<Integer, Integer>(8, 33); - return version; - - } - //5.07.07 - else if (GT_Mod.VERSION == 507){ - version = new Pair<Integer, Integer>(7, 7); - return version; - - } - //Returb Bad Value - version = new Pair<Integer, Integer>(0, 0); - return version; - } - - public static int getGregtechVersionAsInt(){ - Pair<Integer, Integer> ver = getGregtechVersion(); - return 50000+(ver.getKey()*100)+(ver.getValue()); - } - - public static String getGregtechVersionAsString(){ - Pair<Integer, Integer> ver = getGregtechVersion(); - return "5."+ver.getKey()+"."+ver.getValue(); - } - - public static int getGregtechSubVersion(){ - Pair<Integer, Integer> ver = getGregtechVersion(); - return ver.getValue(); - } - - public static SecureRandom generateSecureRandom(){ - SecureRandom secRan; - String secRanType; - - if (SystemUtils.isWindows()){ - secRanType = "Windows-PRNG"; - } - else { - secRanType = "NativePRNG"; - } - try { - secRan = SecureRandom.getInstance(secRanType); - // Default constructor would have returned insecure SHA1PRNG algorithm, so make an explicit call. - byte[] b = new byte[64] ; - secRan.nextBytes(b); - return secRan; - } - catch (NoSuchAlgorithmException e) { - return null; - } - } - - - public static String calculateChecksumMD5(Object bytes) { - byte[] result = new byte[] {}; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutput out = null; - try { - out = new ObjectOutputStream(bos); - out.writeObject(bytes); - out.flush(); - result = bos.toByteArray(); - } - catch (IOException e) { - } finally { - try { - bos.close(); - } - catch (IOException e) {} - } - return calculateChecksumMD5(result); - } - - public static String calculateChecksumMD5(byte[] bytes) { - MessageDigest md; - try { - md = MessageDigest.getInstance("MD5"); - md.update(bytes); - byte[] digest = md.digest(); - String myHash = DatatypeConverter.printHexBinary(digest).toUpperCase(); - return myHash; - } - catch (NoSuchAlgorithmException e) { - return null; - } - } - - public static boolean createNewMobSpawner(int aID, Entity aEntity) { - if (aEntity instanceof Entity) { - Class c = aEntity.getClass(); - return createNewMobSpawner(aID, c); - } - return false; - } - - public static boolean createNewMobSpawner(int aID, Class aEntity) { - Logger.INFO("[Spawn] Generating new spawner for entity with class ("+aEntity.getSimpleName()+")."); - if (TileEntityGenericSpawner.registerNewMobSpawner(aID, (Class<Entity>) aEntity)) { - EntityRegistration x = EntityRegistry.instance().lookupModSpawn((Class<? extends Entity>) aEntity, true); - if (x != null) { - Logger.INFO("[Spawn] Registration for "+x.getEntityName()+" successful"); - return true; - } - else { - Logger.INFO("[Spawn] Registration for "+aEntity.getSimpleName()+" successful"); - return true; - } - } - Logger.INFO("[Spawn] Mob Spawner creation for "+aEntity.getName()+" failed"); - return false; - } - - public static long getMillisSince(long aStartTime, long aCurrentTime) { - return (aCurrentTime - aStartTime); - } - - public static long getSecondsFromMillis(long aMillis) { - return (aMillis/1000); - } - - public static long getTicksFromSeconds(long aSeconds) { - return (aSeconds*20); - } - - 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; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/data/AES.java b/src/Java/gtPlusPlus/core/util/data/AES.java deleted file mode 100644 index 1183cdd8e7..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/AES.java +++ /dev/null @@ -1 +0,0 @@ -\u0070\u0061\u0063\u006b\u0061\u0067\u0065\u0020\u0067\u0074\u0050\u006c\u0075\u0073\u0050\u006c\u0075\u0073\u002e\u0063\u006f\u0072\u0065\u002e\u0075\u0074\u0069\u006c\u002e\u0064\u0061\u0074\u0061\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0069\u006f\u002e\u0055\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u006d\u0061\u0074\u0068\u002e\u0042\u0069\u0067\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u006e\u0069\u006f\u002e\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u002e\u0053\u0074\u0061\u006e\u0064\u0061\u0072\u0064\u0043\u0068\u0061\u0072\u0073\u0065\u0074\u0073\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0073\u0065\u0063\u0075\u0072\u0069\u0074\u0079\u002e\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u0044\u0069\u0067\u0065\u0073\u0074\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0073\u0065\u0063\u0075\u0072\u0069\u0074\u0079\u002e\u004e\u006f\u0053\u0075\u0063\u0068\u0041\u006c\u0067\u006f\u0072\u0069\u0074\u0068\u006d\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0075\u0074\u0069\u006c\u002e\u0041\u0072\u0072\u0061\u0079\u0073\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0075\u0074\u0069\u006c\u002e\u0042\u0061\u0073\u0065\u0036\u0034\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u0078\u002e\u0063\u0072\u0079\u0070\u0074\u006f\u002e\u0043\u0069\u0070\u0068\u0065\u0072\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u0078\u002e\u0063\u0072\u0079\u0070\u0074\u006f\u002e\u0073\u0070\u0065\u0063\u002e\u0053\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0053\u0070\u0065\u0063\u003b\u000d\u000a\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0041\u0045\u0053\u0020\u007b\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0073\u0065\u0063\u0072\u0065\u0074\u003b\u003b\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0053\u0070\u0065\u0063\u0020\u0073\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u003b\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u006b\u0065\u0079\u003b\u0009\u000d\u000a\u0009\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0041\u0045\u0053\u0028\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0074\u0068\u0069\u0073\u0028\u0022\u0044\u0061\u0072\u006b\u006e\u0065\u0073\u0073\u0020\u0049\u006e\u0020\u0054\u0068\u0065\u0069\u0072\u0020\u0048\u0065\u0061\u0072\u0074\u0073\u0022\u0029\u003b\u0009\u0009\u000d\u000a\u0009\u007d\u0009\u000d\u000a\u0009\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0041\u0045\u0053\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0061\u0053\u0065\u0063\u0072\u0065\u0074\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0073\u0065\u0063\u0072\u0065\u0074\u0020\u003d\u0020\u0061\u0053\u0065\u0063\u0072\u0065\u0074\u003b\u000d\u000a\u0009\u0009\u006b\u0065\u0079\u0020\u003d\u0020\u0067\u0065\u0074\u0042\u0079\u0074\u0065\u0073\u0028\u0067\u0065\u0074\u0048\u0061\u0073\u0068\u0065\u0064\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0073\u0065\u0063\u0072\u0065\u0074\u0029\u0029\u003b\u000d\u000a\u0009\u0009\u0073\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0020\u003d\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u004b\u0065\u0079\u0028\u006b\u0065\u0079\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0067\u0065\u0074\u0048\u0061\u0073\u0068\u0065\u0064\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0061\u0053\u0074\u0072\u0069\u006e\u0067\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0074\u006f\u0048\u0065\u0078\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0067\u0065\u0074\u0053\u0048\u0041\u0028\u0061\u0053\u0074\u0072\u0069\u006e\u0067\u0029\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u0067\u0065\u0074\u0053\u0048\u0041\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0069\u006e\u0070\u0075\u0074\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u0044\u0069\u0067\u0065\u0073\u0074\u0020\u006d\u0064\u003b\u000d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u006d\u0064\u0020\u003d\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u0044\u0069\u0067\u0065\u0073\u0074\u002e\u0067\u0065\u0074\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0028\u0022\u0053\u0048\u0041\u002d\u0032\u0035\u0036\u0022\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006d\u0064\u002e\u0064\u0069\u0067\u0065\u0073\u0074\u0028\u0069\u006e\u0070\u0075\u0074\u002e\u0067\u0065\u0074\u0042\u0079\u0074\u0065\u0073\u0028\u0053\u0074\u0061\u006e\u0064\u0061\u0072\u0064\u0043\u0068\u0061\u0072\u0073\u0065\u0074\u0073\u002e\u0055\u0054\u0046\u005f\u0038\u0029\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u004e\u006f\u0053\u0075\u0063\u0068\u0041\u006c\u0067\u006f\u0072\u0069\u0074\u0068\u006d\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0065\u002e\u0070\u0072\u0069\u006e\u0074\u0053\u0074\u0061\u0063\u006b\u0054\u0072\u0061\u0063\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006e\u0065\u0077\u0020\u0062\u0079\u0074\u0065\u005b\u005d\u007b\u007d\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0074\u006f\u0048\u0065\u0078\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u0068\u0061\u0073\u0068\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0042\u0069\u0067\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0042\u0069\u0067\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0028\u0031\u002c\u0020\u0068\u0061\u0073\u0068\u0029\u003b\u000d\u000a\u0009\u0009\u0053\u0074\u0072\u0069\u006e\u0067\u0042\u0075\u0069\u006c\u0064\u0065\u0072\u0020\u0068\u0065\u0078\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0042\u0075\u0069\u006c\u0064\u0065\u0072\u0028\u006e\u0075\u006d\u0062\u0065\u0072\u002e\u0074\u006f\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0031\u0036\u0029\u0029\u003b\u000d\u000a\u0009\u0009\u0077\u0068\u0069\u006c\u0065\u0020\u0028\u0068\u0065\u0078\u0053\u0074\u0072\u0069\u006e\u0067\u002e\u006c\u0065\u006e\u0067\u0074\u0068\u0028\u0029\u0020\u003c\u0020\u0033\u0032\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0068\u0065\u0078\u0053\u0074\u0072\u0069\u006e\u0067\u002e\u0069\u006e\u0073\u0065\u0072\u0074\u0028\u0030\u002c\u0020\u0027\u0030\u0027\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0068\u0065\u0078\u0053\u0074\u0072\u0069\u006e\u0067\u002e\u0074\u006f\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u0067\u0065\u0074\u0042\u0079\u0074\u0065\u0073\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0061\u004b\u0065\u0079\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u0061\u004b\u0065\u0079\u0044\u0061\u0074\u0061\u003b\u000d\u000a\u0009\u0009\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u0044\u0069\u0067\u0065\u0073\u0074\u0020\u0073\u0068\u0061\u003b\u000d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0073\u0068\u0061\u0020\u003d\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u0044\u0069\u0067\u0065\u0073\u0074\u002e\u0067\u0065\u0074\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0028\u0022\u0053\u0048\u0041\u002d\u0032\u0035\u0036\u0022\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0073\u0068\u0061\u002e\u0064\u0069\u0067\u0065\u0073\u0074\u0028\u0061\u004b\u0065\u0079\u002e\u0067\u0065\u0074\u0042\u0079\u0074\u0065\u0073\u0028\u0053\u0074\u0061\u006e\u0064\u0061\u0072\u0064\u0043\u0068\u0061\u0072\u0073\u0065\u0074\u0073\u002e\u0055\u0054\u0046\u005f\u0038\u0029\u0029\u003b\u0020\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u004e\u006f\u0053\u0075\u0063\u0068\u0041\u006c\u0067\u006f\u0072\u0069\u0074\u0068\u006d\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0031\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0065\u0031\u002e\u0070\u0072\u0069\u006e\u0074\u0053\u0074\u0061\u0063\u006b\u0054\u0072\u0061\u0063\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0009\u0061\u004b\u0065\u0079\u0044\u0061\u0074\u0061\u0020\u003d\u0020\u0061\u004b\u0065\u0079\u002e\u0067\u0065\u0074\u0042\u0079\u0074\u0065\u0073\u0028\u0022\u0055\u0054\u0046\u002d\u0038\u0022\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0009\u0073\u0068\u0061\u0020\u003d\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u0044\u0069\u0067\u0065\u0073\u0074\u002e\u0067\u0065\u0074\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0028\u0022\u0053\u0048\u0041\u002d\u0031\u0022\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0009\u0061\u004b\u0065\u0079\u0044\u0061\u0074\u0061\u0020\u003d\u0020\u0073\u0068\u0061\u002e\u0064\u0069\u0067\u0065\u0073\u0074\u0028\u006b\u0065\u0079\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0009\u0061\u004b\u0065\u0079\u0044\u0061\u0074\u0061\u0020\u003d\u0020\u0041\u0072\u0072\u0061\u0079\u0073\u002e\u0063\u006f\u0070\u0079\u004f\u0066\u0028\u006b\u0065\u0079\u002c\u0020\u0031\u0036\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0061\u004b\u0065\u0079\u0044\u0061\u0074\u0061\u003b\u000d\u000a\u0009\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0009\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u004e\u006f\u0053\u0075\u0063\u0068\u0041\u006c\u0067\u006f\u0072\u0069\u0074\u0068\u006d\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0009\u0065\u002e\u0070\u0072\u0069\u006e\u0074\u0053\u0074\u0061\u0063\u006b\u0054\u0072\u0061\u0063\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0009\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0055\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0009\u0065\u002e\u0070\u0072\u0069\u006e\u0074\u0053\u0074\u0061\u0063\u006b\u0054\u0072\u0061\u0063\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u007d\u0009\u0009\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006e\u0065\u0077\u0020\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u007b\u007d\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u0020\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0053\u0070\u0065\u0063\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u004b\u0065\u0079\u0028\u0062\u0079\u0074\u0065\u005b\u005d\u0020\u0061\u004b\u0065\u0079\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006e\u0065\u0077\u0020\u0053\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0053\u0070\u0065\u0063\u0028\u0061\u004b\u0065\u0079\u002c\u0020\u0022\u0041\u0045\u0053\u0022\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0073\u0074\u0072\u0054\u006f\u0045\u006e\u0063\u0072\u0079\u0070\u0074\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0043\u0069\u0070\u0068\u0065\u0072\u0020\u0063\u0069\u0070\u0068\u0065\u0072\u0020\u003d\u0020\u0043\u0069\u0070\u0068\u0065\u0072\u002e\u0067\u0065\u0074\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0028\u0022\u0041\u0045\u0053\u002f\u0045\u0043\u0042\u002f\u0050\u004b\u0043\u0053\u0035\u0050\u0061\u0064\u0064\u0069\u006e\u0067\u0022\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0063\u0069\u0070\u0068\u0065\u0072\u002e\u0069\u006e\u0069\u0074\u0028\u0043\u0069\u0070\u0068\u0065\u0072\u002e\u0045\u004e\u0043\u0052\u0059\u0050\u0054\u005f\u004d\u004f\u0044\u0045\u002c\u0020\u0073\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0042\u0061\u0073\u0065\u0036\u0034\u002e\u0067\u0065\u0074\u0045\u006e\u0063\u006f\u0064\u0065\u0072\u0028\u0029\u002e\u0065\u006e\u0063\u006f\u0064\u0065\u0054\u006f\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0063\u0069\u0070\u0068\u0065\u0072\u002e\u0064\u006f\u0046\u0069\u006e\u0061\u006c\u0028\u0073\u0074\u0072\u0054\u006f\u0045\u006e\u0063\u0072\u0079\u0070\u0074\u002e\u0067\u0065\u0074\u0042\u0079\u0074\u0065\u0073\u0028\u0022\u0055\u0054\u0046\u002d\u0038\u0022\u0029\u0029\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0022\u0045\u0072\u0072\u006f\u0072\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0065\u006e\u0063\u0072\u0079\u0070\u0074\u0069\u006e\u0067\u003a\u0020\u0022\u0020\u002b\u0020\u0065\u002e\u0074\u006f\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0029\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006e\u0075\u006c\u006c\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0073\u0074\u0072\u0054\u006f\u0044\u0065\u0063\u0072\u0079\u0070\u0074\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0043\u0069\u0070\u0068\u0065\u0072\u0020\u0063\u0069\u0070\u0068\u0065\u0072\u0020\u003d\u0020\u0043\u0069\u0070\u0068\u0065\u0072\u002e\u0067\u0065\u0074\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0028\u0022\u0041\u0045\u0053\u002f\u0045\u0043\u0042\u002f\u0050\u004b\u0043\u0053\u0035\u0050\u0041\u0044\u0044\u0049\u004e\u0047\u0022\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0063\u0069\u0070\u0068\u0065\u0072\u002e\u0069\u006e\u0069\u0074\u0028\u0043\u0069\u0070\u0068\u0065\u0072\u002e\u0044\u0045\u0043\u0052\u0059\u0050\u0054\u005f\u004d\u004f\u0044\u0045\u002c\u0020\u0073\u0065\u0063\u0072\u0065\u0074\u004b\u0065\u0079\u0029\u003b\u000d\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006e\u0065\u0077\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0028\u0063\u0069\u0070\u0068\u0065\u0072\u002e\u0064\u006f\u0046\u0069\u006e\u0061\u006c\u0028\u0042\u0061\u0073\u0065\u0036\u0034\u002e\u0067\u0065\u0074\u0044\u0065\u0063\u006f\u0064\u0065\u0072\u0028\u0029\u002e\u0064\u0065\u0063\u006f\u0064\u0065\u0028\u0073\u0074\u0072\u0054\u006f\u0044\u0065\u0063\u0072\u0079\u0070\u0074\u0029\u0029\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u006e\u0075\u006c\u006c\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u007d
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java b/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java deleted file mode 100644 index c9c8d26744..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java +++ /dev/null @@ -1,109 +0,0 @@ -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 gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public class ArrayUtils { - - public static <V> V[] expandArray(final V[] someArray, final V newValueToAdd) { - V[] series = someArray; - series = addElement(series, newValueToAdd); - return series; - } - - private static <V> V[] addElement(V[] series, final V newValueToAdd) { - series = Arrays.copyOf(series, series.length + 1); - series[series.length - 1] = newValueToAdd; - return series; - } - - /*public static <V> Object getMostCommonElement(List<V> list) { - Optional r = list.stream().map(V::getTextureSet).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); - return r.get(); - }*/ - - - public static Object[] removeNulls(final Object[] v) { - List<Object> list = new ArrayList<Object>(Arrays.asList(v)); - list.removeAll(Collections.singleton((Object)null)); - return list.toArray(new Object[list.size()]); - } - - public static ItemStack[] removeNulls(final ItemStack[] v) { - List<ItemStack> list = new ArrayList<ItemStack>(Arrays.asList(v)); - list.removeAll(Collections.singleton((ItemStack)null)); - return list.toArray(new ItemStack[list.size()]); - } - - @SuppressWarnings("unchecked") - public static <T> Set<T> combineSetData(Set<T> S, Set<T> J) { - Set<T> mData = new HashSet<T>(); - T[] array1 = (T[]) S.toArray(); - Collections.addAll(mData, array1); - T[] array2 = (T[]) J.toArray(); - Collections.addAll(mData, array2); - return mData; - } - - public static <A> AutoMap<A> mergeTwoMaps(AutoMap<A> a, AutoMap<A> b) { - AutoMap<A> c = new AutoMap<A>(); - for (A g : a.values()) { - c.put(g); - } - for (A g : b.values()) { - c.put(g); - } - return c; - } - - public static <T> 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); - } - - public static String toString(Object[] aArray) { - return org.apache.commons.lang3.ArrayUtils.toString(aArray); - } - - public static <T> Object[] getArrayFromArrayList(ArrayList<T> aArrayList) { - Object[] aGenericArray = new Object[aArrayList.size()]; - int aIndex = 0; - for (T object : aArrayList) { - aGenericArray[aIndex++] = object; - } - return aGenericArray; - } - -} - diff --git a/src/Java/gtPlusPlus/core/util/data/EnumUtils.java b/src/Java/gtPlusPlus/core/util/data/EnumUtils.java deleted file mode 100644 index edcc071b54..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/EnumUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -package gtPlusPlus.core.util.data; - -import com.google.common.base.Enums; -import com.google.common.base.Optional; - -public class EnumUtils { - - /** - * Returns the value of an Enum if it exists. - * If value is not found, case-insensitive search will occur. - * If value still not found, an IllegalArgumentException is thrown. - **/ - public static <T extends Enum<T>> T getValue(Class<T> enumeration, String name) { - Optional<T> j = Enums.getIfPresent(enumeration, name); - T VALUE; - if (j == null || !j.isPresent()) { - VALUE = valueOfIgnoreCase(enumeration, name); - } - else { - VALUE = j.get(); - } - return VALUE; - } - - /** - * Finds the value of the given enumeration by name, case-insensitive. - * Throws an IllegalArgumentException if no match is found. - **/ - private static <T extends Enum<T>> T valueOfIgnoreCase(Class<T> enumeration, String name) { - - for (T enumValue : enumeration.getEnumConstants()) { - if (enumValue.name().equalsIgnoreCase(name)) { - return enumValue; - } - } - - throw new IllegalArgumentException(String.format( - "There is no value with name '%s' in Enum %s", - name, enumeration.getName() - )); - } - - public static Object getValue(Class class1, String materialName, boolean bool) { - if (Enum.class.isInstance(class1)){ - return getValue(class1, materialName); - } - return null; - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/data/FileUtils.java b/src/Java/gtPlusPlus/core/util/data/FileUtils.java deleted file mode 100644 index bec5e0eeff..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/FileUtils.java +++ /dev/null @@ -1,118 +0,0 @@ -package gtPlusPlus.core.util.data; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.List; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.Utils; - -public class FileUtils { - - private static final Charset utf8 = StandardCharsets.UTF_8; - - public static boolean doesFileExist(File f) { - if (f != null && f.exists() && !f.isDirectory()) { - return true; - } - return false; - } - - public static File createFile(String path, String filename, String extension) { - File file = new File(Utils.getMcDir(), path + filename + extension); - return createFile(file); - } - - public static File createFile(File aFile) { - boolean blnCreated = false; - Logger.INFO("Trying to use path "+aFile.getPath()); - try { - Logger.INFO("Trying to use path "+aFile.getCanonicalPath()); - Logger.INFO("Trying to use absolute path "+aFile.getAbsolutePath()); - blnCreated = aFile.createNewFile(); - } catch (IOException ioe) { - Logger.INFO("Error while creating a new empty file :" + ioe); - return null; - } - return blnCreated ? aFile : null; - } - - public static File getFile(String filename, String extension) { - return getFile("", filename, extension); - } - - public static File getFile(String path, String filename, String extension) { - if (path == null || path.length() <= 0) { - path = ""; - } - else { - path = path + "/"; - } - if (filename == null || filename.length() <= 0) { - return null; - } - if (extension == null || extension.length() <= 0) { - extension = ".txt"; - } - else { - extension = "." + extension; - } - File file = new File(Utils.getMcDir(), path + filename + extension); - boolean doesExist = doesFileExist(file); - - if (doesExist) { - Logger.INFO("Found File: " + file.getAbsolutePath()); - return file; - } else { - Logger.INFO("Creating file, as it was not found."); - return createFile(path, filename, extension); - } - } - - public static boolean appendListToFile(File file, List<String> content) { - try { - long oldSize; - long newSize; - if (doesFileExist(file)) { - Path p = Paths.get(file.getPath()); - if (p != null && Files.isWritable(p)) { - oldSize = Files.size(p); - try { - Files.write(p, content, utf8, StandardOpenOption.APPEND); - } catch (IOException e) { - e.printStackTrace(); - } - newSize = Files.size(p); - return newSize > oldSize; - } - } - } catch (IOException e) { - } - return false; - } - - /** - * Reads the contents of a file line by line to a List of Strings using the default encoding for the VM. - * The file is always closed. - * - * @param file the file to read, must not be {@code null} - * @return the list of Strings representing each line in the file, never {@code null} - * @throws IOException in case of an I/O error - * @since 1.3 - */ - public static List<String> readLines(File file) { - try { - return org.apache.commons.io.FileUtils.readLines(file, utf8); - } - catch (IOException e) { - return new ArrayList<String>(); - } - } -} diff --git a/src/Java/gtPlusPlus/core/util/data/LocaleUtils.java b/src/Java/gtPlusPlus/core/util/data/LocaleUtils.java deleted file mode 100644 index d1a35a661b..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/LocaleUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -package gtPlusPlus.core.util.data; - -import java.io.*; - -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ModContainer; -import cpw.mods.fml.common.registry.GameData; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.minecraft.ItemUtils; - -public class LocaleUtils { - - public static boolean generateFakeLocaleFile() { - for (ModContainer modcontainer : Loader.instance().getModList()){ - if (modcontainer.getModId().toLowerCase().equals("miscutils")) { - String S = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; - writeToFile(S); - dumpItemsAndBlocksForModContainer(modcontainer); - } - } - return true; - } - - public static boolean dumpItemsAndBlocksForModContainer(ModContainer mod) { - writeToFile("Dumping Items from "+mod.getModId()+"."); - for (Object C : GameData.getItemRegistry()) { - - try { - - if (C != null) { - if (C instanceof Item) { - Item R = (Item) C; - ItemStack IS = ItemUtils.getSimpleStack(R); - String modid = ItemUtils.getModId(IS); - if (modid.equals("miscutils") || modid.equals("ToxicEverglades")) { - String S = "["+modid+"] "+IS.getUnlocalizedName()+".name="; - writeToFile(S); - } - } - } - - } - catch (Throwable T) {} - - } - writeToFile("Dumping Blocks from "+mod.getModId()+"."); - for (Object B : GameData.getBlockRegistry()) { - - try { - - if (B != null) { - if (B instanceof Block) { - Block R = (Block) B; - ItemStack IS = ItemUtils.getSimpleStack(R); - String modid = ItemUtils.getModId(IS); - if (modid.equals("miscutils") || modid.equals("ToxicEverglades")) { - String S = "["+modid+"] "+IS.getUnlocalizedName()+".name="; - writeToFile(S); - } - } - } - - } - catch (Throwable T) {} - - } - - - return true; - } - - public static void writeToFile(String S) { - try { - File F = new File(Utils.getMcDir(), "config/GTplusplus/en_US.lang"); - BufferedWriter writer; - writer = new BufferedWriter(new FileWriter(F, true)); - writer.write(S); - writer.newLine(); - writer.close(); - } - catch (IOException e) {} - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/data/LoggingUtils.java b/src/Java/gtPlusPlus/core/util/data/LoggingUtils.java deleted file mode 100644 index 8415ab32fe..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/LoggingUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package gtPlusPlus.core.util.data; - -import java.io.*; -import java.util.Date; - -public class LoggingUtils { - - public static void profileLog(final Object o) { - try { - String content; - final File file = new File("GregtechTimingsTC.txt"); - // if file doesnt exists, then create it - if (!file.exists()) { - file.createNewFile(); - final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - final BufferedWriter bw = new BufferedWriter(fw); - bw.write("============================================================"); - bw.write(System.lineSeparator()); - bw.close(); - } - if (o instanceof String) { - content = (String) o; - } else { - content = o.toString(); - } - final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - final BufferedWriter bw = new BufferedWriter(fw); - bw.write(content); - bw.write(System.lineSeparator()); - bw.close(); - System.out.println("Data Logged."); - - } catch (final IOException e) { - System.out.println("Data logging failed."); - } - } - - public static boolean logCurrentSystemTime(final String message) { - final Date date = new Date(System.currentTimeMillis()); - try { - profileLog(message + " | " + date.toString()); - return true; - } catch (final Throwable r) { - return false; - } - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/data/StringUtils.java b/src/Java/gtPlusPlus/core/util/data/StringUtils.java deleted file mode 100644 index 2372d04c15..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/StringUtils.java +++ /dev/null @@ -1,219 +0,0 @@ -package gtPlusPlus.core.util.data; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.util.Utils; - -public class StringUtils { - - public static String superscript(String str) { - str = str.replaceAll("0", "\u2070"); - str = str.replaceAll("1", "\u00B9"); - str = str.replaceAll("2", "\u00B2"); - str = str.replaceAll("3", "\u00B3"); - str = str.replaceAll("4", "\u2074"); - str = str.replaceAll("5", "\u2075"); - str = str.replaceAll("6", "\u2076"); - str = str.replaceAll("7", "\u2077"); - str = str.replaceAll("8", "\u2078"); - str = str.replaceAll("9", "\u2079"); - return str; - } - - public static String subscript(String str) { - str = str.replaceAll("0", "\u2080"); - str = str.replaceAll("1", "\u2081"); - str = str.replaceAll("2", "\u2082"); - str = str.replaceAll("3", "\u2083"); - str = str.replaceAll("4", "\u2084"); - str = str.replaceAll("5", "\u2085"); - str = str.replaceAll("6", "\u2086"); - str = str.replaceAll("7", "\u2087"); - str = str.replaceAll("8", "\u2088"); - str = str.replaceAll("9", "\u2089"); - return str; - } - - public static boolean containsSuperOrSubScript(final String s){ - if (s.contains(StringUtils.superscript("0"))) { - return true; - } - else if (s.contains(StringUtils.superscript("1"))) { - return true; - } - else if (s.contains(StringUtils.superscript("2"))) { - return true; - } - else if (s.contains(StringUtils.superscript("3"))) { - return true; - } - else if (s.contains(StringUtils.superscript("4"))) { - return true; - } - else if (s.contains(StringUtils.superscript("5"))) { - return true; - } - else if (s.contains(StringUtils.superscript("6"))) { - return true; - } - else if (s.contains(StringUtils.superscript("7"))) { - return true; - } - else if (s.contains(StringUtils.superscript("8"))) { - return true; - } - else if (s.contains(StringUtils.superscript("9"))) { - return true; - } - if (s.contains(StringUtils.subscript("0"))) { - return true; - } - else if (s.contains(StringUtils.subscript("1"))) { - return true; - } - else if (s.contains(StringUtils.subscript("2"))) { - return true; - } - else if (s.contains(StringUtils.subscript("3"))) { - return true; - } - else if (s.contains(StringUtils.subscript("4"))) { - return true; - } - else if (s.contains(StringUtils.subscript("5"))) { - return true; - } - else if (s.contains(StringUtils.subscript("6"))) { - return true; - } - else if (s.contains(StringUtils.subscript("7"))) { - return true; - } - else if (s.contains(StringUtils.subscript("8"))) { - return true; - } - else if (s.contains(StringUtils.subscript("9"))) { - return true; - } - return false; - } - - //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(); - return firstLetter + restLetters; - } - - public static <V> String getDataStringFromArray(V[] parameterTypes) { - if (parameterTypes == null || parameterTypes.length == 0) { - return "empty/null"; - } - else { - String aData = ""; - for (V y : parameterTypes) { - if (y != null) { - aData += ", "+y.toString(); - } - } - return aData; - } - } - - - - /** - * Is this a special regex character for delimination? (.$|()[]{}^?*+\\) - * @param aChar - The char to test - * @return - Is this a special character? - */ - public static boolean isSpecialCharacter(char aChar) { - if (aChar == '"' || aChar == '.' || aChar == '$' || aChar == '|' || aChar == '(' || aChar == ')' || aChar == '[' - || aChar == ']' || aChar == '{' || aChar == '}' || aChar == '^' || aChar == '?' || aChar == '*' - || aChar == '+' || aChar == '\\') { - return true; - } - return false; - } - - public static boolean isEscaped(String aString) { - return aString.substring(0, 1).equals("\\"); - } - - public static String splitAndUppercase(String aInput, String aDelim) { - - if (!isEscaped(aDelim)) { - boolean isSpecial = false; - for (int o=0;o<aInput.length();o++) { - if (isSpecialCharacter(aInput.charAt(o))) { - isSpecial = true; - } - } - if (isSpecial) { - aDelim = "\\"+aDelim; - } - } - - - Logger.INFO("Splitting "+aInput); - String[] aSplit = aInput.split(aDelim); - Logger.INFO("Split into "+aSplit == null ? ""+0 : aSplit.length+" parts."); - if (aSplit == null || aSplit.length == 0) { - return aInput; - } - else { - AutoMap<String> aTemp = new AutoMap<String>(); - for (String s : aSplit) { - Logger.INFO("Found: "+s); - s = s.replace(".", ""); - s = Utils.sanitizeString(s); - s = firstLetterCaps(s); - Logger.INFO("Formatted & Captilized: "+s); - aTemp.put(s); - } - Logger.INFO("Rebuilding"); - String aReturn = ""; - for (String s : aTemp) { - aReturn += 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; - } - } -} diff --git a/src/Java/gtPlusPlus/core/util/data/UUIDUtils.java b/src/Java/gtPlusPlus/core/util/data/UUIDUtils.java deleted file mode 100644 index d6b32314b1..0000000000 --- a/src/Java/gtPlusPlus/core/util/data/UUIDUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package gtPlusPlus.core.util.data; - -import java.nio.ByteBuffer; -import java.util.UUID; - -public class UUIDUtils { - - //UUID Methods below created by https://gist.github.com/jeffjohnson9046 - //https://gist.github.com/jeffjohnson9046/c663dd22bbe6bb0b3f5e - - public static byte[] getBytesFromUUID(UUID uuid) { - ByteBuffer bb = ByteBuffer.wrap(new byte[16]); - bb.putLong(uuid.getMostSignificantBits()); - bb.putLong(uuid.getLeastSignificantBits()); - return bb.array(); - } - - public static UUID getUUIDFromBytes(byte[] bytes) { - ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - Long high = byteBuffer.getLong(); - Long low = byteBuffer.getLong(); - return new UUID(high, low); - } - -} diff --git a/src/Java/gtPlusPlus/core/util/debug/DEBUG_INIT.java b/src/Java/gtPlusPlus/core/util/debug/DEBUG_INIT.java deleted file mode 100644 index f8fc15c778..0000000000 --- a/src/Java/gtPlusPlus/core/util/debug/DEBUG_INIT.java +++ /dev/null @@ -1,37 +0,0 @@ -package gtPlusPlus.core.util.debug; - -import gtPlusPlus.preloader.CORE_Preloader; - -public class DEBUG_INIT { - - public static void registerBlocks(){ - //Debug Loading - if (CORE_Preloader.DEBUG_MODE){ - - } - } - - public static void registerItems(){ - /*ModItems.itemDebugShapeSpawner = new DEBUG_ITEM_ShapeSpawner("itemDebugShapeSpawner", AddToCreativeTab.tabMisc, 1, 500); - GameRegistry.registerItem(ModItems.itemDebugShapeSpawner, "itemDebugShapeSpawner"); - ModItems.itemBedLocator_Base = new BedLocator_Base("itemBedLocator_Base"); - GameRegistry.registerItem(ModItems.itemBedLocator_Base, "itemBedLocator_Base"); - ModItems.itemBaseItemWithCharge = new BaseItemWithCharge("itemBaseItemWithCharge", 0, 1000); - GameRegistry.registerItem(ModItems.itemBaseItemWithCharge, "itemBaseItemWithCharge");*/ - } - - public static void registerTEs(){ - - } - - public static void registerMisc(){ - - - - } - - public static void registerHandlers(){ - //MinecraftForge.EVENT_BUS.register(new DEBUG_ScreenOverlay()); - } - -} diff --git a/src/Java/gtPlusPlus/core/util/debug/DEBUG_ITEM_ShapeSpawner.java b/src/Java/gtPlusPlus/core/util/debug/DEBUG_ITEM_ShapeSpawner.java deleted file mode 100644 index d1e65afe3e..0000000000 --- a/src/Java/gtPlusPlus/core/util/debug/DEBUG_ITEM_ShapeSpawner.java +++ /dev/null @@ -1,58 +0,0 @@ -package gtPlusPlus.core.util.debug; - -import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK; - -import java.util.List; - -import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.creative.AddToCreativeTab; -import gtPlusPlus.core.item.base.BaseItemGeneric; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; - -public class DEBUG_ITEM_ShapeSpawner extends BaseItemGeneric{ - - public DEBUG_ITEM_ShapeSpawner(String s, CreativeTabs c, int stackSize, int maxDmg) { - super(s, c, stackSize, maxDmg); - s = "itemDebugShapeSpawner"; - c = AddToCreativeTab.tabMisc; - stackSize = 1; - maxDmg = 500; - } - - @Override - public ItemStack onItemRightClick(final ItemStack stack, final World world, final EntityPlayer player){ - - if (!world.isRemote){ - Logger.INFO("Constructing the shape for the "+"VACUUM FREEZER"); - final Thread thread = new Thread(new DEBUG_TimerThread(world, player)); - thread.start(); - } - return stack; - } - - - - @SubscribeEvent - public void playerInteractEventHandler(final PlayerInteractEvent event) - { - if (event.isCanceled() || event.world.isRemote || (event.action != RIGHT_CLICK_BLOCK)) { - return; - } - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { - list.add(EnumChatFormatting.GOLD+"For Testing Gregtech Shapes!"); - super.addInformation(stack, aPlayer, list, bool); - } - -} diff --git a/src/Java/gtPlusPlus/core/util/debug/DEBUG_MULTIBLOCK_ShapeSpawner.java b/src/Java/gtPlusPlus/core/util/debug/DEBUG_MULTIBLOCK_ShapeSpawner.java deleted file mode 100644 index 2e46b171f9..0000000000 --- a/src/Java/gtPlusPlus/core/util/debug/DEBUG_MULTIBLOCK_ShapeSpawner.java +++ /dev/null @@ -1,918 +0,0 @@ -package gtPlusPlus.core.util.debug; - -import static gregtech.api.enums.GT_Values.V; - -import java.util.ArrayList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import gregtech.GT_Mod; -import gregtech.api.GregTech_API; -import gregtech.api.enums.ConfigCategories; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.gui.GT_Container_MultiMachine; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.items.GT_MetaGenerated_Tool; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.*; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; -import gregtech.api.util.GT_Utility; -import gregtech.common.items.GT_MetaGenerated_Tool_01; - -import net.minecraftforge.fluids.FluidStack; - -public abstract class DEBUG_MULTIBLOCK_ShapeSpawner extends MetaTileEntity { - - public static boolean disableMaintenance; - public boolean mMachine = false, mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mRunningOnLoad = false; - public int mPollution = 0, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mEfficiencyIncrease = 0, mUpdate = 0, mStartUpCheck = 100, mRuntime = 0, mEfficiency = 0; - public ItemStack[] mOutputItems = null; - public FluidStack[] mOutputFluids = null; - public ArrayList<GT_MetaTileEntity_Hatch_Input> mInputHatches = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_Output> mOutputHatches = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_InputBus> mInputBusses = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_OutputBus> mOutputBusses = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_Dynamo> mDynamoHatches = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_Muffler> mMufflerHatches = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_Energy> mEnergyHatches = new ArrayList<>(); - public ArrayList<GT_MetaTileEntity_Hatch_Maintenance> mMaintenanceHatches = new ArrayList<>(); - - public DEBUG_MULTIBLOCK_ShapeSpawner(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional, 2); - DEBUG_MULTIBLOCK_ShapeSpawner.disableMaintenance = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "MultiBlockMachines.disableMaintenance", false); - } - - public DEBUG_MULTIBLOCK_ShapeSpawner(final String aName) { - super(aName, 2); - DEBUG_MULTIBLOCK_ShapeSpawner.disableMaintenance = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "MultiBlockMachines.disableMaintenance", false); - } - - public static boolean isValidMetaTileEntity(final MetaTileEntity aMetaTileEntity) { - return (aMetaTileEntity.getBaseMetaTileEntity() != null) && (aMetaTileEntity.getBaseMetaTileEntity().getMetaTileEntity() == aMetaTileEntity) && !aMetaTileEntity.getBaseMetaTileEntity().isDead(); - } - - @Override - public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aCoverID) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex > 0; - } - - @Override - public int getProgresstime() { - return this.mProgresstime; - } - - @Override - public int maxProgresstime() { - return this.mMaxProgresstime; - } - - @Override - public int increaseProgress(final int aProgress) { - return aProgress; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mEUt", this.mEUt); - aNBT.setInteger("mProgresstime", this.mProgresstime); - aNBT.setInteger("mMaxProgresstime", this.mMaxProgresstime); - aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); - aNBT.setInteger("mEfficiency", this.mEfficiency); - aNBT.setInteger("mPollution", this.mPollution); - aNBT.setInteger("mRuntime", this.mRuntime); - - if (this.mOutputItems != null) { - for (int i = 0; i < this.mOutputItems.length; i++) { - if (this.mOutputItems[i] != null) { - final NBTTagCompound tNBT = new NBTTagCompound(); - this.mOutputItems[i].writeToNBT(tNBT); - aNBT.setTag("mOutputItem" + i, tNBT); - } - } - } - if (this.mOutputFluids != null) { - for (int i = 0; i < this.mOutputFluids.length; i++) { - if (this.mOutputFluids[i] != null) { - final NBTTagCompound tNBT = new NBTTagCompound(); - this.mOutputFluids[i].writeToNBT(tNBT); - aNBT.setTag("mOutputFluids" + i, tNBT); - } - } - } - - aNBT.setBoolean("mWrench", this.mWrench); - aNBT.setBoolean("mScrewdriver", this.mScrewdriver); - aNBT.setBoolean("mSoftHammer", this.mSoftHammer); - aNBT.setBoolean("mHardHammer", this.mHardHammer); - aNBT.setBoolean("mSolderingTool", this.mSolderingTool); - aNBT.setBoolean("mCrowbar", this.mCrowbar); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mEUt = aNBT.getInteger("mEUt"); - this.mProgresstime = aNBT.getInteger("mProgresstime"); - this.mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); - if (this.mMaxProgresstime > 0) { - this.mRunningOnLoad = true; - } - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mEfficiency = aNBT.getInteger("mEfficiency"); - this.mPollution = aNBT.getInteger("mPollution"); - this.mRuntime = aNBT.getInteger("mRuntime"); - this.mOutputItems = new ItemStack[this.getAmountOfOutputs()]; - for (int i = 0; i < this.mOutputItems.length; i++) { - this.mOutputItems[i] = GT_Utility.loadItem(aNBT, "mOutputItem" + i); - } - this.mOutputFluids = new FluidStack[this.getAmountOfOutputs()]; - for (int i = 0; i < this.mOutputFluids.length; i++) { - this.mOutputFluids[i] = GT_Utility.loadFluid(aNBT, "mOutputFluids" + i); - } - this.mWrench = aNBT.getBoolean("mWrench"); - this.mScrewdriver = aNBT.getBoolean("mScrewdriver"); - this.mSoftHammer = aNBT.getBoolean("mSoftHammer"); - this.mHardHammer = aNBT.getBoolean("mHardHammer"); - this.mSolderingTool = aNBT.getBoolean("mSolderingTool"); - this.mCrowbar = aNBT.getBoolean("mCrowbar"); - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); - } - - @Override - public byte getTileEntityBaseType() { - return 2; - } - - @Override - public void onMachineBlockUpdate() { - this.mUpdate = 50; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mEfficiency < 0) { - this.mEfficiency = 0; - } - if ((--this.mUpdate == 0) || (--this.mStartUpCheck == 0)) { - this.mInputHatches.clear(); - this.mInputBusses.clear(); - this.mOutputHatches.clear(); - this.mOutputBusses.clear(); - this.mDynamoHatches.clear(); - this.mEnergyHatches.clear(); - this.mMufflerHatches.clear(); - this.mMaintenanceHatches.clear(); - this.mMachine = this.checkMachine(aBaseMetaTileEntity, this.mInventory[1]); - } - if (this.mStartUpCheck < 0) { - if (this.mMachine) { - for (final GT_MetaTileEntity_Hatch_Maintenance tHatch : this.mMaintenanceHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (!DEBUG_MULTIBLOCK_ShapeSpawner.disableMaintenance) { - if (tHatch.mWrench) { - this.mWrench = true; - } - if (tHatch.mScrewdriver) { - this.mScrewdriver = true; - } - if (tHatch.mSoftHammer) { - this.mSoftHammer = true; - } - if (tHatch.mHardHammer) { - this.mHardHammer = true; - } - if (tHatch.mSolderingTool) { - this.mSolderingTool = true; - } - if (tHatch.mCrowbar) { - this.mCrowbar = true; - } - } else { - this.mWrench = true; - this.mScrewdriver = true; - this.mSoftHammer = true; - this.mHardHammer = true; - this.mSolderingTool = true; - this.mCrowbar = true; - } - - tHatch.mWrench = false; - tHatch.mScrewdriver = false; - tHatch.mSoftHammer = false; - tHatch.mHardHammer = false; - tHatch.mSolderingTool = false; - tHatch.mCrowbar = false; - } - } - if (this.getRepairStatus() > 0) { - if ((this.mMaxProgresstime > 0) && this.doRandomMaintenanceDamage()) { - if (this.onRunningTick(this.mInventory[1])) { - if (!this.polluteEnvironment(this.getPollutionPerTick(this.mInventory[1]))) { - this.stopMachine(); - } - if ((this.mMaxProgresstime > 0) && (++this.mProgresstime >= this.mMaxProgresstime)) { - if (this.mOutputItems != null) { - for (final ItemStack tStack : this.mOutputItems) { - if (tStack != null) { - try { - GT_Mod.achievements.issueAchivementHatch(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), tStack); - } catch (final Exception e) { - } - this.addOutput(tStack); - } - } - } - if ((this.mOutputFluids != null) && (this.mOutputFluids.length == 1)) { - for (final FluidStack tStack : this.mOutputFluids) { - if (tStack != null) { - this.addOutput(tStack); - } - } - } else if ((this.mOutputFluids != null) && (this.mOutputFluids.length > 1)) { - this.addFluidOutputs(this.mOutputFluids); - } - this.mEfficiency = Math.max(0, Math.min(this.mEfficiency + this.mEfficiencyIncrease, this.getMaxEfficiency(this.mInventory[1]) - ((this.getIdealStatus() - this.getRepairStatus()) * 1000))); - this.mOutputItems = null; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - this.mEfficiencyIncrease = 0; - if (aBaseMetaTileEntity.isAllowedToWork()) { - this.checkRecipe(this.mInventory[1]); - } - if ((this.mOutputFluids != null) && (this.mOutputFluids.length > 0)) { - if (this.mOutputFluids.length > 1) { - GT_Mod.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "oilplant"); - } - } - } - } - } else { - if (((aTick % 100) == 0) || aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified()) { - - if (aBaseMetaTileEntity.isAllowedToWork()) { - this.checkRecipe(this.mInventory[1]); - } - if (this.mMaxProgresstime <= 0) { - this.mEfficiency = Math.max(0, this.mEfficiency - 1000); - } - } - } - } else { - this.stopMachine(); - } - } else { - this.stopMachine(); - } - } - aBaseMetaTileEntity.setErrorDisplayID((aBaseMetaTileEntity.getErrorDisplayID() & ~127) | (this.mWrench ? 0 : 1) | (this.mScrewdriver ? 0 : 2) | (this.mSoftHammer ? 0 : 4) | (this.mHardHammer ? 0 : 8) | (this.mSolderingTool ? 0 : 16) | (this.mCrowbar ? 0 : 32) | (this.mMachine ? 0 : 64)); - aBaseMetaTileEntity.setActive(this.mMaxProgresstime > 0); - } - } - - public boolean polluteEnvironment(final int aPollutionLevel) { - this.mPollution += aPollutionLevel; - for (final GT_MetaTileEntity_Hatch_Muffler tHatch : this.mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (this.mPollution >= 10000) { - if (tHatch.polluteEnvironment()) { - this.mPollution -= 10000; - } - } else { - break; - } - } - } - return this.mPollution < 10000; - } - - /** - * Called every tick the Machine runs - */ - public boolean onRunningTick(final ItemStack aStack) { - if (this.mEUt > 0) { - this.addEnergyOutput(((long) this.mEUt * this.mEfficiency) / 10000); - return true; - } - if (this.mEUt < 0) { - if (!this.drainEnergyInput(((long) -this.mEUt * 10000) / Math.max(1000, this.mEfficiency))) { - this.stopMachine(); - return false; - } - } - return true; - } - - /** - * Checks if this is a Correct Machine Part for this kind of Machine (Turbine Rotor for example) - */ - public abstract boolean isCorrectMachinePart(ItemStack aStack); - - /** - * Checks the Recipe - */ - public abstract boolean checkRecipe(ItemStack aStack); - - /** - * Checks the Machine. You have to assign the MetaTileEntities for the Hatches here. - */ - public abstract boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack); - - /** - * Gets the maximum Efficiency that spare Part can get (0 - 10000) - */ - public abstract int getMaxEfficiency(ItemStack aStack); - - /** - * Gets the pollution this Device outputs to a Muffler per tick (10000 = one Pullution Block) - */ - public abstract int getPollutionPerTick(ItemStack aStack); - - /** - * Gets the damage to the ItemStack, usually 0 or 1. - */ - public abstract int getDamageToComponent(ItemStack aStack); - - /** - * Gets the Amount of possibly outputted Items for loading the Output Stack Array from NBT. - * This should be the largest Amount that can ever happen legitimately. - */ - public abstract int getAmountOfOutputs(); - - /** - * If it explodes when the Component has to be replaced. - */ - public abstract boolean explodesOnComponentBreak(ItemStack aStack); - - public void stopMachine() { - this.mOutputItems = null; - this.mEUt = 0; - this.mEfficiency = 0; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - this.mEfficiencyIncrease = 0; - this.getBaseMetaTileEntity().disableWorking(); - } - - public int getRepairStatus() { - return (this.mWrench ? 1 : 0) + (this.mScrewdriver ? 1 : 0) + (this.mSoftHammer ? 1 : 0) + (this.mHardHammer ? 1 : 0) + (this.mSolderingTool ? 1 : 0) + (this.mCrowbar ? 1 : 0); - } - - public int getIdealStatus() { - return 6; - } - - public boolean doRandomMaintenanceDamage() { - if (!this.isCorrectMachinePart(this.mInventory[1]) || (this.getRepairStatus() == 0)) { - this.stopMachine(); - return false; - } - if (this.mRuntime++ > 1000) { - this.mRuntime = 0; - if (this.getBaseMetaTileEntity().getRandomNumber(6000) == 0) { - switch (this.getBaseMetaTileEntity().getRandomNumber(6)) { - case 0: - this.mWrench = false; - break; - case 1: - this.mScrewdriver = false; - break; - case 2: - this.mSoftHammer = false; - break; - case 3: - this.mHardHammer = false; - break; - case 4: - this.mSolderingTool = false; - break; - case 5: - this.mCrowbar = false; - break; - } - } - if ((this.mInventory[1] != null) && (this.getBaseMetaTileEntity().getRandomNumber(2) == 0) && !this.mInventory[1].getUnlocalizedName().startsWith("gt.blockmachines.basicmachine.")) { - if (this.mInventory[1].getItem() instanceof GT_MetaGenerated_Tool_01) { - final NBTTagCompound tNBT = this.mInventory[1].getTagCompound(); - if (tNBT != null) { - NBTTagCompound tNBT2 = tNBT.getCompoundTag("GT.CraftingComponents"); - if (!tNBT.getBoolean("mDis")) { - tNBT2 = new NBTTagCompound(); - final Materials tMaterial = GT_MetaGenerated_Tool.getPrimaryMaterial(this.mInventory[1]); - final ItemStack tTurbine = GT_OreDictUnificator.get(OrePrefixes.turbineBlade, tMaterial, 1); - final int i = this.mInventory[1].getItemDamage(); - if (i == 170) { - ItemStack tStack = GT_Utility.copyAmount(1, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Magnalium, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } else if (i == 172) { - ItemStack tStack = GT_Utility.copyAmount(1, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.5", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.6", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.7", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.8", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Titanium, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } else if (i == 174) { - ItemStack tStack = GT_Utility.copyAmount(2, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.5", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.6", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.TungstenSteel, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } else if (i == 176) { - ItemStack tStack = GT_Utility.copyAmount(2, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.5", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.6", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.7", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.8", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Americium, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } - tNBT.setTag("GT.CraftingComponents", tNBT2); - tNBT.setBoolean("mDis", true); - this.mInventory[1].setTagCompound(tNBT); - - } - } - - ((GT_MetaGenerated_Tool) this.mInventory[1].getItem()).doDamage(this.mInventory[1], (long) Math.min(this.mEUt / 5, Math.pow(this.mEUt, 0.7))); - if (this.mInventory[1].stackSize == 0) { - this.mInventory[1] = null; - } - } - } - } - return true; - } - - public void explodeMultiblock() { - this.mInventory[1] = null; - for (final MetaTileEntity tTileEntity : this.mInputBusses) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mOutputBusses) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mInputHatches) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mOutputHatches) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mDynamoHatches) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mMufflerHatches) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mEnergyHatches) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - for (final MetaTileEntity tTileEntity : this.mMaintenanceHatches) { - tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); - } - this.getBaseMetaTileEntity().doExplosion(V[8]); - } - - public boolean addEnergyOutput(final long aEU) { - if (aEU <= 0) { - return true; - } - for (final GT_MetaTileEntity_Hatch_Dynamo tHatch : this.mDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (tHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(aEU, false)) { - return true; - } - } - } - return false; - } - - public long getMaxInputVoltage() { - long rVoltage = 0; - for (final GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - rVoltage += tHatch.getBaseMetaTileEntity().getInputVoltage(); - } - } - return rVoltage; - } - - public boolean drainEnergyInput(final long aEU) { - if (aEU <= 0) { - return true; - } - for (final GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(aEU, false)) { - return true; - } - } - } - return false; - } - - public boolean addOutput(final FluidStack aLiquid) { - if (aLiquid == null) { - return false; - } - final FluidStack tLiquid = aLiquid.copy(); - for (final GT_MetaTileEntity_Hatch_Output tHatch : this.mOutputHatches) { - if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? tHatch.outputsSteam() : tHatch.outputsLiquids()) { - final int tAmount = tHatch.fill(tLiquid, false); - if (tAmount >= tLiquid.amount) { - return tHatch.fill(tLiquid, true) >= tLiquid.amount; - } else if (tAmount > 0) { - tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true); - } - } - } - return false; - } - - private void addFluidOutputs(final FluidStack[] mOutputFluids2) { - for (int i = 0; i < mOutputFluids2.length; i++) { - if ((this.mOutputHatches.size() > i) && (this.mOutputHatches.get(i) != null) && (mOutputFluids2[i] != null) && isValidMetaTileEntity(this.mOutputHatches.get(i))) { - this.mOutputHatches.get(i).fill(mOutputFluids2[i], true); - } - } - - } - - public boolean depleteInput(final FluidStack aLiquid) { - if (aLiquid == null) { - return false; - } - for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { - tHatch.mRecipeMap = this.getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - FluidStack tLiquid = tHatch.getFluid(); - if ((tLiquid != null) && tLiquid.isFluidEqual(aLiquid)) { - tLiquid = tHatch.drain(aLiquid.amount, false); - if ((tLiquid != null) && (tLiquid.amount >= aLiquid.amount)) { - tLiquid = tHatch.drain(aLiquid.amount, true); - return (tLiquid != null) && (tLiquid.amount >= aLiquid.amount); - } - } - } - } - return false; - } - - public boolean addOutput(ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack)) { - return false; - } - aStack = GT_Utility.copy(aStack); - // FluidStack aLiquid = GT_Utility.getFluidForFilledItem(aStack, true); - // if (aLiquid == null) { - for (final GT_MetaTileEntity_Hatch_OutputBus tHatch : this.mOutputBusses) { - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getSizeInventory() - 1; i >= 0; i--) { - if (tHatch.getBaseMetaTileEntity().addStackToSlot(i, aStack)) { - return true; - } - } - } - } - for (final GT_MetaTileEntity_Hatch_Output tHatch : this.mOutputHatches) { - if (isValidMetaTileEntity(tHatch) && tHatch.outputsItems()) { - if (tHatch.getBaseMetaTileEntity().addStackToSlot(1, aStack)) { - return true; - } - } - } - // }else { - // for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { - // if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid)?tHatch.outputsSteam():tHatch.outputsLiquids()) { - // int tAmount = tHatch.fill(aLiquid, false); - // if (tAmount >= aLiquid.amount) { - // return tHatch.fill(aLiquid, true) >= aLiquid.amount; - // } - // } - // } - // } - return false; - } - - public boolean depleteInput(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack)) { - return false; - } - final FluidStack aLiquid = GT_Utility.getFluidForFilledItem(aStack, true); - if (aLiquid != null) { - return this.depleteInput(aLiquid); - } - for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { - tHatch.mRecipeMap = this.getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(0))) { - if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { - tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); - return true; - } - } - } - } - for (final GT_MetaTileEntity_Hatch_InputBus tHatch : this.mInputBusses) { - tHatch.mRecipeMap = this.getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(i))) { - if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { - tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); - return true; - } - } - } - } - } - return false; - } - - public ArrayList<ItemStack> getStoredOutputs() { - final ArrayList<ItemStack> rList = new ArrayList<>(); - for (final GT_MetaTileEntity_Hatch_Output tHatch : this.mOutputHatches) { - if (isValidMetaTileEntity(tHatch)) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(1)); - } - } - for (final GT_MetaTileEntity_Hatch_OutputBus tHatch : this.mOutputBusses) { - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - } - return rList; - } - - public ArrayList<FluidStack> getStoredFluids() { - final ArrayList<FluidStack> rList = new ArrayList<>(); - for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { - tHatch.mRecipeMap = this.getRecipeMap(); - if (isValidMetaTileEntity(tHatch) && (tHatch.getFillableStack() != null)) { - rList.add(tHatch.getFillableStack()); - } - } - return rList; - } - - public ArrayList<ItemStack> getStoredInputs() { - final ArrayList<ItemStack> rList = new ArrayList<>(); - for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { - tHatch.mRecipeMap = this.getRecipeMap(); - if (isValidMetaTileEntity(tHatch) && (tHatch.getBaseMetaTileEntity().getStackInSlot(0) != null)) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(0)); - } - } - for (final GT_MetaTileEntity_Hatch_InputBus tHatch : this.mInputBusses) { - tHatch.mRecipeMap = this.getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - } - } - return rList; - } - - public GT_Recipe_Map getRecipeMap() { - return null; - } - - public void updateSlots() { - for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { - if (isValidMetaTileEntity(tHatch)) { - tHatch.updateSlots(); - } - } - for (final GT_MetaTileEntity_Hatch_InputBus tHatch : this.mInputBusses) { - if (isValidMetaTileEntity(tHatch)) { - tHatch.updateSlots(); - } - } - } - - public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { - return this.mInputHatches.add((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { - return this.mInputBusses.add((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { - return this.mOutputHatches.add((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { - return this.mOutputBusses.add((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { - return this.mEnergyHatches.add((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { - return this.mDynamoHatches.add((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { - return this.mMaintenanceHatches.add((GT_MetaTileEntity_Hatch_Maintenance) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { - return this.mMufflerHatches.add((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity); - } - return false; - } - - public boolean addMaintenanceToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - return this.mMaintenanceHatches.add((GT_MetaTileEntity_Hatch_Maintenance) aMetaTileEntity); - } - return false; - } - - public boolean addEnergyInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - return this.mEnergyHatches.add((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity); - } - return false; - } - - public boolean addDynamoToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - return this.mDynamoHatches.add((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity); - } - return false; - } - - public boolean addMufflerToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - return this.mMufflerHatches.add((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity); - } - return false; - } - - public boolean addInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = this.getRecipeMap(); - return this.mInputHatches.add((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = this.getRecipeMap(); - return this.mInputBusses.add((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity); - } - return false; - } - - public boolean addOutputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - return this.mOutputHatches.add((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity); - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - return this.mOutputBusses.add((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity); - } - return false; - } - - @Override - public String[] getInfoData() { - return new String[]{"Progress:", (this.mProgresstime / 20) + "secs", (this.mMaxProgresstime / 20) + "secs", "Efficiency:", (this.mEfficiency / 100.0F) + "%", "Problems:", "" + (this.getIdealStatus() - this.getRepairStatus())}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } -} diff --git a/src/Java/gtPlusPlus/core/util/debug/DEBUG_ScreenOverlay.java b/src/Java/gtPlusPlus/core/util/debug/DEBUG_ScreenOverlay.java deleted file mode 100644 index 1c6a8e9278..0000000000 --- a/src/Java/gtPlusPlus/core/util/debug/DEBUG_ScreenOverlay.java +++ /dev/null @@ -1,47 +0,0 @@ -package gtPlusPlus.core.util.debug; - -import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.item.Item; - -import net.minecraftforge.client.event.RenderGameOverlayEvent; - -public class DEBUG_ScreenOverlay extends Gui { - - int width, height; - Minecraft mc = Minecraft.getMinecraft(); - - @SubscribeEvent - public void eventHandler(final RenderGameOverlayEvent.Text event) - { - - //if (mc.thePlayer.getHeldItem().equals(ModItems.itemStaballoyPickaxe)){ - final ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); - final FontRenderer fontRender = this.mc.fontRenderer; - this.width = res.getScaledWidth(); - this.height = res.getScaledHeight(); - Minecraft.getMinecraft().entityRenderer.setupOverlayRendering(); - final String str = "Words"; - Item heldItem = null; - - try{heldItem = this.mc.thePlayer.getHeldItem().getItem(); - - if (heldItem != null){ - /*if (heldItem instanceof StaballoyPickaxe){ - - int dmg =((StaballoyPickaxe) heldItem).getDamage(((StaballoyPickaxe) heldItem).thisPickaxe); - - ((StaballoyPickaxe) heldItem).checkFacing(((StaballoyPickaxe) heldItem).localWorld); - str = "DAMAGE: "+ dmg +" | FACING: "+((StaballoyPickaxe) heldItem).FACING+" | FACING_HORIZONTAL: "+((StaballoyPickaxe) heldItem).FACING_HORIZONTAL+" | LOOKING DIRECTION: "+((StaballoyPickaxe) heldItem).lookingDirection; - - drawString(fontRender, str, (this.width - fontRender.getStringWidth(str)) / 2, this.height / 10, 0xFFAA00); - }*/ - } - }catch(final NullPointerException e){} - - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/debug/DEBUG_TimerThread.java b/src/Java/gtPlusPlus/core/util/debug/DEBUG_TimerThread.java deleted file mode 100644 index 50d12871cb..0000000000 --- a/src/Java/gtPlusPlus/core/util/debug/DEBUG_TimerThread.java +++ /dev/null @@ -1,64 +0,0 @@ -package gtPlusPlus.core.util.debug; - -import java.util.concurrent.TimeUnit; - -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - -import gtPlusPlus.api.objects.Logger; -import net.minecraftforge.common.util.ForgeDirection; - -public class DEBUG_TimerThread implements Runnable { - - private final World world; - private final EntityPlayer player; - - - public DEBUG_TimerThread(final World WORLD, final EntityPlayer PLAYER) { - this.world = WORLD; - this.player = PLAYER; - } - - @Override - public void run(){ - int xDir = ForgeDirection.getOrientation(this.player.getPlayerCoordinates().posX).offsetX; - int zDir = ForgeDirection.getOrientation(this.player.getPlayerCoordinates().posZ).offsetZ; - - final int stepX = Minecraft.getMinecraft().objectMouseOver.blockX; - final int stepY = Minecraft.getMinecraft().objectMouseOver.blockY; - final int stepZ = Minecraft.getMinecraft().objectMouseOver.blockZ; - Logger.INFO("Clicked on a Block @ "+"[X:"+stepX+"][Y:"+stepY+"][Z:"+stepZ+"]"+" with xDir:"+xDir+" zDir:"+zDir); - this.world.setBlock(stepX, stepY, stepZ, Blocks.bedrock,0,3); - Logger.INFO("Makng it Bedrock for future investment."); - //for (int i = -1; i <= 1; i++) { - //stepX = stepX+i; - 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++){ - - xDir = ForgeDirection.getOrientation(this.player.getPlayerCoordinates().posX).offsetX; - zDir = ForgeDirection.getOrientation(this.player.getPlayerCoordinates().posZ).offsetZ; - - //for (int j = -1; j <= 1; j++) { - //stepZ = stepZ+j; - //for (int h = -1; h <= 1; h++) { - //stepY = stepY+h; - Logger.INFO("Placing Block @ "+"[X:"+i+"][Y:"+h+"][Z:"+j+"]"+" with xDir:"+xDir+" zDir:"+zDir); - if ((h != 0) || ((((xDir + i) != 0) || ((zDir + j) != 0)) && ((i != 0) || (j != 0)))) { - this.world.setBlock(i, h, j, Blocks.stone,0,3); - } - else { - Logger.INFO("Not even sure what this is for, but I got here."); - } - try { - TimeUnit.MILLISECONDS.sleep(500); - } catch (final InterruptedException e1) { - e1.printStackTrace(); - } - } - } - } - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/debug/UtilityGL11Debug.java b/src/Java/gtPlusPlus/core/util/debug/UtilityGL11Debug.java deleted file mode 100644 index 7cb1054d53..0000000000 --- a/src/Java/gtPlusPlus/core/util/debug/UtilityGL11Debug.java +++ /dev/null @@ -1,343 +0,0 @@ -package gtPlusPlus.core.util.debug; - -import java.nio.ByteBuffer; - -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; - - -/** - * User: The Grey Ghost - * Date: 9/02/14 - */ -public class UtilityGL11Debug -{ - public class GLproperty - { - public GLproperty(final int init_gLconstant, final String init_name, final String init_description, final String init_category, final String init_fetchCommand) { - this.gLconstant = init_gLconstant; - this.name = init_name; - this.description = init_description; - this.category = init_category; - this.fetchCommand = init_fetchCommand; - } - - public int gLconstant; - public String name; - public String description; - public String category; - public String fetchCommand; - } - - public static UtilityGL11Debug instance = new UtilityGL11Debug(); - - public GLproperty[] propertyList = - - { - new GLproperty(GL11.GL_CURRENT_COLOR, "GL_CURRENT_COLOR", "Current color", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_INDEX, "GL_CURRENT_INDEX", "Current color index", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_TEXTURE_COORDS, "GL_CURRENT_TEXTURE_COORDS", "Current texture coordinates", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_NORMAL, "GL_CURRENT_NORMAL", "Current normal", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_RASTER_POSITION, "GL_CURRENT_RASTER_POSITION", "Current raster position", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_RASTER_DISTANCE, "GL_CURRENT_RASTER_DISTANCE", "Current raster distance", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_RASTER_COLOR, "GL_CURRENT_RASTER_COLOR", "Color associated with raster position", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_RASTER_INDEX, "GL_CURRENT_RASTER_INDEX", "Color index associated with raster position", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_RASTER_TEXTURE_COORDS, "GL_CURRENT_RASTER_TEXTURE_COORDS", "Texture coordinates associated with raster position", "current", "glGetFloatv()"), - new GLproperty(GL11.GL_CURRENT_RASTER_POSITION_VALID, "GL_CURRENT_RASTER_POSITION_VALID", "Raster position valid bit", "current", "glGetBooleanv()"), - new GLproperty(GL11.GL_EDGE_FLAG, "GL_EDGE_FLAG", "Edge flag", "current", "glGetBooleanv()"), - new GLproperty(GL11.GL_VERTEX_ARRAY, "GL_VERTEX_ARRAY", "Vertex array enable", "vertex-array", "glIsEnabled()"), - new GLproperty(GL11.GL_VERTEX_ARRAY_SIZE, "GL_VERTEX_ARRAY_SIZE", "Coordinates per vertex", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_VERTEX_ARRAY_TYPE, "GL_VERTEX_ARRAY_TYPE", "Type of vertex coordinates", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_VERTEX_ARRAY_STRIDE, "GL_VERTEX_ARRAY_STRIDE", "Stride between vertices", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_VERTEX_ARRAY_POINTER, "GL_VERTEX_ARRAY_POINTER", "Pointer to the vertex array", "vertex-array", "glGetPointerv()"), - new GLproperty(GL11.GL_NORMAL_ARRAY, "GL_NORMAL_ARRAY", "Normal array enable", "vertex-array", "glIsEnabled()"), - new GLproperty(GL11.GL_NORMAL_ARRAY_TYPE, "GL_NORMAL_ARRAY_TYPE", "Type of normal coordinates", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_NORMAL_ARRAY_STRIDE, "GL_NORMAL_ARRAY_STRIDE", "Stride between normals", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_NORMAL_ARRAY_POINTER, "GL_NORMAL_ARRAY_POINTER", "Pointer to the normal array", "vertex-array", "glGetPointerv()"), - new GLproperty(GL11.GL_COLOR_ARRAY, "GL_COLOR_ARRAY", "RGBA color array enable", "vertex-array", "glIsEnabled()"), - new GLproperty(GL11.GL_COLOR_ARRAY_SIZE, "GL_COLOR_ARRAY_SIZE", "Colors per vertex", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_COLOR_ARRAY_TYPE, "GL_COLOR_ARRAY_TYPE", "Type of color components", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_COLOR_ARRAY_STRIDE, "GL_COLOR_ARRAY_STRIDE", "Stride between colors", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_COLOR_ARRAY_POINTER, "GL_COLOR_ARRAY_POINTER", "Pointer to the color array", "vertex-array", "glGetPointerv()"), - new GLproperty(GL11.GL_INDEX_ARRAY, "GL_INDEX_ARRAY", "Color-index array enable", "vertex-array", "glIsEnabled()"), - new GLproperty(GL11.GL_INDEX_ARRAY_TYPE, "GL_INDEX_ARRAY_TYPE", "Type of color indices", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_INDEX_ARRAY_STRIDE, "GL_INDEX_ARRAY_STRIDE", "Stride between color indices", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_INDEX_ARRAY_POINTER, "GL_INDEX_ARRAY_POINTER", "Pointer to the index array", "vertex-array", "glGetPointerv()"), - new GLproperty(GL11.GL_TEXTURE_COORD_ARRAY, "GL_TEXTURE_COORD_ARRAY", "Texture coordinate array enable", "vertex-array", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_COORD_ARRAY_SIZE, "GL_TEXTURE_COORD_ARRAY_SIZE", "Texture coordinates per element", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_TEXTURE_COORD_ARRAY_TYPE, "GL_TEXTURE_COORD_ARRAY_TYPE", "Type of texture coordinates", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_TEXTURE_COORD_ARRAY_STRIDE, "GL_TEXTURE_COORD_ARRAY_STRIDE", "Stride between texture coordinates", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_TEXTURE_COORD_ARRAY_POINTER, "GL_TEXTURE_COORD_ARRAY_POINTER", "Pointer to the texture coordinate array", "vertex-array", "glGetPointerv()"), - new GLproperty(GL11.GL_EDGE_FLAG_ARRAY, "GL_EDGE_FLAG_ARRAY", "Edge flag array enable", "vertex-array", "glIsEnabled()"), - new GLproperty(GL11.GL_EDGE_FLAG_ARRAY_STRIDE, "GL_EDGE_FLAG_ARRAY_STRIDE", "Stride between edge flags", "vertex-array", "glGetIntegerv()"), - new GLproperty(GL11.GL_EDGE_FLAG_ARRAY_POINTER, "GL_EDGE_FLAG_ARRAY_POINTER", "Pointer to the edge flag array", "vertex-array", "glGetPointerv()"), - new GLproperty(GL11.GL_MODELVIEW_MATRIX, "GL_MODELVIEW_MATRIX", "Modelview matrix stack", "matrix", "glGetFloatv()"), - new GLproperty(GL11.GL_PROJECTION_MATRIX, "GL_PROJECTION_MATRIX", "Projection matrix stack", "matrix", "glGetFloatv()"), - new GLproperty(GL11.GL_TEXTURE_MATRIX, "GL_TEXTURE_MATRIX", "Texture matrix stack", "matrix", "glGetFloatv()"), - new GLproperty(GL11.GL_VIEWPORT, "GL_VIEWPORT", "Viewport origin and extent", "viewport", "glGetIntegerv()"), - new GLproperty(GL11.GL_DEPTH_RANGE, "GL_DEPTH_RANGE", "Depth range near and far", "viewport", "glGetFloatv()"), - new GLproperty(GL11.GL_MODELVIEW_STACK_DEPTH, "GL_MODELVIEW_STACK_DEPTH", "Modelview matrix stack pointer", "matrix", "glGetIntegerv()"), - new GLproperty(GL11.GL_PROJECTION_STACK_DEPTH, "GL_PROJECTION_STACK_DEPTH", "Projection matrix stack pointer", "matrix", "glGetIntegerv()"), - new GLproperty(GL11.GL_TEXTURE_STACK_DEPTH, "GL_TEXTURE_STACK_DEPTH", "Texture matrix stack pointer", "matrix", "glGetIntegerv()"), - new GLproperty(GL11.GL_MATRIX_MODE, "GL_MATRIX_MODE", "Current matrix mode", "transform", "glGetIntegerv()"), - new GLproperty(GL11.GL_NORMALIZE, "GL_NORMALIZE", "Current normal normalization on/off", "transform/ enable", "glIsEnabled()"), - new GLproperty(GL11.GL_FOG_COLOR, "GL_FOG_COLOR", "Fog color", "fog", "glGetFloatv()"), - new GLproperty(GL11.GL_FOG_INDEX, "GL_FOG_INDEX", "Fog index", "fog", "glGetFloatv()"), - new GLproperty(GL11.GL_FOG_DENSITY, "GL_FOG_DENSITY", "Exponential fog density", "fog", "glGetFloatv()"), - new GLproperty(GL11.GL_FOG_START, "GL_FOG_START", "Linear fog start", "fog", "glGetFloatv()"), - new GLproperty(GL11.GL_FOG_END, "GL_FOG_END", "Linear fog end", "fog", "glGetFloatv()"), - new GLproperty(GL11.GL_FOG_MODE, "GL_FOG_MODE", "Fog mode", "fog", "glGetIntegerv()"), - new GLproperty(GL11.GL_FOG, "GL_FOG", "True if fog enabled", "fog/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_SHADE_MODEL, "GL_SHADE_MODEL", "glShadeModel() setting", "lighting", "glGetIntegerv()"), - new GLproperty(GL11.GL_LIGHTING, "GL_LIGHTING", "True if lighting is enabled", "lighting/e nable", "glIsEnabled()"), - new GLproperty(GL11.GL_COLOR_MATERIAL, "GL_COLOR_MATERIAL", "True if color tracking is enabled", "lighting", "glIsEnabled()"), - new GLproperty(GL11.GL_COLOR_MATERIAL_PARAMETER, "GL_COLOR_MATERIAL_PARAMETER", "Material properties tracking current color", "lighting", "glGetIntegerv()"), - new GLproperty(GL11.GL_COLOR_MATERIAL_FACE, "GL_COLOR_MATERIAL_FACE", "Face(s) affected by color tracking", "lighting", "glGetIntegerv()"), - new GLproperty(GL11.GL_AMBIENT, "GL_AMBIENT", "Ambient material color", "lighting", "glGetMaterialfv()"), - new GLproperty(GL11.GL_DIFFUSE, "GL_DIFFUSE", "Diffuse material color", "lighting", "glGetMaterialfv()"), - new GLproperty(GL11.GL_SPECULAR, "GL_SPECULAR", "Specular material color", "lighting", "glGetMaterialfv()"), - new GLproperty(GL11.GL_EMISSION, "GL_EMISSION", "Emissive material color", "lighting", "glGetMaterialfv()"), - new GLproperty(GL11.GL_SHININESS, "GL_SHININESS", "Specular exponent of material", "lighting", "glGetMaterialfv()"), - new GLproperty(GL11.GL_LIGHT_MODEL_AMBIENT, "GL_LIGHT_MODEL_AMBIENT", "Ambient scene color", "lighting", "glGetFloatv()"), - new GLproperty(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, "GL_LIGHT_MODEL_LOCAL_VIEWER", "Viewer is local", "lighting", "glGetBooleanv()"), - new GLproperty(GL11.GL_LIGHT_MODEL_TWO_SIDE, "GL_LIGHT_MODEL_TWO_SIDE", "Use two-sided lighting", "lighting", "glGetBooleanv()"), - new GLproperty(GL11.GL_AMBIENT, "GL_AMBIENT", "Ambient intensity of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_DIFFUSE, "GL_DIFFUSE", "Diffuse intensity of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_SPECULAR, "GL_SPECULAR", "Specular intensity of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_POSITION, "GL_POSITION", "Position of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_CONSTANT_ATTENUATION, "GL_CONSTANT_ATTENUATION", "Constant attenuation factor", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_LINEAR_ATTENUATION, "GL_LINEAR_ATTENUATION", "Linear attenuation factor", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_QUADRATIC_ATTENUATION, "GL_QUADRATIC_ATTENUATION", "Quadratic attenuation factor", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_SPOT_DIRECTION, "GL_SPOT_DIRECTION", "Spotlight direction of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_SPOT_EXPONENT, "GL_SPOT_EXPONENT", "Spotlight exponent of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_SPOT_CUTOFF, "GL_SPOT_CUTOFF", "Spotlight angle of light i", "lighting", "glGetLightfv()"), - new GLproperty(GL11.GL_LIGHT0, "GL_LIGHT0", "True if light 0 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT1, "GL_LIGHT1", "True if light 1 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT2, "GL_LIGHT2", "True if light 2 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT3, "GL_LIGHT3", "True if light 3 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT4, "GL_LIGHT4", "True if light 4 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT5, "GL_LIGHT5", "True if light 5 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT6, "GL_LIGHT6", "True if light 6 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LIGHT7, "GL_LIGHT7", "True if light 7 enabled", "lighting/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_COLOR_INDEXES, "GL_COLOR_INDEXES", "ca, cd, and cs for color-index lighting", "lighting/e nable", "glGetMaterialfv()"), - new GLproperty(GL11.GL_POINT_SIZE, "GL_POINT_SIZE", "Point size", "point", "glGetFloatv()"), - new GLproperty(GL11.GL_POINT_SMOOTH, "GL_POINT_SMOOTH", "Point antialiasing on", "point/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LINE_WIDTH, "GL_LINE_WIDTH", "Line width", "line", "glGetFloatv()"), - new GLproperty(GL11.GL_LINE_SMOOTH, "GL_LINE_SMOOTH", "Line antialiasing on", "line/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LINE_STIPPLE_PATTERN, "GL_LINE_STIPPLE_PATTERN", "Line stipple", "line", "glGetIntegerv()"), - new GLproperty(GL11.GL_LINE_STIPPLE_REPEAT, "GL_LINE_STIPPLE_REPEAT", "Line stipple repeat", "line", "glGetIntegerv()"), - new GLproperty(GL11.GL_LINE_STIPPLE, "GL_LINE_STIPPLE", "Line stipple enable", "line/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_CULL_FACE, "GL_CULL_FACE", "Polygon culling enabled", "polygon/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_CULL_FACE_MODE, "GL_CULL_FACE_MODE", "Cull front-/back-facing polygons", "polygon", "glGetIntegerv()"), - new GLproperty(GL11.GL_FRONT_FACE, "GL_FRONT_FACE", "Polygon front-face CW/CCW indicator", "polygon", "glGetIntegerv()"), - new GLproperty(GL11.GL_POLYGON_SMOOTH, "GL_POLYGON_SMOOTH", "Polygon antialiasing on", "polygon/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_POLYGON_MODE, "GL_POLYGON_MODE", "Polygon rasterization mode (front and back)", "polygon", "glGetIntegerv()"), - new GLproperty(GL11.GL_POLYGON_OFFSET_FACTOR, "GL_POLYGON_OFFSET_FACTOR", "Polygon offset factor", "polygon", "glGetFloatv()"), - new GLproperty(GL11.GL_POLYGON_OFFSET_POINT, "GL_POLYGON_OFFSET_POINT", "Polygon offset enable for GL_POINT mode rasterization", "polygon/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_POLYGON_OFFSET_LINE, "GL_POLYGON_OFFSET_LINE", "Polygon offset enable for GL_LINE mode rasterization", "polygon/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_POLYGON_OFFSET_FILL, "GL_POLYGON_OFFSET_FILL", "Polygon offset enable for GL_FILL mode rasterization", "polygon/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_POLYGON_STIPPLE, "GL_POLYGON_STIPPLE", "Polygon stipple enable", "polygon/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_1D, "GL_TEXTURE_1D", "True if 1-D texturing enabled ", "texture/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_2D, "GL_TEXTURE_2D", "True if 2-D texturing enabled ", "texture/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_BINDING_1D, "GL_TEXTURE_BINDING_1D", "Texture object bound to GL_TEXTURE_1D", "texture", "glGetIntegerv()"), - new GLproperty(GL11.GL_TEXTURE_BINDING_2D, "GL_TEXTURE_BINDING_2D", "Texture object bound to GL_TEXTURE_2D", "texture", "glGetIntegerv()"), - new GLproperty(GL11.GL_TEXTURE, "GL_TEXTURE", "x-D texture image at level of detail i", "UNUSED", "glGetTexImage()"), - new GLproperty(GL11.GL_TEXTURE_WIDTH, "GL_TEXTURE_WIDTH", "x-D texture image i's width", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_HEIGHT, "GL_TEXTURE_HEIGHT", "x-D texture image i's height", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_BORDER, "GL_TEXTURE_BORDER", "x-D texture image i's border width", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_RED_SIZE, "GL_TEXTURE_RED_SIZE", "x-D texture image i's red resolution", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_GREEN_SIZE, "GL_TEXTURE_GREEN_SIZE", "x-D texture image i's green resolution", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_BLUE_SIZE, "GL_TEXTURE_BLUE_SIZE", "x-D texture image i's blue resolution", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_ALPHA_SIZE, "GL_TEXTURE_ALPHA_SIZE", "x-D texture image i's alpha resolution", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_LUMINANCE_SIZE, "GL_TEXTURE_LUMINANCE_SIZE", "x-D texture image i's luminance resolution", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_INTENSITY_SIZE, "GL_TEXTURE_INTENSITY_SIZE", "x-D texture image i's intensity resolution", "UNUSED", "glGetTexLevelParameter*()"), - new GLproperty(GL11.GL_TEXTURE_BORDER_COLOR, "GL_TEXTURE_BORDER_COLOR", "Texture border color", "texture", "glGetTexParameter*()"), - new GLproperty(GL11.GL_TEXTURE_MIN_FILTER, "GL_TEXTURE_MIN_FILTER", "Texture minification function", "texture", "glGetTexParameter*()"), - new GLproperty(GL11.GL_TEXTURE_MAG_FILTER, "GL_TEXTURE_MAG_FILTER", "Texture magnification function", "texture", "glGetTexParameter*()"), - new GLproperty(GL11.GL_TEXTURE_WRAP_S, "GL_TEXTURE_WRAP_S", "Texture wrap mode (x is S or T)", "texture", "glGetTexParameter*()"), - new GLproperty(GL11.GL_TEXTURE_WRAP_T, "GL_TEXTURE_WRAP_T", "Texture wrap mode (x is S or T)", "texture", "glGetTexParameter*()"), - new GLproperty(GL11.GL_TEXTURE_PRIORITY, "GL_TEXTURE_PRIORITY", "Texture object priority", "texture", "glGetTexParameter*()"), - new GLproperty(GL11.GL_TEXTURE_ENV_MODE, "GL_TEXTURE_ENV_MODE", "Texture application function", "texture", "glGetTexEnviv()"), - new GLproperty(GL11.GL_TEXTURE_ENV_COLOR, "GL_TEXTURE_ENV_COLOR", "Texture environment color", "texture", "glGetTexEnvfv()"), - new GLproperty(GL11.GL_TEXTURE_GEN_S, "GL_TEXTURE_GEN_S", "Texgen enabled (x is S, T, R, or Q)", "texture/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_GEN_T, "GL_TEXTURE_GEN_T", "Texgen enabled (x is S, T, R, or Q)", "texture/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_GEN_R, "GL_TEXTURE_GEN_R", "Texgen enabled (x is S, T, R, or Q)", "texture/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_TEXTURE_GEN_Q, "GL_TEXTURE_GEN_Q", "Texgen enabled (x is S, T, R, or Q)", "texture/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_EYE_PLANE, "GL_EYE_PLANE", "Texgen plane equation coefficients", "texture", "glGetTexGenfv()"), - new GLproperty(GL11.GL_OBJECT_PLANE, "GL_OBJECT_PLANE", "Texgen object linear coefficients", "texture", "glGetTexGenfv()"), - new GLproperty(GL11.GL_TEXTURE_GEN_MODE, "GL_TEXTURE_GEN_MODE", "Function used for texgen", "texture", "glGetTexGeniv()"), - new GLproperty(GL11.GL_SCISSOR_TEST, "GL_SCISSOR_TEST", "Scissoring enabled", "scissor/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_SCISSOR_BOX, "GL_SCISSOR_BOX", "Scissor box", "scissor", "glGetIntegerv()"), - new GLproperty(GL11.GL_ALPHA_TEST, "GL_ALPHA_TEST", "Alpha test enabled", "color-buffer/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_ALPHA_TEST_FUNC, "GL_ALPHA_TEST_FUNC", "Alpha test function", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_ALPHA_TEST_REF, "GL_ALPHA_TEST_REF", "Alpha test reference value", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_TEST, "GL_STENCIL_TEST", "Stenciling enabled", "stencil-buffer/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_STENCIL_FUNC, "GL_STENCIL_FUNC", "Stencil function", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_VALUE_MASK, "GL_STENCIL_VALUE_MASK", "Stencil mask", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_REF, "GL_STENCIL_REF", "Stencil reference value", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_FAIL, "GL_STENCIL_FAIL", "Stencil fail action", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_PASS_DEPTH_FAIL, "GL_STENCIL_PASS_DEPTH_FAIL", "Stencil depth buffer fail action", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_PASS_DEPTH_PASS, "GL_STENCIL_PASS_DEPTH_PASS", "Stencil depth buffer pass action", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_DEPTH_TEST, "GL_DEPTH_TEST", "Depth buffer enabled", "depth-buffer/ena ble", "glIsEnabled()"), - new GLproperty(GL11.GL_DEPTH_FUNC, "GL_DEPTH_FUNC", "Depth buffer test function", "depth-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_BLEND, "GL_BLEND", "Blending enabled", "color-buffer/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_BLEND_SRC, "GL_BLEND_SRC", "Blending source function", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_BLEND_DST, "GL_BLEND_DST", "Blending destination function", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_DITHER, "GL_DITHER", "Dithering enabled", "color-buffer/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_INDEX_LOGIC_OP, "GL_INDEX_LOGIC_OP", "Color index logical operation enabled", "color-buffer/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_COLOR_LOGIC_OP, "GL_COLOR_LOGIC_OP", "RGBA color logical operation enabled", "color-buffer/enable", "glIsEnabled()"), - new GLproperty(GL11.GL_LOGIC_OP_MODE, "GL_LOGIC_OP_MODE", "Logical operation function", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_DRAW_BUFFER, "GL_DRAW_BUFFER", "Buffers selected for drawing", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_INDEX_WRITEMASK, "GL_INDEX_WRITEMASK", "Color-index writemask", "color-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_COLOR_WRITEMASK, "GL_COLOR_WRITEMASK", "Color write enables; R, G, B, or A", "color-buffer", "glGetBooleanv()"), - new GLproperty(GL11.GL_DEPTH_WRITEMASK, "GL_DEPTH_WRITEMASK", "Depth buffer enabled for writing", "depth-buffer", "glGetBooleanv()"), - new GLproperty(GL11.GL_STENCIL_WRITEMASK, "GL_STENCIL_WRITEMASK", "Stencil-buffer writemask", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_COLOR_CLEAR_VALUE, "GL_COLOR_CLEAR_VALUE", "Color-buffer clear value (RGBA mode)", "color-buffer", "glGetFloatv()"), - new GLproperty(GL11.GL_INDEX_CLEAR_VALUE, "GL_INDEX_CLEAR_VALUE", "Color-buffer clear value (color-index mode)", "color-buffer", "glGetFloatv()"), - new GLproperty(GL11.GL_DEPTH_CLEAR_VALUE, "GL_DEPTH_CLEAR_VALUE", "Depth-buffer clear value", "depth-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_CLEAR_VALUE, "GL_STENCIL_CLEAR_VALUE", "Stencil-buffer clear value", "stencil-buffer", "glGetIntegerv()"), - new GLproperty(GL11.GL_ACCUM_CLEAR_VALUE, "GL_ACCUM_CLEAR_VALUE", "Accumulation-buffer clear value", "accum-buffer", "glGetFloatv()"), - new GLproperty(GL11.GL_UNPACK_SWAP_BYTES, "GL_UNPACK_SWAP_BYTES", "Value of GL_UNPACK_SWAP_BYTES", "pixel-store", "glGetBooleanv()"), - new GLproperty(GL11.GL_UNPACK_LSB_FIRST, "GL_UNPACK_LSB_FIRST", "Value of GL_UNPACK_LSB_FIRST", "pixel-store", "glGetBooleanv()"), - new GLproperty(GL11.GL_UNPACK_ROW_LENGTH, "GL_UNPACK_ROW_LENGTH", "Value of GL_UNPACK_ROW_LENGTH", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_UNPACK_SKIP_ROWS, "GL_UNPACK_SKIP_ROWS", "Value of GL_UNPACK_SKIP_ROWS", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_UNPACK_SKIP_PIXELS, "GL_UNPACK_SKIP_PIXELS", "Value of GL_UNPACK_SKIP_PIXELS", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_UNPACK_ALIGNMENT, "GL_UNPACK_ALIGNMENT", "Value of GL_UNPACK_ALIGNMENT", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_PACK_SWAP_BYTES, "GL_PACK_SWAP_BYTES", "Value of GL_PACK_SWAP_BYTES", "pixel-store", "glGetBooleanv()"), - new GLproperty(GL11.GL_PACK_LSB_FIRST, "GL_PACK_LSB_FIRST", "Value of GL_PACK_LSB_FIRST", "pixel-store", "glGetBooleanv()"), - new GLproperty(GL11.GL_PACK_ROW_LENGTH, "GL_PACK_ROW_LENGTH", "Value of GL_PACK_ROW_LENGTH", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_PACK_SKIP_ROWS, "GL_PACK_SKIP_ROWS", "Value of GL_PACK_SKIP_ROWS", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_PACK_SKIP_PIXELS, "GL_PACK_SKIP_PIXELS", "Value of GL_PACK_SKIP_PIXELS", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_PACK_ALIGNMENT, "GL_PACK_ALIGNMENT", "Value of GL_PACK_ALIGNMENT", "pixel-store", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAP_COLOR, "GL_MAP_COLOR", "True if colors are mapped", "pixel", "glGetBooleanv()"), - new GLproperty(GL11.GL_MAP_STENCIL, "GL_MAP_STENCIL", "True if stencil values are mapped", "pixel", "glGetBooleanv()"), - new GLproperty(GL11.GL_INDEX_SHIFT, "GL_INDEX_SHIFT", "Value of GL_INDEX_SHIFT", "pixel", "glGetIntegerv()"), - new GLproperty(GL11.GL_INDEX_OFFSET, "GL_INDEX_OFFSET", "Value of GL_INDEX_OFFSET", "pixel", "glGetIntegerv()"), - new GLproperty(GL11.GL_ZOOM_X, "GL_ZOOM_X", "x zoom factor", "pixel", "glGetFloatv()"), - new GLproperty(GL11.GL_ZOOM_Y, "GL_ZOOM_Y", "y zoom factor", "pixel", "glGetFloatv()"), - new GLproperty(GL11.GL_READ_BUFFER, "GL_READ_BUFFER", "Read source buffer", "pixel", "glGetIntegerv()"), - new GLproperty(GL11.GL_ORDER, "GL_ORDER", "1D map order", "capability", "glGetMapiv()"), - new GLproperty(GL11.GL_ORDER, "GL_ORDER", "2D map orders", "capability", "glGetMapiv()"), - new GLproperty(GL11.GL_COEFF, "GL_COEFF", "1D control points", "capability", "glGetMapfv()"), - new GLproperty(GL11.GL_COEFF, "GL_COEFF", "2D control points", "capability", "glGetMapfv()"), - new GLproperty(GL11.GL_DOMAIN, "GL_DOMAIN", "1D domain endpoints", "capability", "glGetMapfv()"), - new GLproperty(GL11.GL_DOMAIN, "GL_DOMAIN", "2D domain endpoints", "capability", "glGetMapfv()"), - new GLproperty(GL11.GL_MAP1_GRID_DOMAIN, "GL_MAP1_GRID_DOMAIN", "1D grid endpoints", "eval", "glGetFloatv()"), - new GLproperty(GL11.GL_MAP2_GRID_DOMAIN, "GL_MAP2_GRID_DOMAIN", "2D grid endpoints", "eval", "glGetFloatv()"), - new GLproperty(GL11.GL_MAP1_GRID_SEGMENTS, "GL_MAP1_GRID_SEGMENTS", "1D grid divisions", "eval", "glGetFloatv()"), - new GLproperty(GL11.GL_MAP2_GRID_SEGMENTS, "GL_MAP2_GRID_SEGMENTS", "2D grid divisions", "eval", "glGetFloatv()"), - new GLproperty(GL11.GL_AUTO_NORMAL, "GL_AUTO_NORMAL", "True if automatic normal generation enabled", "eval", "glIsEnabled()"), - new GLproperty(GL11.GL_PERSPECTIVE_CORRECTION_HINT, "GL_PERSPECTIVE_CORRECTION_HINT", "Perspective correction hint", "hint", "glGetIntegerv()"), - new GLproperty(GL11.GL_POINT_SMOOTH_HINT, "GL_POINT_SMOOTH_HINT", "Point smooth hint", "hint", "glGetIntegerv()"), - new GLproperty(GL11.GL_LINE_SMOOTH_HINT, "GL_LINE_SMOOTH_HINT", "Line smooth hint", "hint", "glGetIntegerv()"), - new GLproperty(GL11.GL_POLYGON_SMOOTH_HINT, "GL_POLYGON_SMOOTH_HINT", "Polygon smooth hint", "hint", "glGetIntegerv()"), - new GLproperty(GL11.GL_FOG_HINT, "GL_FOG_HINT", "Fog hint", "hint", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_LIGHTS, "GL_MAX_LIGHTS", "Maximum number of lights", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES", "Maximum number of user clipping planes", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH", "Maximum modelview-matrix stack depth", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH", "Maximum projection-matrix stack depth", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH", "Maximum depth of texture matrix stack", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_SUBPIXEL_BITS, "GL_SUBPIXEL_BITS", "Number of bits of subpixel precision in x and y", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE", "See discussion in Texture Proxy in Chapter 9", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE", "Maximum size of a glPixelMap() translation table", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH", "Maximum selection-name stack depth", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING", "Maximum display-list call nesting", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER", "Maximum evaluator polynomial order", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS", "Maximum viewport dimensions", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH", "Maximum depth of the attribute stack", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH", "Maximum depth of the client attribute stack", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_AUX_BUFFERS, "GL_AUX_BUFFERS", "Number of auxiliary buffers", "capability", "glGetBooleanv()"), - new GLproperty(GL11.GL_RGBA_MODE, "GL_RGBA_MODE", "True if color buffers store RGBA", "capability", "glGetBooleanv()"), - new GLproperty(GL11.GL_INDEX_MODE, "GL_INDEX_MODE", "True if color buffers store indices", "capability", "glGetBooleanv()"), - new GLproperty(GL11.GL_DOUBLEBUFFER, "GL_DOUBLEBUFFER", "True if front and back buffers exist", "capability", "glGetBooleanv()"), - new GLproperty(GL11.GL_STEREO, "GL_STEREO", "True if left and right buffers exist", "capability", "glGetBooleanv()"), - new GLproperty(GL11.GL_POINT_SIZE_RANGE, "GL_POINT_SIZE_RANGE", "Range (low to high) of antialiased point sizes", "capability", "glGetFloatv()"), - new GLproperty(GL11.GL_POINT_SIZE_GRANULARITY, "GL_POINT_SIZE_GRANULARITY", "Antialiased point-size granularity", "capability", "glGetFloatv()"), - new GLproperty(GL11.GL_LINE_WIDTH_RANGE, "GL_LINE_WIDTH_RANGE", "Range (low to high) of antialiased line widths", "capability", "glGetFloatv()"), - new GLproperty(GL11.GL_LINE_WIDTH_GRANULARITY, "GL_LINE_WIDTH_GRANULARITY", "Antialiased line-width granularity", "capability", "glGetFloatv()"), - new GLproperty(GL11.GL_RED_BITS, "GL_RED_BITS", "Number of bits per red component in color buffers", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_GREEN_BITS, "GL_GREEN_BITS", "Number of bits per green component in color buffers", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_BLUE_BITS, "GL_BLUE_BITS", "Number of bits per blue component in color buffers", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_ALPHA_BITS, "GL_ALPHA_BITS", "Number of bits per alpha component in color buffers", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_INDEX_BITS, "GL_INDEX_BITS", "Number of bits per index in color buffers", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_DEPTH_BITS, "GL_DEPTH_BITS", "Number of depth-buffer bitplanes", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_STENCIL_BITS, "GL_STENCIL_BITS", "Number of stencil bitplanes", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_ACCUM_RED_BITS, "GL_ACCUM_RED_BITS", "Number of bits per red component in the accumulation buffer", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_ACCUM_GREEN_BITS, "GL_ACCUM_GREEN_BITS", "Number of bits per green component in the accumulation buffer", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_ACCUM_BLUE_BITS, "GL_ACCUM_BLUE_BITS", "Number of bits per blue component in the accumulation buffer", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_ACCUM_ALPHA_BITS, "GL_ACCUM_ALPHA_BITS", "Number of bits per alpha component in the accumulation buffer", "capability", "glGetIntegerv()"), - new GLproperty(GL11.GL_LIST_BASE, "GL_LIST_BASE", "Setting of glListBase()", "list", "glGetIntegerv()"), - new GLproperty(GL11.GL_LIST_INDEX, "GL_LIST_INDEX", "Number of display list under construction; 0 if none", "current", "glGetIntegerv()"), - new GLproperty(GL11.GL_LIST_MODE, "GL_LIST_MODE", "Mode of display list under construction; undefined if none", "current", "glGetIntegerv()"), - new GLproperty(GL11.GL_ATTRIB_STACK_DEPTH, "GL_ATTRIB_STACK_DEPTH", "Attribute stack pointer", "current", "glGetIntegerv()"), - new GLproperty(GL11.GL_CLIENT_ATTRIB_STACK_DEPTH, "GL_CLIENT_ATTRIB_STACK_DEPTH", "Client attribute stack pointer", "current", "glGetIntegerv()"), - new GLproperty(GL11.GL_NAME_STACK_DEPTH, "GL_NAME_STACK_DEPTH", "Name stack depth", "current", "glGetIntegerv()"), - new GLproperty(GL11.GL_RENDER_MODE, "GL_RENDER_MODE", "glRenderMode() setting", "current", "glGetIntegerv()"), - new GLproperty(GL11.GL_SELECTION_BUFFER_POINTER, "GL_SELECTION_BUFFER_POINTER", "Pointer to selection buffer", "select", "glGetPointerv()"), - new GLproperty(GL11.GL_SELECTION_BUFFER_SIZE, "GL_SELECTION_BUFFER_SIZE", "Size of selection buffer", "select", "glGetIntegerv()"), - new GLproperty(GL11.GL_FEEDBACK_BUFFER_POINTER, "GL_FEEDBACK_BUFFER_POINTER", "Pointer to feedback buffer", "feedback", "glGetPointerv()"), - new GLproperty(GL11.GL_FEEDBACK_BUFFER_SIZE, "GL_FEEDBACK_BUFFER_SIZE", "Size of feedback buffer", "feedback", "glGetIntegerv()"), - new GLproperty(GL11.GL_FEEDBACK_BUFFER_TYPE, "GL_FEEDBACK_BUFFER_TYPE", "Type of feedback buffer", "feedback", "glGetIntegerv()"), - }; - - public static void dumpOpenGLstate() - { - } - - public static void dumpAllIsEnabled() //Call This - { - for (int i = 0; i < instance.propertyList.length; ++i) - - { - if (instance.propertyList[i].fetchCommand == "glIsEnabled()") - - { - System.out.print(instance.propertyList[i].name + ":"); - System.out.print(GL11.glIsEnabled(instance.propertyList[i].gLconstant)); - System.out.println(" (" + instance.propertyList[i].description + ")"); - } - } - } - - public static void dumpAllType(final String type) - - { - for (int i = 0; i < instance.propertyList.length; ++i) - - { - if (instance.propertyList[i].category.equals(type)) - - { - System.out.print(instance.propertyList[i].name + ":"); - System.out.println(getPropertyAsString(i)); - System.out.println(" (" + instance.propertyList[i].description + ")"); - } - } - } - - private static String getPropertyAsString(final int propertyListIndex) - { - final int gLconstant = instance.propertyList[propertyListIndex].gLconstant; - if (instance.propertyList[propertyListIndex].fetchCommand.equals("glIsEnabled()")) { - return "" + GL11.glIsEnabled(gLconstant); - } - - if (instance.propertyList[propertyListIndex].fetchCommand == "glGetBooleanv()") - - { - final ByteBuffer params = BufferUtils.createByteBuffer(16); - - GL11.glGetBoolean(gLconstant, params); - String out = ""; - for (int i = 0; i < params.capacity(); ++i) - - { - out += (i == 0 ? "" : ", ") + params.get(i); - } - return out; - } - - return ""; - } -} - diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java deleted file mode 100644 index 2f4db2efcc..0000000000 --- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java +++ /dev/null @@ -1,771 +0,0 @@ -package gtPlusPlus.core.util.math; - -import java.util.Map; -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; - -public class MathUtils { - - final static Random rand = CORE.RANDOM; - - /** - * Returns a psuedo-random number between min and max, inclusive. - * The difference between min and max can be at most - * Integer.MAX_VALUE - 1. - * - * @param min Minimim value - * @param max Maximim value. Must be greater than min. - * @return Integer between min and max, inclusive. - * @see java.util.Random#nextInt(int) - */ - public static int randInt(final int min, final int max) { - // nextInt is normally exclusive of the top value, - // so add 1 to make it inclusive - 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. - * - * @param min Minimim value - * @param max Maximim value. Must be greater than min. - * @return Long between min and max, inclusive. - * @see java.util.Random#nextLong(long) - */ - public static long randLong(final long min, final long max) { - // nextInt is normally exclusive of the top value, - // so add 1 to make it inclusive - return MathUtils.nextLong(rand,(max - min) + 1) + min; - } - private static long nextLong(final Random rng, final long n) { - // error checking and 2^x checking removed for simplicity. - long bits, val; - do { - bits = (rng.nextLong() << 1) >>> 1; - val = bits % n; - } while (((bits-val)+(n-1)) < 0L); - return val; - } - - - /** - * Returns a psuedo-random number between min and max, inclusive. - * The difference between min and max can be at most - * Double.MAX_VALUE - 1. - * - * @param min Minimim value - * @param max Maximim value. Must be greater than min. - * @return Double between min and max, inclusive. - * @see java.util.Random#nextDouble(double) - */ - public static double randDouble(final double min, final double max) { - // nextInt is normally exclusive of the top value, - // so add 1 to make it inclusive - return MathUtils.nextDouble(rand,(max - min) + 1) + min; - } - - private static double nextDouble(final Random rng, final double n) { - // error checking and 2^x checking removed for simplicity. - double bits, val; - do { - bits = (rng.nextLong() << 1) >>> 1; - val = bits % n; - } while (((bits-val)+(n-1)) < 0L); - return val; - } - - /** - * Returns a psuedo-random number between min and max, inclusive. - * The difference between min and max can be at most - * Float.MAX_VALUE - 1. - * - * @param min Minimim value - * @param max Maximim value. Must be greater than min. - * @return Float between min and max, inclusive. - * @see java.util.Random#nextFloat(float) - */ - public static float randFloat(final float min, final float max) { - // nextInt is normally exclusive of the top value, - // so add 1 to make it inclusive - return MathUtils.nextFloat(rand,(max - min) + 1) + min; - } - - private static float nextFloat(final Random rng, final float n) { - // error checking and 2^x checking removed for simplicity. - float bits, val; - do { - bits = (rng.nextLong() << 1) >>> 1; - val = bits % n; - } while (((bits-val)+(n-1)) < 0L); - return val; - } - - - /** - * Returns a percentage. - * The returned number is the % of X in Y. - * Supports Doubles. - * - * @param current Current value. - * @param max Maximim value. Must be greater than min. - * @return double between min and max, inclusive. - */ - public static double findPercentage(final double current, final double max){ - return Math.round(((current / max) * 100) * 100.00) / 100.00; - } - - public static int findPercentageOfInt(long input, float percentage){ - return (int)(input*(percentage/100.0f)); - } - - - //Smooth Rounding Function - /** - * 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) { - return Math.round(d * 2) / 2.0; - } - - - //Smooth Rounding Function (Nearest 5) - /** - * 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) { - return 5*(Math.round(d/5)); - } - - //Smooth Rounding Function - /** - * 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. - * - * @param x Value A. - * @return boolean Whether or not it divides evenly. - */ - public static boolean isNumberEven(final long x){ - if ((x % 2) == 0) - { - return true; - } - return false; - } - - - - /** - * Returns an int. - * The returned number is the value on i + 273.15F. - * Supports ints. - * - * @param i Temp in Celcius. - * @return int The celcius temp returned as Kelvin, rounded to the readest whole. - */ - public static float celsiusToKelvin(final int i){ - final double f = i + 273.15F; - 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. - * - * @return hexInteger between min and max, inclusive. - */ - public static int generateSingularRandomHexValue(){ - String temp; - final int randomInt = randInt(1, 5); - final Map<Integer, String> colours = Utils.hexColourGeneratorRandom(5); - - if ((colours.get(randomInt) != null) && (colours.size() > 0)){ - temp = colours.get(randomInt); - } - else { - temp = "0F0F0F"; - } - - 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); - } - - public static long[] simplifyNumbersToSmallestForm(final long[] inputArray){ - final long GCD = gcd(inputArray); - final long[] outputArray = new long[inputArray.length]; - for (int i=0;i<inputArray.length;i++){ - if (GCD != 0) { - outputArray[i] = (inputArray[i]/GCD); - } else { - outputArray[i] = inputArray[i]; - } - } - if (outputArray.length > 0) { - return outputArray; - } - return new long[] {}; - } - - private static long gcd(long a, long b){ - while (b > 0) - { - final long temp = b; - b = a % b; // % is remainder - a = temp; - } - return a; - } - - private static long gcd(final long[] input){ - long result = input[0]; - for(int i = 1; i < input.length; i++) { - result = gcd(result, input[i]); - } - return result; - } - - final public static int getRgbAsHex(final short[] RGBA){ - final int returnValue = Utils.rgbtoHexValue(RGBA[0], RGBA[1], RGBA[2]); - return (returnValue == 0) ? 0 : returnValue; - } - - - public final static 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; - } - - public static short safeShort(long number){ - return number>Short.MAX_VALUE ? Short.MAX_VALUE :(short)number; - } - - public static int safeInt(long number, int margin){ - return number>Integer.MAX_VALUE-margin ? Integer.MAX_VALUE-margin :(int)number; - } - - public static int safeInt(long number){ - return number>GT_Values.V[GT_Values.V.length-1] ? safeInt(GT_Values.V[GT_Values.V.length-1],1) : number<Integer.MIN_VALUE ? Integer.MIN_VALUE : (int)number; - } - - public static int getRandomFromArray(int[] mValues) { - int[] mLargeChanceArray = new int[(mValues.length-1)*1000]; - int mValueSelection; - for (int g = 0; g < mLargeChanceArray.length; g++) { - mValueSelection = randInt(0, mValues.length-1); - mLargeChanceArray[g] = mValues[mValueSelection]; - } - return mLargeChanceArray[randInt(0, mLargeChanceArray.length-1)]; - - } - - - /* - * Averages - */ - - public static byte getByteAverage(AutoMap<Byte> aDataSet) { - byte[] aNewSet = new byte[aDataSet.size()]; - for (int u=0;u<aDataSet.size();u++) { - byte b = getSafeByte(aDataSet.get(u)); - aNewSet[u] = b; - } - return getByteAverage(aNewSet); - } - - public static short getShortAverage(AutoMap<Short> aDataSet) { - short[] aNewSet = new short[aDataSet.size()]; - for (int u=0;u<aDataSet.size();u++) { - short b = getSafeShort(aDataSet.get(u)); - aNewSet[u] = b; - } - return getShortAverage(aNewSet); - } - - public static int getIntAverage(AutoMap<Integer> aDataSet) { - int[] aNewSet = new int[aDataSet.size()]; - for (int u=0;u<aDataSet.size();u++) { - int b = getSafeInt(aDataSet.get(u)); - aNewSet[u] = b; - } - return getIntAverage(aNewSet); - } - - public static float getFloatAverage(AutoMap<Float> 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<Long> aDataSet) { - long[] aNewSet = new long[aDataSet.size()]; - for (int u=0;u<aDataSet.size();u++) { - long b = getSafeLong(aDataSet.get(u)); - aNewSet[u] = b; - } - return getLongAverage(aNewSet); - } - - public static double getDoubleAverage(AutoMap<Double> 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) { - return 0; - } - int divisor = aDataSet.length; - byte total = 0; - for (byte i : aDataSet) { - total += i; - } - byte result = safeByte(total/divisor); - return result; - } - - public static short getShortAverage(short[] aDataSet) { - if (aDataSet.length <= 0) { - return 0; - } - int divisor = aDataSet.length; - Logger.WARNING("Calculating Average Short. Divisor: "+divisor); - short total = 0; - for (short i : aDataSet) { - Logger.WARNING("Adding "+i); - total += i; - } - short result = safeShort((total/divisor)); - Logger.WARNING("Average: "+result); - return result; - } - public static int getIntAverage(int[] aDataSet) { - if (aDataSet.length <= 0) { - return 0; - } - int divisor = aDataSet.length; - int total = 0; - for (int i : aDataSet) { - total += i; - } - int result = safeInt(total/divisor); - 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) { - return 0; - } - int divisor = aDataSet.length; - long total = 0; - 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; - } - - public static int howManyPlaces(int aValueForGen) { - if (aValueForGen < 0) { - aValueForGen = makeNegative(aValueForGen); - } - String a = String.valueOf(aValueForGen); - return a.length(); - } - - /** - * Inverts the value, making Positives into Negatives and vice versa. - * @param aPositive - An int value, either positive or negative. - * @return - Inverted int Value. - */ - public static int makeNegative(int aPositive) { - if (aPositive > 0) { - return -aPositive; - } - else if (aPositive < 0) { - return +aPositive; - } - else { - return 0; - } - } - - public static <V> V safeCast(Object aNumberType) { - long a1; - double a2; - a1 = Long.parseLong(aNumberType.toString()); - a2 = Double.parseDouble(aNumberType.toString()); - - if ((aNumberType.getClass() == byte.class) || (aNumberType instanceof Byte)){ - if (a1 >= Byte.MIN_VALUE && a1 <= Byte.MAX_VALUE) { - String s = ""+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; - 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; - 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; - 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; - 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; - Double s1 = Double.valueOf(s); - return (V) s1; - - } - } - - Integer o = 0; - return (V) o; - - } - - public static byte getSafeByte(Byte b) { - Byte a = safeCast(b); - return a.byteValue(); - } - - public static short getSafeShort(Short b) { - Short a = safeCast(b); - return a.shortValue(); - } - - public static int getSafeInt(Integer b) { - Integer a = safeCast(b); - return a.intValue(); - } - - 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; - } - - public static int safeCast_LongToInt(long o) { - if (o > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } - else { - int i = (int) o; - return i; - } - } - - 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. - * @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 balance(int aInput, int aMin, int aMax) { - 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<Integer, Integer> 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<Integer, Integer>(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. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b}. - */ - public static Number min(Number a, Number b) { - return (a.longValue() <= b.longValue()) ? a : b; - } - - /** - * Returns the greater of two {@code Number}s. That is, the - * result is the argument closer to the value of - * {@link Long#MAX_VALUE}. If the arguments have the same value, - * the result is that same value. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static Number max(Number a, Number b) { - return (a.longValue() >= b.longValue()) ? a : b; - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ClientUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ClientUtils.java deleted file mode 100644 index 806f83d830..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/ClientUtils.java +++ /dev/null @@ -1,18 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; - -public class ClientUtils { - - static { - if (FMLCommonHandler.instance().getSide() == Side.SERVER) { - Logger.ERROR("Something tried to access the ClientUtils class from the Server Side."); - Logger.ERROR("Soft crashing to prevent data corruption."); - CORE.crash(); - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java deleted file mode 100644 index 2f273d5f7f..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java +++ /dev/null @@ -1,102 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import gtPlusPlus.api.objects.Logger; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -public class EnchantingUtils { - - - public static final int XP_PER_BOTTLE = 8; - public static final int RATIO = 20; - public static final int LIQUID_PER_XP_BOTTLE = 160; - public static final double RATIO_MOB_ESSENCE_TO_LIQUID_XP = 13.32; - - public static int liquidToXpRatio(final int liquid) { - return liquid / RATIO; - } - - public static int xpToLiquidRatio(final int xp) { - return xp * RATIO; - } - - public static FluidStack getEssenceFromLiquidXp(final int xpAmount){ - if (xpAmount <= 0){ - return null; - } - return getMobEssence((int) (xpAmount*RATIO_MOB_ESSENCE_TO_LIQUID_XP)); - } - - public static FluidStack getLiquidXpFromEssence(final int essenceAmount){ - if (essenceAmount <= 0){ - return null; - } - return getLiquidXP((int) (essenceAmount/RATIO_MOB_ESSENCE_TO_LIQUID_XP)); - } - - public static int getLiquidForLevel(final int level) { - final int xp = getExperienceForLevel(level); - return xpToLiquidRatio(xp); - } - - public static int getLevelForLiquid(final int liquid) { - final int xp = liquidToXpRatio(liquid); - return getLevelForExperience(xp); - } - - public static int getExperienceForLevel(final int level) { - if (level == 0) { - return 0; - } - if ((level > 0) && (level < 16)) { - return level * 17; - } - if ((level > 15) && (level < 31)) { - return (int) (((1.5 * Math.pow(level, 2.0)) - (29.5 * level)) + 360.0); - } - return (int) (((3.5 * Math.pow(level, 2.0)) - (151.5 * level)) + 2220.0); - } - - public static int getXpToNextLevel(final int level) { - final int levelXP = getLevelForExperience(level); - final int nextXP = getExperienceForLevel(level + 1); - return nextXP - levelXP; - } - - public static int getLevelForExperience(final int experience) { - int i; - for (i = 0; getExperienceForLevel(i) <= experience; ++i) { - } - return i - 1; - } - - - - - - - - //Xp Fluids - public static FluidStack getMobEssence(final int amount){ - Logger.WARNING("Trying to get a fluid stack of Mob Essence."); - try { - return FluidRegistry.getFluidStack("mobessence", amount).copy(); - } - catch (final Throwable e){ - return null; - } - - } - - public static FluidStack getLiquidXP(final int amount){ - Logger.WARNING("Trying to get a fluid stack of Liquid XP."); - try { - return FluidRegistry.getFluidStack("xpjuice", amount).copy(); - } - catch (final Throwable e){ - return null; - } - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java deleted file mode 100644 index 8b02ea9c7c..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java +++ /dev/null @@ -1,134 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import gregtech.api.util.GT_ModHandler; -import ic2.api.item.IElectricItem; -import ic2.api.item.IElectricItemManager; -import ic2.api.item.ISpecialElectricItem; -import net.minecraft.item.ItemRedstone; -import net.minecraft.item.ItemStack; - -public class EnergyUtils { - - public static class EU { - - public static boolean isElectricItem(ItemStack aStack) { - if (aStack == null || aStack.getItem() == null || aStack.getItem() instanceof ItemRedstone) { - return false; - } - if (aStack.getItem() instanceof ISpecialElectricItem) { - return true; - } - else if (aStack.getItem() instanceof IElectricItem) { - return true; - } - else if (aStack.getItem() instanceof IElectricItemManager) { - return true; - } - else { - return GT_ModHandler.isElectricItem(aStack); - } - } - - public static boolean isChargerItem(ItemStack aStack) { - return GT_ModHandler.isChargerItem(aStack); - } - - public static boolean charge(ItemStack aStack, int aEnergyToInsert, int aTier) { - return 0 != GT_ModHandler.chargeElectricItem(aStack, aEnergyToInsert, aTier, true, false); - } - - public static boolean discharge(ItemStack aStack, int aEnergyToDrain, int aTier) { - if (isElectricItem(aStack)) { - int tTier = ((IElectricItem) aStack.getItem()).getTier(aStack); - int aDischargeValue = GT_ModHandler.dischargeElectricItem(aStack, aEnergyToDrain, tTier, true, false, false); - //Logger.INFO("Trying to drain "+aDischargeValue); - return aDischargeValue > 0; - } - else { - return false; - } - } - - public static long getMaxStorage(ItemStack aStack) { - if (isElectricItem(aStack)) { - if (aStack.getItem() instanceof ISpecialElectricItem) { - ISpecialElectricItem bStack = (ISpecialElectricItem) aStack.getItem(); - return (long) bStack.getMaxCharge(aStack); - } - if (aStack.getItem() instanceof IElectricItem) { - IElectricItem bStack = (IElectricItem) aStack.getItem(); - return (long) bStack.getMaxCharge(aStack); - } - if (aStack.getItem() instanceof IElectricItemManager) { - IElectricItemManager bStack = (IElectricItemManager) aStack.getItem(); - return (long) bStack.getCharge(aStack); - } - } - else { - return 0; - } - return 0; - } - - public static long getCharge(ItemStack aStack) { - if (isElectricItem(aStack)) { - if (aStack.getItem() instanceof ISpecialElectricItem) { - ISpecialElectricItem bStack = (ISpecialElectricItem) aStack.getItem(); - return (long) bStack.getManager(aStack).getCharge(aStack); - } - if (aStack.getItem() instanceof IElectricItemManager) { - IElectricItemManager bStack = (IElectricItemManager) aStack.getItem(); - return (long) bStack.getCharge(aStack); - } - } - else { - return 0; - } - return 0; - } - - public static boolean hasCharge(ItemStack aStack) { - if (isElectricItem(aStack)) { - if (aStack.getItem() instanceof ISpecialElectricItem) { - ISpecialElectricItem bStack = (ISpecialElectricItem) aStack.getItem(); - return bStack.canProvideEnergy(aStack); - } - if (aStack.getItem() instanceof IElectricItem) { - IElectricItem bStack = (IElectricItem) aStack.getItem(); - return bStack.canProvideEnergy(aStack); - } - if (aStack.getItem() instanceof IElectricItemManager) { - IElectricItemManager bStack = (IElectricItemManager) aStack.getItem(); - return bStack.getCharge(aStack) > 0; - } - } - else { - return false; - } - return false; - } - - public static int getTier(ItemStack aStack) { - if (isElectricItem(aStack)) { - if (aStack.getItem() instanceof ISpecialElectricItem) { - ISpecialElectricItem bStack = (ISpecialElectricItem) aStack.getItem(); - return bStack.getTier(aStack); - } - if (aStack.getItem() instanceof IElectricItem) { - IElectricItem bStack = (IElectricItem) aStack.getItem(); - return bStack.getTier(aStack); - } - } - else { - return 0; - } - return 0; - } - - } - - public static class RF { - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java deleted file mode 100644 index fda7b0b738..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ /dev/null @@ -1,290 +0,0 @@ -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 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.ReflectionUtils; -import ic2.core.IC2Potion; -import ic2.core.item.armor.ItemArmorHazmat; -import net.minecraft.block.Block; -import net.minecraft.entity.*; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -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; - -public class EntityUtils { - - public static void setEntityOnFire(final Entity aEntity, final int length){ - if (!isEntityImmuneToFire(aEntity)) { - aEntity.setFire(length); - } - } - - public static boolean isEntityOnFire(final Entity aEntity) { - Field aIsOnFire = ReflectionUtils.getField(Entity.class, "fire"); - if (aIsOnFire != null) { - int aFireTime = (int) ReflectionUtils.getFieldValue(aIsOnFire, aEntity); - return aFireTime > 0; - } - return false; - } - - public static boolean isEntityImmuneToFire(Entity aEntity) { - return aEntity.isImmuneToFire(); - } - - public static int getFacingDirection(final Entity entity){ - final int d = MathHelper.floor_double((entity.rotationYaw * 4.0F) / 360 + 0.50) & 3; - return d; - } - - @Deprecated - public static Block findBlockUnderEntityNonBoundingBox(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.posY-0.2D - parEntity.yOffset); - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return parEntity.worldObj.getBlock(blockX, blockY, blockZ); - } - - public static Block findBlockUnderEntity(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1; - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return parEntity.worldObj.getBlock(blockX, blockY, blockZ); - } - - public static BlockPos findBlockPosUnderEntity(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1; - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return new BlockPos(blockX, blockY, blockZ, parEntity.worldObj); - } - - public static BlockPos findBlockPosOfEntity(final Entity parEntity){ - final int blockX = MathHelper.floor_double(parEntity.posX); - final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY); - final int blockZ = MathHelper.floor_double(parEntity.posZ); - return new BlockPos(blockX, blockY, blockZ, parEntity.worldObj); - } - - //TODO - public static void registerEntityToBiomeSpawns(final Class<EntityLiving> classy, final EnumCreatureType EntityType, final BiomeGenBase baseBiomeGen){ - EntityRegistry.addSpawn(classy, 6, 1, 5, EntityType, baseBiomeGen); //change the values to vary the spawn rarity, biome, etc. - } - - public static boolean applyRadiationDamageToEntity(final int stackSize, final int radiationLevel, final World world, final Entity entityHolding){ - if (!world.isRemote){ - if ((radiationLevel > 0) && (entityHolding instanceof EntityLivingBase)) { - final EntityLivingBase entityLiving = (EntityLivingBase) entityHolding; - if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode){ - if (!ItemArmorHazmat.hasCompleteHazmat(entityLiving) && !GT_Utility.isWearingFullRadioHazmat(entityLiving)) { - int duration; - if (entityLiving.getActivePotionEffect(IC2Potion.radiation) != null){ - //Utils.LOG_INFO("t"); - duration = (radiationLevel*5)+entityLiving.getActivePotionEffect(IC2Potion.radiation).getDuration(); - } - else { - //Utils.LOG_INFO("f"); - duration = radiationLevel*30; - } - //IC2Potion.radiation.applyTo(entityLiving, duration, damage * 15); - applyRadioactivity(entityLiving, radiationLevel, stackSize); - } - } - } - return true; - } - return false; - } - - public static boolean isWearingFullFrostHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!HazmatUtils.providesProtetion_Frost(aEntity.getEquipmentInSlot(i))) { - return false; - } - return true; - } - - public static boolean isWearingFullHeatHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!HazmatUtils.providesProtetion_Fire(aEntity.getEquipmentInSlot(i))) { - return false; - } - return true; - } - - public static boolean isWearingFullBioHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!HazmatUtils.providesProtetion_Biohazard(aEntity.getEquipmentInSlot(i))) { - return false; - } - return true; - } - - public static boolean isWearingFullRadioHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!HazmatUtils.providesProtetion_Radiation(aEntity.getEquipmentInSlot(i))) { - return false; - } - return true; - } - - public static boolean isWearingFullElectroHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!HazmatUtils.providesProtetion_Electricity(aEntity.getEquipmentInSlot(i))) { - return false; - } - return true; - } - - public static boolean isWearingFullGasHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!HazmatUtils.providesProtetion_Gas(aEntity.getEquipmentInSlot(i))) { - return false; - } - return true; - } - - public static boolean applyRadioactivity(EntityLivingBase aEntity, int aLevel, int aAmountOfItems) { - if (aLevel > 0 && aEntity != null && aEntity.getCreatureAttribute() != EnumCreatureAttribute.UNDEAD && aEntity.getCreatureAttribute() != EnumCreatureAttribute.ARTHROPOD && !ItemArmorHazmat.hasCompleteHazmat(aEntity)) { - PotionEffect tEffect = null; - aEntity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, aLevel * 140 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.moveSlowdown)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, aLevel * 150 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.digSlowdown)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.confusion.id, aLevel * 130 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.confusion)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.weakness.id, aLevel * 150 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.weakness)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.hunger.id, aLevel * 130 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.hunger)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(IC2Potion.radiation.id, aLevel * 180 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.potionTypes[24])) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - return true; - } - return false; - } - - public static boolean applyHeatDamageToEntity(final int heatLevel, final World world, final Entity entityHolding){ - if (!world.isRemote){ - if ((heatLevel > 0) && (entityHolding instanceof EntityLivingBase)) { - final EntityLivingBase entityLiving = (EntityLivingBase) entityHolding; - if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode){ - if (!GT_Utility.isWearingFullHeatHazmat(entityLiving)) { - return GT_Utility.applyHeatDamage(entityLiving, heatLevel); - } - } - } - } - return false; - } - - - /** - * Static Version of the method used in {@code doFireDamage(entity, int)} to save memory. - */ - private volatile static Method dealFireDamage = null; - - /** - * Reflective Call to do Fire Damage to an entity (Does not set entity on fire though) - */ - public synchronized static boolean doFireDamage(Entity entity, int amount){ - if (dealFireDamage == null){ - dealFireDamage = ReflectionUtils.getMethod(Entity.class, "dealFireDamage", int.class); - } - else { - try { - dealFireDamage.invoke(entity, amount); - } - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} - } - return false; - } - - public static void doDamage(Entity entity, DamageSource dmg, int i) { - entity.attackEntityFrom(dmg, i); - } - - public static boolean isTileEntityRegistered(Class aTileClass, String aTileName) { - Field aRegistry = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "nameToClassMap"); - Field aRegistry2 = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "classToNameMap"); - try { - Object o = aRegistry.get(null); - if (o != null) { - Map nameToClassMap = (Map) o; - if (!nameToClassMap.containsKey(aTileName)) { - o = aRegistry2.get(null); - if (o != null) { - Map classToNameMap = (Map) o; - if (!classToNameMap.containsKey(aTileClass)) { - return false; - } - else { - return true; - } - } - } - else { - return true; - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - } - return false; - } - - public static double getDistance(Entity p1, Entity p2) { - return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2)); - } - - public static AutoMap<Entity> getEntitiesWithinBoundingBoxExcluding(Entity aExclusion, AABB aBoundingBox){ - if (aExclusion == null) { - return new AutoMap<Entity>(); - } - else { - List<Entity> aEntities = aBoundingBox.world().getEntitiesWithinAABBExcludingEntity(aExclusion, aBoundingBox.get()); - return new AutoMap<Entity>(aEntities); - } - } - - public static AutoMap<Entity> getEntitiesWithinBoundingBox(Class aEntityType, AABB aBoundingBox){ - if (aEntityType == null) { - return new AutoMap<Entity>(); - } - else { - List<Entity> aEntities = aBoundingBox.world().getEntitiesWithinAABB(aEntityType, aBoundingBox.get()); - return new AutoMap<Entity>(aEntities); - } - } - - /** - * Provides the ability to provide custom drops upon the death of EntityLivingBase objects. Simplified function with static Max drop size of 1. - * @param aMobClass - The Base Class you want to drop this item. - * @param aStack - The ItemStack, stack size is not respected. - * @param aChance - Chance out of 10000, where 100 is 1%. (1 = 0.01% - this is ok) - */ - public static void registerDropsForMob(Class aMobClass, ItemStack aStack, int aChance) { - registerDropsForMob(aMobClass, aStack, 1, aChance); - } - - /** - * Provides the ability to provide custom drops upon the death of EntityLivingBase objects. - * @param aMobClass - The Base Class you want to drop this item. - * @param aStack - The ItemStack, stack size is not respected. - * @param aMaxAmount - The maximum size of the ItemStack which drops. - * @param aChance - Chance out of 10000, where 100 is 1%. (1 = 0.01% - this is ok) - */ - public static void registerDropsForMob(Class aMobClass, ItemStack aStack, int aMaxAmount, int aChance) { - EntityDeathHandler.registerDropsForMob(aMobClass, aStack, aMaxAmount, aChance); - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java deleted file mode 100644 index 758ec8bab0..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java +++ /dev/null @@ -1,621 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import gregtech.api.enums.Dyes; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.util.GT_LanguageManager; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.minecraft.FluidGT6; -import gtPlusPlus.core.item.base.BaseItemComponent; -import gtPlusPlus.core.item.base.cell.BaseItemPlasmaCell; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.material.MaterialStack; -import gtPlusPlus.core.recipe.common.CI; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; - -public class FluidUtils { - - public static FluidStack getWater(final int amount){ - return FluidUtils.getFluidStack("water", amount); - } - - public static FluidStack getDistilledWater(final int amount){ - return FluidUtils.getFluidStack("ic2distilledwater", amount); - } - - public static FluidStack getHotWater(final int amount) { - return FluidUtils.getFluidStack("ic2hotwater", amount); - } - - public static FluidStack getLava(final int amount){ - return FluidUtils.getFluidStack("lava", amount); - } - - public static FluidStack getPahoehoeLava(final int amount){ - return FluidUtils.getFluidStack("ic2pahoehoelava", amount); - } - - public static FluidStack getMilk(final int amount){ - return FluidUtils.getFluidStack("milk", amount); - } - - public static FluidStack getColdCoolant(final int amount){ - return FluidUtils.getFluidStack("ic2coolant", amount); - } - - public static FluidStack getHotCoolant(final int amount){ - return FluidUtils.getFluidStack("ic2hotcoolant", amount); - } - - public static FluidStack getSteam(final int amount){ - return FluidUtils.getFluidStack("steam", amount); - } - - public static FluidStack getIC2Steam(final int amount){ - return FluidUtils.getFluidStack("ic2steam", amount); - } - - public static FluidStack getSuperHeatedSteam(final int amount){ - return FluidUtils.getFluidStack("ic2superheatedsteam", amount); - } - - @Deprecated - /** - * Do not use - Gives third tier steam - Not implemented - * @param amount - * @return - */ - public static FluidStack getHyperSteam(final int amount){ - return FluidUtils.getFluidStack("water", amount); - } - - public static FluidStack getUUA(final int amount){ - return FluidUtils.getFluidStack("uuamplifier", amount); - } - - public static FluidStack getUUM(final int amount){ - return FluidUtils.getFluidStack("ic2uumatter", amount); - } - - public static FluidStack getFluidStack(final String fluidName, final int amount){ - Logger.WARNING("Trying to get a fluid stack of "+fluidName); - try { - FluidStack x = FluidRegistry.getFluidStack(fluidName, amount); - return x != null ? x.copy() : null; - } - catch (final Throwable e){ - return null; - } - - } - - public static FluidStack getFluidStack(final FluidStack vmoltenFluid, final int fluidAmount) { - Logger.WARNING("Trying to get a fluid stack of "+vmoltenFluid.getFluid().getName()); - try { - FluidStack x = FluidRegistry.getFluidStack(vmoltenFluid.getFluid().getName(), fluidAmount); - return x != null ? x.copy() : null; - } - catch (final Throwable e){ - return null; - } - } - - public static FluidStack getFluidStack(final Fluid vFluid, final int fluidAmount) { - Logger.WARNING("Trying to get a fluid stack of "+vFluid.getName()); - try { - FluidStack x = FluidRegistry.getFluidStack(vFluid.getName(), fluidAmount); - return x != null ? x.copy() : null; - } - catch (final Throwable e){ - return null; - } - } - - public static FluidStack[] getFluidStackArray(final String fluidName, final int amount){ - Logger.WARNING("Trying to get a fluid stack of "+fluidName); - try { - final FluidStack[] singleFluid = {FluidRegistry.getFluidStack(fluidName, amount)}; - return singleFluid; - } - catch (final Throwable e){ - return null; - } - - } - - public static FluidStack[] getFluidStackArray(final FluidStack fluidName, final int amount){ - Logger.WARNING("Trying to get a fluid stack of "+fluidName); - try { - final FluidStack[] singleFluid = {FluidRegistry.getFluidStack(fluidName.getLocalizedName(), amount)}; - return singleFluid; - } - catch (final Throwable e){ - return null; - } - - } - - public static Fluid addGtFluid(final String aName, final String aLocalized, final GT_Materials aMaterial, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) { - return addGtFluid(aName, aLocalized, aMaterial, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount, true); - } - - - public static Fluid addGtFluid(final String aName, final String aLocalized, final GT_Materials aMaterial, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount, final boolean aGenerateCell) { - Fluid g = addGTFluid(aName, "fluid.autogenerated", aLocalized, aMaterial != null ? aMaterial.mRGBa : new short[]{255, 255, 255, 0}, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount, aGenerateCell); - if (g != null) { - if (aMaterial != null) { - switch (aState) { - case 1: { - aMaterial.mFluid = (g); - break; - } - case 2: { - aMaterial.mGas = (g); - break; - } - case 3: { - aMaterial.mPlasma = (g); - break; - } - } - } - return g; - } - return null; - } - - public static Fluid addGTFluid(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount, final boolean aGenerateCell) { - return addGTFluid("molten."+aName, "molten.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount, aGenerateCell); - } - - public static Fluid addGTFluidNonMolten(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount, final boolean aGenerateCell) { - return addGTFluid("fluid."+aName, "fluid.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount, aGenerateCell); - } - - public static Fluid addGTFluidNoPrefix(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount, final boolean aGenerateCell) { - return addGTFluid(aName, "fluid.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount, aGenerateCell); - } - //Gass - public static Fluid addGtGas(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount, final boolean aGenerateCell) { - return addGTFluid(aName, "fluid.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount, aGenerateCell); - } - - public static Fluid addGTPlasma(final Material aMaterial) { - if (aMaterial.getLocalizedName().toLowerCase().contains("clay") || (aMaterial.getComposites().size()>1) || aMaterial.getLocalizedName().toLowerCase().contains("wrought")){ - return null; - } - Logger.INFO("Generating a "+aMaterial.getLocalizedName()+" Plasma Cell"); - if (aMaterial.vComponentCount != 1){ - Logger.INFO("Compound made from: "); - for (final MaterialStack x : aMaterial.getComposites()){ - Logger.INFO(x.getStackMaterial().getLocalizedName()); - } - Logger.INFO("Material is a composite, not generating plasma."); - return null; - } - - ItemStack temp = null; - //Generate a Cell if we need to - if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellPlasma"+aMaterial.getUnlocalizedName(), 1) == null){ - new BaseItemPlasmaCell(aMaterial); - temp = aMaterial.getPlasmaCell(1); - } - else { - temp = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellPlasma"+aMaterial.getUnlocalizedName(), 1); - } - if (temp != null){ - return addGTFluid( - "plasma." + Utils.sanitizeString(aMaterial.getLocalizedName().toLowerCase()), - "plasma.autogenerated", - aMaterial.getLocalizedName() + " Plasma", - aMaterial.getRGBA(), - 3, - 10000, - temp, - ItemUtils.getEmptyCell(), - 1000, - false); - } - return null; - } - - public static Fluid addGTFluid(String aName, final String aTexture, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount, final boolean aGenerateFilledCell) { - - String aNameOriginal = aName; - - aName = Utils.sanitizeString(aName.toLowerCase()); - - String aLocalName = (aLocalized == null) ? aName : aLocalized; - - Fluid rFluid; - Fluid gFluid = FluidRegistry.getFluid(aName); - FluidStack aCheck = FluidUtils.getWildcardFluidStack(aName.toLowerCase(), 1000); - boolean register = false; - if (aCheck != null) { - rFluid = aCheck.getFluid(); - } - else if (gFluid != null) { - rFluid = gFluid; - } - else { - rFluid = new FluidGT6(aName, aTexture, (aRGBa != null) ? aRGBa : Dyes._NULL.getRGBA()); - register = true; - - } - - if (register) { - GT_LanguageManager.addStringLocalization(rFluid.getUnlocalizedName(), aLocalName); - if (FluidRegistry.registerFluid(rFluid)) { - switch (aState) { - case 0: { - rFluid.setGaseous(false); - rFluid.setViscosity(10000); - break; - } - case 1: - case 4: { - rFluid.setGaseous(false); - rFluid.setViscosity(1000); - break; - } - case 2: { - rFluid.setGaseous(true); - rFluid.setDensity(-100); - rFluid.setViscosity(200); - break; - } - case 3: { - rFluid.setGaseous(true); - rFluid.setDensity(-10000); - rFluid.setViscosity(10); - rFluid.setLuminosity(15); - break; - } - } - } - } - - - - if (aFullContainer == null) { - ItemStack oreStack = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+aName, 1); - aFullContainer = oreStack; - } - - Item tempCell = null; - //Generate a Cell if we need to - if (aGenerateFilledCell && aFullContainer == null) { - String aMatName = aNameOriginal; - if (aMatName.contains("molten.")) { - aMatName = aMatName.replace("molten.", ""); - aMatName = aMatName.substring(0, 1).toUpperCase() + aMatName.substring(1); - } - if (aMatName.contains("fluid.")) { - aMatName = aMatName.replace("fluid.", ""); - aMatName = aMatName.substring(0, 1).toUpperCase() + aMatName.substring(1); - } - tempCell = new BaseItemComponent(aMatName, aLocalized, aRGBa); - aFullContainer = ItemUtils.getSimpleStack(tempCell); - } - - if ((rFluid.getTemperature() == new Fluid("test").getTemperature()) || (rFluid.getTemperature() <= 0)) { - rFluid.setTemperature((int) (aTemperatureK)); - } - if ((aFullContainer != null) && (aEmptyContainer != null) && !FluidContainerRegistry.registerFluidContainer(new FluidStack(rFluid, aFluidAmount), aFullContainer, aEmptyContainer)) { - CORE.RA.addFluidCannerRecipe(CI.emptyCells(1), aFullContainer, new FluidStack(rFluid, aFluidAmount)); - } - else { - //Utils.LOG_INFO("Failed creating recipes to fill/empty cells of "+aName+"."); - } - return rFluid; - } - - public static boolean valid(final Object aStack) { - return (aStack != null) && (aStack instanceof ItemStack) && (((ItemStack)aStack).getItem() != null) && (((ItemStack)aStack).stackSize >= 0); - } - - public static boolean invalid(final Object aStack) { - return (aStack == null) || !(aStack instanceof ItemStack) || (((ItemStack)aStack).getItem() == null) || (((ItemStack)aStack).stackSize < 0); - } - - public static boolean equal(final ItemStack aStack1, final ItemStack aStack2) { - return equal(aStack1, aStack2, false); - } - - public static boolean equal(final ItemStack aStack1, final ItemStack aStack2, final boolean aIgnoreNBT) { - return (aStack1 != null) && (aStack2 != null) && equal_(aStack1, aStack2, aIgnoreNBT); - } - - public static boolean equal_(final ItemStack aStack1, final ItemStack aStack2, final boolean aIgnoreNBT) { - return (aStack1.getItem() == aStack2.getItem()) && (aIgnoreNBT || ((aStack1.getTagCompound() == null == (aStack2.getTagCompound() == null)) && ((aStack1.getTagCompound() == null) || aStack1.getTagCompound().equals(aStack2.getTagCompound())))) && ((meta(aStack1) == meta(aStack2)) || (meta(aStack1) == 32767) || (meta(aStack2) == 32767)); - } - - public static ItemStack copy(final Object... aStacks) { - for (final Object tStack : aStacks) { - if (valid(tStack)) { - return ((ItemStack)tStack).copy(); - } - } - return null; - } - - public static ItemStack copyMeta(final long aMetaData, final Object... aStacks) { - final ItemStack rStack = copy(aStacks); - if (invalid(rStack)) { - return null; - } - return meta(rStack, aMetaData); - } - - public static short meta(final ItemStack aStack) { - return (short)Items.feather.getDamage(aStack); - } - - public static ItemStack meta(final ItemStack aStack, final long aMeta) { - Items.feather.setDamage(aStack, (short)aMeta); - return aStack; - } - - public static ItemStack amount(final long aAmount, final Object... aStacks) { - final ItemStack rStack = copy(aStacks); - if (invalid(rStack)) { - return null; - } - rStack.stackSize = (int)aAmount; - return rStack; - } - - public static ItemStack container(final ItemStack aStack, final boolean aCheckIFluidContainerItems) { - if (invalid(aStack)) { - return null; - } - if (aStack.getItem().hasContainerItem(aStack)) { - return aStack.getItem().getContainerItem(aStack); - } - if (equal(aStack, ItemUtils.getEmptyCell(), true)) { - return null; - } - if (aCheckIFluidContainerItems && (aStack.getItem() instanceof IFluidContainerItem) && (((IFluidContainerItem)aStack.getItem()).getCapacity(aStack) > 0)) { - final ItemStack tStack = amount(1L, aStack); - ((IFluidContainerItem)aStack.getItem()).drain(tStack, Integer.MAX_VALUE, true); - if (!equal(aStack, tStack)) { - return tStack; - } - return null; - } - if (equal(aStack, ItemList.IC2_ForgeHammer.get(1)) || equal(aStack, ItemList.IC2_WireCutter.get(1))) { - return copyMeta(meta(aStack) + 1, aStack); - } - return null; - } - - public static ItemStack container(final ItemStack aStack, final boolean aCheckIFluidContainerItems, final int aStacksize) { - return amount(aStacksize, container(aStack, aCheckIFluidContainerItems)); - } - - public final static Fluid generateFluid(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, boolean aGenerateCell){ - FluidStack aFStack = (FluidUtils.getFluidStack("molten"+"."+unlocalizedName.toLowerCase(), 1)); - if (aFStack == null){ - Logger.WARNING("Generating our own fluid."); -/* ItemStack cell = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1); - if (cell == null){ - final Item temp = new BaseItemComponent(unlocalizedName, localizedName, RGBA); - cell = ItemUtils.getSimpleStack(temp); - }*/ - final Fluid gtFluid = FluidUtils.addGTFluid( - unlocalizedName, - "Molten "+localizedName, - RGBA, - 4, - MeltingPoint, - null, - ItemUtils.getEmptyCell(), - 1000, - aGenerateCell); - - return gtFluid; - } - else { - Logger.INFO("FLUID GENERATION FAILED FOR "+localizedName+", ALREADY EXISTS"); - return aFStack.getFluid(); - } - } - - public final static Fluid generateFluidNonMolten(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, final boolean aGenerateCell){ - return generateFluidNonMolten(unlocalizedName, localizedName, MeltingPoint, RGBA, null, null, 0, aGenerateCell); - } - - - public final static Fluid generateFluidNonMolten(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, final ItemStack dustStack, final ItemStack dustStack2){ - return generateFluidNonMolten(unlocalizedName, localizedName, MeltingPoint, RGBA, dustStack, dustStack2, 144, true); - } - - public final static Fluid generateFluidNonMolten(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, final ItemStack dustStack, final ItemStack dustStack2, final boolean aGenerateCell){ - return generateFluidNonMolten(unlocalizedName, localizedName, MeltingPoint, RGBA, dustStack, dustStack2, 144, aGenerateCell); - } - - public final static Fluid generateFluidNonMolten(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, ItemStack dustStack, final ItemStack dustStack2, final int amountPerItem, final boolean aGenerateCell){ - if (dustStack == null){ - dustStack = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dust"+Utils.sanitizeString(localizedName), 1); - } - FluidStack aFStack = (FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1)); - if (aFStack == null){ - Logger.WARNING("Generating our own fluid."); - - final Fluid gtFluid = FluidUtils.addGTFluidNonMolten( - unlocalizedName, - localizedName, - RGBA, - 4, - MeltingPoint, - null, - ItemUtils.getEmptyCell(), - 1000, - aGenerateCell); - - if (dustStack != null){ - CORE.RA.addFluidExtractionRecipe( - dustStack, //Input 2 - FluidUtils.getFluidStack(gtFluid, amountPerItem), //Fluid Output - 1*20, //Duration - 16 //Eu Tick - ); - } - if (dustStack2 != null){ - CORE.RA.addFluidExtractionRecipe( - dustStack2, //Input 2 - FluidUtils.getFluidStack(gtFluid, amountPerItem), //Fluid Output - 1*20, //Duration - 16 //Eu Tick - ); - } - - return gtFluid; - } - else { - Logger.INFO("FLUID GENERATION FAILED FOR "+localizedName+", ALREADY EXISTS"); - return aFStack.getFluid(); - } - } - - public final static Fluid generateFluidNoPrefix(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA){ - return generateFluidNoPrefix(unlocalizedName, localizedName, MeltingPoint, RGBA, true); - } - - public final static Fluid generateFluidNoPrefix(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, final boolean aGenerateCell){ - Fluid gtFluid; - if (FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1) == null){ - Logger.WARNING("Generating our own fluid."); - gtFluid = FluidUtils.addGTFluidNoPrefix( - unlocalizedName, - localizedName, - RGBA, - 4, - MeltingPoint, - null, - ItemUtils.getEmptyCell(), - 1000, - aGenerateCell); - } - else { - gtFluid = FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1).getFluid(); - } - //Generate a Cell if we need to -// if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1) == null){ -// new BaseItemCell(unlocalizedName, localizedName, RGBA, gtFluid); -// } - return gtFluid; - } - - public final static Fluid generateGas(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, final boolean aGenerateCell){ - Fluid gtFluid; - if (FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1) == null){ - Logger.WARNING("Generating our own gas."); - gtFluid = FluidUtils.addGtGas( - unlocalizedName, - localizedName, - RGBA, - 3, - MeltingPoint, - null, - ItemUtils.getEmptyCell(), - 1000, - aGenerateCell); - } - else { - gtFluid = FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1).getFluid(); - } - //Generate a Cell if we need to -/* if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1) == null){ - new BaseItemCell(unlocalizedName, localizedName, RGBA, gtFluid); - }*/ - return gtFluid; - } - - - - - public static FluidStack getMobEssence(final int amount){ - return EnchantingUtils.getMobEssence(amount); - } - - public static FluidStack getLiquidXP(final int amount){ - return EnchantingUtils.getLiquidXP(amount); - } - - public static boolean doesFluidExist(String aFluidName) { - FluidStack aFStack1 = (FluidUtils.getFluidStack("molten"+"."+aFluidName.toLowerCase(), 1)); - FluidStack aFStack2 = (FluidUtils.getFluidStack("fluid"+"."+aFluidName.toLowerCase(), 1)); - FluidStack aFStack3 = (FluidUtils.getFluidStack(aFluidName.toLowerCase(), 1)); - FluidStack aFStack4 = (FluidUtils.getFluidStack(aFluidName, 1)); - FluidStack aFStack5 = (FluidUtils.getFluidStack("liquid_"+aFluidName.toLowerCase(), 1)); - FluidStack aFStack6 = (FluidUtils.getFluidStack("liquid"+"."+aFluidName.toLowerCase(), 1)); - return aFStack1 != null || aFStack2 != null || aFStack3 != null || aFStack4 != null || aFStack5 != null || aFStack6 != null; - } - - public static FluidStack getWildcardFluidStack(String aFluidName, int amount) { - FluidStack aFStack1 = (FluidUtils.getFluidStack("molten"+"."+aFluidName.toLowerCase(), amount)); - FluidStack aFStack2 = (FluidUtils.getFluidStack("fluid"+"."+aFluidName.toLowerCase(), amount)); - FluidStack aFStack3 = (FluidUtils.getFluidStack(aFluidName.toLowerCase(), amount)); - FluidStack aFStack4 = (FluidUtils.getFluidStack(aFluidName, amount)); - FluidStack aFStack5 = (FluidUtils.getFluidStack("liquid_"+aFluidName.toLowerCase(), amount)); - FluidStack aFStack6 = (FluidUtils.getFluidStack("liquid"+"."+aFluidName.toLowerCase(), amount)); - if (aFStack1 != null) { - return aFStack1; - } - if (aFStack2 != null) { - return aFStack2; - } - if (aFStack3 != null) { - return aFStack3; - } - if (aFStack4 != null) { - return aFStack4; - } - if (aFStack5 != null) { - return aFStack5; - } - if (aFStack6 != null) { - return aFStack6; - } - return null; - } - - public static FluidStack getWildcardFluidStack(Materials aMaterial, int amount) { - FluidStack aFStack1 = aMaterial.getFluid(amount); - FluidStack aFStack2 = aMaterial.getGas(amount); - FluidStack aFStack3 = aMaterial.getMolten(amount); - FluidStack aFStack4 = aMaterial.getSolid(amount); - if (aFStack1 != null) { - return aFStack1; - } - else if (aFStack2 != null) { - return aFStack2; - } - else if (aFStack3 != null) { - return aFStack3; - } - else if (aFStack4 != null) { - return aFStack4; - } - else { - return null; - } - } - - public static FluidStack getAir(int aAmount) { - return FluidUtils.getFluidStack("air", aAmount); - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java deleted file mode 100644 index 9f5d4f36ca..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java +++ /dev/null @@ -1,60 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.init.Items; -import net.minecraft.item.EnumAction; -import net.minecraft.item.Item; -import net.minecraft.item.ItemBlock; -import net.minecraft.item.ItemFood; -import net.minecraft.item.ItemStack; - -public class FoodUtils { - - public static final Class IEdibleClass; - - static { - IEdibleClass = ReflectionUtils.getClass("squeek.applecore.api.food.IEdible"); - } - - public static boolean isFood(ItemStack food) { - - if (food == null) { - return false; - } - - Item item = food.getItem(); - - if(item == null) { - return false; - } - - EnumAction action = item.getItemUseAction(food); - - if(item instanceof ItemBlock || action == EnumAction.eat || action == EnumAction.drink) { - if(getUnmodifiedFoodValues(food) > 0) { - return true; - } - } - - return false; - } - - private static int getUnmodifiedFoodValues(ItemStack stack) { - - if (stack == null) { - return 0; - } - - Item item = stack.getItem(); - - if(item == null) { - return 0; - } - - if(IEdibleClass.isInstance(item) || item instanceof ItemFood || item == Items.cake) { - return 1; - } - - return 0; - } -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java deleted file mode 100644 index b322036ef7..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ /dev/null @@ -1,604 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import static gregtech.api.GregTech_API.*; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.HashMap; - -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import gregtech.api.objects.GT_HashSet; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.GTplusplus; -import gtPlusPlus.GTplusplus.INIT_PHASE; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.lib.LoadedMods; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import ic2.core.Ic2Items; -import ic2.core.item.armor.ItemArmorHazmat; -import ic2.core.item.armor.ItemArmorNanoSuit; -import ic2.core.item.armor.ItemArmorQuantumSuit; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; - -public class HazmatUtils { - - public static final GT_HashSet<GT_ItemStack> sHazmatList = new GT_HashSet<GT_ItemStack>(); - - private static final HashMap<String, AutoMap<String>> mToolTips = new HashMap<String, AutoMap<String>>(); - - private static boolean mInit = false; - private static HazmatUtils mInstance; - - @SuppressWarnings("rawtypes") - public static void init() { - if (mInit) { - return; - } - //doInit(); Disabled, hazmat moved to gt5u - } - public static void doInit() { - - mInstance = new HazmatUtils(); - - sHazmatList.add(ItemUtils.getSimpleStack(Ic2Items.hazmatHelmet, 1)); - sHazmatList.add(ItemUtils.getSimpleStack(Ic2Items.hazmatChestplate, 1)); - sHazmatList.add(ItemUtils.getSimpleStack(Ic2Items.hazmatLeggings, 1)); - sHazmatList.add(ItemUtils.getSimpleStack(Ic2Items.hazmatBoots, 1)); - - // Make Nano a hazmat suit - // Make Quantum a hazmat suit - - - if (LoadedMods.IndustrialCraft2 || LoadedMods.IndustrialCraft2Classic) { - AutoMap<ItemStack> aVanillaIC2Armour = new AutoMap<ItemStack>(); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.nanoHelmet, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.nanoBodyarmor, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.nanoLeggings, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.nanoBoots, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.quantumHelmet, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.quantumBodyarmor, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.quantumLeggings, 1)); - aVanillaIC2Armour.add(ItemUtils.getSimpleStack(Ic2Items.quantumBoots, 1)); - for (ItemStack aItem : aVanillaIC2Armour) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered IC2 Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("EMT")) { - AutoMap<Field> aItemFields = new AutoMap<Field>(); - Class aItemsEMT = ReflectionUtils.getClass("emt.init.EMTItems"); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "nanoThaumicHelmet")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "nanoWing")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "nanoBootsTraveller")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "quantumThaumicHelmet")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "quantumWing")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "quantumArmor")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "quantumBootsTraveller")); - AutoMap<ItemStack> aEMT = new AutoMap<ItemStack>(); - for (Field aItemField : aItemFields) { - Item aItemObject = null; - if (aItemField != null) { - try { - aItemObject = (Item) aItemField.get(null); - } - catch (Exception t) { - t.printStackTrace(); - } - } - if (aItemObject != null) { - aEMT.add(ItemUtils.getSimpleStack(aItemObject)); - } - else { - Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsEMT.getName()); - } - } - Logger.INFO("[Hazmat] Registering "+aEMT.size()+" EMT Items as hazmat gear."); - for (ItemStack aItem : aEMT) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered EMT Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("DraconicEvolution")) { - AutoMap<Field> aItemFields = new AutoMap<Field>(); - Class aItemsDE = ReflectionUtils.getClass("com.brandon3055.draconicevolution.ModItems"); - - aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicHelm")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicChest")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicLeggs")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicBoots")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernHelm")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernChest")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernLeggs")); - aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernBoots")); - AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>(); - for (Field aItemField : aItemFields) { - Item aItemObject = null; - if (aItemField != null) { - try { - aItemObject = (Item) aItemField.get(null); - } - catch (Exception t) { - t.printStackTrace(); - } - } - if (aItemObject != null) { - aItemMap.add(ItemUtils.getSimpleStack(aItemObject)); - } - else { - Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsDE.getName()); - } - } - Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Draconic Evolution Items as hazmat gear."); - for (ItemStack aItem : aItemMap) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered Draconic Evolution Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("TaintedMagic")) { - AutoMap<Field> aItemFields = new AutoMap<Field>(); - Class aItemsTaintedMagic = ReflectionUtils.getClass("taintedmagic.common.registry.ItemRegistry"); - - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemShadowFortressHelmet")); - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemShadowFortressChestplate")); - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemShadowFortressLeggings")); - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemVoidwalkerBoots")); - AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>(); - for (Field aItemField : aItemFields) { - Item aItemObject = null; - if (aItemField != null) { - try { - aItemObject = (Item) aItemField.get(null); - } - catch (Exception t) { - t.printStackTrace(); - } - } - if (aItemObject != null) { - aItemMap.add(ItemUtils.getSimpleStack(aItemObject)); - } - else { - Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsTaintedMagic.getName()); - } - } - Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Tainted Magic Items as hazmat gear."); - for (ItemStack aItem : aItemMap) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered Tainted Magic Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("WitchingGadgets")) { - AutoMap<Field> aItemFields = new AutoMap<Field>(); - Class aItemsTaintedMagic = ReflectionUtils.getClass("witchinggadgets.common.WGContent"); - - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialHelm")); - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialChest")); - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialLegs")); - aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialBoots")); - AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>(); - for (Field aItemField : aItemFields) { - Item aItemObject = null; - if (aItemField != null) { - try { - aItemObject = (Item) aItemField.get(null); - } - catch (Exception t) { - t.printStackTrace(); - } - } - if (aItemObject != null) { - aItemMap.add(ItemUtils.getSimpleStack(aItemObject)); - } - else { - Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsTaintedMagic.getName()); - } - } - Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Witching Gadgets Items as hazmat gear."); - for (ItemStack aItem : aItemMap) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered Witching Gadgets Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("ThaumicTinkerer")) { - /* - AutoMap<Item> aItems = new AutoMap<Item>(); - Class aMainTT = ReflectionUtils.getClass("thaumic.tinkerer.common.ThaumicTinkerer"); - Class aItemRegistryTT = ReflectionUtils.getClass("thaumic.tinkerer.common.registry.TTRegistry"); - Field aRegistryInstance = ReflectionUtils.getField(aMainTT, "registry"); - Object aRegistry = ReflectionUtils.getFieldValue(aRegistryInstance); - Method aFuckingStupidMethodHandlingMethod = ReflectionUtils.getMethod(aItemRegistryTT, "getFirstItemFromClass", new Class[] {Class.class}); - Item aIchorHelm = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemHelm")}); - Item aIchorChest = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemChest")}); - Item aIchorLegs = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemLegs")}); - Item aIchorBoots = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemBoots")}); - aItems.add(aIchorHelm); - aItems.add(aIchorChest); - aItems.add(aIchorLegs); - aItems.add(aIchorBoots); - AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>(); - int aIndex = 0; - for (Item aItem : aItems) { - Item aItemObject = null; - if (aItem != null) { - aItemMap.add(ItemUtils.getSimpleStack(aItemObject)); - } - else { - Logger.INFO("[Hazmat] Could not get item "+aIndex+" from "+aItemRegistryTT.getName()); - } - aIndex++; - } - Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Thaumic Tinkerer Items as hazmat gear."); - for (ItemStack aItem : aItemMap) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered Thaumic Tinkerer Items as hazmat gear."); - */ - Logger.INFO("[Hazmat] Did not register Thaumic Tinkerer Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("GraviSuite")) { - AutoMap<Field> aItemFields = new AutoMap<Field>(); - Class aItemsGravisuite = ReflectionUtils.getClass("gravisuite.GraviSuite"); - aItemFields.add(ReflectionUtils.getField(aItemsGravisuite, "advNanoChestPlate")); - aItemFields.add(ReflectionUtils.getField(aItemsGravisuite, "graviChestPlate")); - AutoMap<ItemStack> aGravisuite = new AutoMap<ItemStack>(); - for (Field aItemField : aItemFields) { - Item aItemObject = (Item) ReflectionUtils.getFieldValue(aItemField); - if (aItemObject != null) { - aGravisuite.add(ItemUtils.getSimpleStack(aItemObject)); - } - } - Logger.INFO("[Hazmat] Registering "+aGravisuite.size()+" Gravisuit Items as hazmat gear."); - for (ItemStack aItem : aGravisuite) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered Gravisuit Items as hazmat gear."); - } - - if (LoadedMods.isModLoaded("AdvancedSolarPanel")) { - AutoMap<Field> aItemFields = new AutoMap<Field>(); - Class aItemsEMT = ReflectionUtils.getClass("advsolar.common.AdvancedSolarPanel"); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "advancedSolarHelmet")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "hybridSolarHelmet")); - aItemFields.add(ReflectionUtils.getField(aItemsEMT, "ultimateSolarHelmet")); - AutoMap<ItemStack> aASP = new AutoMap<ItemStack>(); - for (Field aItemField : aItemFields) { - Item aItemObject = (Item) ReflectionUtils.getFieldValue(aItemField); - if (aItemObject != null) { - aASP.add(ItemUtils.getSimpleStack(aItemObject)); - } - } - Logger.INFO("[Hazmat] Registering "+aASP.size()+" Adv. Solar Items as hazmat gear."); - for (ItemStack aItem : aASP) { - addProtection(aItem); - } - Logger.INFO("[Hazmat] Registered Adv. Solar Items as hazmat gear."); - } - - Utils.registerEvent(mInstance); - Logger.INFO("[Hazmat] Registered Tooltip handler for hazmat gear."); - mInit = true; - - } - - private final static String mToolTipText = "Provides protection from:"; - - @SubscribeEvent - public void onItemTooltip(ItemTooltipEvent event) { - //Logger.INFO("Ticking Hazmat handler"); - if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { - - if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { - //Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); - return; - } else { - ItemStack aStackTemp = event.itemStack; - GT_ItemStack aStack = new GT_ItemStack(aStackTemp); - if (isNanoArmourPiece(aStackTemp) || isQuantumArmourPiece(aStackTemp)) { - event.toolTip.add(EnumChatFormatting.DARK_PURPLE+"Provides full hazmat protection."); - } - else { - //Logger.INFO("[Hazmat] Finding Tooltip Data"); - String[] aTooltips = getTooltips(aStack); - if (aTooltips == null || aTooltips.length == 0) { - //Logger.INFO("[Hazmat] No Info!"); - return; - } else { - //Logger.INFO("[Hazmat] Found Tooltips!"); - if (providesProtection(aStackTemp)) { - event.toolTip.add(EnumChatFormatting.LIGHT_PURPLE+"Provides full hazmat protection."); - } else { - event.toolTip.add(mToolTipText); - for (String r : aTooltips) { - event.toolTip.add(" - " + r); - } - } - } - } - } - } - } - - /** - * Static function to replace - * {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. - * Because IC2 doesn't let us register things ourself, anything registered via - * GT/GT++ will return true. - * - * @param living - Entity Wearing Armour - * @return - Does {@link EntityLivingBase} have a full hazmat suit on? - */ - public static boolean hasCompleteHazmat(EntityLivingBase living) { - // Entity is Null, cannot have Hazmat. - if (living == null || living.isDead) { - return false; - } else { - - // Map All Player Armour slots - AutoMap<ItemStack> aEquipment = new AutoMap<ItemStack>(); - for (int i = 1; i < 5; ++i) { - ItemStack stack = living.getEquipmentInSlot(i); - - // Item is Null, cannot have full suit - if (stack == null) { - return false; - } else { - aEquipment.put(stack); - } - } - - // Compare Equipment to all items mapped for full hazmat. - for (ItemStack aSlotStack : aEquipment) { - if (!isHazmatPiece(aSlotStack)) { - //Logger.INFO("Found item which is not hazmat. "+ItemUtils.getItemName(aSlotStack)); - return false; - } - } - - // We are in some kind of full hazmat, huzzah! - //Logger.INFO("Has full hazmat."); - return true; - } - } - - /** - * Is this item vanilla IC2 hazmat? - * - * @param aArmour - The Armour to provide protection. - * @return - */ - public static boolean isVanillaHazmatPiece(ItemStack aArmour) { - return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; - } - - /** - * Is this item vanilla IC2 Nanosuit? - * - * @param aArmour - The Armour to provide protection. - * @return - */ - public static boolean isNanoArmourPiece(ItemStack aArmour) { - return aArmour != null ? aArmour.getItem() instanceof ItemArmorNanoSuit : false; - } - - /** - * Is this item vanilla IC2 Quantum? - * - * @param aArmour - The Armour to provide protection. - * @return - */ - public static boolean isQuantumArmourPiece(ItemStack aArmour) { - return aArmour != null ? aArmour.getItem() instanceof ItemArmorQuantumSuit : false; - } - - /** - * Is this item a registered piece of full hazmat? (Provides all 6 protections) - * - * @param aStack - The Armour to provide protection. - * @return - */ - public static boolean isHazmatPiece(ItemStack aStack) { - return isVanillaHazmatPiece(aStack) || providesProtection(aStack); - } - - /** - * Registers the {@link ItemStack} to all types of protection. Provides full - * hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. - * - * @param aStack - The Armour to provide protection. - * @return - Did we register this ItemStack properly? - */ - public static boolean addProtection(ItemStack aVanStack) { - if (!ItemUtils.checkForInvalidItems(aVanStack)) { - Logger.INFO("=================Bad Hazmat Addition======================"); - Logger.INFO("Called from: "+ReflectionUtils.getMethodName(0)); - Logger.INFO(ReflectionUtils.getMethodName(1)); - Logger.INFO(ReflectionUtils.getMethodName(2)); - Logger.INFO(ReflectionUtils.getMethodName(3)); - Logger.INFO(ReflectionUtils.getMethodName(4)); - Logger.INFO(ReflectionUtils.getMethodName(5)); - Logger.INFO(ReflectionUtils.getMethodName(6)); - Logger.INFO("=========================================================="); - return false; - } - Logger.INFO("[Hazmat] Registering " + ItemUtils.getItemName(aVanStack) + " for full Hazmat protection."); - GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); - AutoMap<Boolean> aAdded = new AutoMap<Boolean>(); - aAdded.put(addProtection_Frost(aStack)); - aAdded.put(addProtection_Fire(aStack)); - aAdded.put(addProtection_Biohazard(aStack)); - aAdded.put(addProtection_Gas(aStack)); - aAdded.put(addProtection_Radiation(aStack)); - aAdded.put(addProtection_Electricty(aStack)); - for (boolean b : aAdded) { - if (!b) { - return false; - } - } - Logger.INFO("[Hazmat] Protection added for all 6 damage types, registering to master Hazmat list."); - sHazmatList.add(aStack); - return true; - } - - public static boolean addProtection_Frost(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.AQUA + "Frost"); - return addProtection_Generic(sFrostHazmatList, aStack); - } - - public static boolean addProtection_Fire(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.DARK_RED + "Heat"); - return addProtection_Generic(sHeatHazmatList, aStack); - } - - public static boolean addProtection_Biohazard(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.GREEN + "Biohazards"); - return addProtection_Generic(sBioHazmatList, aStack); - } - - public static boolean addProtection_Gas(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.WHITE + "Gas"); - return addProtection_Generic(sGasHazmatList, aStack); - } - - public static boolean addProtection_Radiation(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.DARK_GREEN + "Radiation"); - return addProtection_Generic(sRadioHazmatList, aStack); - } - - public static boolean addProtection_Electricty(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.YELLOW + "Electricity"); - return addProtection_Generic(sElectroHazmatList, aStack); - } - - private static boolean addProtection_Generic(GT_HashSet<GT_ItemStack> aSet, GT_ItemStack aStack) { - int aMapSize = aSet.size(); - aSet.add(aStack); - return aMapSize < aSet.size(); - } - - /** - * Does this item provide hazmat protection? (Protection against Frost, Heat, - * Bio, Gas, Rads, Elec) An item may return false even if it protects against - * all six damage types. This is because it's not actually registered as hazmat - * correct. - * - * @param aStack - The item to check for protection - * @return - */ - public static boolean providesProtection(ItemStack aStack) { - return providesProtetion_Generic(sHazmatList, aStack); - } - - public static boolean providesProtetion_Frost(ItemStack aStack) { - return providesProtetion_Generic(sFrostHazmatList, aStack); - } - - public static boolean providesProtetion_Fire(ItemStack aStack) { - return providesProtetion_Generic(sHeatHazmatList, aStack); - } - - public static boolean providesProtetion_Biohazard(ItemStack aStack) { - return providesProtetion_Generic(sBioHazmatList, aStack); - } - - public static boolean providesProtetion_Gas(ItemStack aStack) { - return providesProtetion_Generic(sGasHazmatList, aStack); - } - - public static boolean providesProtetion_Radiation(ItemStack aStack) { - return providesProtetion_Generic(sRadioHazmatList, aStack); - } - - public static boolean providesProtetion_Electricity(ItemStack aStack) { - return providesProtetion_Generic(sElectroHazmatList, aStack); - } - - private static boolean providesProtetion_Generic(GT_HashSet<GT_ItemStack> aSet, ItemStack aStack) { - if (isVanillaHazmatPiece(aStack)) { - return true; - } - for (GT_ItemStack o : aSet) { - if (o != null && o.mItem != null && aStack != null && aStack.getItem() != null) { - if (GT_Utility.areStacksEqual(o.toStack(), aStack, true)) { - return true; - } - if (o.isStackEqual(aStack)){ - return true; - } - if (o.mItem == aStack.getItem() && EnergyUtils.EU.isElectricItem(aStack)) { - return true; - } - } - } - return false; - } - - private static String[] getTooltips(GT_ItemStack aStack) { - String aKey = convertGtItemstackToStringDataIgnoreDamage(aStack); - AutoMap<String> aTempTooltipData = mToolTips.get(aKey); - if (aTempTooltipData == null || aTempTooltipData.isEmpty()) { - //Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); - return new String[] {}; - } else { - //Logger.INFO("[Hazmat] Item was mapped for TTs"); - //Collections.sort(aTempTooltipData); - //Logger.INFO("[Hazmat] Sorted TTs"); - - String[] mBuiltOutput = new String[aTempTooltipData.size()]; - int aIndex = 0; - for (String i : aTempTooltipData) { - mBuiltOutput[aIndex++] = i; - } - - return mBuiltOutput; - } - } - - private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { - String aKey = convertGtItemstackToStringDataIgnoreDamage(aStack); - Logger.INFO("[Hazmat] Mapping " + aTooltip + " for " + aKey); - AutoMap<String> aTempTooltipData = mToolTips.get(aKey); - if (aTempTooltipData == null) { - Logger.INFO("No data mapped yet, creating."); - aTempTooltipData = new AutoMap<String>(); - mToolTips.put(aKey, aTempTooltipData); - } - aTempTooltipData.add(aTooltip); - } - - public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { - return ItemUtils.simpleMetaStack(aGtStack.mItem, aGtStack.mMetaData, aGtStack.mStackSize); - } - - public static GT_ItemStack getGtStackFromVanilla(ItemStack aStack) { - return new GT_ItemStack(aStack); - } - - private static String convertGtItemstackToStringData(GT_ItemStack aStack) { - if (aStack == null) { - return "NULL"; - } else { - return aStack.mItem.getUnlocalizedName() + "." + aStack.mMetaData + "." + aStack.mStackSize; - } - } - - private static String convertGtItemstackToStringDataIgnoreDamage(GT_ItemStack aStack) { - if (aStack == null) { - return "NULL"; - } else { - return aStack.mItem.getUnlocalizedName() + "." + aStack.mStackSize; - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java deleted file mode 100644 index fe67c88d69..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java +++ /dev/null @@ -1,88 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.Random; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy_RTG; -import net.minecraft.block.Block; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -public class InventoryUtils { - - private final static Random mRandom = new Random(); - - public static void dropInventoryItems(World world, int x, int y, int z, Block block) { - TileEntity tileentity = world.getTileEntity(x, y, z); - - if (tileentity != null && tileentity instanceof IInventory && ((IInventory) tileentity).getSizeInventory() > 0) { - - IInventory aTileInv = (IInventory) tileentity; - int aMinSlot = 0; - int aMaxSlot = aTileInv.getSizeInventory()-1; - - for (int i1 = aMinSlot; i1 < aMaxSlot; ++i1) { - ItemStack itemstack = aTileInv.getStackInSlot(i1); - - if (itemstack != null) { - float f = mRandom.nextFloat() * 0.8F + 0.1F; - float f1 = mRandom.nextFloat() * 0.8F + 0.1F; - EntityItem entityitem; - - for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { - int j1 = mRandom.nextInt(21) + 10; - - if (j1 > itemstack.stackSize) { - j1 = itemstack.stackSize; - } - - itemstack.stackSize -= j1; - entityitem = new EntityItem(world, x + f, y + f1, z + f2, - new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); - float f3 = 0.05F; - entityitem.motionX = (float) mRandom.nextGaussian() * f3; - entityitem.motionY = (float) mRandom.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float) mRandom.nextGaussian() * f3; - - if (itemstack.hasTagCompound()) { - entityitem.getEntityItem() - .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); - } - } - } - } - - world.func_147453_f(x, y, z, block); - } - - } - - public static void sortInventoryItems(MetaTileEntity aTile) { - sortInventoryItems(aTile.getBaseMetaTileEntity()); - } - - public static void sortInventoryItems(IGregTechTileEntity aBaseMetaTileEntity) { - IInventory mInv = aBaseMetaTileEntity.getIInventory(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getZCoord()); - AutoMap<ItemStack> aInvContents = new AutoMap<ItemStack>(); - int aSize = mInv.getSizeInventory(); - for (int slot=0; slot<aSize; slot++) { - aInvContents.put(mInv.getStackInSlot(slot)); - } - ItemStack[] mInventory = aInvContents.toArray(); - for (int i = 0; i < mInventory.length; i++) { - for (int j = i + 1; j < mInventory.length; j++) { - if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB(aBaseMetaTileEntity, aBaseMetaTileEntity, j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java deleted file mode 100644 index 1e282fb849..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ /dev/null @@ -1,1380 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Utility; -import gregtech.common.items.GT_MetaGenerated_Tool_01; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.data.Pair; -import gtPlusPlus.api.objects.minecraft.BlockPos; -import gtPlusPlus.core.item.ModItems; -import gtPlusPlus.core.item.base.BasicSpawnEgg; -import gtPlusPlus.core.item.base.dusts.BaseItemDustUnique; -import gtPlusPlus.core.item.base.dusts.decimal.BaseItemCentidust; -import gtPlusPlus.core.item.base.dusts.decimal.BaseItemDecidust; -import gtPlusPlus.core.item.base.plates.BaseItemPlate_OLD; -import gtPlusPlus.core.item.chemistry.AgriculturalChem; -import gtPlusPlus.core.item.chemistry.GenericChem; -import gtPlusPlus.core.item.chemistry.RocketFuels; -import gtPlusPlus.core.item.tool.staballoy.MultiPickaxeBase; -import gtPlusPlus.core.item.tool.staballoy.MultiSpadeBase; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.lib.LoadedMods; -import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.recipe.common.CI; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import gtPlusPlus.preloader.CORE_Preloader; -import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool; -import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; -import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration; -import net.minecraft.block.Block; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentData; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.Item.ToolMaterial; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.oredict.OreDictionary; - -public class ItemUtils { - - public static ItemStack getSimpleStack(final Item x) { - return getSimpleStack(x, 1); - } - - public static ItemStack getSimpleStack(final Block x) { - return simpleMetaStack(Item.getItemFromBlock(x), 0, 1); - } - - - public static ItemStack getSimpleStack(final Block x, int i) { - if (i == 0) { - return getSimpleStack(x, i, 1); - } - - return getSimpleStack(x, 0, i); - } - - public static ItemStack getSimpleStack(final Block x, int meta, int i) { - return simpleMetaStack(Item.getItemFromBlock(x), meta, i); - } - - public static ItemStack getSimpleStack(final Item x, final int i) { - try { - final ItemStack r = new ItemStack(x, i); - return r.copy(); - } catch (final Throwable e) { - return null; - } - } - - public static ItemStack getSimpleStack(final ItemStack x, final int i) { - try { - final ItemStack r = x.copy(); - r.stackSize = i; - return r; - } catch (final Throwable e) { - return null; - } - } - - public static final int WILDCARD_VALUE = Short.MAX_VALUE; - - public static ItemStack getWildcardStack(final Item x) { - final ItemStack y = new ItemStack(x, 1, WILDCARD_VALUE); - return y; - } - - public static ItemStack getWildcardStack(final ItemStack x) { - final ItemStack y = ItemUtils.simpleMetaStack(x, WILDCARD_VALUE, 1); - return y; - } - - public static ItemStack getIC2Cell(final String S) { - final ItemStack moreTemp = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell" + S, 1); - - if (moreTemp == null) { - final int cellID = 0; - final ItemStack temp = GT_ModHandler.getModItem("IC2", "itemCellEmpty", 1L, cellID); - return temp != null ? temp : null; - } - - return moreTemp; - } - - public static ItemStack getIC2Cell(final int meta) { - final ItemStack temp = GT_ModHandler.getModItem("IC2", "itemCellEmpty", 1L, meta); - return temp != null ? temp : null; - } - - public static ItemStack getEmptyCell() { - return getEmptyCell(1); - } - - public static ItemStack getEmptyCell(int i) { - if (ItemList.Cell_Empty.hasBeenSet()) { - return ItemList.Cell_Empty.get(i); - } - final ItemStack temp = GT_ModHandler.getModItem("IC2", "itemCellEmpty", i, 0); - return temp != null ? temp : null; - } - - public static void getItemForOreDict(final String FQRN, final String oreDictName, final String itemName, - final int meta) { - try { - Item em = null; - final Item em1 = getItemFromFQRN(FQRN); - // Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); - if (em1 != null) { - em = em1; - } - if (em != null) { - - final ItemStack metaStack = new ItemStack(em, 1, meta); - GT_OreDictUnificator.registerOre(oreDictName, metaStack); - - /* - * ItemStack itemStackWithMeta = new ItemStack(em,1,meta); - * GT_OreDictUnificator.registerOre(oreDictName, new - * ItemStack(itemStackWithMeta.getItem())); - */ - } - } catch (final NullPointerException e) { - Logger.ERROR(itemName + " not found. [NULL]"); - } - } - - public static void addItemToOreDictionary(ItemStack stack, final String oreDictName, boolean useWildcardMeta) { - if (useWildcardMeta) { - stack = ItemUtils.getWildcardStack(stack); - } - try { - OreDictionary.registerOre(oreDictName, stack); - } catch (final NullPointerException e) { - Logger.ERROR(ItemUtils.getItemName(stack) + " not registered. [NULL]"); - } - } - - public static void addItemToOreDictionary(final ItemStack stack, final String oreDictName) { - addItemToOreDictionary(stack, oreDictName, false); - } - - public static ItemStack getItemStackWithMeta(final boolean MOD, final String FQRN, final String itemName, - final int meta, final int itemstackSize) { - if (MOD) { - try { - Item em = null; - final Item em1 = getItemFromFQRN(FQRN); - // Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); - if (em1 != null) { - if (null == em) { - em = em1; - } - if (em != null) { - final ItemStack metaStack = new ItemStack(em, itemstackSize, meta); - return metaStack; - } - } - return null; - } catch (final NullPointerException e) { - Logger.ERROR(itemName + " not found. [NULL]"); - return null; - } - } - return null; - } - - public static ItemStack simpleMetaStack(final String FQRN, final int meta, final int itemstackSize) { - try { - Item em = null; - final Item em1 = getItemFromFQRN(FQRN); - // Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); - if (em1 != null) { - if (null == em) { - em = em1; - } - if (em != null) { - final ItemStack metaStack = new ItemStack(em, itemstackSize, meta); - return metaStack; - } - } - return null; - } catch (final NullPointerException e) { - Logger.ERROR(FQRN + " not found. [NULL]"); - return null; - } - } - - public static ItemStack simpleMetaStack(ItemStack simpleStack, int meta, int size) { - return simpleMetaStack(simpleStack.getItem(), meta, size); - } - - public static ItemStack simpleMetaStack(final Item item, int meta, int size) { - if (item == null) { - return null; - } - if (meta < 0 || meta > Short.MAX_VALUE) { - meta = 0; - } - if (size < 0 || size > 64) { - size = 1; - } - //Logger.INFO("Found Metastack: " + item.getUnlocalizedName() + ":" + meta); - //Logger.INFO(""+ReflectionUtils.getMethodName(0)); - //Logger.INFO(""+ReflectionUtils.getMethodName(1)); - //Logger.INFO(""+ReflectionUtils.getMethodName(2)); - //Logger.INFO(""+ReflectionUtils.getMethodName(3)); - //Logger.INFO(""+ReflectionUtils.getMethodName(4)); - final ItemStack metaStack = new ItemStack(item, size, meta); - return metaStack; - } - - public static ItemStack simpleMetaStack(final Block block, final int meta, final int size) { - return simpleMetaStack(Item.getItemFromBlock(block), meta, size); - } - - public static ItemStack getCorrectStacktype(final String fqrn, final int stackSize) { - final String oreDict = "ore:"; - ItemStack temp; - if (fqrn.toLowerCase().contains(oreDict.toLowerCase())) { - final String sanitizedName = fqrn.replace(oreDict, ""); - temp = ItemUtils.getItemStackFromFQRN(sanitizedName, stackSize); - return temp; - } - final String[] fqrnSplit = fqrn.split(":"); - String temp1; - String temp2; - temp1 = fqrnSplit[1]; - if (fqrnSplit.length < 3) { - temp2 = "0"; - } else { - temp2 = fqrnSplit[2]; - } - temp = ItemUtils.getItemStackWithMeta(LoadedMods.MiscUtils, fqrn, temp1, Integer.parseInt(temp2), stackSize); - return temp; - } - - public static ItemStack getCorrectStacktype(final Object item_Input, final int stackSize) { - if (item_Input instanceof String) { - return getItemStackOfAmountFromOreDictNoBroken((String) item_Input, stackSize); - } else if (item_Input instanceof ItemStack) { - return (ItemStack) item_Input; - } - return null; - } - - public static Item getItemFromFQRN(final String fqrn) // fqrn = fully qualified resource name - { - final String[] fqrnSplit = fqrn.split(":"); - return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]); - } - - public static ItemStack getItemStackFromFQRN(final String fqrn, final int Size) // fqrn = fully qualified resource name - { - Logger.INFO("Trying to split string '"+fqrn+"'."); - final String[] fqrnSplit = fqrn.split(":"); - if (fqrnSplit.length < 2) { - return null; - } - else { - if (fqrnSplit.length == 2) { - Logger.INFO("Mod: "+fqrnSplit[0]+", Item: "+fqrnSplit[1]); - return GameRegistry.findItemStack(fqrnSplit[0], fqrnSplit[1], Size); - } - else if (fqrnSplit.length == 3 && fqrnSplit[2] != null && fqrnSplit[2].length() > 0) { - Logger.INFO("Mod: "+fqrnSplit[0]+", Item: "+fqrnSplit[1]+", Meta: "+fqrnSplit[2]); - ItemStack aStack = GameRegistry.findItemStack(fqrnSplit[0], fqrnSplit[1], Size); - int aMeta = Integer.parseInt(fqrnSplit[2]); - if (aStack != null && (aMeta >= 0 && aMeta <= Short.MAX_VALUE)){ - return ItemUtils.simpleMetaStack(aStack, aMeta, Size); - } - else { - Logger.INFO("Could not find instance of Item: "+fqrnSplit[1]); - - } - } - - } - return null; - } - - public static void generateSpawnEgg(final String entityModID, final String parSpawnName, final int colourEgg, - final int colourOverlay) { - final Item itemSpawnEgg = new BasicSpawnEgg(entityModID, parSpawnName, colourEgg, colourOverlay) - .setUnlocalizedName("spawn_egg_" + parSpawnName.toLowerCase()) - .setTextureName(CORE.MODID + ":spawn_egg"); - GameRegistry.registerItem(itemSpawnEgg, "spawnEgg" + parSpawnName); - } - - public static ItemStack[] validItemsForOreDict(final String oredictName) { - final List<?> validNames = MaterialUtils.oreDictValuesForEntry(oredictName); - final ItemStack[] inputs = new ItemStack[validNames.size()]; - for (int i = 0; i < validNames.size(); i++) { - inputs[i] = (ItemStack) validNames.get(i); - } - return inputs; - } - - public static ItemStack getItemStackOfAmountFromOreDict(String oredictName, final int amount) { - String mTemp = oredictName; - - if (oredictName.contains("-") || oredictName.contains("_")) { - mTemp = Utils.sanitizeString(mTemp, new char[] {'-', '_'}); - } - else { - mTemp = Utils.sanitizeString(mTemp); - } - - - - if (oredictName.contains("rod")) { - String s = "stick"+oredictName.substring(3); - oredictName = s; - } - - // Banned Materials and replacements for GT5.8 compat. - - if (oredictName.toLowerCase().contains("ingotclay")) { - return getSimpleStack(Items.clay_ball, amount); - } - - if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - if (oredictName.toLowerCase().contains("rutile")) { - mTemp = oredictName.replace("Rutile", "Titanium"); - } - if (oredictName.toLowerCase().contains("vanadiumsteel")) { - mTemp = oredictName.replace("VanadiumSteel", "StainlessSteel"); - } - } - final ArrayList<ItemStack> oreDictList = OreDictionary.getOres(mTemp); - if (!oreDictList.isEmpty()) { - final ItemStack returnValue = oreDictList.get(0).copy(); - returnValue.stackSize = amount; - return returnValue; - } - Logger.INFO("Failed to find `" + oredictName + "` in OD."); - return getErrorStack(amount, oredictName+" x"+amount); - //return getItemStackOfAmountFromOreDictNoBroken(mTemp, amount); - } - - public static ItemStack getItemStackOfAmountFromOreDictNoBroken(String oredictName, final int amount) { - if (CORE_Preloader.DEBUG_MODE) { - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(1)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(2)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(3)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(4)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(5)); - } - - try { - - if (oredictName.contains("-") || oredictName.contains("_")) { - oredictName = Utils.sanitizeString(oredictName, new char[] {'-', '_'}); - } - else { - oredictName = Utils.sanitizeString(oredictName); - } - - // Adds a check to grab dusts using GT methodology if possible. - ItemStack returnValue = null; - if (oredictName.toLowerCase().contains("dust")) { - final String MaterialName = oredictName.toLowerCase().replace("dust", ""); - final Materials m = Materials.get(MaterialName); - if (m != null && m != Materials._NULL) { - returnValue = getGregtechDust(m, amount); - if (checkForInvalidItems(returnValue)) { - return returnValue; - } - } - } - if (returnValue == null) { - returnValue = getItemStackOfAmountFromOreDict(oredictName, amount); - if (ItemUtils.checkForInvalidItems(returnValue)) { - return returnValue.copy(); - } - } - - Logger.RECIPE(oredictName + " was not valid."); - return null; - } catch (final Throwable t) { - return null; - } - } - - public static ItemStack getGregtechDust(final Materials material, final int amount) { - final ItemStack returnValue = GT_OreDictUnificator.get(OrePrefixes.dust, material, 1L); - if (returnValue != null) { - if (ItemUtils.checkForInvalidItems(returnValue)) { - return returnValue.copy(); - } - } - Logger.WARNING(material + " was not valid."); - return null; - } - - // NullFormula - public static Item[] generateSpecialUseDusts(final String unlocalizedName, final String materialName, - final int Colour) { - return generateSpecialUseDusts(unlocalizedName, materialName, "NullFormula", Colour); - } - - public static Item[] generateSpecialUseDusts(final String unlocalizedName, final String materialName, - String mChemForm, final int Colour) { - final Item[] output = { - new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, mChemForm, Colour, "Dust"), - new BaseItemDustUnique("itemDustSmall" + unlocalizedName, materialName, mChemForm, Colour, "Small"), - new BaseItemDustUnique("itemDustTiny" + unlocalizedName, materialName, mChemForm, Colour, "Tiny") }; - - //Generate Shaped/Shapeless Recipes - - final ItemStack normalDust = ItemUtils.getSimpleStack(output[0]); - final ItemStack smallDust = ItemUtils.getSimpleStack(output[1]); - final ItemStack tinyDust = ItemUtils.getSimpleStack(output[2]); - - CORE.RA.addpackagerRecipe(ItemList.Schematic_Dust.get(0), smallDust, tinyDust, normalDust); - - if (ItemUtils.checkForInvalidItems(tinyDust) && ItemUtils.checkForInvalidItems(normalDust)) { - if (RecipeUtils.addShapedRecipe( - tinyDust, tinyDust, tinyDust, - tinyDust, tinyDust, tinyDust, - tinyDust, tinyDust, tinyDust, - normalDust)){ - Logger.WARNING("9 Tiny dust to 1 Dust Recipe: "+materialName+" - Success"); - } - else { - Logger.WARNING("9 Tiny dust to 1 Dust Recipe: "+materialName+" - Failed"); - } - - if (RecipeUtils.addShapedRecipe( - normalDust, null, null, - null, null, null, - null, null, null, - ItemUtils.getSimpleStack(tinyDust, 9))){ - Logger.WARNING("9 Tiny dust from 1 Recipe: "+materialName+" - Success"); - } - else { - Logger.WARNING("9 Tiny dust from 1 Recipe: "+materialName+" - Failed"); - } - } - - if (ItemUtils.checkForInvalidItems(smallDust) && ItemUtils.checkForInvalidItems(normalDust)) { - if (RecipeUtils.addShapedRecipe( - smallDust, smallDust, null, - smallDust, smallDust, null, - null, null, null, - normalDust)){ - Logger.WARNING("4 Small dust to 1 Dust Recipe: "+materialName+" - Success"); - } - else { - Logger.WARNING("4 Small dust to 1 Dust Recipe: "+materialName+" - Failed"); - } - if (RecipeUtils.addShapedRecipe( - null, normalDust, null, - null, null, null, - null, null, null, - ItemUtils.getSimpleStack(smallDust, 4))){ - Logger.WARNING("4 Small dust from 1 Dust Recipe: "+materialName+" - Success"); - } - else { - Logger.WARNING("4 Small dust from 1 Dust Recipe: "+materialName+" - Failed"); - } - } - - return output; - } - - public static Item generateSpecialUsePlate(final String internalName, final String displayName, final short[] rgb, - final int radioactivity) { - return generateSpecialUsePlate(internalName, displayName, Utils.rgbtoHexValue(rgb[0], rgb[1], rgb[2]), - radioactivity); - } - - public static Item generateSpecialUsePlate(final String internalName, final String displayName, - final String mFormula, final short[] rgb, final int radioactivity) { - return generateSpecialUsePlate(internalName, displayName, mFormula, Utils.rgbtoHexValue(rgb[0], rgb[1], rgb[2]), - radioactivity); - } - - public static Item generateSpecialUsePlate(final String internalName, final String displayName, final int rgb, - final int radioactivity) { - return new BaseItemPlate_OLD(internalName, displayName, rgb, radioactivity); - } - - public static Item generateSpecialUsePlate(final String internalName, final String displayName, - final String mFormula, final int rgb, final int radioactivity) { - return new BaseItemPlate_OLD(internalName, displayName, mFormula, rgb, radioactivity); - } - - - public static Item[] generateSpecialUseDusts(final Material material, final boolean onlyLargeDust) { - return generateSpecialUseDusts(material, onlyLargeDust, false); - } - - public static Item[] generateSpecialUseDusts(final Material material, final boolean onlyLargeDust, final boolean disableExtraRecipes) { - final String materialName = material.getLocalizedName(); - final String unlocalizedName = Utils.sanitizeString(materialName); - final int Colour = material.getRgbAsHex(); - final String aChemForm = material.vChemicalFormula; - final boolean isChemFormvalid = (aChemForm != null && aChemForm.length() > 0); - Item[] output = null; - if (onlyLargeDust == false) { - output = new Item[] { new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, isChemFormvalid ? aChemForm : "", Colour, "Dust"), - new BaseItemDustUnique("itemDustSmall" + unlocalizedName, materialName, isChemFormvalid ? aChemForm : "", Colour, "Small"), - new BaseItemDustUnique("itemDustTiny" + unlocalizedName, materialName, isChemFormvalid ? aChemForm : "", Colour, "Tiny") }; - } else { - output = new Item[] { new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, Colour, "Dust") }; - } - - new RecipeGen_DustGeneration(material, disableExtraRecipes); - - return output; - } - - public static MultiPickaxeBase generateMultiPick(final boolean GT_Durability, final Materials material) { - final ToolMaterial customMaterial = Utils.generateToolMaterialFromGT(material); - final int enchantLevel = material.mEnchantmentToolsLevel; - final Object enchant = new Pair(material.mEnchantmentTools, enchantLevel); - return generateMultiPick(GT_Durability, customMaterial, material.mDefaultLocalName, material.mDurability, - material.mRGBa, enchant); - } - - public static MultiPickaxeBase generateMultiPick(final Material material) { - final ToolMaterial customMaterial = Utils.generateToolMaterial(material); - return generateMultiPick(true, customMaterial, material.getLocalizedName(), (int) material.vDurability, - material.getRGBA(), null); - } - - public static MultiPickaxeBase generateMultiPick(final boolean GT_Durability, final ToolMaterial customMaterial, - final String name, final int durability, final short[] rgba, final Object enchantment) { - Logger.WARNING("Generating a Multi-Pick out of " + name); - final short[] rgb = rgba; - int dur = customMaterial.getMaxUses(); - Logger.WARNING("Determined durability for " + name + " is " + dur); - if (GT_Durability) { - dur = durability * 100; - Logger.WARNING("Using gregtech durability value, " + name + " is now " + dur + "."); - } else if (dur <= 0) { - dur = durability; - Logger.WARNING("Determined durability too low, " + name + " is now " + dur - + " based on the GT material durability."); - } - if (dur <= 0) { - Logger.WARNING("Still too low, " + name + " will now go unused."); - return null; - } - - Object enchant; - if (enchantment != null) { - if (enchantment instanceof Pair) { - enchant = enchantment; - } - } else { - enchant = null; - } - - final MultiPickaxeBase MP_Redstone = new MultiPickaxeBase(name + " Multipick", (customMaterial), dur, - Utils.rgbtoHexValue(rgb[0], rgb[1], rgb[2]), enchantment); - - if (MP_Redstone.isValid) { - return MP_Redstone; - } - Logger.WARNING("Pickaxe was not valid."); - return null; - } - - public static MultiSpadeBase generateMultiShovel(final boolean GT_Durability, final Materials material) { - final ToolMaterial customMaterial = Utils.generateToolMaterialFromGT(material); - return generateMultiShovel(GT_Durability, customMaterial, material.mDefaultLocalName, material.mDurability, - material.mRGBa); - } - - public static MultiSpadeBase generateMultiShovel(final Material material) { - final ToolMaterial customMaterial = Utils.generateToolMaterial(material); - return generateMultiShovel(true, customMaterial, material.getLocalizedName(), (int) material.vDurability, - material.getRGBA()); - } - - public static MultiSpadeBase generateMultiShovel(final boolean GT_Durability, final ToolMaterial customMaterial, - final String name, final int durability, final short[] rgba) { - Logger.WARNING("Generating a Multi-Spade out of " + name); - final short[] rgb = rgba; - int dur = customMaterial.getMaxUses(); - Logger.WARNING("Determined durability for " + name + " is " + dur); - if (GT_Durability) { - dur = durability * 100; - Logger.WARNING("Using gregtech durability value, " + name + " is now " + dur + "."); - } else if (dur <= 0) { - dur = durability; - Logger.WARNING("Determined durability too low, " + name + " is now " + dur - + " based on the GT material durability."); - } - if (dur <= 0) { - Logger.WARNING("Still too low, " + name + " will now go unused."); - return null; - } - final MultiSpadeBase MP_Redstone = new MultiSpadeBase(name + " Multispade", (customMaterial), dur, - Utils.rgbtoHexValue(rgb[0], rgb[1], rgb[2])); - - if (MP_Redstone.isValid) { - return MP_Redstone; - } - return null; - } - - public static BaseItemDecidust generateDecidust(final Materials material) { - if (GT_OreDictUnificator.get(OrePrefixes.dust, material, 1L) != null) { - final Material placeholder = MaterialUtils.generateMaterialFromGtENUM(material); - if (placeholder != null) { - generateDecidust(placeholder); - } - } - return null; - } - - public static BaseItemDecidust generateDecidust(final Material material) { - if ((material.getDust(1) != null) && MaterialUtils.hasValidRGBA(material.getRGBA())) { - final BaseItemDecidust Decidust = new BaseItemDecidust(material); - return Decidust; - } - return null; - } - - public static BaseItemCentidust generateCentidust(final Materials material) { - if (GT_OreDictUnificator.get(OrePrefixes.dust, material, 1L) != null) { - final Material placeholder = MaterialUtils.generateMaterialFromGtENUM(material); - if (placeholder != null) { - generateCentidust(placeholder); - } - } - return null; - } - - public static BaseItemCentidust generateCentidust(final Material material) { - if ((material.getDust(1) != null) && MaterialUtils.hasValidRGBA(material.getRGBA())) { - final BaseItemCentidust Centidust = new BaseItemCentidust(material); - return Centidust; - } - return null; - } - - public static boolean isRadioactive(final String materialName) { - int sRadiation = 0; - if (materialName.toLowerCase().contains("uranium")) { - sRadiation = 2; - } else if (materialName.toLowerCase().contains("plutonium")) { - sRadiation = 4; - } else if (materialName.toLowerCase().contains("thorium")) { - sRadiation = 1; - } - if (sRadiation >= 1) { - return true; - } - return false; - } - - public static int getRadioactivityLevel(final String materialName) { - int sRadiation = 0; - if (materialName.toLowerCase().contains("uranium")) { - sRadiation = 2; - } else if (materialName.toLowerCase().contains("plutonium")) { - sRadiation = 4; - } else if (materialName.toLowerCase().contains("thorium")) { - sRadiation = 1; - } - return sRadiation; - } - - public static String getArrayStackNames(final FluidStack[] aStack) { - String itemNames = "Fluid Array: "; - for (final FluidStack alph : aStack) { - if (alph != null) { - final String temp = itemNames; - itemNames = temp + ", " + alph.getLocalizedName() + " x" + alph.amount; - } else { - final String temp = itemNames; - itemNames = temp + ", " + "null" + " x" + "0"; - } - } - return itemNames; - } - - public static String getArrayStackNames(final ItemStack[] aStack) { - String itemNames = ""; - int aPos = 0; - for (final ItemStack alph : aStack) { - if (alph == null) { - continue; - } - if (alph != null) { - final String temp = itemNames; - itemNames = temp + (aPos > 0 ? ", " : "") + alph.getDisplayName() + " x" + alph.stackSize; - aPos++; - } - } - return itemNames; - } - - public static String[] getArrayStackNamesAsArray(final ItemStack[] aStack) { - final String[] itemNames = aStack == null ? new String[] {} : new String[aStack.length]; - if (aStack != null){ - Logger.INFO(""+aStack.length); - } - - if (aStack == null || aStack.length < 1) { - return itemNames; - } - - int arpos = 0; - for (final ItemStack alph : aStack) { - if (alph == null) { - continue; - } - try { - itemNames[arpos] = alph.getDisplayName(); - arpos++; - } - catch (Throwable t) { - t.printStackTrace(); - } - } - return itemNames; - - } - - public static String getFluidArrayStackNames(final FluidStack[] aStack) { - String itemNames = "Fluid Array: "; - for (final FluidStack alph : aStack) { - final String temp = itemNames; - itemNames = temp + ", " + alph.getFluid().getName() + " x" + alph.amount; - } - return itemNames; - - } - - public static ItemStack getGregtechCircuit(final int Meta) { - return ItemUtils.getItemStackWithMeta(LoadedMods.Gregtech, "gregtech:gt.integrated_circuit", "Gregtech Circuit", - Meta, 0); - } - - public static ItemStack[] getBlockDrops(final ArrayList<ItemStack> blockDrops) { - if (blockDrops == null) { - return null; - } - if (blockDrops.isEmpty()) { - return null; - } - final ItemStack[] outputs = new ItemStack[blockDrops.size()]; - short forCounter = 0; - for (final ItemStack I : blockDrops) { - outputs[forCounter++] = I; - } - return outputs; - } - - private static Map<Item, String> mModidCache = new HashMap<Item, String>(); - - private static String getModId(final Item item) { - if (mModidCache.containsKey(item)) { - return mModidCache.get(item); - } - String value = ""; - try { - final GameRegistry.UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(item); - if (id != null) { - final String modname = (id.modId == null ? id.name : id.modId); - value = ((id == null) || id.modId.equals("")) ? "minecraft" : modname; - } - } catch (final Throwable t) { - try { - final UniqueIdentifier t2 = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(item)); - if (t2 != null) { - final String modname = (t2.modId == null ? t2.name : t2.modId); - value = ((t2 == null) || t2.modId.equals("")) ? "minecraft" : modname; - } - } catch (final Throwable t3) { - t3.printStackTrace(); - value = "bad modid"; - } - } - if (!mModidCache.containsKey(item)) { - return mModidCache.put(item, value); - } - return value; - } - - public static String getModId(final ItemStack key) { - return getModId(key.getItem()); - } - - // Take 2 - GT/GT++ Dusts - public static ItemStack getGregtechDust(final String oredictName, final int amount) { - final ArrayList<ItemStack> oreDictList = OreDictionary.getOres(oredictName); - if (!oreDictList.isEmpty()) { - ItemStack returnvalue; - for (int xrc = 0; xrc < oreDictList.size(); xrc++) { - final String modid = getModId(oreDictList.get(xrc).getItem()); - if (modid != null && (modid.equals("gregtech") || modid.equals(CORE.MODID))) { - returnvalue = oreDictList.get(xrc).copy(); - returnvalue.stackSize = amount; - return returnvalue; - } - } - } - return getNonTinkersDust(oredictName, amount); - } - - // Anything But Tinkers Dust - public static ItemStack getNonTinkersDust(final String oredictName, final int amount) { - final ArrayList<ItemStack> oreDictList = OreDictionary.getOres(oredictName); - if (!oreDictList.isEmpty()) { - ItemStack returnvalue; - for (int xrc = 0; xrc < oreDictList.size(); xrc++) { - final String modid = getModId(oreDictList.get(xrc).getItem()); - if (modid != null && !modid.equals("tconstruct")) { - returnvalue = oreDictList.get(xrc).copy(); - returnvalue.stackSize = amount; - return returnvalue; - } - } - } - // If only Tinkers dust exists, bow down and just use it. - return getItemStackOfAmountFromOreDictNoBroken(oredictName, amount); - } - - @Deprecated - public static ItemStack getGregtechOreStack(OrePrefixes mPrefix, Materials mMat, int mAmount) { - - ItemStack aTemp = getOrePrefixStack(mPrefix, mMat, mAmount); - if (aTemp != null) { - return aTemp; - } - - String mName = MaterialUtils.getMaterialName(mMat); - - String mItemName = mPrefix.name() + mName; - // Utils.LOG_INFO("[Component Maker] Trying to get "+mItemName+"."); - ItemStack gregstack = ItemUtils.getItemStackOfAmountFromOreDictNoBroken(mItemName, mAmount); - if (gregstack == null) { - // Utils.LOG_INFO("[Component Maker] Failed to get "+mItemName+"."); - return null; - } - // Utils.LOG_INFO("[Component Maker] Found "+mItemName+"."); - return (gregstack); - } - - public static ItemStack getOrePrefixStack(OrePrefixes mPrefix, Material mMat, int mAmount) { - - String mName = Utils.sanitizeString(mMat.getLocalizedName()); - - String mItemName = mPrefix.name() + mName; - ItemStack gregstack = ItemUtils.getItemStackOfAmountFromOreDictNoBroken(mItemName, mAmount); - if (gregstack == null) { - return null; - } - return (gregstack); - } - - public static ItemStack getOrePrefixStack(OrePrefixes mPrefix, Materials mMat, int mAmount) { - if (mPrefix == OrePrefixes.rod) { - mPrefix = OrePrefixes.stick; - } - ItemStack aGtStack = GT_OreDictUnificator.get(mPrefix, mMat, mAmount); - if (aGtStack == null) { - Logger.INFO( - "Failed to find `" + mPrefix + MaterialUtils.getMaterialName(mMat) + "` in OD. [Prefix Search]"); - return getErrorStack(mAmount, (mPrefix.toString()+MaterialUtils.getMaterialName(mMat)+" x"+mAmount)); - } else { - return aGtStack; - } - } - - public static ItemStack getErrorStack(int mAmount) { - return getErrorStack(mAmount, null); - } - - public static ItemStack getErrorStack(int mAmount, String aName) { - ItemStack g = getSimpleStack(ModItems.AAA_Broken, 1); - NBTUtils.setString(g, "Lore", EnumChatFormatting.RED+aName); - if (aName != null) { - NBTUtils.setBookTitle(g, EnumChatFormatting.YELLOW+"Maybe Alkalus should know about this"); - } - return g; - } - - public static ItemStack[] getStackOfAllOreDictGroup(String oredictname) { - final ArrayList<ItemStack> oreDictList = OreDictionary.getOres(oredictname); - if (!oreDictList.isEmpty()) { - final ItemStack[] returnValues = new ItemStack[oreDictList.size()]; - for (int i = 0; i < oreDictList.size(); i++) { - if (oreDictList.get(i) != null) { - returnValues[i] = oreDictList.get(i); - } - } - return returnValues.length > 0 ? returnValues : null; - } else { - return null; - } - } - - public static boolean registerFuel(ItemStack aBurnable, int burn) { - return CORE.burnables.add(new Pair<Integer, ItemStack>(burn, aBurnable)); - } - - public static String getLocalizedNameOfBlock(BlockPos pos) { - Block block = pos.world.getBlock(pos.xPos, pos.yPos, pos.zPos); - int metaData = pos.world.getBlockMetadata(pos.xPos, pos.yPos, pos.zPos); - return LangUtils.getLocalizedNameOfBlock(block, metaData); - } - - public static boolean checkForInvalidItems(ItemStack mInput) { - return checkForInvalidItems(new ItemStack[] { mInput }); - } - - public static boolean checkForInvalidItems(ItemStack[] mInput) { - return checkForInvalidItems(mInput, new ItemStack[] {}); - } - - /** - * - * @param mInputs - * @return {@link Boolean} - True if {@link ItemStack}[] only contains valid - * items. - */ - public static boolean checkForInvalidItems(ItemStack[] mInputs, ItemStack[] mOutputs) { - if (mInputs == null || mOutputs == null) { - return false; - } - - if (mInputs.length > 0) { - for (ItemStack stack : mInputs) { - if (stack != null) { - if (stack.getItem() != null) { - if (stack.getItem() == ModItems.AAA_Broken - || stack.getItem().getClass() == ModItems.AAA_Broken.getClass()) { - return false; - } else if (stack.getItem() == ModItems.ZZZ_Empty - || stack.getItem().getClass() == ModItems.ZZZ_Empty.getClass()) { - return false; - } else { - continue; - } - } else { - continue; - } - } else { - return false; - } - } - } - if (mOutputs.length > 0) { - for (ItemStack stack : mOutputs) { - if (stack != null) { - if (stack.getItem() != null) { - if (stack.getItem() == ModItems.AAA_Broken - || stack.getItem().getClass() == ModItems.AAA_Broken.getClass()) { - return false; - } else if (stack.getItem() == ModItems.ZZZ_Empty - || stack.getItem().getClass() == ModItems.ZZZ_Empty.getClass()) { - return false; - } else { - continue; - } - } else { - continue; - } - } else { - return false; - } - } - } - - return true; - } - - - public static IInventory organiseInventory(IInventory aInputInventory) { - ItemStack[] p = new ItemStack[aInputInventory.getSizeInventory()]; - for (int o = 0; o < aInputInventory.getSizeInventory(); o++) { - p[o] = aInputInventory.getStackInSlot(o); - } - //ItemStack[] g = organiseInventory(p); - - IInventory aTemp = aInputInventory; - for (int i = 0; i < p.length; ++i) { - for (int j = i + 1; j < p.length; ++j) { - if (p[j] != null && (p[i] == null - || GT_Utility.areStacksEqual(p[i], p[j]))) { - GT_Utility.moveStackFromSlotAToSlotB(aTemp, aTemp, j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } - } - - /* - for (int o = 0; o < aInputInventory.getSizeInventory(); o++) { - aTemp.setInventorySlotContents(o, g[o]); - }*/ - return aTemp; - } - - - public static ItemStack[] organiseInventory(ItemStack[] aInputs) { - - //Update Slots - int aInvSize = aInputs.length; - ItemStack[] newArray = new ItemStack[aInvSize]; - - - //Try merge stacks - for (int i = 0; i < aInvSize; i++) { - for (int i2 = 0; i2 < aInvSize; i2++) { - if (i != i2) { - ItemStack[] t1 = new ItemStack[] {aInputs[i], aInputs[i2]}; - if (t1[0] == null || t1[1] == null) { - continue; - } - else if (!GT_Utility.areStacksEqual(t1[0], t1[1])) { - continue; - } - //Try Merge - else { - - if (GT_Utility.areStacksEqual(t1[0], t1[1])) { - while ((t1[0].stackSize < 64 && t1[1].stackSize > 0)) { - t1[0].stackSize++; - t1[1].stackSize--; - if (t1[1].stackSize <= 0) { - t1[1] = null; - break; - } - if (t1[0].stackSize == 64) { - break; - } - } - newArray[i] = t1[1]; - newArray[i2] = t1[0]; - } - } - } - } - } - - ItemStack[] newArray2 = new ItemStack[aInvSize]; - - //Move nulls to end - int count2 = 0; - for (int i = 0; i < aInvSize; i++) - if (newArray[i] != null) - newArray2[count2++] = newArray[i]; - while (count2 < aInvSize) - newArray2[count2++] = null; - - return newArray2; - - - } - - public static String getFluidName(FluidStack aFluid) { - return aFluid != null ? aFluid.getFluid().getLocalizedName(aFluid) : "NULL"; - } - - public static String getFluidName(Fluid aFluid) { - return aFluid != null ? aFluid.getLocalizedName() : "NULL"; - } - - public static String getItemName(ItemStack aStack) { - if (aStack == null) { - return "ERROR - Empty Stack"; - } - String aDisplay = null; - try { - aDisplay = ("" + StatCollector - .translateToLocal(aStack.getItem().getUnlocalizedNameInefficiently(aStack) + ".name")) - .trim(); - if (aStack.hasTagCompound()) { - if (aStack.stackTagCompound != null && aStack.stackTagCompound.hasKey("display", 10)) { - NBTTagCompound nbttagcompound = aStack.stackTagCompound.getCompoundTag("display"); - - if (nbttagcompound.hasKey("Name", 8)) { - aDisplay = nbttagcompound.getString("Name"); - } - } - } - } catch (Throwable t) { - - } - if (aDisplay == null || aDisplay.length() <= 0) { - aDisplay = aStack.getUnlocalizedName() + ":" + aStack.getItemDamage(); - } else { - aDisplay += " | Meta: " + aStack.getItemDamage(); - } - return aDisplay; - } - - public static String getUnlocalizedItemName(ItemStack aStack) { - if (aStack == null) { - return "ERROR.Empty.Stack"; - } - String aDisplay = null; - try { - aDisplay = (aStack.getUnlocalizedName()).trim(); - } - catch (Throwable t) { - aDisplay = aStack.getItem().getUnlocalizedName(); - } - if (aDisplay == null || aDisplay.length() <= 0) { - aDisplay = aStack.getItem().getUnlocalizedNameInefficiently(aStack); - } - return aDisplay; - } - - public static boolean isItemGregtechTool(ItemStack aStack) { - if (aStack == null) { - return false; - } - final Item mItem = aStack.getItem(); - final Item aSkookum = ItemUtils.getItemFromFQRN("miscutils:gt.plusplus.metatool.01"); - final Class aSkookClass = aSkookum.getClass(); - if (aSkookClass.isInstance(mItem) || mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool || mItem == aSkookum) { - return true; - } - return false; - } - - public static boolean isToolWrench(ItemStack aWrench) { - if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124 || aWrench.getItemDamage() == 7734)) { - return true; - } - return false; - } - - public static boolean isToolMallet(ItemStack aMallet) { - if (isItemGregtechTool(aMallet) && (aMallet.getItemDamage() == 14)) { - return true; - } - return false; - } - - public static boolean isToolScrewdriver(ItemStack aScrewdriver) { - if (isItemGregtechTool(aScrewdriver) && (aScrewdriver.getItemDamage() == 22 || aScrewdriver.getItemDamage() == 150)) { - return true; - } - return false; - } - - public static boolean isToolCrowbar(ItemStack aCrowbar) { - if (isItemGregtechTool(aCrowbar) && (aCrowbar.getItemDamage() == 20)) { - return true; - } - return false; - } - - public static boolean isToolWirecutters(ItemStack aWirecutters) { - if (isItemGregtechTool(aWirecutters) && (aWirecutters.getItemDamage() == 26)) { - return true; - } - return false; - } - - public static boolean isToolHammer(ItemStack aHammer) { - if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12 || aHammer.getItemDamage() == 7734)) { - return true; - } - return false; - } - - public static boolean isToolSolderingIron(ItemStack aSoldering) { - if (isItemGregtechTool(aSoldering) && (aSoldering.getItemDamage() == 160)) { - return true; - } - return false; - } - - public static ItemStack[] cleanItemStackArray(ItemStack[] input) { - int aArraySize = input.length; - ItemStack[] aOutput = new ItemStack[aArraySize]; - AutoMap<ItemStack> aCleanedItems = new AutoMap<ItemStack>(); - for (ItemStack checkStack : input) { - if (ItemUtils.checkForInvalidItems(checkStack)) { - aCleanedItems.put(checkStack); - } - } - for (int i=0;i<aArraySize;i++) { - ItemStack aMappedStack = aCleanedItems.get(i); - if (aMappedStack != null){ - aOutput[i] = aMappedStack; - } - } - return aOutput; - } - - public static ItemStack getEnchantedBook(Enchantment aEnch, int aLevel) { - return enchantItem(new ItemStack(Items.enchanted_book), aEnch, aLevel); - } - - public static ItemStack enchantItem(ItemStack aStack, Enchantment aEnch, int aLevel) { - Items.enchanted_book.addEnchantment(aStack, new EnchantmentData(aEnch, aLevel)); - return aStack; - } - - public static boolean doesOreDictHaveEntryFor(String string) { - return OreDictUtils.containsValidEntries(string); - } - - public static void hideItemFromNEI(ItemStack aItemToHide) { - codechicken.nei.api.API.hideItem(aItemToHide); - } - - public static ItemStack getNullStack() { - return GT_Values.NI; - } - - public static ItemStack depleteStack(ItemStack aStack) { - return depleteStack(aStack, 1); - } - - public static ItemStack depleteStack(ItemStack aStack, int aAmount) { - final int cap = aStack.stackSize; - if (cap >= 1 && cap >= aAmount) { - ItemStack aDepStack = aStack.copy(); - aDepStack.stackSize = (MathUtils.balance((aDepStack.stackSize - 1), 0, 64)); - if (aDepStack.stackSize > 0) { - return aDepStack; - } - } - return getNullStack(); - } - - public static boolean isControlCircuit(ItemStack aStack) { - if (aStack != null) { - Item aItem = aStack.getItem(); - if (aItem == CI.getNumberedBioCircuit(0).getItem() || aItem == CI.getNumberedCircuit(0).getItem() || aItem == CI.getNumberedAdvancedCircuit(0).getItem()) { - return true; - } - } - return false; - } - - public static boolean isCatalyst(ItemStack aStack) { - if (GT_Utility.areStacksEqual(aStack, RocketFuels.Formaldehyde_Catalyst_Stack, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mBlueCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mBrownCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mOrangeCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mPurpleCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mRedCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mYellowCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mPinkCatalyst, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, AgriculturalChem.mGreenCatalyst, true)) { - return true; - } - return false; - } - - public static boolean isMillingBall(ItemStack aStack) { - if (GT_Utility.areStacksEqual(aStack, GenericChem.mMillingBallAlumina, true)) { - return true; - } - if (GT_Utility.areStacksEqual(aStack, GenericChem.mMillingBallSoapstone, true)) { - return true; - } - return false; - } - - public static String getLocalizedNameOfBlock(Block aBlock, int aMeta) { - return LangUtils.getLocalizedNameOfBlock(aBlock, aMeta); - } - - - - public static boolean doesItemListEntryExist(String string) { - ItemList[] aListValues = ItemList.class.getEnumConstants(); - for (ItemList aItem : aListValues) { - if (aItem != null) { - if (aItem.name().equals(string) || aItem.name().toLowerCase().equals(string.toLowerCase())) { - return true; - } - } - } - return false; - } - - public static ItemList getValueOfItemList(String string, ItemList aOther) { - ItemList[] aListValues = ItemList.class.getEnumConstants(); - for (ItemList aItem : aListValues) { - if (aItem != null) { - if (aItem.name().equals(string) || aItem.name().toLowerCase().equals(string.toLowerCase())) { - return aItem; - } - } - } - Logger.INFO("Tried to obtain '"+string+"' from the GT ItemList, however it does not exist."); - if (aOther != null) { - Logger.INFO("Using fallback option instead - "+aOther.name()); - } - return aOther; - } - - public static ItemStack getValueOfItemList(String string, int aAmount, ItemList aOther) { - return getValueOfItemList(string, aOther).get(aAmount); - } - - public static ItemStack getValueOfItemList(String string, int aAmount, ItemStack aOther) { - ItemList[] aListValues = ItemList.class.getEnumConstants(); - for (ItemList aItem : aListValues) { - if (aItem != null) { - if (aItem.name().equals(string) || aItem.name().toLowerCase().equals(string.toLowerCase())) { - return aItem.get(aAmount); - } - } - } - Logger.INFO("Tried to obtain '"+string+"' from the GT ItemList, however it does not exist."); - if (aOther != null) { - Logger.INFO("Using fallback option instead - "+ItemUtils.getItemName(aOther)); - } - return aOther; - } - - public static boolean areItemsEqual(ItemStack aStack1, ItemStack aStack2) { - return areItemsEqual(aStack1, aStack2, true); - } - - public static boolean areItemsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { - return GT_Utility.areStacksEqual(aStack1, aStack2, aIgnoreNBT); - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/LangUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/LangUtils.java deleted file mode 100644 index 0b24e962af..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/LangUtils.java +++ /dev/null @@ -1,150 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import cpw.mods.fml.common.registry.LanguageRegistry; -import gregtech.api.util.GT_LanguageManager; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.StatCollector; - -public class LangUtils { - - - public static boolean rewriteEntryForLanguageRegistry(String aKey, String aNewValue){ - return rewriteEntryForLanguageRegistry("en_US", aKey, aNewValue); - } - - @SuppressWarnings("unchecked") - public static boolean rewriteEntryForLanguageRegistry(String aLang, String aKey, String aNewValue){ - LanguageRegistry aInstance = LanguageRegistry.instance(); - Field aModLanguageData = ReflectionUtils.getField(LanguageRegistry.class, "modLanguageData"); - if (aModLanguageData != null){ - Map<String,Properties> aProps = new HashMap<String, Properties>(); - Object aInstanceProps; - try { - aInstanceProps = aModLanguageData.get(aInstance); - if (aInstanceProps != null){ - aProps = (Map<String, Properties>) aInstanceProps; - Properties aLangProps = aProps.get(aLang); - if (aLangProps != null){ - if (aLangProps.containsKey(aKey)) { - aLangProps.remove(aKey); - aLangProps.put(aKey, aNewValue); - } - else { - aLangProps.put(aKey, aNewValue); - } - aProps.remove(aLang); - aProps.put(aLang, aLangProps); - ReflectionUtils.setField(aInstance, aModLanguageData, aProps); - } - } - } - catch (IllegalArgumentException | IllegalAccessException e) { - - } - } - return false; - } - - public static String trans(String aNr, String aEnglish) { - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_GTPP_" + aNr, aEnglish, false); - } - - - - /** - * Quick Block Name Lookup that is friendly to servers and locale. - */ - private static final Map<String, String> mLocaleCache = new HashMap<String, String>(); - - public static String getLocalizedNameOfBlock(Block aBlock, int aMeta) { - if (aBlock != null) { - return getLocalizedNameOfItemStack(ItemUtils.simpleMetaStack(aBlock, aMeta, 1)); - } - return "Bad Block Name"; - } - - public static String getLocalizedNameOfItem(Item aItem, int aMeta) { - if (aItem != null) { - return getLocalizedNameOfItemStack(ItemUtils.simpleMetaStack(aItem, aMeta, 1)); - } - return "Bad Item Name"; - } - - public static String getLocalizedNameOfItemStack(ItemStack aStack) { - String aUnlocalized; - if (aStack != null) { - aUnlocalized = ItemUtils.getUnlocalizedItemName(aStack)+"."+aStack.getItemDamage()+".name"; - if (aUnlocalized == null || aUnlocalized.length() <= 0) { - return "Bad Locale Data"; - } - String mCacheKey = aUnlocalized; - if (mLocaleCache.containsKey(mCacheKey)) { - // Recache the key if it's invalid. - if (mLocaleCache.get(mCacheKey).toLowerCase().contains(".name") || mLocaleCache.get(mCacheKey).toLowerCase().contains("|")) { - mLocaleCache.remove(mCacheKey); - String mNew; - try { - mNew = ("" + StatCollector - .translateToLocal(aStack.getItem().getUnlocalizedNameInefficiently(aStack) + ".name")) - .trim(); - if (aStack.hasTagCompound()) { - if (aStack.stackTagCompound != null && aStack.stackTagCompound.hasKey("display", 10)) { - NBTTagCompound nbttagcompound = aStack.stackTagCompound.getCompoundTag("display"); - - if (nbttagcompound.hasKey("Name", 8)) { - mNew = nbttagcompound.getString("Name"); - } - } - } - } catch (Throwable t) { - mNew = "ERROR - Empty Stack"; - } - Logger.INFO("Re-caching "+mNew+" into locale cache. Key: "+mCacheKey); - mLocaleCache.put(mCacheKey, mNew); - } - Logger.INFO("Returning Cached Value. Key: "+mCacheKey); - return mLocaleCache.get(mCacheKey); - } - else { - String unlocalizedName = aStack.getItem().getUnlocalizedName(aStack); - Logger.INFO("Cached New Value. UnlocalName: "+unlocalizedName); - String blockName = StatCollector.translateToLocal(unlocalizedName + ".name"); - Logger.INFO("Cached New Value. TranslatedName: "+unlocalizedName); - if (blockName.toLowerCase().contains(".name") || blockName.toLowerCase().contains("|")) { - try { - blockName = ("" + StatCollector - .translateToLocal(aStack.getItem().getUnlocalizedNameInefficiently(aStack) + ".name")) - .trim(); - if (aStack.hasTagCompound()) { - if (aStack.stackTagCompound != null && aStack.stackTagCompound.hasKey("display", 10)) { - NBTTagCompound nbttagcompound = aStack.stackTagCompound.getCompoundTag("display"); - if (nbttagcompound.hasKey("Name", 8)) { - blockName = nbttagcompound.getString("Name"); - } - } - } - } catch (Throwable t) { - blockName = "ERROR - Empty Stack"; - } - } - mLocaleCache.put(mCacheKey, blockName); - Logger.INFO("Cached New Value. Key: "+mCacheKey); - return blockName; - } - - } - return "Bad ItemStack Name"; - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java deleted file mode 100644 index 7e9e34ae47..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java +++ /dev/null @@ -1,516 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import gregtech.api.enums.Dyes; -import gregtech.api.enums.Element; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.TextureSet; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.data.TypeCounter; -import gtPlusPlus.core.client.CustomTextureSet.TextureSets; -import gtPlusPlus.core.item.base.BaseItemComponent; -import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes; -import gtPlusPlus.core.item.base.plates.BaseItemPlateHeavy; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.material.MaterialStack; -import gtPlusPlus.core.material.state.MaterialState; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.data.EnumUtils; -import gtPlusPlus.core.util.data.StringUtils; -import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; - -public class MaterialUtils { - - public static short firstID = 791; - - @SuppressWarnings({ "rawtypes", "unused" }) - private static Class[][] commonTypes = -{{Materials.class, int.class, TextureSet.class, float.class, int.class, - int.class, int.class, int.class, int.class, int.class, int.class, - String.class, int.class, int.class, int.class, int.class, boolean.class, - boolean.class, int.class, int.class, int.class, Dyes.class, int.class, - List.class , List.class}}; - - public static List<?> oreDictValuesForEntry(final String oredictName){ - List<?> oredictItemNames; - if(OreDictionary.doesOreNameExist(oredictName)){ - final List<ItemStack> oredictItems = OreDictionary.getOres(oredictName); - oredictItemNames = oredictItems; - return oredictItemNames; - } - return null; - } - - private static Map<String, Material> mGeneratedMaterialMap = new HashMap(); - - public static Material generateMaterialFromGtENUM(final Materials material){ - return generateMaterialFromGtENUM(material, null, null); - } - - public static Material generateMaterialFromGtENUM(final Materials material, TextureSet aCustomTextures){ - return generateMaterialFromGtENUM(material, null, aCustomTextures); - } - - public static Material generateMaterialFromGtENUM(final Materials material, short[] customRGB){ - return generateMaterialFromGtENUM(material, customRGB, null); - } - - public static Material generateMaterialFromGtENUM(final Materials material, short[] customRGB, TextureSet aCustomTextures){ - String aMaterialKey = getMaterialName(material).toLowerCase(); - if (mGeneratedMaterialMap.containsKey(aMaterialKey)) { - return mGeneratedMaterialMap.get(aMaterialKey); - } - - try { - @SuppressWarnings("deprecation") - String name = material.name(); - final short[] rgba = (customRGB == null ? material.mRGBa : customRGB); - final int melting = material.mMeltingPoint; - final int boiling = material.mBlastFurnaceTemp; - final long protons = material.getProtons(); - final long neutrons = material.getNeutrons(); - final boolean blastFurnace = material.mBlastFurnaceRequired; - Integer radioactivity = 0; - if (material.isRadioactive()){ - ItemStack aDustStack = ItemUtils.getOrePrefixStack(OrePrefixes.dust, material, 1); - radioactivity = aDustStack != null ? GT_Utility.getRadioactivityLevel(aDustStack) : 0; - if (radioactivity == 0) { - long aProtons = material.getProtons(); - radioactivity = (int) Math.min(Math.max((aProtons / 30), 1), 9); - } - } - Logger.MATERIALS("[Debug] Calculated Radiation level to be "+radioactivity.intValue()+"."); - TextureSet iconSet = null; - if (aCustomTextures == null) { - if (material.isRadioactive()) { - iconSet = TextureSets.NUCLEAR.get(); - } - else { - iconSet = material.mIconSet; - } - } - else { - iconSet = aCustomTextures; - } - if (iconSet == null || iconSet.mSetName.toLowerCase().contains("fluid")) { - iconSet = TextureSet.SET_METALLIC; - } - Logger.MATERIALS("[Debug] Calculated Texture Set to be "+iconSet.mSetName+"."); - - - final int durability = material.mDurability; - boolean mGenerateCell = false; - boolean mGenerateFluid = true; - MaterialState materialState; - String chemicalFormula = StringUtils.subscript(Utils.sanitizeString(material.mChemicalFormula)); - final Element element = material.mElement; - - - //Weird Blacklist of Bad Chemical Strings - if (material.mElement == Element.Pb || material.mElement == Element.Na || material.mElement == Element.Ar){ - chemicalFormula = StringUtils.subscript(Utils.sanitizeString(material.mElement.name())); - } - - //Determine default state - Logger.MATERIALS("[Debug] Setting State of GT generated material. "+material.mDefaultLocalName); - if (material.getMolten(1) != null || material.getSolid(1) != null){ - materialState = MaterialState.SOLID; - Logger.MATERIALS("[Debug] Molten or Solid was not null."); - if (material.getMolten(1) == null && material.getSolid(1) != null){ - Logger.MATERIALS("[Debug] Molten is Null, Solid is not. Enabling cell generation."); - mGenerateCell = true; - } - else if (material.getMolten(1) != null && material.getSolid(1) == null){ - Logger.MATERIALS("[Debug] Molten is not Null, Solid is null. Not enabling cell generation."); - //mGenerateCell = true; - } - Logger.MATERIALS("[Debug] State set as solid."); - } - else if (material.getFluid(1) != null){ - Logger.MATERIALS("[Debug] State set as liquid."); - materialState = MaterialState.LIQUID; - } - else if (material.getGas(1) != null){ - Logger.MATERIALS("[Debug] State set as gas."); - materialState = MaterialState.GAS; - }/* - else if (material.getPlasma(1) != null){ - Logger.MATERIALS("[Debug] State set as plasma."); - materialState = MaterialState.PLASMA; - }*/ - else { - Logger.MATERIALS("[Debug] State set as solid. This material has no alternative states, so for safety we wont generate anything."); - materialState = MaterialState.SOLID; - mGenerateFluid = false; - } - - - if (name.toLowerCase().contains("infused")){ - final String tempname = name.substring(7, name.length()); - name = "Infused " + tempname; - } - if (hasValidRGBA(rgba) || (element == Element.H) || ((material == Materials.InfusedAir) || (material == Materials.InfusedFire) || (material == Materials.InfusedEarth) || (material == Materials.InfusedWater))){ - //ModItems.itemBaseDecidust = UtilsItems.generateDecidust(material); - //ModItems.itemBaseCentidust = UtilsItems.generateCentidust(material); - Material M = new Material(name, materialState,iconSet, durability, rgba, melting, boiling, protons, neutrons, blastFurnace, chemicalFormula, radioactivity.intValue(), mGenerateCell, mGenerateFluid); - mGeneratedMaterialMap.put(aMaterialKey, M); - return M; - } - else { - Logger.DEBUG_MATERIALS("Failed to generate GT++ material instance for "+material.name() +" | Valid RGB? "+(hasValidRGBA(rgba))); - } - } - catch (Throwable t) { - Logger.DEBUG_MATERIALS("Failed to generate GT++ material instance for "+material.name()); - t.printStackTrace(); - } - return null; - - } - - public static Material generateQuickMaterial(final String materialName, final MaterialState defaultState, final short[] colour, final int sRadioactivity) { - String aMaterialKey = materialName.toLowerCase(); - if (mGeneratedMaterialMap.containsKey(aMaterialKey)) { - return mGeneratedMaterialMap.get(aMaterialKey); - } - - final Material temp = new Material( - materialName, - defaultState, - colour, - 1000, //melting - 3000, //boiling - 50, //Protons - 50, //Neutrons - false, - "", - sRadioactivity); - mGeneratedMaterialMap.put(aMaterialKey, temp); - return temp; - } - - public static boolean hasValidRGBA(final short[] rgba){ - if (rgba == null || rgba.length < 3 || rgba.length > 4){ - return false; - } - return true; - } - - public static int getTierOfMaterial(final double aMeltingPoint){ - - return aMeltingPoint < 1000 ? 0 : (MathUtils.roundToClosestInt(aMeltingPoint/1000f)); - - - /*if ((aMeltingPoint >= 0) && (aMeltingPoint <= 1000)){ - return 1; - } - else if((aMeltingPoint >= 1001) && (aMeltingPoint <= 2000)){ - return 2; - } - else if((aMeltingPoint >= 2001) && (aMeltingPoint <= 3000)){ - return 3; - } - else if((aMeltingPoint >= 3001) && (aMeltingPoint <= 4000)){ - return 4; - } - else if((aMeltingPoint >= 4001) && (aMeltingPoint <= 5000)){ - return 5; - } - else if((aMeltingPoint >= 5001) && (aMeltingPoint <= 6000)){ - return 6; - } - else if((aMeltingPoint >= 6001) && (aMeltingPoint <= 7000)){ - return 7; - } - else if((aMeltingPoint >= 7001) && (aMeltingPoint <= 8000)){ - return 8; - } - else if((aMeltingPoint >= 8001) && (aMeltingPoint <= 9000)){ - return 9; - } - else if((aMeltingPoint >= 9001) && (aMeltingPoint <= 9999)){ - return 10; - } - else { - return 0; - }*/ - } - - public static int getVoltageForTier(int aTier) { - //aTier += 1; - Probably some logic to this, idk. - - switch(aTier){ - case 0: - return 16; - case 1: - return 30; - case 2: - return 120; - case 3: - return 480; - case 4: - return 1920; - case 5: - return 7680; - case 6: - return 30720; - case 7: - return 122880; - case 8: - return 491520; - case 9: - return 1966080; - case 10: - return 7864320; - case 11: - return 31457280; - case 12: - return 125829120; - case 13: - return 503316480; - case 14: - return 2013265920; - default: - return Integer.MAX_VALUE; - } - - /*else { - int newTier = aTier - 1; - return (int) ((4*(Math.pow(4, newTier)))*7.5); - }*/ - } - - private static Materials getMaterialByName(String materialName) { - - if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - return (Materials) EnumUtils.getValue(gregtech.api.enums.Materials.class, materialName, false); - } - else { - for (Materials m : Materials.values()) { - if (MaterialUtils.getMaterialName(m).toLowerCase().equals(materialName.toLowerCase())) { - return m; - } - } - return null; - } - } - - @SuppressWarnings("deprecation") - public static String getMaterialName(Materials mat){ - - String mName = null; - - try { - mName = (String) ReflectionUtils.getField(Materials.class, "mDefaultLocalName").get(mat); - if (mName == null) { - mName = (String) ReflectionUtils.getField(Materials.class, "mName").get(mat); - } - } - catch (IllegalArgumentException | IllegalAccessException e) { - } - - - if (mName == null || mName.equals("")){ - mName = mat.name(); - } - return mName; - } - - public static TextureSet getMostCommonTextureSet(List<Material> list) { - TypeCounter<TextureSet> aCounter = new TypeCounter<TextureSet>(TextureSet.class); - for (Material m : list) { - TextureSet t = m.getTextureSet(); - if (t == null) { - t = Materials.Gold.mIconSet; - } - if (t != null) { - aCounter.add(t, t.mSetName); - } - } - return aCounter.getResults(); - /*Optional<TextureSet> r = list.stream().map(Material::getTextureSet).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); - TextureSet o = (r != null && r.isPresent() && r.get() != null) ? r.get() : null; - return o;*/ - } - - - - public static Materials getMaterial(String aMaterialName, String aFallbackMaterialName) { - Materials g = getMaterial(aMaterialName); - if (g == null) { - g = getMaterial(aFallbackMaterialName); - } - if (g == null) { - Logger.INFO("Failed finding material '"+aMaterialName+"' & fallback '"+aFallbackMaterialName+"', returning _NULL."); - CORE.crash(); - //g = Materials._NULL; - } - return g; - } - - public static Materials getMaterial(String aMaterialName) { - Materials m = gtPlusPlus.xmod.gregtech.common.StaticFields59.getMaterial(aMaterialName); - if (m == null) { - m = getMaterialByName(aMaterialName); - } - if (m == null) { - Logger.INFO("Failed finding material '"+aMaterialName+"', returning _NULL."); - m = Materials._NULL; - } - return m; - } - - public static AutoMap<Material> getCompoundMaterialsRecursively(Material aMat){ - return getCompoundMaterialsRecursively_Speiger(aMat); - /* - AutoMap<Material> aDataSet = new AutoMap<Material>(); - final int HARD_LIMIT = 1000; - int mLoopCounter = 0; - if (aMat.getComposites().size() > 0) { - try { - List<Material> xList = Lists.newLinkedList(); - for (MaterialStack kj : aMat.getComposites()) { - xList.add(kj.getStackMaterial()); - } - if (xList.isEmpty()) { - aDataSet.put(aMat); - return aDataSet; - } - ListIterator<Material> listIterator = xList.listIterator(); - while(listIterator.hasNext()){ - Material e = listIterator.next(); - listIterator.remove(); - if (mLoopCounter > HARD_LIMIT) { - break; - } - - if (e.getComposites().isEmpty()) { - aDataSet.put(e); - } - else { - for (MaterialStack x : e.getComposites()) { - listIterator.add(x.getStackMaterial()); - } - } - mLoopCounter++; - - - }} - catch (Throwable t) { - aDataSet.put(aMat); - t.printStackTrace(); - } - } - if (aDataSet.isEmpty()) { - aDataSet.put(aMat); - return aDataSet; - } - return aDataSet; - */} - - public static AutoMap<Material> getCompoundMaterialsRecursively_Speiger(Material toSearch) { - AutoMap<Material> resultList = new AutoMap<Material>(); - if (toSearch.getComposites().isEmpty()) { - resultList.put(toSearch); - return resultList; - } - final int HARD_LIMIT = 1000; - - // Could be a Deque but i dont use the interface - // enough to use it as default. - LinkedList<Material> toCheck = new LinkedList<Material>(); - - toCheck.add(toSearch); - int processed = 0; - while (toCheck.size() > 0 && processed < HARD_LIMIT) { - Material current = toCheck.remove(); - if (current.getComposites().isEmpty()) { - resultList.put(current); - } else { - for (MaterialStack entry : current.getComposites()) { - toCheck.add(entry.getStackMaterial()); - } - } - processed++; - } - return resultList; - } - - public static void generateComponentAndAssignToAMaterial(ComponentTypes aType, Material aMaterial) { - generateComponentAndAssignToAMaterial(aType, aMaterial, true); - } - - public static void generateComponentAndAssignToAMaterial(ComponentTypes aType, Material aMaterial, boolean generateRecipes) { - Item aGC; - if (aType == ComponentTypes.PLATEHEAVY) { - aGC = new BaseItemPlateHeavy(aMaterial); - } - else { - aGC = new BaseItemComponent(aMaterial, aType); - } - if (aGC != null) { - String aFormattedLangName = aType.getName(); - - if (!aFormattedLangName.startsWith(" ")) { - if (aFormattedLangName.contains("@")) { - String[] aSplit = aFormattedLangName.split("@"); - aFormattedLangName = aSplit[0] + " " + aMaterial.getLocalizedName() + " " + aSplit[1]; - } - } - - if (aFormattedLangName.equals(aType.getName())) { - aFormattedLangName = aMaterial.getLocalizedName() + aFormattedLangName; - - } - - - - Logger.MATERIALS("[Lang] "+aGC.getUnlocalizedName()+".name="+aFormattedLangName); - aMaterial.registerComponentForMaterial(aType, ItemUtils.getSimpleStack(aGC)); - } - } - - - - - - - - - public static void generateSpecialDustAndAssignToAMaterial(Material aMaterial) { - generateSpecialDustAndAssignToAMaterial(aMaterial, true); - } - - public static void generateSpecialDustAndAssignToAMaterial(Material aMaterial, boolean generateMixerRecipes) { - Item[] aDusts = ItemUtils.generateSpecialUseDusts(aMaterial, false, Utils.invertBoolean(generateMixerRecipes)); - if (aDusts != null && aDusts.length > 0) { - aMaterial.registerComponentForMaterial(OrePrefixes.dust, ItemUtils.getSimpleStack(aDusts[0])); - aMaterial.registerComponentForMaterial(OrePrefixes.dustSmall, ItemUtils.getSimpleStack(aDusts[1])); - aMaterial.registerComponentForMaterial(OrePrefixes.dustTiny, ItemUtils.getSimpleStack(aDusts[2])); - } - - } - - public static boolean doesMaterialExist(String aMatName) { - for (Materials m : Materials.values()) { - if (m.name().toLowerCase().equals(aMatName.toLowerCase())) { - return true; - } - } - return false; - } - - -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java deleted file mode 100644 index 080b5665a3..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java +++ /dev/null @@ -1,265 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.HashMap; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - -import gregtech.common.GT_Worldgen_GT_Ore_Layer; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.util.reflect.ReflectionUtils; - -public class MiningUtils { - - public static Boolean canPickaxeBlock(final Block currentBlock, final World currentWorld){ - String correctTool = ""; - if (!currentWorld.isRemote){ - try { - correctTool = currentBlock.getHarvestTool(0); - //Utils.LOG_WARNING(correctTool); - if (correctTool.equals("pickaxe")){ - return true;} - } catch (final NullPointerException e){ - return false;} - } - return false; - } - - private static void removeBlockAndDropAsItem(final World world, final int X, final int Y, final int Z){ - try { - final Block block = world.getBlock(X, Y, Z); - if (canPickaxeBlock(block, world)){ - if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){ - block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); - world.setBlockToAir(X, Y, Z); - - } - else { - Logger.WARNING("Incorrect Tool for mining this block."); - } - } - } catch (final NullPointerException e){ - - } - } - - public static boolean getBlockType(final Block block, final World world, final int[] xyz, final int miningLevel){ - final String LIQUID = "liquid"; - final String BLOCK = "block"; - final String ORE = "ore"; - final String AIR = "air"; - String blockClass = ""; - - if (world.isRemote){ - return false; - } - - if (block == Blocks.end_stone) { - return true; - } - if (block == Blocks.stone) { - return true; - } - if (block == Blocks.sandstone) { - return true; - } - if (block == Blocks.netherrack) { - return true; - } - if (block == Blocks.nether_brick) { - return true; - } - if (block == Blocks.nether_brick_stairs) { - return true; - } - if (block == Blocks.nether_brick_fence) { - return true; - } - if (block == Blocks.glowstone) { - return true; - } - - - - try { - blockClass = block.getClass().toString().toLowerCase(); - Logger.WARNING(blockClass); - if (blockClass.toLowerCase().contains(LIQUID)){ - Logger.WARNING(block.toString()+" is a Liquid."); - return false; - } - else if (blockClass.toLowerCase().contains(ORE)){ - Logger.WARNING(block.toString()+" is an Ore."); - return true; - } - else if (block.getHarvestLevel(world.getBlockMetadata(xyz[0], xyz[1], xyz[2])) >= miningLevel){ - Logger.WARNING(block.toString()+" is minable."); - return true; - } - else if (blockClass.toLowerCase().contains(AIR)){ - Logger.WARNING(block.toString()+" is Air."); - return false; - } - else if (blockClass.toLowerCase().contains(BLOCK)){ - Logger.WARNING(block.toString()+" is a block of some kind."); - return false; - } - else { - Logger.WARNING(block.toString()+" is mystery."); - return false; - } - } - catch(final NullPointerException e){ - return false; - } - } - - public static int mMoonID =-99; - public static int mMarsID = -99; - public static int mCometsID = -99; - public static AutoMap<GT_Worldgen_GT_Ore_Layer> getOresForDim(int dim) { - if (dim == -1) { - return Ores_Nether; - } - else if (dim == 1) { - return Ores_End; - } - else if (dim == mMoonID) { - return Ores_Moon; - } - else if (dim == mMarsID) { - return Ores_Mars; - } - else if (dim == mCometsID) { - return Ores_Comets; - } - else { - return Ores_Overworld; - } - - } - - public static void iterateAllOreTypes() { - HashMap<String, Integer> M = new HashMap<String, Integer>(); - String aTextWorldGen = null; - if (MiningUtils.findAndMapOreTypesFromGT()) { - int mapKey = 0; - for (AutoMap<GT_Worldgen_GT_Ore_Layer> g : MiningUtils.mOreMaps) { - for (GT_Worldgen_GT_Ore_Layer h : g) { - - try { - aTextWorldGen = (String) ReflectionUtils.getField(GT_Worldgen_GT_Ore_Layer.class, "aTextWorldgen").get(h); - } catch (IllegalArgumentException | IllegalAccessException e) { - aTextWorldGen = h.mWorldGenName; - } - - //if (M.containsKey(h.aTextWorldgen + h.mWorldGenName)) { - M.put(aTextWorldGen + h.mWorldGenName, mapKey); - Logger.INFO("Found Vein type: " + aTextWorldGen + h.mWorldGenName + " in map with key: "+mapKey); - //} - } - mapKey++; - } - } - } - - public static AutoMap<GT_Worldgen_GT_Ore_Layer>[] mOreMaps = new AutoMap[7]; - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_Overworld = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_Nether = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_End = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_Moon = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_Mars = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_Comets = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - private static AutoMap<GT_Worldgen_GT_Ore_Layer> Ores_Misc = new AutoMap<GT_Worldgen_GT_Ore_Layer>(); - - public static boolean findAndMapOreTypesFromGT() { - //Gets Moon ID - - boolean aEndAsteroids; - try { - if (ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.util.ConfigManagerCore") != null && mMoonID == -99) { - mMoonID = ReflectionUtils.getField(ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.util.ConfigManagerCore"), "idDimensionMoon").getInt(null); - } - } - catch (IllegalArgumentException | IllegalAccessException e) {} - - //Gets Mars ID - try { - if (ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars") != null && mMarsID == -99) { - mMarsID = ReflectionUtils.getField(ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars"), "dimensionIDMars").getInt(null); - } - } - catch (IllegalArgumentException | IllegalAccessException e) {} - - //Get Comets ID - try { - if (ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids") != null && mCometsID == -99) { - mCometsID = ReflectionUtils.getField(ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids"), "dimensionIDAsteroids").getInt(null); - } - } - catch (IllegalArgumentException | IllegalAccessException e) {} - - //Clear Cache - Ores_Overworld.clear(); - Ores_Nether.clear(); - Ores_End.clear(); - Ores_Misc.clear(); - - for (GT_Worldgen_GT_Ore_Layer x : GT_Worldgen_GT_Ore_Layer.sList) { - if (x.mEnabled) { - - - try { - aEndAsteroids = ReflectionUtils.getField(GT_Worldgen_GT_Ore_Layer.class, "mEndAsteroid").getBoolean(x); - } - catch (IllegalArgumentException | IllegalAccessException e) { - aEndAsteroids = false; - } - - if (x.mOverworld) { - Ores_Overworld.put(x); - } - if (x.mNether) { - Ores_Nether.put(x); - } - if (x.mEnd || aEndAsteroids) { - Ores_End.put(x); - } - if (x.mOverworld || x.mNether || (x.mEnd || aEndAsteroids)) { - continue; - } - /*if (x.mMoon) { - Ores_Moon.put(x); - continue; - } - if (x.mMars) { - Ores_Mars.put(x); - continue; - } - if (x.mAsteroid) { - Ores_Comets.put(x); - continue; - }*/ - Ores_Misc.put(x); - continue; - } - else { - Ores_Comets.put(x); - } - } - - - mOreMaps[0] = Ores_Overworld; - mOreMaps[1] = Ores_Nether; - mOreMaps[2] = Ores_End; - mOreMaps[3] = Ores_Moon; - mOreMaps[4] = Ores_Mars; - mOreMaps[5] = Ores_Comets; - mOreMaps[6] = Ores_Misc; - return true; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ModularArmourUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ModularArmourUtils.java deleted file mode 100644 index e3ffb5c410..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/ModularArmourUtils.java +++ /dev/null @@ -1,161 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import gregtech.api.util.GT_Utility; - -import baubles.api.BaubleType; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.Pair; - -public class ModularArmourUtils { - - public static ItemStack addComponent(ItemStack tArmour, ItemStack[] tComponents) { - if (tArmour != null) { - ItemStack rArmour = NBTUtils.writeItemsToGtCraftingComponents(tArmour, tComponents, true); - if (rArmour != null) { - - } - } - return null; - } - - public static enum Modifiers { - BOOST_HP("skill.hpboost"), BOOST_DEF("skill.defenceboost"), BOOST_SPEED("skill.speedboost"), BOOST_MINING( - "skill.miningboost"), BOOST_DAMAGE("skill.damageboost"), BOOST_HOLY("skill.holyboost"); - private String MODIFIER_NAME; - - private Modifiers(final String mModifier) { - this.MODIFIER_NAME = mModifier; - } - - public String getModifier() { - return this.MODIFIER_NAME; - } - - public boolean isValidLevel(int i) { - if (i >= 0 && i <= 100) { - return true; - } - return false; - } - } - - public static enum BT { - TYPE_AMULET(BaubleType.AMULET, 0), TYPE_RING(BaubleType.RING, 1), TYPE_BELT(BaubleType.BELT, 2); - private final BaubleType mType; - private final int mID; - private final String mBaubleType; - - private BT(final BaubleType tType, int tID) { - this.mType = tType; - this.mID = tID; - this.mBaubleType = tType.name().toLowerCase(); - } - - public BaubleType getType() { - return this.mType; - } - - public BT getThis() { - return this; - } - - public BaubleType getBaubleByID(int tID) { - if (tID == 0) { - return BaubleType.AMULET; - } else if (tID == 1) { - return BaubleType.RING; - } else if (tID == 2) { - return BaubleType.BELT; - } else { - return BaubleType.RING; - } - } - - public int getID() { - return this.mID; - } - - public String getTypeAsString() { - return this.mBaubleType; - } - } - - public static void setModifierLevel(ItemStack aStack, Pair<Modifiers, Integer> mPair) { - setModifierLevel(aStack, mPair.getKey(), mPair.getValue().intValue()); - } - - public static void setModifierLevel(ItemStack aStack, Modifiers aMod, Integer aInt) { - setModifierLevel(aStack, aMod, aInt.intValue()); - } - - public static void setModifierLevel(ItemStack aStack, Modifiers aMod, int aInt) { - - int mCurrentLevel = getModifierLevel(aStack, aMod); - int mNewTotalLevel = mCurrentLevel + aInt; - - NBTTagCompound tNBT = NBTUtils.getNBT(aStack); - if (aMod.isValidLevel(mNewTotalLevel)) { - tNBT.setInteger(aMod.getModifier(), mNewTotalLevel); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } else { - if (getModifierLevel(aStack, aMod) > 100) { - setModifierLevel(aStack, aMod, 100); - } - } - } - - public static int getModifierLevel(ItemStack aStack, Pair<Modifiers, Integer> newPair) { - return getModifierLevel(aStack, newPair.getKey()); - } - - public static int getModifierLevel(ItemStack aStack, Modifiers aMod) { - NBTTagCompound tNBT = NBTUtils.getNBT(aStack); - return tNBT.getInteger(aMod.getModifier()); - } - - public static void setBaubleType(ItemStack aStack, BT aMod) { - Logger.INFO("Changing bauble type."); - NBTTagCompound tNBT = NBTUtils.getNBT(aStack); - if (aMod != null) { - tNBT.setInteger("mBaubleType", aMod.getID()); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - } - - public static int getBaubleTypeID(ItemStack aStack) { - NBTTagCompound tNBT = NBTUtils.getNBT(aStack); - return tNBT.getInteger("mBaubleType"); - } - - public static BaubleType getBaubleType(ItemStack aStack) { - NBTTagCompound tNBT = NBTUtils.getNBT(aStack); - return getBaubleByID(tNBT.getInteger("mBaubleType")); - } - - public static BaubleType getBaubleByID(int tID) { - if (tID == 0) { - return BaubleType.AMULET; - } else if (tID == 1) { - return BaubleType.RING; - } else if (tID == 2) { - return BaubleType.BELT; - } else { - return BaubleType.RING; - } - } - - public static ItemStack setDefaultStats(ItemStack aStack) { - ItemStack tempStack = aStack; - setModifierLevel(tempStack, Modifiers.BOOST_DAMAGE, 0); - setModifierLevel(tempStack, Modifiers.BOOST_DEF, 0); - setModifierLevel(tempStack, Modifiers.BOOST_HOLY, 0); - setModifierLevel(tempStack, Modifiers.BOOST_HP, 0); - setModifierLevel(tempStack, Modifiers.BOOST_MINING, 0); - setModifierLevel(tempStack, Modifiers.BOOST_SPEED, 0); - return tempStack; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java deleted file mode 100644 index 7ed4d887cc..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java +++ /dev/null @@ -1,580 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import static gtPlusPlus.core.item.ModItems.ZZZ_Empty; - -import java.util.HashMap; -import java.util.Map; - -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import gregtech.api.items.GT_MetaGenerated_Tool; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_Utility; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.reflect.ReflectionUtils; - -public class NBTUtils { - - public static NBTTagCompound getNBT(ItemStack aStack) { - NBTTagCompound rNBT = aStack.getTagCompound(); - return ((rNBT == null) ? new NBTTagCompound() : rNBT); - } - - public static void setBookTitle(ItemStack aStack, String aTitle) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setString("title", aTitle); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - - public static String getBookTitle(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getString("title"); - } - - public static ItemStack[] readItemsFromNBT(ItemStack itemstack) { - NBTTagCompound tNBT = getNBT(itemstack); - final NBTTagList list = tNBT.getTagList("Items", 10); - ItemStack inventory[] = new ItemStack[list.tagCount()]; - for (int i = 0; i < list.tagCount(); i++) { - final NBTTagCompound data = list.getCompoundTagAt(i); - final int slot = data.getInteger("Slot"); - if ((slot >= 0) && (slot < list.tagCount())) { - if (ItemStack.loadItemStackFromNBT(data) == ItemUtils.getSimpleStack(ZZZ_Empty)) { - inventory[slot] = null; - } else { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - - } - } - return inventory; - } - - public static ItemStack[] readItemsFromNBT(ItemStack itemstack, String customkey) { - NBTTagCompound tNBT = getNBT(itemstack); - final NBTTagList list = tNBT.getTagList(customkey, 10); - ItemStack inventory[] = new ItemStack[list.tagCount()]; - for (int i = 0; i < list.tagCount(); i++) { - final NBTTagCompound data = list.getCompoundTagAt(i); - final int slot = data.getInteger("Slot"); - if ((slot >= 0) && (slot < list.tagCount())) { - if (ItemStack.loadItemStackFromNBT(data) == ItemUtils.getSimpleStack(ZZZ_Empty)) { - inventory[slot] = null; - } else { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - - } - } - return inventory; - } - - public static ItemStack writeItemsToNBT(ItemStack itemstack, ItemStack[] stored) { - NBTTagCompound tNBT = getNBT(itemstack); - final NBTTagList list = new NBTTagList(); - for (int i = 0; i < stored.length; i++) { - final ItemStack stack = stored[i]; - if (stack != null) { - final NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } else { - final NBTTagCompound data = new NBTTagCompound(); - ItemStack nullstack = ItemUtils.getSimpleStack(ZZZ_Empty); - nullstack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - tNBT.setTag("Items", list); - itemstack.setTagCompound(tNBT); - return itemstack; - } - - public static ItemStack writeItemsToNBT(ItemStack itemstack, ItemStack[] stored, String customkey) { - NBTTagCompound tNBT = getNBT(itemstack); - final NBTTagList list = new NBTTagList(); - for (int i = 0; i < stored.length; i++) { - final ItemStack stack = stored[i]; - if (stack != null) { - final NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - tNBT.setTag(customkey, list); - itemstack.setTagCompound(tNBT); - return itemstack; - } - - public static ItemStack writeItemsToGtCraftingComponents(ItemStack rStack, ItemStack[] input, boolean copyTags) { - try { - ItemStack stored[] = new ItemStack[9]; - if (input.length != 9) { - for (int e=0;e<input.length;e++) { - if (input[e] != null) - stored[e] = input[e]; - } - } - - if (copyTags) { - for (int i = 0; i < stored.length; i++) { - if (stored[i] != null && stored[i].hasTagCompound()) { - rStack.setTagCompound((NBTTagCompound) stored[i].getTagCompound().copy()); - break; - } - } - } - - NBTTagCompound rNBT = rStack.getTagCompound(), tNBT = new NBTTagCompound(); - if (rNBT == null) - rNBT = new NBTTagCompound(); - for (int i = 0; i < 9; i++) { - ItemStack tStack = stored[i]; - if (tStack != null && GT_Utility.getContainerItem(tStack, true) == null - && !(tStack.getItem() instanceof GT_MetaGenerated_Tool)) { - tStack = GT_Utility.copyAmount(1, tStack); - if (GT_Utility.isStackValid(tStack)) { - GT_ModHandler.dischargeElectricItem(tStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, - true); - tNBT.setTag("Ingredient." + i, tStack.writeToNBT(new NBTTagCompound())); - } - } - } - rNBT.setTag("GT.CraftingComponents", tNBT); - rStack.setTagCompound(rNBT); - } - catch (Throwable t) { - t.printStackTrace(); - } - return rStack; - } - - public static void setBoolean(ItemStack aStack, String aTag, boolean aBoolean) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setBoolean(aTag, aBoolean); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - - public static boolean getBoolean(ItemStack aStack, String aTag) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getBoolean(aTag); - } - - public static void setInteger(ItemStack aStack, String aTag, int aInt) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setInteger(aTag, aInt); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - - public static int getInteger(ItemStack aStack, String aTag) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getInteger(aTag); - } - - public static void setLong(ItemStack aStack, String aTag, long aInt) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setLong(aTag, aInt); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - - public static long getLong(ItemStack aStack, String aTag) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getLong(aTag); - } - - public static void setFloat(ItemStack aStack, String aTag, float aInt) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setFloat(aTag, aInt); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - - public static float getFloat(ItemStack aStack, String aTag) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getFloat(aTag); - } - - public static void setString(ItemStack aStack, String aTag, String aString) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setString(aTag, aString); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - } - - public static String getString(ItemStack aStack, String aTag) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getString(aTag); - } - - public static boolean doesStringExist(ItemStack aStack, String aTag) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.hasKey(aTag); - } - - public static boolean tryIterateNBTData(ItemStack aStack) { - try { - NBTTagCompound aNBT = NBTUtils.getNBT(aStack); - if (aNBT != null) { - if (!aNBT.hasNoTags()) { - Map<?, ?> mInternalMap = ReflectionUtils.getField(aNBT, "tagMap"); - if (mInternalMap != null) { - for (Map.Entry<?, ?> e : mInternalMap.entrySet()) { - Logger.INFO("Key: " + e.getKey().toString() + " | Value: " + e.getValue()); - } - return true; - } else { - Logger.INFO("Data map reflected from NBTTagCompound was not valid."); - return false; - } - } - } - } catch (Throwable t) {} - return false; - } - - // Botania soulbind handling - public static boolean setBotanicaSoulboundOwner(ItemStack aStack, String aName) { - final String TAG_SOULBIND = "soulbind"; - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setString(TAG_SOULBIND, aName); - GT_Utility.ItemNBT.setNBT(aStack, tNBT); - if (NBTUtils.doesStringExist(aStack, TAG_SOULBIND)) { - return true; - } else { - return false; - } - } - - public static String getBotanicaSoulboundOwner(ItemStack aStack) { - final String TAG_SOULBIND = "soulbind"; - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getString(TAG_SOULBIND); - } - - public static boolean hasKey(ItemStack stack, String key) { - final NBTTagCompound itemData = getNBT(stack); - if (itemData.hasKey(key)) { - return true; - } - return false; - } - - public static boolean createIntegerTagCompound(ItemStack rStack, String tagName, String keyName, int keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - final NBTTagCompound tagNBT = new NBTTagCompound(); - tagNBT.setInteger(keyName, keyValue); - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static boolean createLongTagCompound(ItemStack rStack, String tagName, String keyName, long keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - final NBTTagCompound tagNBT = new NBTTagCompound(); - tagNBT.setLong(keyName, keyValue); - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static boolean createStringTagCompound(ItemStack rStack, String tagName, String keyName, String keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - final NBTTagCompound tagNBT = new NBTTagCompound(); - tagNBT.setString(keyName, keyValue); - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static boolean createFloatTagCompound(ItemStack rStack, String tagName, String keyName, float keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - final NBTTagCompound tagNBT = new NBTTagCompound(); - tagNBT.setFloat(keyName, keyValue); - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static boolean createDoubleTagCompound(ItemStack rStack, String tagName, String keyName, double keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - final NBTTagCompound tagNBT = new NBTTagCompound(); - tagNBT.setDouble(keyName, keyValue); - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static boolean createBooleanTagCompound(ItemStack rStack, String tagName, String keyName, boolean keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - final NBTTagCompound tagNBT = new NBTTagCompound(); - tagNBT.setBoolean(keyName, keyValue); - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static boolean createTagCompound(ItemStack rStack, String tagName, NBTTagCompound keyValue) { - final NBTTagCompound tagMain = getNBT(rStack); - NBTTagCompound tagNBT = keyValue; - tagMain.setTag(tagName, tagNBT); - rStack.setTagCompound(tagMain); - return true; - } - - public static int getIntegerTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT.getInteger(keyName); - } - } - return 0; - } - - public static long getLongTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT.getLong(keyName); - } - } - return 0L; - } - - public static String getStringTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT.getString(keyName); - } - } - return null; - } - - public static float getFloatTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT.getFloat(keyName); - } - } - return 0; - } - - public static double getDoubleTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT.getDouble(keyName); - } - } - return 0; - } - - public static boolean getBooleanTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT.getBoolean(keyName); - } - } - return false; - } - - public static NBTTagCompound getTagCompound(ItemStack aStack, String tagName) { - NBTTagCompound aNBT = getNBT(aStack); - if (aNBT != null && hasKey(aStack, tagName)) { - aNBT = aNBT.getCompoundTag(tagName); - if (aNBT != null) { - return aNBT; - } - } - return null; - } - - public static boolean hasKeyInTagCompound(ItemStack stack, String tag, String key) { - NBTTagCompound aNBT = stack.getTagCompound(); - if (aNBT != null) { - aNBT = aNBT.getCompoundTag(tag); - if (aNBT.hasKey(key)) { - return true; - } - } - return false; - } - - public static Map getTagMap(NBTTagCompound aNBT) { - Map tagMap = new HashMap(); - if (!aNBT.hasNoTags()) { - Map<?, ?> mInternalMap = ReflectionUtils.getField(aNBT, "tagMap"); - if (mInternalMap != null && !mInternalMap.isEmpty()) { - tagMap.putAll(mInternalMap); - } - } - return tagMap; - } - - public static boolean isTagString(NBTTagCompound aNBT, String aTagName) { - Map<?, ?> aTagMap = getTagMap(aNBT); - if (aTagMap != null && !aTagMap.isEmpty()) { - for (Map.Entry<?, ?> e : aTagMap.entrySet()) { - if (e.getKey().equals(aTagName)) { - Object aValue = e.getValue(); - if (aValue instanceof String) { - return true; - } - } - } - } - return false; - } - - public static boolean isTagInteger(NBTTagCompound aNBT, String aTagName) { - Map<?, ?> aTagMap = getTagMap(aNBT); - if (aTagMap != null && !aTagMap.isEmpty()) { - for (Map.Entry<?, ?> e : aTagMap.entrySet()) { - if (e.getKey().equals(aTagName)) { - Object aValue = e.getValue(); - if (int.class.isInstance(aValue) || aValue instanceof Integer) { - return true; - } - } - } - } - return false; - } - - public static boolean isTagLong(NBTTagCompound aNBT, String aTagName) { - Map<?, ?> aTagMap = getTagMap(aNBT); - if (aTagMap != null && !aTagMap.isEmpty()) { - for (Map.Entry<?, ?> e : aTagMap.entrySet()) { - if (e.getKey().equals(aTagName)) { - Object aValue = e.getValue(); - if (long.class.isInstance(aValue) || aValue instanceof Long) { - return true; - } - } - } - } - return false; - } - - public static boolean isTagFloat(NBTTagCompound aNBT, String aTagName) { - Map<?, ?> aTagMap = getTagMap(aNBT); - if (aTagMap != null && !aTagMap.isEmpty()) { - for (Map.Entry<?, ?> e : aTagMap.entrySet()) { - if (e.getKey().equals(aTagName)) { - Object aValue = e.getValue(); - if (float.class.isInstance(aValue) || aValue instanceof Float) { - return true; - } - } - } - } - return false; - } - - public static boolean isTagDouble(NBTTagCompound aNBT, String aTagName) { - Map<?, ?> aTagMap = getTagMap(aNBT); - if (aTagMap != null && !aTagMap.isEmpty()) { - for (Map.Entry<?, ?> e : aTagMap.entrySet()) { - if (e.getKey().equals(aTagName)) { - Object aValue = e.getValue(); - if (double.class.isInstance(aValue) || aValue instanceof Double) { - return true; - } - } - } - } - return false; - } - - public static boolean isTagBoolean(NBTTagCompound aNBT, String aTagName) { - Map<?, ?> aTagMap = getTagMap(aNBT); - if (aTagMap != null && !aTagMap.isEmpty()) { - for (Map.Entry<?, ?> e : aTagMap.entrySet()) { - if (e.getKey().equals(aTagName)) { - Object aValue = e.getValue(); - if (boolean.class.isInstance(aValue) || aValue instanceof Boolean) { - return true; - } - } - } - } - return false; - } - - public static boolean tryCloneTagCompoundDataIntoSubTag(ItemStack aStack, NBTTagCompound aTagCompound) { - try { - NBTTagCompound aNBT = aTagCompound; - if (aNBT != null) { - if (!aNBT.hasNoTags()) { - Map<?, ?> mInternalMap = ReflectionUtils.getField(aNBT, "tagMap"); - if (mInternalMap != null) { - for (Map.Entry<?, ?> e : mInternalMap.entrySet()) { - Logger.INFO("Key: " + e.getKey().toString() + " | Value: " + e.getValue().toString()); - if (e.getValue().getClass() == String.class){ - createStringTagCompound(aStack, "mEntityTag", (String) e.getKey(), (String) e.getValue()); - } - else if (e.getValue().getClass() == Boolean.class || e.getValue().getClass() == boolean.class){ - createBooleanTagCompound(aStack, "mEntityTag", (String) e.getKey(), (Boolean) e.getValue()); - } - else if (e.getValue().getClass() == Integer.class || e.getValue().getClass() == int.class){ - createIntegerTagCompound(aStack, "mEntityTag", (String) e.getKey(), (Integer) e.getValue()); - } - else if (e.getValue().getClass() == Double.class || e.getValue().getClass() == double.class){ - createDoubleTagCompound(aStack, "mEntityTag", (String) e.getKey(), (Double) e.getValue()); - } - else if (e.getValue().getClass() == Long.class || e.getValue().getClass() == long.class){ - createLongTagCompound(aStack, "mEntityTag", (String) e.getKey(), (Long) e.getValue()); - } - else if (e.getValue().getClass() == Float.class || e.getValue().getClass() == float.class){ - createFloatTagCompound(aStack, "mEntityTag", (String) e.getKey(), (Float) e.getValue()); - } - else { - - - } - - } - return true; - } - } - } - return false; - } catch (Throwable t) { - return false; - } - } - - public static NBTTagCompound getEntityCustomData(Entity aEntity){ - return ReflectionUtils.getField(aEntity, "customEntityData"); - } - - public static boolean setEntityCustomData(Entity aEntity, NBTTagCompound aTag){ - return ReflectionUtils.setField(aEntity, "customEntityData", aTag); - } - - public static boolean hasTagCompound(ItemStack aStack) { - return aStack.hasTagCompound(); - } - - public static void createEmptyTagCompound(ItemStack aStack) { - if (!hasTagCompound(aStack)) { - NBTTagCompound aTag = new NBTTagCompound(); - aStack.setTagCompound(aTag); - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/OreDictUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/OreDictUtils.java deleted file mode 100644 index 324d39b863..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/OreDictUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; - -public class OreDictUtils { - - public static boolean containsValidEntries(String aOreName) { - boolean a = OreDictionary.doesOreNameExist(aOreName); - List<ItemStack> b = OreDictionary.getOres(aOreName, false); - - if (!a) { - return false; - } - else { - if (b == null || b.isEmpty()) { - return false; - } - } - return true; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java deleted file mode 100644 index 24ffa295b7..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java +++ /dev/null @@ -1,260 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.*; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.world.World; -import net.minecraftforge.common.util.FakePlayer; - -public class PlayerUtils { - - public static final Map<String, EntityPlayer> mCachedFakePlayers = new WeakHashMap<String, EntityPlayer>(); - private static final Class mThaumcraftFakePlayer; - - static { - if (ReflectionUtils.doesClassExist("thaumcraft.common.lib.FakeThaumcraftPlayer")) { - mThaumcraftFakePlayer = ReflectionUtils.getClass("thaumcraft.common.lib.FakeThaumcraftPlayer"); - } - else { - mThaumcraftFakePlayer = null; - } - } - - public static void messagePlayer(final EntityPlayer P, final String S){ - gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); - } - - public static EntityPlayer getPlayer(final String name){ - try{ - final List<EntityPlayer> i = new ArrayList<>(); - final Iterator<EntityPlayerMP> iterator = MinecraftServer.getServer().getConfigurationManager().playerEntityList.iterator(); - while (iterator.hasNext()) { - i.add((iterator.next())); - } - for (final EntityPlayer temp : i) { - if (temp.getDisplayName().toLowerCase().equals(name.toLowerCase())){ - return temp; - } - } - } - catch(final Throwable e){} - return null; - } - - public static EntityPlayer getPlayerOnServerFromUUID(final UUID parUUID){ - if (parUUID == null) - { - return null; - } - final List<EntityPlayerMP> allPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList; - for (final EntityPlayerMP player : allPlayers) - { - if (player.getUniqueID().equals(parUUID)) - { - return player; - } - } - return null; - } - - //Not Clientside - public static EntityPlayer getPlayerInWorld(final World world, final String Name){ - final List<EntityPlayer> i = world.playerEntities; - final Minecraft mc = Minecraft.getMinecraft(); - try{ - for (final EntityPlayer temp : i) { - if (temp.getDisplayName().toLowerCase().equals(Name.toLowerCase())){ - return temp; - } - } - } - catch(final NullPointerException e){} - return null; - } - - public static boolean isPlayerOP(final EntityPlayer player){ - if (player.canCommandSenderUseCommand(2, "")){ - return true; - } - return false; - } - - //Not Clientside - public static ItemStack getItemStackInPlayersHand(final World world, final String Name){ - final EntityPlayer thePlayer = getPlayer(Name); - ItemStack heldItem = null; - try{heldItem = thePlayer.getHeldItem(); - }catch(final NullPointerException e){return null;} - if (heldItem != null){ - return heldItem; - } - return null; - } - - @SideOnly(Side.CLIENT) - public static ItemStack getItemStackInPlayersHand(){ - final Minecraft mc = Minecraft.getMinecraft(); - ItemStack heldItem = null; - try{heldItem = mc.thePlayer.getHeldItem(); - }catch(final NullPointerException e){return null;} - if (heldItem != null){ - return heldItem; - } - return null; - } - - public static ItemStack getItemStackInPlayersHand(final EntityPlayer player){ - ItemStack heldItem = null; - try{ - heldItem = player.getHeldItem(); - } - catch(final NullPointerException e){ - e.printStackTrace(); - return null; - } - if (heldItem != null){ - return heldItem; - } - else { - if (Utils.isClient()) { - heldItem = player.getItemInUse(); - } - else { - heldItem = player.getCurrentEquippedItem(); - } - } - return heldItem; - } - - @SideOnly(Side.CLIENT) - public static Item getItemInPlayersHandClient(){ - final Minecraft mc = Minecraft.getMinecraft(); - Item heldItem = null; - - try{heldItem = mc.thePlayer.getHeldItem().getItem(); - }catch(final NullPointerException e){return null;} - - if (heldItem != null){ - return heldItem; - } - - return null; - } - - public static Item getItemInPlayersHand(final EntityPlayer player){ - Item heldItem = null; - try{ - heldItem = player.getHeldItem().getItem(); - }catch(final NullPointerException e){return null;} - - if (heldItem != null){ - return heldItem; - } - return null; - } - - public final static EntityPlayer getPlayerEntityByName(final String aPlayerName){ - final EntityPlayer player = PlayerUtils.getPlayer(aPlayerName); - if (player != null){ - return player; - } - return null; - } - - public final static UUID getPlayersUUIDByName(final String aPlayerName){ - final EntityPlayer player = PlayerUtils.getPlayer(aPlayerName); - if (player != null){ - return player.getUniqueID(); - } - return null; - } - - @SideOnly(Side.CLIENT) - public static final boolean isPlayerAlkalus(){ - if (Utils.isServer()){ - return false; - } - return isPlayerAlkalus(Minecraft.getMinecraft().thePlayer); - } - - public static final boolean isPlayerAlkalus(EntityPlayer player){ - if (player != null){ - if (player.getDisplayName().toLowerCase().equals("draknyte1") || player.getDisplayName().toLowerCase().equals("alkalus")){ - return true; - } - } - return false; - } - - public static void messageAllPlayers(String string) { - Utils.sendServerMessage(string); - } - - public static boolean isCreative(EntityPlayer aPlayer) { - return aPlayer.capabilities.isCreativeMode; - } - - public static boolean canTakeDamage(EntityPlayer aPlayer) { - return !aPlayer.capabilities.disableDamage; - } - - public static void cacheFakePlayer(EntityPlayer aPlayer) { - ChunkCoordinates aChunkLocation = aPlayer.getPlayerCoordinates(); - // Cache Fake Player - if (aPlayer instanceof FakePlayer || (mThaumcraftFakePlayer != null && mThaumcraftFakePlayer.isInstance(aPlayer)) - || (aPlayer.getCommandSenderName() == null - || aPlayer.getCommandSenderName().length() <= 0) - || (aPlayer.isEntityInvulnerable() && !aPlayer.canCommandSenderUseCommand(0, "") - && (aChunkLocation == null) || (aChunkLocation.posX == 0 && aChunkLocation.posY == 0 - && aChunkLocation.posZ == 0))) { - mCachedFakePlayers.put(aPlayer.getUniqueID().toString(), aPlayer); - } - } - - public static boolean isCachedFakePlayer(String aUUID) { - return mCachedFakePlayers.containsKey(aUUID); - } - - public static boolean isRealPlayer(EntityLivingBase aEntity) { - if (aEntity instanceof EntityPlayer) { - EntityPlayer p = (EntityPlayer) aEntity; - ChunkCoordinates aChunkLocation = p.getPlayerCoordinates(); - if (p instanceof FakePlayer) { - cacheFakePlayer(p); - return false; - } - if (mThaumcraftFakePlayer != null && mThaumcraftFakePlayer.isInstance(p) ) { - cacheFakePlayer(p); - return false; - } - if (p.getCommandSenderName() == null) { - cacheFakePlayer(p); - return false; - } - if (p.getCommandSenderName().length() <= 0) { - cacheFakePlayer(p); - return false; - } - if (p.isEntityInvulnerable() && !p.canCommandSenderUseCommand(0, "") && (aChunkLocation.posX == 0 && aChunkLocation.posY == 0 && aChunkLocation.posZ == 0)) { - cacheFakePlayer(p); - return false; - } - if (!isCachedFakePlayer(p.getUniqueID().toString())) { - return true; - } - } - return false; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java deleted file mode 100644 index a20678c354..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java +++ /dev/null @@ -1,798 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.enums.Materials; -import gregtech.api.objects.ItemData; -import gregtech.api.util.*; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; -import gtPlusPlus.GTplusplus; -import gtPlusPlus.api.interfaces.RunnableWithInfo; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.minecraft.ShapedRecipe; -import gtPlusPlus.core.handler.COMPAT_HANDLER; -import gtPlusPlus.core.handler.Recipes.LateRegistrationHandler; -import gtPlusPlus.core.handler.Recipes.RegistrationHandler; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.recipe.common.CI; -import gtPlusPlus.core.util.data.ArrayUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.ShapelessRecipes; -import net.minecraftforge.oredict.OreDictionary; -import net.minecraftforge.oredict.ShapedOreRecipe; -import net.minecraftforge.oredict.ShapelessOreRecipe; - -public class RecipeUtils { -public static int mInvalidID = 1; - public static boolean recipeBuilder(final Object slot_1, final Object slot_2, final Object slot_3, final Object slot_4, final Object slot_5, final Object slot_6, final Object slot_7, final Object slot_8, final Object slot_9, ItemStack resultItem){ - - //Old Debug Code, useful for finding recipes loading too early. - /*if (gtPlusPlus.GTplusplus.CURRENT_LOAD_PHASE != GTplusplus.INIT_PHASE.POST_INIT) { - Logger.RECIPE(ReflectionUtils.getMethodName(1)); - Logger.RECIPE(ReflectionUtils.getMethodName(2)); - Logger.RECIPE(ReflectionUtils.getMethodName(3)); - Logger.RECIPE(ReflectionUtils.getMethodName(4)); - Logger.RECIPE(ReflectionUtils.getMethodName(5)); - Logger.RECIPE(ReflectionUtils.getMethodName(6)); - Logger.RECIPE(ReflectionUtils.getMethodName(7)); - Logger.RECIPE(ReflectionUtils.getMethodName(8)); - Logger.RECIPE(ReflectionUtils.getMethodName(9)); - System.exit(1); - }*/ - - if (resultItem == null){ - Logger.RECIPE("[Fix] Found a recipe with an invalid output, yet had a valid inputs. Using Dummy output so recipe can be found.."); - resultItem = ItemUtils.getItemStackOfAmountFromOreDict("givemeabrokenitem", 1); - resultItem.setItemDamage(mInvalidID++); - RegistrationHandler.recipesFailed++; - //return false; - } - else if ((slot_1 == null) && (slot_2 == null) && (slot_3 == null) && - (slot_4 == null) && (slot_5 == null) && (slot_6 == null) && - (slot_7 == null) && (slot_8 == null) && (slot_9 == null)){ - Logger.RECIPE("[Fix] Found a recipe with 0 inputs, yet had a valid output."); - Logger.RECIPE("[Fix] Error found while adding a recipe for: "+resultItem != null ? resultItem.getDisplayName() : "Bad Output Item"+" | Please report this issue on Github."); - RegistrationHandler.recipesFailed++; - return false; - } - - Object[] o = new Object[] {slot_1, slot_2, slot_3, slot_4, slot_5, slot_6, slot_7, slot_8, slot_9}; - - try { - int size = COMPAT_HANDLER.mRecipesToGenerate.size(); - COMPAT_HANDLER.mRecipesToGenerate.put(new InternalRecipeObject(o, resultItem, false)); - //Utils.LOG_WARNING("Success! Added a recipe for "+resultItem.getDisplayName()); - if (COMPAT_HANDLER.mRecipesToGenerate.size() > size) { - if (!COMPAT_HANDLER.areInitItemsLoaded){ - RegistrationHandler.recipesSuccess++; - } - else { - LateRegistrationHandler.recipesSuccess++; - } - return true; - } - return false; - } - catch(RuntimeException k){ - //k.getMessage(); - //k.getClass(); - //k.printStackTrace(); - //k.getLocalizedMessage(); - Logger.RECIPE("[Fix] Invalid Recipe detected for: "+resultItem != null ? resultItem.getUnlocalizedName() : "INVALID OUTPUT ITEM"); - if (!COMPAT_HANDLER.areInitItemsLoaded){ - RegistrationHandler.recipesFailed++; - } - else { - LateRegistrationHandler.recipesFailed++; - } - return false; - } - } - - public static void shapelessBuilder(final ItemStack Output, final Object slot_1, final Object slot_2, final Object slot_3, final Object slot_4, final Object slot_5, final Object slot_6, final Object slot_7, final Object slot_8, final Object slot_9){ - //Item output_ITEM = Output.getItem(); - - final ArrayList<Object> validSlots = new ArrayList<>(); - - Logger.WARNING("Trying to add a recipe for "+Output.toString()); - String a,b,c,d,e,f,g,h,i; - if (slot_1 == null){ a = " ";} else { a = "1";validSlots.add('1');validSlots.add(slot_1);} - Logger.WARNING(a); - if (slot_2 == null){ b = " ";} else { b = "2";validSlots.add('2');validSlots.add(slot_2);} - Logger.WARNING(b); - if (slot_3 == null){ c = " ";} else { c = "3";validSlots.add('3');validSlots.add(slot_3);} - Logger.WARNING(c); - if (slot_4 == null){ d = " ";} else { d = "4";validSlots.add('4');validSlots.add(slot_4);} - Logger.WARNING(d); - if (slot_5 == null){ e = " ";} else { e = "5";validSlots.add('5');validSlots.add(slot_5);} - Logger.WARNING(e); - if (slot_6 == null){ f = " ";} else { f = "6";validSlots.add('6');validSlots.add(slot_6);} - Logger.WARNING(f); - if (slot_7 == null){ g = " ";} else { g = "7";validSlots.add('7');validSlots.add(slot_7);} - Logger.WARNING(g); - if (slot_8 == null){ h = " ";} else { h = "8";validSlots.add('8');validSlots.add(slot_8);} - Logger.WARNING(h); - if (slot_9 == null){ i = " ";} else { i = "9";validSlots.add('9');validSlots.add(slot_9);} - Logger.WARNING(i); - - - Logger.ERROR("_______"); - Logger.ERROR("|"+a+"|"+b+"|"+c+"|"); - Logger.ERROR("_______"); - Logger.ERROR("|"+d+"|"+e+"|"+f+"|"); - Logger.ERROR("_______"); - Logger.ERROR("|"+g+"|"+h+"|"+i+"|"); - Logger.ERROR("_______"); - - validSlots.add(0, a); - validSlots.add(1, b); - validSlots.add(2, c); - validSlots.add(3, d); - validSlots.add(4, e); - validSlots.add(5, f); - validSlots.add(6, g); - validSlots.add(7, h); - validSlots.add(8, i); - - try { - //GameRegistry.addRecipe(new ShapelessOreRecipe(Output, outputAmount), (Object[]) validSlots.toArray()); - GameRegistry.addRecipe(new ShapelessOreRecipe(Output, validSlots.toArray())); - //GameRegistry.addShapelessRecipe(new ItemStack(output_ITEM, 1), new Object[] {slot_1, slot_2}); - Logger.RECIPE("Success! Added a recipe for "+Output.getDisplayName()); - RegistrationHandler.recipesSuccess++; - } - catch(final RuntimeException k){ - k.getMessage(); - k.getClass(); - k.printStackTrace(); - k.getLocalizedMessage(); - Logger.RECIPE("[Fix] Invalid Recipe detected for: "+Output.getUnlocalizedName()); - RegistrationHandler.recipesFailed++; - } - - - //GameRegistry.addShapelessRecipe(new ItemStack(output_ITEM, 1), new Object[] {slot_1, slot_2}); - } - - public static void recipeBuilder(final Object[] array, final ItemStack outPut) { - Logger.SPECIFIC_WARNING("object Array - recipeBuilder", "Attempting to build a recipe using an object array as an input, splitting it, then running the normal recipeBuilder() method.", 396); - Object a=null; - Object b=null; - Object c=null; - Object d=null; - Object e=null; - Object f=null; - Object g=null; - Object h=null; - Object i=null; - for(int z =0; z <= array.length; z++){ - array[z].toString(); - switch(z) - { - case 0: - a = array[z]; - break; - case 1: - b = array[z]; - break; - case 2: - c = array[z]; - break; - case 3: - d = array[z]; - break; - case 4: - e = array[z]; - break; - case 5: - f = array[z]; - break; - case 6: - g = array[z]; - break; - case 7: - h = array[z]; - break; - case 8: - i = array[z]; - break; - default: - break; - } - recipeBuilder(a, b, c, d, e, f, g, h, i, outPut); - } - } - - public static boolean removeCraftingRecipe(Object x){ - if (null == x){return false;} - if (x instanceof String){ - final Item R = ItemUtils.getItemFromFQRN((String) x); - if (R != null){ - x = R; - } - else { - return false; - } - } - if ((x instanceof Item) || (x instanceof ItemStack)){ - if (x instanceof Item){ - final ItemStack r = new ItemStack((Item) x); - Logger.RECIPE("Removing Recipe for "+r.getUnlocalizedName()); - } - else { - Logger.RECIPE("Removing Recipe for "+((ItemStack) x).getUnlocalizedName()); - } - if (x instanceof ItemStack){ - final Item r = ((ItemStack) x).getItem(); - if (null != r){ - x = r; - } - else { - Logger.RECIPE("Recipe removal failed - Tell Alkalus."); - return false; - } - } - if (RecipeUtils.attemptRecipeRemoval((Item) x)){ - Logger.RECIPE("Recipe removal successful"); - return true; - } - Logger.RECIPE("Recipe removal failed - Tell Alkalus."); - return false; - } - return false; - } - - private static boolean attemptRecipeRemoval(final Item I){ - Logger.RECIPE("Create list of recipes."); - final List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList(); - final Iterator<IRecipe> items = recipes.iterator(); - Logger.RECIPE("Begin list iteration."); - while (items.hasNext()) { - final ItemStack is = items.next().getRecipeOutput(); - if ((is != null) && (is.getItem() == I)){ - items.remove(); - Logger.RECIPE("Remove a recipe with "+I.getUnlocalizedName()+" as output."); - continue; - } - } - Logger.RECIPE("All recipes should be gone?"); - if (!items.hasNext()){ - Logger.RECIPE("We iterated once, let's try again to double check."); - final Iterator<IRecipe> items2 = recipes.iterator(); - while (items2.hasNext()) { - final ItemStack is = items2.next().getRecipeOutput(); - if ((is != null) && (is.getItem() == I)){ - items.remove(); - Logger.RECIPE("REMOVING MISSED RECIPE - RECHECK CONSTRUCTORS"); - return true; - } - } - Logger.RECIPE("Should be all gone now after double checking, so return true."); - return true; - } - Logger.RECIPE("Return false, because something went wrong."); - return false; - } - - - - public static boolean addShapedGregtechRecipeForTypes( - final Object InputItem1, final Object InputItem2, final Object InputItem3, - final Object InputItem4, final Object InputItem5, final Object InputItem6, - final Object InputItem7, final Object InputItem8, final Object InputItem9, - final ItemStack OutputItem){ - - int using = 0, recipeSlotCurrent = 0; - boolean[] hasMultiStack = new boolean[9]; - boolean inUse[] = {false, false, false}; - ItemStack array[][] = new ItemStack[3][9]; - - Object[] inputs = { - InputItem1, InputItem2, InputItem3, - InputItem4, InputItem5, InputItem6, - InputItem7, InputItem8, InputItem9}; - - for (Object o : inputs){ - if (o.getClass().isArray()){ - if (inUse[using] == false){ - inUse[using] = true; - array[using] = (ItemStack[]) o; - hasMultiStack[recipeSlotCurrent] = true; - using++; - } - } - else { - hasMultiStack[recipeSlotCurrent] = false; - } - recipeSlotCurrent++; - } - - int using2 = 0; - for (boolean t : inUse){ - - if (t){ - if (array[using2] != null){ - //addShapedGregtechRecipe - } - } - using2++; - } - - - return false; - } - - - - public static boolean addShapedGregtechRecipe( - final Object InputItem1, final Object InputItem2, final Object InputItem3, - final Object InputItem4, final Object InputItem5, final Object InputItem6, - final Object InputItem7, final Object InputItem8, final Object InputItem9, - final ItemStack OutputItem){ - - Object[] o = { - InputItem1, InputItem2, InputItem3, - InputItem4, InputItem5, InputItem6, - InputItem7, InputItem8, InputItem9 - }; - - - if (gtPlusPlus.GTplusplus.CURRENT_LOAD_PHASE != GTplusplus.INIT_PHASE.POST_INIT) { - Logger.RECIPE(ReflectionUtils.getMethodName(1)); - Logger.RECIPE(ReflectionUtils.getMethodName(2)); - Logger.RECIPE(ReflectionUtils.getMethodName(3)); - Logger.RECIPE(ReflectionUtils.getMethodName(4)); - Logger.RECIPE(ReflectionUtils.getMethodName(5)); - Logger.RECIPE(ReflectionUtils.getMethodName(6)); - Logger.RECIPE(ReflectionUtils.getMethodName(7)); - Logger.RECIPE(ReflectionUtils.getMethodName(8)); - Logger.RECIPE(ReflectionUtils.getMethodName(9)); - System.exit(1); - } - - - int size = COMPAT_HANDLER.mGtRecipesToGenerate.size(); - COMPAT_HANDLER.mGtRecipesToGenerate.put(new InternalRecipeObject(o, OutputItem, true)); - - if (COMPAT_HANDLER.mGtRecipesToGenerate.size() > size) { - if (!COMPAT_HANDLER.areInitItemsLoaded){ - RegistrationHandler.recipesSuccess++; - } - else { - LateRegistrationHandler.recipesSuccess++; - } - return true; - } - return false; - - } - - public static boolean addShapedGregtechRecipe(final Object[] inputs, ItemStack output){ - - if (inputs.length != 9){ - Logger.RECIPE("[Fix] Input array for "+output.getDisplayName()+" does not equal 9. "+inputs.length+" is the actual size."); - RegistrationHandler.recipesFailed++; - return false; - } - - for (int x=0;x<9;x++){ - if (inputs[x] == null){ - inputs[x] = " "; - Logger.WARNING("Input slot "+x+" changed from NULL to a blank space."); - } - else if (!(inputs[x] instanceof ItemStack) && !(inputs[x] instanceof String) && !(inputs[x] instanceof Item)){ - if (output != null){ - Logger.RECIPE("[Fix] Invalid Item inserted into inputArray. Item:"+output.getDisplayName()+" has a bad recipe. Please report to Alkalus."); - RegistrationHandler.recipesFailed++; - return false; - } - else { - Logger.RECIPE("[Fix] Output is Null for a recipe. Report to Alkalus."); - output = ItemUtils.getItemStackOfAmountFromOreDict("sadibasdkjnad", 1); - RegistrationHandler.recipesFailed++; - } - } - } - - int size = COMPAT_HANDLER.mGtRecipesToGenerate.size(); - COMPAT_HANDLER.mGtRecipesToGenerate.put(new InternalRecipeObject(inputs, output, true)); - - if (COMPAT_HANDLER.mGtRecipesToGenerate.size() > size) { - if (!COMPAT_HANDLER.areInitItemsLoaded){ - RegistrationHandler.recipesSuccess++; - } - else { - LateRegistrationHandler.recipesSuccess++; - } - return true; - } - return false; - } - - public static boolean addShapelessGregtechRecipe(final Object[] inputItems, final ItemStack OutputItem){ - //Catch Invalid Recipes - if (inputItems.length > 9 || inputItems.length < 1){ - if (OutputItem != null){ - Logger.RECIPE("[Fix] Invalid input array for shapeless recipe, which should output "+OutputItem.getDisplayName()); - } - return false; - } - //let gregtech handle shapeless recipes. - if (GT_ModHandler.addShapelessCraftingRecipe(OutputItem, inputItems)){ - return true; - } - return false; - } - - public static ItemStack getItemStackFromOreDict(final String oredictName){ - final ArrayList<ItemStack> oreDictList = OreDictionary.getOres(oredictName); - return oreDictList.get(0); - } - - public static boolean buildShapelessRecipe(final ItemStack output, final Object[] input){ - return ShapelessUtils.addShapelessRecipe(output, input); - } - - public static boolean generateMortarRecipe(ItemStack aStack, ItemStack aOutput) { - return RecipeUtils.addShapedGregtechRecipe( - aStack, null, null, - CI.craftingToolMortar, null, null, - null, null, null, - aOutput); - } - - public static boolean doesGregtechRecipeHaveEqualCells(GT_Recipe x) { - if (x.mInputs.length == 0 && x.mOutputs.length == 0) { - return true; - } - - final int tInputAmount = GT_ModHandler.getCapsuleCellContainerCountMultipliedWithStackSize(x.mInputs); - final int tOutputAmount = GT_ModHandler.getCapsuleCellContainerCountMultipliedWithStackSize(x.mOutputs); - - if (tInputAmount < tOutputAmount) { - if (!Materials.Tin.contains(x.mInputs)) { - return false; - } - else { - return true; - } - } - else if (tInputAmount > tOutputAmount && !Materials.Tin.contains(x.mOutputs)) { - return false; - } - else { - return true; - } - } - - public static String[] getRecipeInfo(GT_Recipe m) { - if (m == null) { - return new String[] {}; - } - AutoMap<String> result = new AutoMap<String>(); - result.put(m.toString()); - result.put("Input "+ItemUtils.getArrayStackNames(m.mInputs)); - result.put("Output "+ItemUtils.getArrayStackNames(m.mOutputs)); - result.put("Input "+ItemUtils.getArrayStackNames(m.mFluidInputs)); - result.put("Output "+ItemUtils.getArrayStackNames(m.mFluidOutputs)); - result.put("Can be buffered? "+m.mCanBeBuffered); - result.put("Duration: "+m.mDuration); - result.put("EU/t: "+m.mEUt); - result.put("Is Hidden? "+m.mHidden); - result.put("Is Enabled? "+m.mEnabled); - result.put("Special Value: "+m.mSpecialValue); - result.put("====================================="); - String s[] = new String[result.size()]; - for (int i=0;i<result.size();i++) { - s[i] = result.get(i); - } - return s; - } - - - public static class InternalRecipeObject implements RunnableWithInfo<String> { - final ItemStack mOutput; - final ShapedOreRecipe mRecipe; - public final boolean isValid; - - public InternalRecipeObject(Object[] aInputs, ItemStack aOutput, boolean gtRecipe) { - Logger.RECIPE("==================================="); - mOutput = aOutput != null ? aOutput.copy() : null; - Object[] aFiltered = new Object[9]; - int aValid = 0; - for (Object o : aInputs) { - if (o instanceof ItemStack) { - aFiltered[aValid++] = o; - } - else if (o instanceof Item) { - aFiltered[aValid++] = ItemUtils.getSimpleStack((Item) o); - } - else if (o instanceof Block) { - aFiltered[aValid++] = ItemUtils.getSimpleStack((Block) o); - } - else if (o instanceof String) { - aFiltered[aValid++] = o; - } - else if (o == null) { - aFiltered[aValid++] = null; - } - else { - Logger.RECIPE("Cleaned a "+o.getClass().getSimpleName()+" from recipe input."); - } - } - - int validCounter = 0, invalidCounter = 0; - for (Object p : aFiltered) { - if (p instanceof ItemStack) { - validCounter++; - } - else if (p instanceof Item) { - validCounter++; - } - else if (p instanceof Block) { - validCounter++; - } - else if (p instanceof String) { - validCounter++; - } - else if (p == null) { - validCounter++; - } - else { - invalidCounter++; - } - } - - Logger.RECIPE("Using "+validCounter+" valid inputs and "+invalidCounter+" invalid inputs."); - ShapedRecipe r = new ShapedRecipe(aFiltered, mOutput); - if (r != null && r.mRecipe != null) { - isValid = true; - } - else { - isValid = false; - } - mRecipe = r != null ? r.mRecipe : null; - } - - @Override - public void run() { - if (this.isValid) { - GameRegistry.addRecipe(mRecipe); - } - else { - Logger.RECIPE("[Fix] Invalid shapped recipe outputting "+mOutput != null ? mOutput.getDisplayName() : "Bad Output Item"); - } - } - - @Override - public String getInfoData() { - if (mOutput != null && mOutput instanceof ItemStack) { - return ((ItemStack) mOutput).getDisplayName(); - } - return ""; - } - - } - - - public static boolean removeGtRecipe(GT_Recipe aRecipeToRemove, GT_Recipe_Map aRecipeMap) { - if (aRecipeMap.mRecipeList.contains(aRecipeToRemove)) { - return aRecipeMap.mRecipeList.remove(aRecipeToRemove); - } - return false; - } - - public static boolean addGtRecipe(GT_Recipe aRecipeToAdd, GT_Recipe_Map aRecipeMap) { - if (!aRecipeMap.mRecipeList.contains(aRecipeToAdd)) { - return aRecipeMap.mRecipeList.add(aRecipeToAdd); - } - return false; - } - - public static boolean removeRecipeByOutput(ItemStack aOutput) { - return removeRecipeByOutput(aOutput, true, false, false); - } - - public static boolean removeRecipeByOutput(ItemStack aOutput, boolean aIgnoreNBT, - boolean aNotRemoveShapelessRecipes, boolean aOnlyRemoveNativeHandlers) { - if (aOutput == null) { - return false; - } else { - boolean rReturn = false; - ArrayList<IRecipe> tList = (ArrayList) CraftingManager.getInstance().getRecipeList(); - aOutput = GT_OreDictUnificator.get(aOutput); - int tList_sS = tList.size(); - - for (int i = 0; i < tList_sS; ++i) { - IRecipe tRecipe = (IRecipe) tList.get(i); - if (!aNotRemoveShapelessRecipes - || !(tRecipe instanceof ShapelessRecipes) && !(tRecipe instanceof ShapelessOreRecipe)) { - if (aOnlyRemoveNativeHandlers) { - if (!gregtech.api.util.GT_ModHandler.sNativeRecipeClasses.contains(tRecipe.getClass().getName())) { - continue; - } - } else if (gregtech.api.util.GT_ModHandler.sSpecialRecipeClasses.contains(tRecipe.getClass().getName())) { - continue; - } - - ItemStack tStack = tRecipe.getRecipeOutput(); - if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get(tStack), aOutput, aIgnoreNBT)) { - tList.remove(i--); - tList_sS = tList.size(); - rReturn = true; - } - } - } - - return rReturn; - } - } - - - public static void addSmeltingRecipe(ItemStack aStackInput, ItemStack aStackOutput) { - addSmeltingRecipe(aStackInput, aStackOutput, 0f); - } - - public static void addSmeltingRecipe(ItemStack aStackInput, ItemStack aStackOutput, float aXpGained) { - - GameRegistry.addSmelting(aStackInput, aStackOutput, aXpGained); - - } - - public static boolean addShapedRecipe( - Object Input_1, Object Input_2, Object Input_3, - Object Input_4, Object Input_5, Object Input_6, - Object Input_7, Object Input_8, Object Input_9, - ItemStack aOutputStack) { - return addShapedRecipe(new Object[] {Input_1, Input_2, Input_3, Input_4, Input_5, Input_6, Input_7, Input_8, Input_9}, aOutputStack); - } - - private static boolean addShapedRecipe(Object[] Inputs, ItemStack aOutputStack) { - Object[] Slots = new Object[9]; - - String aFullString = ""; - String aFullStringExpanded = "abcdefghi"; - - for (int i=0; i<9; i++) { - Object o = Inputs[i]; - - if (o instanceof ItemStack) { - Slots[i] = ItemUtils.getSimpleStack((ItemStack) o, 1); - aFullString += aFullStringExpanded.charAt(i); - } - else if (o instanceof Item) { - Slots[i] = ItemUtils.getSimpleStack((Item) o, 1); - aFullString += aFullStringExpanded.charAt(i); - } - else if (o instanceof Block) { - Slots[i] = ItemUtils.getSimpleStack((Block) o, 1); - aFullString += aFullStringExpanded.charAt(i); - } - else if (o instanceof String) { - Slots[i] = o; - aFullString += aFullStringExpanded.charAt(i); - } - else if (o instanceof ItemData) { - ItemData aData = (ItemData) o; - ItemStack aStackFromGT = ItemUtils.getOrePrefixStack(aData.mPrefix, aData.mMaterial.mMaterial, 1); - Slots[i] = aStackFromGT; - aFullString += aFullStringExpanded.charAt(i); - } - else if (o == null) { - Slots[i] = null; - aFullString += " "; - } - else { - Slots[i] = null; - Logger.INFO("Cleaned a "+o.getClass().getSimpleName()+" from recipe input."); - Logger.INFO("ERROR"); - CORE.crash("Bad Shaped Recipe."); - } - } - Logger.INFO("Using String: "+aFullString); - - String aRow1 = aFullString.substring(0, 3); - String aRow2 = aFullString.substring(3, 6); - String aRow3 = aFullString.substring(6, 9); - Logger.INFO(""+aRow1); - Logger.INFO(""+aRow2); - Logger.INFO(""+aRow3); - - String[] aStringData = new String[] {aRow1, aRow2, aRow3}; - Object[] aDataObject = new Object[19]; - aDataObject[0] = aStringData; - int aIndex = 0; - - - for (int u=1;u<20;u+=2) { - if (aIndex == 9) { - break; - } - if (aFullString.charAt(aIndex) != (' ')) { - aDataObject[u] = aFullString.charAt(aIndex); - aDataObject[u+1] = Slots[aIndex]; - Logger.INFO("("+aIndex+") "+aFullString.charAt(aIndex)+" | "+ (Slots[aIndex] instanceof ItemStack ? ItemUtils.getItemName((ItemStack) Slots[aIndex]) : Slots[aIndex] instanceof String ? (String) Slots[aIndex] : "Unknown")); - } - aIndex++; - } - - Logger.INFO("Data Size: "+aDataObject.length); - aDataObject = ArrayUtils.removeNulls(aDataObject); - Logger.INFO("Clean Size: "+aDataObject.length); - Logger.INFO("ArrayData: "+aDataObject.toString()); - - ShapedOreRecipe aRecipe = new ShapedOreRecipe(aOutputStack, aDataObject); - - /*ShapedOreRecipe aRecipe = new ShapedOreRecipe(aOutputStack, - aStringData, - 'a', Slots[0], - 'b', Slots[1], - 'c', Slots[2], - 'd', Slots[3], - 'e', Slots[4], - 'f', Slots[5], - 'g', Slots[6], - 'h', Slots[7], - 'i', Slots[8]);*/ - - int size = COMPAT_HANDLER.mRecipesToGenerate.size(); - COMPAT_HANDLER.mRecipesToGenerate.put(new InternalRecipeObject2(aRecipe)); - if (COMPAT_HANDLER.mRecipesToGenerate.size() > size) { - if (!COMPAT_HANDLER.areInitItemsLoaded){ - RegistrationHandler.recipesSuccess++; - } - else { - LateRegistrationHandler.recipesSuccess++; - } - return true; - } - return false; - } - public static class InternalRecipeObject2 implements RunnableWithInfo<String> { - - final ItemStack mOutput; - final ShapedOreRecipe mRecipe; - final boolean isValid; - - public InternalRecipeObject2(ShapedOreRecipe aRecipe) { - mRecipe = aRecipe; - mOutput = aRecipe.getRecipeOutput(); - if (mOutput != null) { - this.isValid = true; - } - else { - this.isValid = false; - } - } - - @Override - public void run() { - if (this.isValid) { - GameRegistry.addRecipe(mRecipe); - } - else { - Logger.INFO("[Fix] Invalid shapped recipe outputting "+mOutput != null ? mOutput.getDisplayName() : "Bad Output Item"); - } - } - - @Override - public String getInfoData() { - if (mOutput != null && mOutput instanceof ItemStack) { - return ((ItemStack) mOutput).getDisplayName(); - } - return ""; - } - - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ShapelessUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ShapelessUtils.java deleted file mode 100644 index 3caa9d4e4f..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/ShapelessUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -package gtPlusPlus.core.util.minecraft; - -import java.util.ArrayList; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.item.crafting.ShapelessRecipes; - -import gtPlusPlus.api.objects.Logger; - -public class ShapelessUtils { - - - public static boolean addShapelessRecipe(final ItemStack output, final Object ... params) - { - final ArrayList<ItemStack> arraylist = new ArrayList<>(); - final Object[] aobject = params; - final int i = params.length; - - for (int j = 0; j < i; ++j) - { - final Object object1 = aobject[j]; - - if (object1 instanceof ItemStack) - { - arraylist.add(((ItemStack)object1).copy()); - } - else if (object1 instanceof Item) - { - arraylist.add(new ItemStack((Item)object1)); - } - else - { - if ((object1 == null)) - { - Logger.INFO(("Invalid shapeless input, ignoring!")); - } - else if (!(object1 instanceof Block) && (object1 != null)) - { - Logger.INFO(("Invalid shapeless recipe!")); - return false; - } - else { - arraylist.add(new ItemStack((Block)object1)); - } - } - } - CraftingManager.getInstance().getRecipeList().add(new ShapelessRecipes(output, arraylist)); - //CraftingManager.getInstance().addShapelessRecipe(output, arraylist); - return true; - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java deleted file mode 100644 index 2ae2a9f1de..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java +++ /dev/null @@ -1,305 +0,0 @@ -package gtPlusPlus.core.util.minecraft.gregtech; - -import static gtPlusPlus.core.lib.CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.commons.lang3.ArrayUtils; - -import gregtech.GT_Mod; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; -import gregtech.common.GT_Proxy; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.item.base.cell.BaseItemCell; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.material.MISC_MATERIALS; -import gtPlusPlus.core.material.MaterialGenerator; -import gtPlusPlus.core.util.minecraft.FluidUtils; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.item.ItemStack; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.fluids.FluidStack; - -public class PollutionUtils { - - private static boolean mIsPollutionEnabled = true; - - private static Method mAddPollution; - private static Method mAddPollution2; - - private static Method mGetPollution; - private static Method mGetPollution2; - - public static AutoMap<FluidStack> mPollutionFluidStacks = new AutoMap<FluidStack>(); - - static { - if (MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) { - mIsPollutionEnabled = mPollution(); - } else { - mIsPollutionEnabled = false; - } - } - - public static boolean isPollutionEnabled() { - return mIsPollutionEnabled; - } - - public static boolean mPollution() { - try { - GT_Proxy GT_Pollution = GT_Mod.gregtechproxy; - if (GT_Pollution != null) { - Field mPollution = ReflectionUtils.getField(GT_Pollution.getClass(), "mPollution"); - if (mPollution != null) { - return mPollution.getBoolean(GT_Pollution); - } - } - } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { - } - return false; - } - - public static boolean addPollution(IGregTechTileEntity te, int pollutionValue) { - if (mIsPollutionEnabled) - try { - if (te == null) { - return false; - } - if (mAddPollution != null) { - mAddPollution.invoke(null, te, pollutionValue); - } - Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "addPollution", IGregTechTileEntity.class, int.class); - if (addPollution != null) { - mAddPollution = addPollution; - addPollution.invoke(null, te, pollutionValue); - return true; - } - } - } catch (SecurityException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } - return false; - } - - public static boolean addPollution(IHasWorldObjectAndCoords aTileOfSomeSort, int pollutionValue) { - if (mIsPollutionEnabled) - try { - if (aTileOfSomeSort == null) { - return false; - } - IHasWorldObjectAndCoords j = (IHasWorldObjectAndCoords) aTileOfSomeSort; - Chunk c = j.getWorld().getChunkFromBlockCoords(j.getXCoord(), j.getZCoord()); - return addPollution(c, pollutionValue); - } catch (SecurityException | IllegalArgumentException e) { - } - return false; - } - - public static boolean addPollution(Chunk aChunk, int pollutionValue) { - if (mIsPollutionEnabled) - try { - if (aChunk == null) { - return false; - } - if (mAddPollution2 != null) { - mAddPollution2.invoke(null, aChunk, pollutionValue); - return true; - } - Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "addPollution", Chunk.class, int.class); - if (addPollution != null) { - mAddPollution2 = addPollution; - mAddPollution2.invoke(null, aChunk, pollutionValue); - return true; - } - } - } catch (SecurityException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } - return false; - } - - public static boolean removePollution(IGregTechTileEntity te, int pollutionValue) { - return addPollution(te, -pollutionValue); - } - - public static boolean removePollution(IHasWorldObjectAndCoords aTileOfSomeSort, int pollutionValue) { - return addPollution(aTileOfSomeSort, -pollutionValue); - } - - public static boolean removePollution(Chunk aChunk, int pollutionValue) { - return addPollution(aChunk, -pollutionValue); - } - - public static boolean nullifyPollution(IGregTechTileEntity te) { - if (te == null) { - return false; - } - return nullifyPollution((IHasWorldObjectAndCoords) te); - } - - public static boolean nullifyPollution(IHasWorldObjectAndCoords aTileOfSomeSort) { - if (aTileOfSomeSort == null) { - return false; - } - IHasWorldObjectAndCoords j = (IHasWorldObjectAndCoords) aTileOfSomeSort; - Chunk c = j.getWorld().getChunkFromBlockCoords(j.getXCoord(), j.getZCoord()); - return nullifyPollution(c); - } - - public static boolean nullifyPollution(Chunk aChunk) { - try { - if (aChunk == null) { - return false; - } - long getCurrentPollution = getPollution(aChunk); - if (getCurrentPollution <= 0) { - return false; - } - else { - if (mAddPollution2 != null) { - mAddPollution2.invoke(null, aChunk, -getCurrentPollution); - return true; - } - else { - Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "addPollution", Chunk.class, int.class); - if (addPollution != null) { - mAddPollution2 = addPollution; - mAddPollution2.invoke(null, aChunk, 0); - return true; - } - } - } - } - - } catch (SecurityException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } - return false; - } - - public static int getPollution(IGregTechTileEntity te) { - if (MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) - try { - if (te == null) { - return 0; - } - if (mGetPollution != null) { - mGetPollution.invoke(null, te); - } - Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "getPollution", IGregTechTileEntity.class); - if (addPollution != null) { - mGetPollution = addPollution; - return (int) addPollution.invoke(null, te); - } - } - } catch (SecurityException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } - return 0; - } - - public static int getPollution(Chunk te) { - if (MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) - try { - if (te == null) { - return 0; - } - if (mGetPollution2 != null) { - mGetPollution2.invoke(null, te); - } - Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); - if (GT_Pollution != null) { - Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "getPollution", Chunk.class); - if (addPollution != null) { - mGetPollution2 = addPollution; - return (int) addPollution.invoke(null, te); - } - } - } catch (SecurityException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } - return 0; - } - - public static boolean setPollutionFluids() { - if (mPollutionFluidStacks.isEmpty()) { - FluidStack CD, CM, SD; - CD = FluidUtils.getFluidStack("carbondioxide", 1000); - CM = FluidUtils.getFluidStack("carbonmonoxide", 1000); - SD = FluidUtils.getFluidStack("sulfurdioxide", 1000); - if (PollutionUtils.mPollutionFluidStacks.size() == 0) { - if (CD != null) { - Logger.INFO("[PollutionCompat] Found carbon dioxide fluid, registering it."); - PollutionUtils.mPollutionFluidStacks.put(CD); - MISC_MATERIALS.CARBON_DIOXIDE.registerComponentForMaterial(CD); - ItemStack cellCD = ItemUtils.getItemStackOfAmountFromOreDict("cellCarbonDioxide", 1); - if (ItemUtils.checkForInvalidItems(cellCD)) { - Logger.INFO("[PollutionCompat] Found carbon dioxide cell, registering component."); - MISC_MATERIALS.CARBON_DIOXIDE.registerComponentForMaterial(OrePrefixes.cell, cellCD); - } - else { - Logger.INFO("[PollutionCompat] Did not find carbon dioxide cell, registering new component."); - new BaseItemCell(MISC_MATERIALS.CARBON_DIOXIDE); - } - } - else { - MaterialGenerator.generate(MISC_MATERIALS.CARBON_DIOXIDE, false, false); - } - - if (CM != null) { - Logger.INFO("[PollutionCompat] Found carbon monoxide fluid, registering it."); - PollutionUtils.mPollutionFluidStacks.put(CM); - MISC_MATERIALS.CARBON_MONOXIDE.registerComponentForMaterial(CM); - ItemStack cellCD = ItemUtils.getItemStackOfAmountFromOreDict("cellCarbonMonoxide", 1); - if (ItemUtils.checkForInvalidItems(cellCD)) { - Logger.INFO("[PollutionCompat] Found carbon monoxide cell, registering component."); - MISC_MATERIALS.CARBON_MONOXIDE.registerComponentForMaterial(OrePrefixes.cell, cellCD); - } - else { - Logger.INFO("[PollutionCompat] Did not find carbon monoxide cell, registering new component."); - new BaseItemCell(MISC_MATERIALS.CARBON_MONOXIDE); - } - } - else { - MaterialGenerator.generate(MISC_MATERIALS.CARBON_MONOXIDE, false, false); - } - - if (SD != null) { - Logger.INFO("[PollutionCompat] Found sulfur dioxide fluid, registering it."); - PollutionUtils.mPollutionFluidStacks.put(SD); - } - } - if (PollutionUtils.mPollutionFluidStacks.size() > 0) { - return true; - } - return false; - } - else { - if (mPollutionFluidStacks.size() != 3) { - Logger.INFO("Unable to detect all 3 pollution fluids. Found: "); - Logger.INFO(ArrayUtils.toString(mPollutionFluidStacks)); - return false; - } - else { - return true; - } - } - - - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/material/MaterialBuilder.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/material/MaterialBuilder.java deleted file mode 100644 index 44c0f66732..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/material/MaterialBuilder.java +++ /dev/null @@ -1,244 +0,0 @@ -package gtPlusPlus.core.util.minecraft.gregtech.material; - -public class MaterialBuilder { - /*public static final int DIESEL = 0, GAS = 1, THERMAL = 2, SEMIFLUID = 3, PLASMA = 4, MAGIC = 5; - - private int metaItemSubID; - private TextureSet iconSet; - private float toolSpeed = 1.0f; - private int durability = 0; - private int toolQuality = 0; - private int types = 0; - private int r = 255, g = 255, b = 255, a = 0; - private String name; - private String defaultLocalName; - private int fuelType = 0; - private int fuelPower = 0; - private int meltingPoint = 0; - private int blastFurnaceTemp = 0; - private boolean blastFurnaceRequired = false; - private boolean transparent = false; - private int oreValue = 1; - private int densityMultiplier = 1; - private int densityDivider = 1; - private Dyes color = Dyes._NULL; - private int extraData = 0; - private List<MaterialStack> materialList = new ArrayList<MaterialStack>(); - private List<TC_Aspects.TC_AspectStack> aspects = new ArrayList<TC_Aspects.TC_AspectStack>(); - private boolean canBeCracked = false; - private int liquidTemperature = 300; - private int gasTemperature = 300; - - public MaterialBuilder(int metaItemSubID, TextureSet iconSet, String defaultLocalName) { - this.metaItemSubID = metaItemSubID; - this.iconSet = iconSet; - this.name = defaultLocalName.replace(" ", "").replace("-", ""); - this.defaultLocalName = defaultLocalName; - } - - public Materials constructMaterial() { - return new Materials( - metaItemSubID, iconSet, toolSpeed, durability, toolQuality, types, r, g, b, a, name, defaultLocalName, fuelType, fuelPower, meltingPoint, blastFurnaceTemp, - blastFurnaceRequired, transparent, oreValue, densityMultiplier, densityDivider, color, extraData, materialList, aspects); - - } - - public MaterialBuilder setName(String name){ - this.name = name; - return this; - } - - public MaterialBuilder setTypes(int types){ - this.types = types; - return this; - } - - public MaterialBuilder addDustItems(){ - types = types | 1; - return this; - } - - public MaterialBuilder addMetalItems(){ - types = types | 2; - return this; - } - - public MaterialBuilder addGemItems(){ - types = types | 4; - return this; - } - - public MaterialBuilder addOreItems(){ - types = types | 8; - return this; - } - - public MaterialBuilder addCell(){ - types = types | 16; - return this; - } - - public MaterialBuilder addPlasma(){ - types = types | 32; - return this; - } - - public MaterialBuilder addToolHeadItems(){ - types = types | 64; - return this; - } - - public MaterialBuilder addGearItems(){ - types = types | 128; - return this; - } - - public MaterialBuilder addFluid(){ - return this; - } - - public MaterialBuilder addGas(){ - return this; - } - - - public MaterialBuilder setRGBA(int r, int g, int b, int a){ - this.r = r; - this.g = g; - this.b = b; - this.a = a; - return this; - } - - public MaterialBuilder setRGB(int r, int g, int b){ - this.r = r; - this.g = g; - this.b = b; - return this; - } - - public MaterialBuilder setTransparent(boolean transparent){ - this.transparent = transparent; - return this; - } - - public MaterialBuilder setColor(Dyes color){ - this.color = color; - return this; - } - - - public MaterialBuilder setToolSpeed(float toolSpeed) { - this.toolSpeed = toolSpeed; - return this; - } - - public MaterialBuilder setDurability(int durability) { - this.durability = durability; - return this; - } - - public MaterialBuilder setToolQuality(int toolQuality) { - this.toolQuality = toolQuality; - return this; - } - - - public MaterialBuilder setFuelType(int fuelType) { - this.fuelType = fuelType; - return this; - } - - public MaterialBuilder setFuelPower(int fuelPower) { - this.fuelPower = fuelPower; - return this; - } - - public MaterialBuilder setMeltingPoint(int meltingPoint) { - this.meltingPoint = meltingPoint; - return this; - } - - public MaterialBuilder setBlastFurnaceTemp(int blastFurnaceTemp) { - this.blastFurnaceTemp = blastFurnaceTemp; - return this; - } - - public MaterialBuilder setBlastFurnaceRequired(boolean blastFurnaceRequired) { - this.blastFurnaceRequired = blastFurnaceRequired; - return this; - } - - public MaterialBuilder setOreValue(int oreValue) { - this.oreValue = oreValue; - return this; - } - - public MaterialBuilder setDensityMultiplier(int densityMultiplier) { - this.densityMultiplier = densityMultiplier; - return this; - } - - public MaterialBuilder setDensityDivider(int densityDivider) { - this.densityDivider = densityDivider; - return this; - } - - public MaterialBuilder setExtraData(int extraData) { - this.extraData = extraData; - return this; - } - - public MaterialBuilder addElectrolyzerRecipe(){ - extraData = extraData | 1; - return this; - } - - public MaterialBuilder addCentrifugeRecipe(){ - extraData = extraData | 2; - return this; - } - - public MaterialBuilder setMaterialList(List<MaterialStack> materialList) { - this.materialList = materialList; - return this; - } - - public MaterialBuilder setMaterialList(MaterialStack ... materials) { - this.materialList = Arrays.asList(materials); - return this; - } - - public MaterialBuilder setAspects(List<TC_Aspects.TC_AspectStack> aspects) { - this.aspects = aspects; - return this; - } - - public int getLiquidTemperature() { - return liquidTemperature; - } - - public MaterialBuilder setLiquidTemperature(int liquidTemperature) { - this.liquidTemperature = liquidTemperature; - return this; - } - - public int getGasTemperature() { - return gasTemperature; - } - - public MaterialBuilder setGasTemperature(int gasTemperature) { - this.gasTemperature = gasTemperature; - return this; - } - - public boolean canBeCracked() { - return canBeCracked; - } - - public MaterialBuilder setCanBeCracked(boolean canBeCracked) { - this.canBeCracked = canBeCracked; - return this; - } -*/ -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java deleted file mode 100644 index 635239bbfc..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java +++ /dev/null @@ -1,3 +0,0 @@ -package gtPlusPlus.core.util.minecraft.gregtech.recipehandlers; - -public final class GregtechRecipe {}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/CustomPacket.java b/src/Java/gtPlusPlus/core/util/minecraft/network/CustomPacket.java deleted file mode 100644 index def836eac9..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/network/CustomPacket.java +++ /dev/null @@ -1,39 +0,0 @@ -package gtPlusPlus.core.util.minecraft.network; - -import cpw.mods.fml.common.network.internal.FMLProxyPacket; -import io.netty.buffer.Unpooled; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import mods.railcraft.common.util.misc.Game; - -public abstract class CustomPacket { - public static final String CHANNEL_NAME = "GTPP"; - - public enum PacketType { - TILE_ENTITY, - } - - public FMLProxyPacket getPacket() { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - try { - data.writeByte(this.getID()); - this.writeData(data); - } catch (IOException var4) { - Game.logThrowable("Error constructing packet: {0}", var4, new Object[]{this.getClass()}); - } - return new FMLProxyPacket(Unpooled.wrappedBuffer(bytes.toByteArray()), "GTPP"); - } - - public abstract void writeData(DataOutputStream var1) throws IOException; - - public abstract void readData(DataInputStream var1) throws IOException; - - public abstract int getID(); - - public String toString() { - return this.getClass().getSimpleName(); - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketBuilder.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketBuilder.java deleted file mode 100644 index edbc6aaf83..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketBuilder.java +++ /dev/null @@ -1,25 +0,0 @@ -package gtPlusPlus.core.util.minecraft.network; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.world.WorldServer; - -public class PacketBuilder { - - private static PacketBuilder instance; - - public static PacketBuilder instance() { - if (instance == null) { - instance = new PacketBuilder(); - } - return instance; - } - - public void sendTileEntityPacket(IGregTechTileEntity tile) { - if (tile.getWorld() instanceof WorldServer) { - WorldServer world = (WorldServer) tile.getWorld(); - PacketTileEntity pkt = new PacketTileEntity(tile); - PacketDispatcher.sendToWatchers(pkt, world, tile.getXCoord(), tile.getZCoord()); - } - } - -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketDispatcher.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketDispatcher.java deleted file mode 100644 index f61a6f2b6c..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketDispatcher.java +++ /dev/null @@ -1,88 +0,0 @@ -package gtPlusPlus.core.util.minecraft.network; - -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; -import cpw.mods.fml.relauncher.ReflectionHelper; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.preloader.DevHelper; - -import java.lang.reflect.Method; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.Packet; -import net.minecraft.server.management.PlayerManager; -import net.minecraft.world.WorldServer; - -@SuppressWarnings("unchecked") -public class PacketDispatcher { - private static final Class playerInstanceClass; - private static final Method getOrCreateChunkWatcher; - private static final Method sendToAllPlayersWatchingChunk; - - public static void sendToServer(CustomPacket packet) { - PacketHandler.INSTANCE.channel.sendToServer(packet.getPacket()); - } - - public static void sendToPlayer(CustomPacket packet, EntityPlayerMP player) { - PacketHandler.INSTANCE.channel.sendTo(packet.getPacket(), player); - } - - public static void sendToAll(CustomPacket packet) { - PacketHandler.INSTANCE.channel.sendToAll(packet.getPacket()); - } - - public static void sendToAllAround(CustomPacket packet, TargetPoint zone) { - PacketHandler.INSTANCE.channel.sendToAllAround(packet.getPacket(), zone); - } - - public static void sendToDimension(CustomPacket packet, int dimensionId) { - PacketHandler.INSTANCE.channel.sendToDimension(packet.getPacket(), dimensionId); - } - - public static void sendToWatchers(CustomPacket packet, WorldServer world, int worldX, int worldZ) { - try { - Object playerInstance = getOrCreateChunkWatcher.invoke(world.getPlayerManager(), worldX >> 4, worldZ >> 4, - false); - if (playerInstance != null) { - sendToAllPlayersWatchingChunk.invoke(playerInstance, packet.getPacket()); - } - - } catch (Exception var5) { - Logger.ERROR("Reflection Failure in PacketDispatcher.sendToWatchers() {0} {1}" + 20 + var5 + - new Object[]{getOrCreateChunkWatcher.getName() + sendToAllPlayersWatchingChunk.getName()}); - throw new RuntimeException(var5); - } - } - - static { - try { - playerInstanceClass = PlayerManager.class.getDeclaredClasses()[0]; - - Method a, b; - - try { - a = DevHelper.getForgeMethod(PlayerManager.class, "getOrCreateChunkWatcher", int.class, int.class, boolean.class); - } - catch (Throwable t) { - a = ReflectionHelper.findMethod(playerInstanceClass, (Object) null, - new String[]{"func_72690_a", "getOrCreateChunkWatcher"}, - new Class[]{Integer.TYPE, Integer.TYPE, Boolean.TYPE}); - } - try { - b = DevHelper.getForgeMethod(PlayerManager.class, "sendToAllPlayersWatchingChunk", Packet.class); - } - catch (Throwable t) { - b = ReflectionHelper.findMethod(playerInstanceClass, (Object) null, - new String[]{"func_151251_a", "sendToAllPlayersWatchingChunk"}, - new Class[]{Packet.class}); - } - - - getOrCreateChunkWatcher = a; - sendToAllPlayersWatchingChunk = b; - getOrCreateChunkWatcher.setAccessible(true); - sendToAllPlayersWatchingChunk.setAccessible(true); - } catch (Exception var1) { - Logger.ERROR("Reflection Failure in PacketDispatcher initalization {0} {1}" + var1); - throw new RuntimeException(var1); - } - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketHandler.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketHandler.java deleted file mode 100644 index 158f9f9483..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -package gtPlusPlus.core.util.minecraft.network; - -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.network.FMLEventChannel; -import cpw.mods.fml.common.network.NetworkRegistry; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.minecraft.network.CustomPacket.PacketType; -import cpw.mods.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent; -import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.util.Arrays; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.NetHandlerPlayServer; - -public class PacketHandler { - public static final PacketHandler INSTANCE = new PacketHandler(); - private static final PacketType[] packetTypes = PacketType.values(); - final FMLEventChannel channel; - - private PacketHandler() { - this.channel = NetworkRegistry.INSTANCE.newEventDrivenChannel("GTPP"); - this.channel.register(this); - } - - public static void init() { - } - - @SubscribeEvent - public void onPacket(ServerCustomPacketEvent event) { - byte[] data = new byte[event.packet.payload().readableBytes()]; - event.packet.payload().readBytes(data); - this.onPacketData(data, ((NetHandlerPlayServer) event.handler).playerEntity); - } - - @SubscribeEvent - public void onPacket(ClientCustomPacketEvent event) { - byte[] data = new byte[event.packet.payload().readableBytes()]; - event.packet.payload().readBytes(data); - this.onPacketData(data, (EntityPlayerMP) null); - } - - public void onPacketData(byte[] bData, EntityPlayerMP player) { - DataInputStream data = new DataInputStream(new ByteArrayInputStream(bData)); - - try { - byte packetID = data.readByte(); - if (packetID < 0) { - return; - } - PacketType type = packetTypes[packetID]; - Object pkt; - - switch(type.ordinal()) { - case 0: - pkt = new PacketTileEntity(); - break; - default: - return; - } - - if (pkt != null) { - ((CustomPacket)pkt).readData(data); - } - } catch (IOException var7) { - Logger.ERROR("Exception in PacketHandler.onPacketData: {0}"+ var7 + new Object[]{Arrays.toString(bData)}); - } - - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketTileEntity.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketTileEntity.java deleted file mode 100644 index d59bee3c27..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketTileEntity.java +++ /dev/null @@ -1,79 +0,0 @@ -package gtPlusPlus.core.util.minecraft.network; - -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gtPlusPlus.api.interfaces.IGregtechPacketEntity; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import mods.railcraft.common.util.misc.Game; -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -public class PacketTileEntity extends CustomPacket { - private IGregTechTileEntity tile; - private IGregtechPacketEntity ptile; - - public PacketTileEntity() { - } - - public PacketTileEntity(IGregTechTileEntity tile) { - this.tile = tile; - if (tile instanceof IGregtechPacketEntity) { - ptile = (IGregtechPacketEntity) tile; - } - } - - public void writeData(DataOutputStream data) throws IOException { - if (ptile != null) { - data.writeInt(this.tile.getXCoord()); - data.writeInt(this.tile.getYCoord()); - data.writeInt(this.tile.getZCoord()); - data.writeShort(this.tile.getMetaTileID()); - this.ptile.writePacketData(data); - } - } - - @SideOnly(Side.CLIENT) - public void readData(DataInputStream data) throws IOException { - Minecraft mc = FMLClientHandler.instance().getClient(); - World world = mc != null ? mc.theWorld : null; - if (world != null) { - int x = data.readInt(); - int y = data.readInt(); - int z = data.readInt(); - short id = data.readShort(); - if (id >= 0 && y >= 0 && world.blockExists(x, y, z)) { - TileEntity te = world.getTileEntity(x, y, z); - if (te instanceof IGregTechTileEntity) { - this.tile = (IGregTechTileEntity) te; - if (this.tile.getMetaTileID() != id) { - this.tile = null; - } - } else { - this.tile = null; - } - if (this.tile != null) { - if (tile instanceof IGregtechPacketEntity) { - ptile = (IGregtechPacketEntity) tile; - try { - this.ptile.readPacketData(data); - } catch (IOException var10) { - throw var10; - } catch (RuntimeException var11) { - Game.logThrowable("Exception in PacketTileEntity.readData:", var11, new Object[0]); - } - } - } - } - } - } - - public int getID() { - return 0; - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/particles/BlockBreakParticles.java b/src/Java/gtPlusPlus/core/util/minecraft/particles/BlockBreakParticles.java deleted file mode 100644 index 9046a57120..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/particles/BlockBreakParticles.java +++ /dev/null @@ -1,18 +0,0 @@ -package gtPlusPlus.core.util.minecraft.particles; - -import net.minecraft.block.Block; -import net.minecraft.world.World; - -import gtPlusPlus.xmod.forestry.HANDLER_FR; - -public class BlockBreakParticles { - - public BlockBreakParticles(final World world, final int x, final int y, final int z, final Block block){ - try { - HANDLER_FR.createBlockBreakParticles(world, x, y, z, block); - } catch (final Throwable T){ - - } - } - -} diff --git a/src/Java/gtPlusPlus/core/util/minecraft/particles/EntityParticleFXMysterious.java b/src/Java/gtPlusPlus/core/util/minecraft/particles/EntityParticleFXMysterious.java deleted file mode 100644 index d996cf705a..0000000000 --- a/src/Java/gtPlusPlus/core/util/minecraft/particles/EntityParticleFXMysterious.java +++ /dev/null @@ -1,17 +0,0 @@ -package gtPlusPlus.core.util.minecraft.particles; - -import net.minecraft.client.particle.EntityAuraFX; -import net.minecraft.world.World; - -public class EntityParticleFXMysterious extends EntityAuraFX -{ - public EntityParticleFXMysterious(final World parWorld, - final double parX, final double parY, final double parZ, - final double parMotionX, final double parMotionY, final double parMotionZ) - { - super(parWorld, parX, parY, parZ, parMotionX, parMotionY, parMotionZ); - this.setParticleTextureIndex(82); // same as happy villager - this.particleScale = 2.0F; - this.setRBGColorF(0x88, 0x00, 0x88); - } -} diff --git a/src/Java/gtPlusPlus/core/util/player/PlayerCache.java b/src/Java/gtPlusPlus/core/util/player/PlayerCache.java deleted file mode 100644 index 753124dcd7..0000000000 --- a/src/Java/gtPlusPlus/core/util/player/PlayerCache.java +++ /dev/null @@ -1,160 +0,0 @@ -package gtPlusPlus.core.util.player; - -import java.io.*; -import java.util.*; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.server.MinecraftServer; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; - -public class PlayerCache { - - private static final File cache = new File("PlayerCache.dat"); - - public static final void initCache() { - if (CORE.PlayerCache == null){ - try { - - if (cache != null){ - CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); - Logger.INFO("Loaded PlayerCache.dat"); - } - - - } catch (final Exception e) { - Logger.INFO("Failed to initialise PlayerCache.dat"); - PlayerCache.createPropertiesFile("PLAYER_", "DATA"); - //e.printStackTrace(); - } - } - } - - public static void createPropertiesFile(final String playerName, final String playerUUIDasString) { - try { - final Properties props = new Properties(); - props.setProperty(playerName+" ", playerUUIDasString); - final OutputStream out = new FileOutputStream(cache); - props.store(out, "Player Cache."); - Logger.INFO("PlayerCache.dat created for future use."); - out.close(); - } - catch (final Exception e ) { - e.printStackTrace(); - } - } - - public static void appendParamChanges(final String playerName, final String playerUUIDasString) { - final HashMap<String, UUID> playerInfo = new HashMap<>(); - playerInfo.put(playerName, UUID.fromString(playerUUIDasString)); - - /*try { - Utils.LOG_INFO("Attempting to load "+cache.getName()); - properties.load(new FileInputStream(cache)); - if (properties == null || properties.equals(null)){ - Utils.LOG_INFO("Please wait."); - } - else { - Utils.LOG_INFO("Loaded PlayerCache.dat"); - properties.setProperty(playerName+"_", playerUUIDasString); - FileOutputStream fr=new FileOutputStream(cache); - properties.store(fr, "Player Cache."); - fr.close(); - } - - } */ - - try - { - final FileOutputStream fos = new FileOutputStream("PlayerCache.dat"); - final ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(playerInfo); - oos.close(); - fos.close(); - Logger.INFO("Serialized Player data saved in PlayerCache.dat"); - } - - catch (final IOException e) { - Logger.INFO("No PlayerCache file found, creating one."); - createPropertiesFile(playerName, playerUUIDasString); - } - } - - /** - * Reads a "properties" file, and returns it as a Map - * (a collection of key/value pairs). - * - * Credit due to Alvin Alexander - http://alvinalexander.com/java/java-properties-file-map-example?nocache=1#comment-8215 - * Changed slightly as the filename and delimiter are constant in my case. - * - * @param filename The properties filename to read. - * @param delimiter The string (or character) that separates the key - * from the value in the properties file. - * @return The Map that contains the key/value pairs. - * @throws Exception - */ - @Deprecated - public static Map<String, String> readPropertiesFileAsMapOld() throws Exception { - final String delimiter = "="; - @SuppressWarnings({ "rawtypes", "unchecked" }) - final - Map<String, String> map = new HashMap<>(); - final BufferedReader reader = new BufferedReader(new FileReader(cache)); - String line; - while ((line = reader.readLine()) != null) - { - if (line.trim().length()==0) { - continue; - } - if (line.charAt(0)=='#') { - continue; - } - // assumption here is that proper lines are like "String : <a href="http://xxx.yyy.zzz/foo/bar"" title="http://xxx.yyy.zzz/foo/bar"">http://xxx.yyy.zzz/foo/bar"</a>, - // and the ":" is the delimiter - final int delimPosition = line.indexOf(delimiter); - final String key = line.substring(0, delimPosition-1).trim(); - final String value = line.substring(delimPosition+1).trim(); - map.put(key, value); - } - reader.close(); - CORE.PlayerCache = map; - return map; - } - - public static HashMap<String, UUID> readPropertiesFileAsMap() { - HashMap<String, UUID> map = null; - try - { - final FileInputStream fis = new FileInputStream(cache); - final ObjectInputStream ois = new ObjectInputStream(fis); - map = (HashMap<String, UUID>) ois.readObject(); - ois.close(); - fis.close(); - }catch(final IOException ioe) - { - ioe.printStackTrace(); - return null; - }catch(final ClassNotFoundException c) - { - Logger.INFO("Class not found"); - c.printStackTrace(); - return null; - } - Logger.WARNING("Deserialized PlayerCache.."); - return map; - } - - public static String lookupPlayerByUUID(final UUID UUID){ - if (UUID == null) { - return null; - } - final List<EntityPlayerMP> allPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList; - for (final EntityPlayerMP player : allPlayers) { - if (player.getUniqueID().equals(UUID)) { - return player.getDisplayName(); - } - } - return "Offline Player."; - } -} diff --git a/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java b/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java deleted file mode 100644 index 0b22ea3acc..0000000000 --- a/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java +++ /dev/null @@ -1,298 +0,0 @@ -package gtPlusPlus.core.util.reflect; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import net.minecraft.item.ItemStack; - -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.internal.IGT_RecipeAdder; -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.recipe.common.CI; -import gtPlusPlus.core.util.minecraft.FluidUtils; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import net.minecraftforge.fluids.FluidStack; - -public final class AddGregtechRecipe { - - - public static boolean importPyroRecipe(GT_Recipe aRecipe) { - - int aModifiedTime = (int) (aRecipe.mDuration * 0.8); - - if (aRecipe.mInputs == null || aRecipe.mFluidInputs == null || aRecipe.mFluidOutputs == null || aRecipe.mOutputs == null) { - return false; - } - - if (aRecipe.mInputs.length > 2 || aRecipe.mFluidInputs.length > 1 || aRecipe.mFluidOutputs.length > 1 || aRecipe.mOutputs.length > 1) { - return false; - } - else if (aRecipe.mInputs.length <= 0 || aRecipe.mFluidInputs.length <= 0 || aRecipe.mFluidOutputs.length <= 0 || aRecipe.mOutputs.length <= 0) { - return false; - } - - int aCircuitNumber = -1; - int aItemSlot = -1; - - int aSlot = 0; - for (ItemStack a : aRecipe.mInputs) { - if (a != null && a.getItem() != CI.getNumberedCircuit(1).getItem()) { - aItemSlot = aSlot; - } - else { - aSlot++; - } - } - - for (int i=0;i<25;i++) { - ItemStack aTest = CI.getNumberedCircuit(i); - for (ItemStack a : aRecipe.mInputs) { - if (a != null && GT_Utility.areStacksEqual(a, aTest)) { - aCircuitNumber = i; - break; - } - } - } - - if (aCircuitNumber < 0) { - return false; - } - - - return CORE.RA.addCokeOvenRecipe( - aRecipe.mInputs[aItemSlot], - ItemUtils.getGregtechCircuit(aCircuitNumber), - aRecipe.mFluidInputs[0], - aRecipe.mFluidOutputs[0], - aRecipe.mOutputs[0], - aModifiedTime, - aRecipe.mEUt); - - - } - - - public static boolean addCokeAndPyrolyseRecipes( - ItemStack input1, int circuitNumber, - FluidStack inputFluid1, - ItemStack output1, - FluidStack outputFluid1, - int timeInSeconds, - int euTick - ){ - //Seconds Conversion - int TIME = timeInSeconds*20; - int TIMEPYRO = TIME+(TIME/5); - CORE.RA.addCokeOvenRecipe( - input1, - ItemUtils.getGregtechCircuit(circuitNumber), - inputFluid1, - outputFluid1, - output1, - TIME, - euTick); - PyrolyseOven( - input1, - inputFluid1, - circuitNumber, - output1, - outputFluid1, - TIMEPYRO, - euTick); - - - return false; - } - - - - - public static boolean PyrolyseOven(final ItemStack p0, final FluidStack p1, final int p2, final ItemStack p3, - final FluidStack p4, final int p5, final int p6){ - - try { - IGT_RecipeAdder IGT_RecipeAdder = GT_Values.RA; - if (IGT_RecipeAdder != null){ - Class<? extends IGT_RecipeAdder> classRA = IGT_RecipeAdder.getClass(); - Method addRecipe = classRA.getMethod("addPyrolyseRecipe", ItemStack.class, FluidStack.class, int.class, ItemStack.class, FluidStack.class, int.class, int.class); - if (addRecipe != null){ - return (boolean) addRecipe.invoke(IGT_RecipeAdder, p0, p1, p2, p3, p4, p5, p6); - } - } - } - catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - return false; - } - return false; - } - - - - public static boolean addAssemblylineRecipe( - ItemStack aResearchItem, - int aResearchTime, - ItemStack[] aInputs, - FluidStack[] aFluidInputs, - ItemStack aOutput, - int aDuration, int aEUt){ - /* - try { - IGT_RecipeAdder IGT_RecipeAdder = GT_Values.RA; - if (IGT_RecipeAdder != null){ - Class<? extends IGT_RecipeAdder> classRA = IGT_RecipeAdder.getClass(); - - for(Method current : classRA.getDeclaredMethods()){ - //Utils.LOG_INFO("-----------------------------------------------"); - ////Utils.LOG_INFO("Found method: "+current.getName()); - //Utils.LOG_INFO("With Parameters: "); - //Utils.LOG_INFO("==============================================="); - for (Class<?> P : current.getParameterTypes()){ - //Utils.LOG_INFO(""+P.getName()); - //Utils.LOG_INFO(""+P.getClass().getName()); - } - //Utils.LOG_INFO("==============================================="); - } - - try { - Method testRA = GT_Values.RA.getClass().getMethod("addAssemblylineRecipe", GT_Values.RA.getClass(), aResearchItem.getClass(), int.class, aInputs.getClass(), aFluidInputs.getClass(), aOutput.getClass(), int.class, int.class); - testRA.invoke(aResearchItem, aResearchTime, aInputs, aFluidInputs, aOutput, aDuration, aEUt); - } - catch (Throwable masndj){ - masndj.printStackTrace(); - } - - - Method addRecipe = classRA.getDeclaredMethod( - "addAssemblylineRecipe", - ItemStack.class, - int.class, - ItemStack.class, - FluidStack.class, - ItemStack.class, - int.class, - int.class); - if (addRecipe != null){ - return (boolean) addRecipe.invoke(aResearchItem, aResearchTime, aInputs, aFluidInputs, aOutput, aDuration, aEUt); - } - } - } - catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Utils.LOG_INFO("[Assembly Line] - Failed to add recipe, due to GT not being .09 branch. Research: "+aResearchItem.getDisplayName()+" | Result: "+aOutput.getDisplayName()); - e.printStackTrace(); - return false; - } - Utils.LOG_INFO("[Assembly Line] - Failed to add recipe. Research: "+aResearchItem.getDisplayName()+" | Result: "+aOutput.getDisplayName()); - */return false; - } - - public static boolean addCircuitAssemblerRecipe( - ItemStack[] aInputs, - FluidStack aFluidInput, - ItemStack aOutput, - int aDuration, - int aEUt) { - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){ - try { - IGT_RecipeAdder IGT_RecipeAdder = GT_Values.RA; - if (IGT_RecipeAdder != null){ - Class<? extends IGT_RecipeAdder> classRA = IGT_RecipeAdder.getClass(); - Method addRecipe = classRA.getMethod( - "addCircuitAssemblerRecipe", - ItemStack.class, - FluidStack.class, - ItemStack.class, - int.class, - int.class); - if (addRecipe != null){ - if (aFluidInput.isFluidEqual(FluidUtils.getFluidStack("molten.tin", 1))){ - boolean[] didAdd = new boolean[3]; - FluidStack moltenMetal = FluidUtils.getFluidStack("molten.tin", 144); - //Tin - didAdd[0] = (boolean) addRecipe.invoke( - IGT_RecipeAdder, - aInputs, - moltenMetal, - aOutput, - aDuration, - aEUt); - moltenMetal = FluidUtils.getFluidStack("molten.lead", 144); - //Lead - didAdd[1] = (boolean) addRecipe.invoke( - IGT_RecipeAdder, - aInputs, - moltenMetal, - aOutput, - aDuration, - aEUt); - moltenMetal = FluidUtils.getFluidStack("molten.solderingalloy", 144/2); - //Soldering Alloy - didAdd[2] = (boolean) addRecipe.invoke( - IGT_RecipeAdder, - aInputs, - moltenMetal, - aOutput, - aDuration, - aEUt); - - if (didAdd[0] && didAdd[1] && didAdd[2]){ - return true; - } - else { - return false; - } - } - else { - return (boolean) addRecipe.invoke( - IGT_RecipeAdder, - aInputs, - aFluidInput, - aOutput, - aDuration, - aEUt); - } - } - } - } - catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - return false; - } - } - return false; - } - - - public static boolean addChemicalRecipeForBasicMachineOnly(final ItemStack p0, final ItemStack p1, final FluidStack p2, final FluidStack p3, final ItemStack p4, final ItemStack p5, final int p6, final int p7){ - - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - try { - IGT_RecipeAdder IGT_RecipeAdder = GT_Values.RA; - if (IGT_RecipeAdder != null){ - Class<? extends IGT_RecipeAdder> classRA = IGT_RecipeAdder.getClass(); - //final ItemStack p0, final ItemStack p1, final FluidStack p2, final FluidStack p3, final ItemStack p4, final ItemStack p5, final int p6, final int p7 - Method addRecipe = classRA.getMethod("addChemicalRecipeForBasicMachineOnly", ItemStack.class, ItemStack.class, FluidStack.class, FluidStack.class, ItemStack.class, ItemStack.class, int.class, int.class); - if (addRecipe != null){ - return (boolean) addRecipe.invoke(IGT_RecipeAdder, p0, p1, p2, p3, p4, p5, p6, p7); - } - } - } - catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - - } - } - - return GT_Values.RA.addChemicalRecipe( - p0, - p1, - p2, - p3, - p4, - p6); - - } - - - - -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java deleted file mode 100644 index aaa9b2fae7..0000000000 --- a/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java +++ /dev/null @@ -1,55 +0,0 @@ -package gtPlusPlus.core.util.reflect; - -import java.lang.reflect.Field; - -import cpw.mods.fml.common.SidedProxy; - -public class ProxyFinder { - - public static Object getServerProxy(final Object modInstance) throws ReflectiveOperationException { - for(final Field field : modInstance.getClass().getDeclaredFields()) { - if(field.isAnnotationPresent(SidedProxy.class)) { - final SidedProxy sidedProxy = field.getAnnotation(SidedProxy.class); - final Object fieldValue = field.get(modInstance); - try { - final Class<?> serverSideClass = ReflectionUtils.getClass(sidedProxy.serverSide()); - if(serverSideClass.isAssignableFrom(fieldValue.getClass())) { - final Object serverProxy = serverSideClass.cast(fieldValue); - //do what you want with server proxy instance - return serverProxy; - } - - } catch (final NoClassDefFoundError err) { - //its client side - return null; - } - break; - } - } - return null; - } - - public static Object getClientProxy(final Object modInstance) throws ReflectiveOperationException { - for(final Field field : modInstance.getClass().getDeclaredFields()) { - if(field.isAnnotationPresent(SidedProxy.class)) { - final SidedProxy sidedProxy = field.getAnnotation(SidedProxy.class); - final Object fieldValue = field.get(modInstance); - try { - final Class<?> clientSideClass = ReflectionUtils.getClass(sidedProxy.clientSide()); - if(clientSideClass.isAssignableFrom(fieldValue.getClass())) { - final Object clientProxy = clientSideClass.cast(fieldValue); - //do what you want with client proxy instance - return clientProxy; - } - - } catch (final NoClassDefFoundError err) { - //its server side - return null; - } - break; - } - } - return null; - } - -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java deleted file mode 100644 index e0634dfb14..0000000000 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ /dev/null @@ -1,1078 +0,0 @@ -package gtPlusPlus.core.util.reflect; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.GenericDeclaration; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.ArrayUtils; - -import com.google.common.reflect.ClassPath; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.data.StringUtils; -import gtPlusPlus.xmod.gregtech.common.StaticFields59; - -public class ReflectionUtils { - - public static Map<String, Class<?>> mCachedClasses = new LinkedHashMap<String, Class<?>>(); - public static Map<String, CachedMethod> mCachedMethods = new LinkedHashMap<String, CachedMethod>(); - public static Map<String, CachedField> mCachedFields = new LinkedHashMap<String, CachedField>(); - public static Map<String, CachedConstructor> mCachedConstructors = new LinkedHashMap<String, CachedConstructor>(); - - private static class CachedConstructor { - - private final Constructor<?> METHOD; - - public CachedConstructor(Constructor<?> aCons) { - METHOD = aCons; - } - - public Constructor<?> get() { - return METHOD; - } - - } - - private static class CachedMethod { - - private final boolean STATIC; - private final Method METHOD; - - public CachedMethod(Method aMethod, boolean isStatic) { - METHOD = aMethod; - STATIC = isStatic; - } - - public Method get() { - return METHOD; - } - - public boolean type() { - return STATIC; - } - - } - - private static class CachedField { - - private final boolean STATIC; - private final Field FIELD; - - public CachedField(Field aField, boolean isStatic) { - FIELD = aField; - STATIC = isStatic; - } - - public Field get() { - return FIELD; - } - - public boolean type() { - return STATIC; - } - - } - - private static boolean cacheClass(Class<?> aClass) { - if (aClass == null) { - return false; - } - Class<?> y = mCachedClasses.get(aClass.getCanonicalName()); - if (y == null) { - mCachedClasses.put(aClass.getCanonicalName(), aClass); - return true; - } - return false; - } - - private static boolean cacheMethod(Class<?> aClass, Method aMethod) { - if (aMethod == null) { - return false; - } - boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); - CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethod.getName()+"."+ArrayUtils.toString(aMethod.getParameterTypes())); - if (y == null) { - mCachedMethods.put(aClass.getName()+"."+aMethod.getName()+"."+ArrayUtils.toString(aMethod.getParameterTypes()), new CachedMethod(aMethod, isStatic)); - return true; - } - return false; - } - - private static boolean cacheField(Class<?> aClass, Field aField) { - if (aField == null) { - return false; - } - boolean isStatic = Modifier.isStatic(aField.getModifiers()); - CachedField y = mCachedFields.get(aClass.getName()+"."+aField.getName()); - if (y == null) { - mCachedFields.put(aClass.getName()+"."+aField.getName(), new CachedField(aField, isStatic)); - return true; - } - return false; - } - - private static boolean cacheConstructor(Class<?> aClass, Constructor<?> aConstructor) { - if (aConstructor == null) { - return false; - } - CachedConstructor y = mCachedConstructors.get(aClass.getName()+"."+ArrayUtils.toString(aConstructor.getParameterTypes())); - if (y == null) { - mCachedConstructors.put(aClass.getName()+"."+ArrayUtils.toString(aConstructor.getParameterTypes()), new CachedConstructor(aConstructor)); - return true; - } - return false; - } - - - /** - * Returns a cached {@link Constructor} object. - * @param aClass - Class containing the Constructor. - * @param aTypes - Varags Class Types for objects constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Constructor<?> getConstructor(Class<?> aClass, Class<?>... aTypes) { - if (aClass == null || aTypes == null) { - return null; - } - - String aMethodKey = ArrayUtils.toString(aTypes); - //Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); - CachedConstructor y = mCachedConstructors.get(aClass.getName() + "." + aMethodKey); - if (y == null) { - Constructor<?> u = getConstructor_Internal(aClass, aTypes); - if (u != null) { - Logger.REFLECTION("Caching Constructor: "+aClass.getName() + "." + aMethodKey); - cacheConstructor(aClass, u); - return u; - } else { - return null; - } - } else { - return y.get(); - } - } - - - - - /** - * Returns a cached {@link Class} object. - * @param aClassCanonicalName - The canonical name of the underlying class. - * @return - Valid, {@link Class} object, or {@link null}. - */ - public static Class<?> getClass(String aClassCanonicalName) { - if (aClassCanonicalName == null || aClassCanonicalName.length() <= 0) { - return null; - } - Class<?> y = mCachedClasses.get(aClassCanonicalName); - if (y == null) { - y = getClass_Internal(aClassCanonicalName); - if (y != null) { - Logger.REFLECTION("Caching Class: "+aClassCanonicalName); - cacheClass(y); - } - } - return y; - } - - - - /** - * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. - * @param aObject - Object containing the Method. - * @param aMethodName - Method's name in {@link String} form. - * @param aTypes - Class Array of Types for {@link Method}'s constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Method getMethod(Object aObject, String aMethodName, Class[] aTypes) { - return getMethod(aObject.getClass(), aMethodName, aTypes); - } - - - /** - * Returns a cached {@link Method} object. - * @param aClass - Class containing the Method. - * @param aMethodName - Method's name in {@link String} form. - * @param aTypes - Varags Class Types for {@link Method}'s constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Method getMethod(Class<?> aClass, String aMethodName, Class<?>... aTypes) { - if (aClass == null || aMethodName == null || aMethodName.length() <= 0) { - return null; - } - String aMethodKey = ArrayUtils.toString(aTypes); - //Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); - CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethodName + "." + aMethodKey); - if (y == null) { - Method u = getMethod_Internal(aClass, aMethodName, aTypes); - if (u != null) { - Logger.REFLECTION("Caching Method: "+aMethodName + "." + aMethodKey); - cacheMethod(aClass, u); - return u; - } else { - return null; - } - } else { - return y.get(); - } - } - - public static boolean isStaticMethod(Class<?> aClass, String aMethodName, Class<?>... aTypes) { - return isStaticMethod(ReflectionUtils.getMethod(aClass, aMethodName, aTypes)); - } - - public static boolean isStaticMethod(Method aMethod) { - if (aMethod != null && Modifier.isStatic(aMethod.getModifiers())) { - return true; - } - return false; - } - - - - /** - * Returns a cached {@link Field} object. - * @param aClass - Class containing the Method. - * @param aFieldName - Field name in {@link String} form. - * @return - Valid, non-final, {@link Field} object, or {@link null}. - */ - public static Field getField(final Class<?> aClass, final String aFieldName) { - if (aClass == null || aFieldName == null || aFieldName.length() <= 0) { - return null; - } - CachedField y = mCachedFields.get(aClass.getName()+"."+aFieldName); - if (y == null) { - Field u; - try { - u = getField_Internal(aClass, aFieldName); - if (u != null) { - Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getName()); - cacheField(aClass, u); - return u; - } - } catch (NoSuchFieldException e) { - } - return null; - - } else { - return y.get(); - } - } - - /** - * Returns a cached {@link Field} object. - * @param aInstance - {@link Object} to get the field instance from. - * @param aFieldName - Field name in {@link String} form. - * @return - Valid, non-final, {@link Field} object, or {@link null}. - */ - public static <T> T getField(final Object aInstance, final String aFieldName) { - try { - return (T) getField(aInstance.getClass(), aFieldName).get(aInstance); - } catch (IllegalArgumentException | IllegalAccessException e) { - return null; - } - } - - - - - /* - * Utility Functions - */ - - public static boolean doesClassExist(final String classname) { - return isClassPresent(classname); - } - - - /** - * Returns the class of the objects type parameter - * @param o - Object to examine paramters on - * @return - a Class<?> or null - */ - public static Class<?> getTypeOfGenericObject(Object o) { - Class<?> aTypeParam = findSuperClassParameterType(o, o.getClass(), 0); - if (aTypeParam == null) { - aTypeParam = findSubClassParameterType(o, o.getClass(), 0); - } - return aTypeParam; - } - - public static void makeFieldAccessible(final Field field) { - if (!Modifier.isPublic(field.getModifiers()) || - !Modifier.isPublic(field.getDeclaringClass().getModifiers())) - { - field.setAccessible(true); - } - } - - public static void makeMethodAccessible(final Method field) { - if (!Modifier.isPublic(field.getModifiers()) || - !Modifier.isPublic(field.getDeclaringClass().getModifiers())) - { - field.setAccessible(true); - } - } - - /** - * Get the method name for a depth in call stack. <br /> - * Utility function - * @param depth depth in the call stack (0 means current method, 1 means call method, ...) - * @return Method name - */ - public static String getMethodName(final int depth) { - final StackTraceElement[] ste = new Throwable().getStackTrace(); - //System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName()); - return ste[depth+1].getMethodName(); - } - - - /** - * - * @param aPackageName - The full {@link Package} name in {@link String} form. - * @return - {@link Boolean} object. True if loaded > 0 classes. - */ - public static boolean dynamicallyLoadClassesInPackage(String aPackageName) { - ClassLoader classLoader = ReflectionUtils.class.getClassLoader(); - int loaded = 0; - try { - ClassPath path = ClassPath.from(classLoader); - for (ClassPath.ClassInfo info : path.getTopLevelClassesRecursive(aPackageName)) { - Class<?> clazz = Class.forName(info.getName(), true, classLoader); - if (clazz != null) { - loaded++; - Logger.INFO("Found "+clazz.getCanonicalName()+". ["+loaded+"]"); - } - } - } catch (ClassNotFoundException | IOException e) { - - } - - return loaded > 0; - } - - - - public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { - Class<?> clazz; - if (object instanceof Class) { - clazz = (Class<?>) object; - } - else { - clazz = object.getClass(); - } - while (clazz != null) { - try { - final Field field = getField(clazz, fieldName); - if (field != null) { - setFieldValue_Internal(object, field, fieldValue); - return true; - } - } catch (final NoSuchFieldException e) { - Logger.REFLECTION("setField("+object.toString()+", "+fieldName+") failed."); - clazz = clazz.getSuperclass(); - } catch (final Exception e) { - Logger.REFLECTION("setField("+object.toString()+", "+fieldName+") failed."); - throw new IllegalStateException(e); - } - } - return false; - - - } - - public static boolean setField(final Object object, final Field field, final Object fieldValue) { - Class<?> clazz; - if (object instanceof Class) { - clazz = (Class<?>) object; - } - else { - clazz = object.getClass(); - } - while (clazz != null) { - try { - final Field field2 = getField(clazz, field.getName()); - if (field2 != null) { - setFieldValue_Internal(object, field, fieldValue); - return true; - } - } catch (final NoSuchFieldException e) { - Logger.REFLECTION("setField("+object.toString()+", "+field.getName()+") failed."); - clazz = clazz.getSuperclass(); - } catch (final Exception e) { - Logger.REFLECTION("setField("+object.toString()+", "+field.getName()+") failed."); - throw new IllegalStateException(e); - } - } - return false; - } - - - /** - * Allows to change the state of an immutable instance. Huh?!? - */ - public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) { - Field nameField = getField(clazz, fieldName); - try { - setFieldValue_Internal(clazz, nameField, newValue); - } - catch (Throwable t) { - t.printStackTrace(); - } - } - - @Deprecated - public static void setFinalStatic(Field field, Object newValue) throws Exception { - field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); - } - - - public static void setByte(Object clazz, String fieldName, byte newValue) throws Exception { - Field nameField = getField(clazz.getClass(), fieldName); - nameField.setAccessible(true); - int modifiers = nameField.getModifiers(); - Field modifierField = nameField.getClass().getDeclaredField("modifiers"); - modifiers = modifiers & ~Modifier.FINAL; - modifierField.setAccessible(true); - modifierField.setInt(nameField, modifiers); - //Utils.LOG_INFO("O-"+(byte) nameField.get(clazz) + " | "+newValue); - nameField.setByte(clazz, newValue); - //Utils.LOG_INFO("N-"+(byte) nameField.get(clazz)); - - /*final Field fieldA = getField(clazz.getClass(), fieldName); - fieldA.setAccessible(true); - fieldA.setByte(clazz, newValue);*/ - - } - - public static boolean invoke(Object objectInstance, String methodName, Class[] parameters, Object[] values){ - if (objectInstance == null || methodName == null || parameters == null || values == null){ - return false; - } - Class<?> mLocalClass = (objectInstance instanceof Class ? (Class<?>) objectInstance : objectInstance.getClass()); - Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+mLocalClass.getCanonicalName()+"."); - try { - Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters); - if (mInvokingMethod != null){ - return invoke(objectInstance, mInvokingMethod, values); - } - } - catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName()); - } - - Logger.REFLECTION("Invoke failed or did something wrong."); - return false; - } - - public static boolean invoke(Object objectInstance, Method method, Object[] values){ - if (method == null || values == null || (!ReflectionUtils.isStaticMethod(method) && objectInstance == null)){ - //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName()); - return false; - } - String methodName = method.getName(); - String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName(); - Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+"."); - try { - Method mInvokingMethod = method; - if (mInvokingMethod != null){ - Logger.REFLECTION(methodName+" was not null."); - if ((boolean) mInvokingMethod.invoke(objectInstance, values)){ - Logger.REFLECTION("Successfully invoked "+methodName+"."); - return true; - } - else { - Logger.REFLECTION("Invocation failed for "+methodName+"."); - } - } - } - catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname); - } - Logger.REFLECTION("Invoke failed or did something wrong."); - return false; - } - - public static boolean invokeVoid(Object objectInstance, Method method, Object[] values){ - if (method == null || values == null || (!ReflectionUtils.isStaticMethod(method) && objectInstance == null)){ - //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName()); - return false; - } - String methodName = method.getName(); - String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName(); - Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+"."); - try { - Method mInvokingMethod = method; - if (mInvokingMethod != null){ - Logger.REFLECTION(methodName+" was not null."); - mInvokingMethod.invoke(objectInstance, values); - Logger.REFLECTION("Successfully invoked "+methodName+"."); - return true; - } - } - catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname); - } - Logger.REFLECTION("Invoke failed or did something wrong."); - return false; - } - - public static boolean invokeVoid(Object objectInstance, String methodName, Class[] parameters, Object[] values){ - if (objectInstance == null || methodName == null || parameters == null || values == null){ - return false; - } - Class<?> mLocalClass = (objectInstance instanceof Class ? (Class<?>) objectInstance : objectInstance.getClass()); - Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+mLocalClass.getCanonicalName()+"."); - try { - Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters); - if (mInvokingMethod != null){ - Logger.REFLECTION(methodName+" was not null."); - mInvokingMethod.invoke(objectInstance, values); - Logger.REFLECTION("Successfully invoked "+methodName+"."); - return true; - } - else { - Logger.REFLECTION(methodName+" is null."); - } - } - catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName()); - } - - Logger.REFLECTION("Invoke failed or did something wrong."); - return false; - } - - - public static Object invokeNonBool(Object objectInstance, Method method, Object[] values){ - if ((!ReflectionUtils.isStaticMethod(method) && objectInstance == null) || method == null || values == null){ - return false; - } - String methodName = method.getName(); - String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName(); - Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+"."); - try { - return method.invoke(objectInstance, values); - } - catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname); - } - - Logger.REFLECTION("Invoke failed or did something wrong."); - return null; - } - - public static Object invokeNonBool(Object objectInstance, String methodName, Class[] parameters, Object[] values){ - if (objectInstance == null || methodName == null || parameters == null || values == null){ - return false; - } - Class<?> mLocalClass = (objectInstance instanceof Class ? (Class<?>) objectInstance : objectInstance.getClass()); - Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+mLocalClass.getCanonicalName()+"."); - try { - Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters); - if (mInvokingMethod != null){ - Logger.REFLECTION(methodName+" was not null."); - return mInvokingMethod.invoke(objectInstance, values); - } - else { - Logger.REFLECTION(methodName+" is null."); - } - } - catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName()); - } - - Logger.REFLECTION("Invoke failed or did something wrong."); - return null; - } - - - - - - - - - - - - - - - - - - - - - - /* - * Internal Magic that probably should not get exposed. - */ - - - - - - - - - - /* - * - * Below Code block is used for determining generic types associated with type<E> - * - */ - - - //https://xebia.com/blog/acessing-generic-types-at-runtime-in-java/ - //https://www.javacodegeeks.com/2013/12/advanced-java-generics-retreiving-generic-type-arguments.html - public static Class<?> findSuperClassParameterType(Object instance, Class<?> classOfInterest, int parameterIndex) { - Class<?> subClass = instance.getClass(); - while (classOfInterest != subClass.getSuperclass()) { - // instance.getClass() is no subclass of classOfInterest or instance is a direct instance of classOfInterest - subClass = subClass.getSuperclass(); - if (subClass == null) { - return null; - } - } - ParameterizedType parameterizedType = (ParameterizedType) subClass.getGenericSuperclass(); - Class<?> aReturn; - aReturn = (Class<?>) parameterizedType.getActualTypeArguments()[parameterIndex]; - return aReturn; - } - - public static Class<?> findSubClassParameterType(Object instance, Class<?> classOfInterest, int parameterIndex) { - Map<Type, Type> typeMap = new HashMap<Type, Type>(); - Class<?> instanceClass = instance.getClass(); - while (classOfInterest != instanceClass.getSuperclass()) { - extractTypeArguments(typeMap, instanceClass); - instanceClass = instanceClass.getSuperclass(); - if (instanceClass == null) { - return null; - } - } - - ParameterizedType parameterizedType = (ParameterizedType) instanceClass.getGenericSuperclass(); - Type actualType = parameterizedType.getActualTypeArguments()[parameterIndex]; - if (typeMap.containsKey(actualType)) { - actualType = typeMap.get(actualType); - } - if (actualType instanceof Class) { - return (Class<?>) actualType; - } else if (actualType instanceof TypeVariable) { - return browseNestedTypes(instance, (TypeVariable<?>) actualType); - } else { - return null; - } - } - - private static void extractTypeArguments(Map<Type, Type> typeMap, Class<?> clazz) { - Type genericSuperclass = clazz.getGenericSuperclass(); - if (!(genericSuperclass instanceof ParameterizedType)) { - return; - } - - ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass; - Type[] typeParameter = ((Class<?>) parameterizedType.getRawType()).getTypeParameters(); - Type[] actualTypeArgument = parameterizedType.getActualTypeArguments(); - for (int i = 0; i < typeParameter.length; i++) { - if(typeMap.containsKey(actualTypeArgument[i])) { - actualTypeArgument[i] = typeMap.get(actualTypeArgument[i]); - } - typeMap.put(typeParameter[i], actualTypeArgument[i]); - } - } - - private static Class<?> browseNestedTypes(Object instance, TypeVariable<?> actualType) { - Class<?> instanceClass = instance.getClass(); - List<Class<?>> nestedOuterTypes = new LinkedList<Class<?>>(); - for (Class<?> enclosingClass = instanceClass - .getEnclosingClass(); enclosingClass != null; enclosingClass = enclosingClass.getEnclosingClass()) { - try { - Field this$0 = instanceClass.getDeclaredField("this$0"); - Object outerInstance = this$0.get(instance); - Class<?> outerClass = outerInstance.getClass(); - nestedOuterTypes.add(outerClass); - Map<Type, Type> outerTypeMap = new HashMap<Type, Type>(); - extractTypeArguments(outerTypeMap, outerClass); - for (Map.Entry<Type, Type> entry : outerTypeMap.entrySet()) { - if (!(entry.getKey() instanceof TypeVariable)) { - continue; - } - TypeVariable<?> foundType = (TypeVariable<?>) entry.getKey(); - if (foundType.getName().equals(actualType.getName()) - && isInnerClass(foundType.getGenericDeclaration(), actualType.getGenericDeclaration())) { - if (entry.getValue() instanceof Class) { - return (Class<?>) entry.getValue(); - } - actualType = (TypeVariable<?>) entry.getValue(); - } - } - } catch (NoSuchFieldException | IllegalAccessException e) { - - } - - } - return null; - } - - private static boolean isInnerClass(GenericDeclaration outerDeclaration, GenericDeclaration innerDeclaration) { - if (!(outerDeclaration instanceof Class) || !(innerDeclaration instanceof Class)) { - return false; - } - Class<?> outerClass = (Class<?>) outerDeclaration; - Class<?> innerClass = (Class<?>) innerDeclaration; - while ((innerClass = innerClass.getEnclosingClass()) != null) { - if (innerClass == outerClass) { - return true; - } - } - return false; - } - - - /* - * - * End of Generics Block - * - */ - - - - private static Field getField_Internal(final Class<?> clazz, final String fieldName) throws NoSuchFieldException { - try { - Logger.REFLECTION("Field: Internal Lookup: "+fieldName); - Field k = clazz.getDeclaredField(fieldName); - makeFieldAccessible(k); - //Logger.REFLECTION("Got Field from Class. "+fieldName+" did exist within "+clazz.getCanonicalName()+"."); - return k; - } catch (final NoSuchFieldException e) { - Logger.REFLECTION("Field: Internal Lookup Failed: "+fieldName); - final Class<?> superClass = clazz.getSuperclass(); - if (superClass == null) { - Logger.REFLECTION("Unable to find field '"+fieldName+"'"); - //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+"."); - throw e; - } - Logger.REFLECTION("Method: Recursion Lookup: "+fieldName+" - Checking in "+superClass.getName()); - //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+". Trying super class."); - return getField_Internal(superClass, fieldName); - } - } - - /** - * 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. - */ - private static boolean isClassPresent(final String className) { - try { - Class.forName(className); - return true; - } catch (final Throwable ex) { - // Class or one of its dependencies is not present... - return false; - } - } - - @Deprecated - public static Method getMethodViaReflection(final Class<?> lookupClass, final String methodName, - final boolean invoke) throws Exception { - final Class<? extends Class> lookup = lookupClass.getClass(); - final Method m = lookup.getDeclaredMethod(methodName); - m.setAccessible(true);// Abracadabra - if (invoke) { - m.invoke(lookup);// now its OK - } - return m; - } - - private static Method getMethod_Internal(Class<?> aClass, String aMethodName, Class<?>... aTypes) { - Method m = null; - try { - Logger.REFLECTION("Method: Internal Lookup: "+aMethodName); - m = aClass.getDeclaredMethod(aMethodName, aTypes); - if (m != null) { - m.setAccessible(true); - int modifiers = m.getModifiers(); - Field modifierField = m.getClass().getDeclaredField("modifiers"); - modifiers = modifiers & ~Modifier.FINAL; - modifierField.setAccessible(true); - modifierField.setInt(m, modifiers); - } - } - catch (Throwable t) { - Logger.REFLECTION("Method: Internal Lookup Failed: "+aMethodName); - try { - m = getMethodRecursively(aClass, aMethodName); - } catch (NoSuchMethodException e) { - Logger.REFLECTION("Unable to find method '"+aMethodName+"'"); - e.printStackTrace(); - dumpClassInfo(aClass); - } - } - return m; - } - - private static Constructor<?> getConstructor_Internal(Class<?> aClass, Class<?>... aTypes) { - Constructor<?> c = null; - try { - Logger.REFLECTION("Constructor: Internal Lookup: "+aClass.getName()); - c = aClass.getDeclaredConstructor(aTypes); - if (c != null) { - c.setAccessible(true); - int modifiers = c.getModifiers(); - Field modifierField = c.getClass().getDeclaredField("modifiers"); - modifiers = modifiers & ~Modifier.FINAL; - modifierField.setAccessible(true); - modifierField.setInt(c, modifiers); - } - } - catch (Throwable t) { - Logger.REFLECTION("Constructor: Internal Lookup Failed: "+aClass.getName()); - try { - c = getConstructorRecursively(aClass, aTypes); - } catch (Exception e) { - Logger.REFLECTION("Unable to find method '"+aClass.getName()+"'"); - e.printStackTrace(); - dumpClassInfo(aClass); - } - } - return c; - } - - private static Constructor<?> getConstructorRecursively(Class<?> aClass, Class<?>... aTypes) throws Exception { - try { - Logger.REFLECTION("Constructor: Recursion Lookup: "+aClass.getName()); - Constructor<?> c = aClass.getConstructor(aTypes); - if (c != null) { - c.setAccessible(true); - int modifiers = c.getModifiers(); - Field modifierField = c.getClass().getDeclaredField("modifiers"); - modifiers = modifiers & ~Modifier.FINAL; - modifierField.setAccessible(true); - modifierField.setInt(c, modifiers); - } - return c; - } catch (final NoSuchMethodException | IllegalArgumentException | IllegalAccessException e) { - final Class<?> superClass = aClass.getSuperclass(); - if (superClass == null || superClass == Object.class) { - throw e; - } - return getConstructor_Internal(superClass, aTypes); - } - } - - private static Method getMethodRecursively(final Class<?> clazz, final String aMethodName) throws NoSuchMethodException { - try { - Logger.REFLECTION("Method: Recursion Lookup: "+aMethodName); - Method k = clazz.getDeclaredMethod(aMethodName); - makeMethodAccessible(k); - return k; - } catch (final NoSuchMethodException e) { - final Class<?> superClass = clazz.getSuperclass(); - if (superClass == null || superClass == Object.class) { - throw e; - } - return getMethod_Internal(superClass, aMethodName); - } - } - - private static void dumpClassInfo(Class<?> aClass) { - Logger.INFO("We ran into an error processing reflection in "+aClass.getName()+", dumping all data for debugging."); - // Get the methods - Method[] methods = aClass.getDeclaredMethods(); - Field[] fields = aClass.getDeclaredFields(); - Constructor[] consts = aClass.getDeclaredConstructors(); - - Logger.INFO("Dumping all Methods."); - for (Method method : methods) { - System.out.println(method.getName()+" | "+StringUtils.getDataStringFromArray(method.getParameterTypes())); - } - Logger.INFO("Dumping all Fields."); - for (Field f : fields) { - System.out.println(f.getName()); - } - Logger.INFO("Dumping all Constructors."); - for (Constructor<?> c : consts) { - System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes())); - } - } - - private static Class<?> getNonPublicClass(final String className) { - Class<?> c = null; - try { - c = Class.forName(className); - } catch (final ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // full package name --------^^^^^^^^^^ - // or simpler without Class.forName: - // Class<package1.A> c = package1.A.class; - - if (null != c) { - // In our case we need to use - Constructor<?> constructor = null; - try { - constructor = c.getDeclaredConstructor(); - } catch (NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // note: getConstructor() can return only public constructors - // so we needed to search for any Declared constructor - - // now we need to make this constructor accessible - if (null != constructor) { - constructor.setAccessible(true);// ABRACADABRA! - - try { - final Object o = constructor.newInstance(); - return (Class<?>) o; - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - return null; - } - - private static Class<?> getClass_Internal(String string) { - Class<?> aClass = null; - if (ReflectionUtils.doesClassExist(string)) { - try { - aClass = Class.forName(string); - } - catch (ClassNotFoundException e) { - aClass = getNonPublicClass(string); - } - } - - if (aClass == null) { - String aClassName = ""; - Logger.REFLECTION("Splitting "+string+" to try look for hidden classes."); - String[] aData = string.split("\\."); - Logger.REFLECTION("Obtained "+aData.length+" pieces."); - for (int i=0;i<(aData.length-1);i++) { - aClassName += (i > 0) ? "."+aData[i] : ""+aData[i]; - Logger.REFLECTION("Building: "+aClassName); - } - if (aClassName != null && aClassName.length() > 0) { - Logger.REFLECTION("Trying to search '"+aClassName+"' for inner classes."); - Class<?> clazz = ReflectionUtils.getClass(aClassName); - if (clazz != null) { - Class[] y = clazz.getDeclaredClasses(); - if (y == null || y.length <= 0) { - Logger.REFLECTION("No hidden inner classes found."); - return null; - } - else { - boolean found = false; - for (Class<?> h : y) { - Logger.REFLECTION("Found hidden inner class: "+h.getCanonicalName()); - if (h.getSimpleName().toLowerCase().equals(aData[aData.length-1].toLowerCase())) { - Logger.REFLECTION("Found correct class. ["+aData[aData.length-1]+"] Caching at correct location: "+string); - Logger.REFLECTION("Found at location: "+h.getCanonicalName()); - ReflectionUtils.mCachedClasses.put(string, h); - aClass = h; - found = true; - break; - } - } - if (!found) { - return null; - } - } - } - else { - return null; - } - } - else { - return null; - } - } - return aClass; - } - - /** - * - * Set the value of a field reflectively. - */ - private static void setFieldValue_Internal(Object owner, Field field, Object value) throws Exception { - makeModifiable(field); - field.set(owner, value); - } - - /** - * Force the field to be modifiable and accessible. - */ - private static void makeModifiable(Field nameField) throws Exception { - nameField.setAccessible(true); - Field modifiers = getField(Field.class, "modifiers"); - modifiers.setAccessible(true); - modifiers.setInt(nameField, nameField.getModifiers() & ~Modifier.FINAL); - } - - - public static boolean doesFieldExist(String clazz, String string) { - return doesFieldExist(ReflectionUtils.getClass(clazz), string); - } - - public static boolean doesFieldExist(Class<?> clazz, String string) { - if (clazz != null) { - if (ReflectionUtils.getField(clazz, string) != null) { - return true; - } - } - return false; - } - - public static Object getFieldValue(Field field) { - return getFieldValue(field, null); - } - - public static Object getFieldValue(Field field, Object instance) { - try { - return field.get(instance); - } catch (IllegalArgumentException | IllegalAccessException e) { - } - return null; - } - - public static <T> T createNewInstanceFromConstructor(Constructor aConstructor, Object[] aArgs) { - T aInstance; - try { - aInstance = (T) aConstructor.newInstance(aArgs); - if (aInstance != null) { - return aInstance; - } - } - catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - -} diff --git a/src/Java/gtPlusPlus/core/util/sys/KeyboardUtils.java b/src/Java/gtPlusPlus/core/util/sys/KeyboardUtils.java deleted file mode 100644 index ea87677ee2..0000000000 --- a/src/Java/gtPlusPlus/core/util/sys/KeyboardUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -package gtPlusPlus.core.util.sys; - -import org.lwjgl.input.Keyboard; - -import net.minecraft.client.Minecraft; - -public class KeyboardUtils { - - public static boolean isCtrlKeyDown(){ - try { - if (!Keyboard.isCreated()) { - return false; - } - // prioritize CONTROL, but allow OPTION as well on Mac (note: GuiScreen's isCtrlKeyDown only checks for the OPTION key on Mac) - boolean isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL); - if (!isCtrlKeyDown && Minecraft.isRunningOnMac) - isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA); - - return isCtrlKeyDown; - } - catch (Throwable t) { - return false; - } - } - - public static boolean isShiftKeyDown(){ - try { - if (!Keyboard.isCreated()) { - return false; - } - return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); - } - catch (Throwable t) { - return false; - } - - } - -} diff --git a/src/Java/gtPlusPlus/core/util/sys/Log.java b/src/Java/gtPlusPlus/core/util/sys/Log.java deleted file mode 100644 index fcd4f34c1b..0000000000 --- a/src/Java/gtPlusPlus/core/util/sys/Log.java +++ /dev/null @@ -1,24 +0,0 @@ -package gtPlusPlus.core.util.sys; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public final class Log { - public static final Logger LOGGER = LogManager.getLogger("MiscUtils"); - - public static void warn(final String msg) { - LOGGER.warn(msg); - } - - public static void error(final String msg) { - LOGGER.error(msg); - } - - public static void info(final String msg) { - LOGGER.info(msg); - } - - public static void debug(final String msg) { - LOGGER.debug(msg); - } -} diff --git a/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java b/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java deleted file mode 100644 index 2788ba688e..0000000000 --- a/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -package gtPlusPlus.core.util.sys; - -public class SystemUtils { - - private static OS SystemType; - - public static OS getOS(){ - if (SystemType != null){ - return SystemType; - } - else { - SystemType = getOperatingSystem(); - return SystemType; - } - } - - /** - * Try invoke the runtime's Garbage Collector. - */ - public static void invokeGC() { - try { - Runtime r = Runtime.getRuntime(); - r.gc(); - } - catch (Throwable t) { - //Do nothing. - } - } - - public static boolean isWindows() { - return (getOSString().indexOf("win") >= 0); - } - - public static boolean isMac() { - return (getOSString().indexOf("mac") >= 0); - } - - public static boolean isUnix() { - return (getOSString().indexOf("nix") >= 0 || getOSString().indexOf("nux") >= 0 || getOSString().indexOf("aix") > 0 ); - } - - public static boolean isSolaris() { - return (getOSString().indexOf("sunos") >= 0); - } - - public static String getOSString(){ - try { - return System.getProperty("os.name").toLowerCase(); - } - catch (Throwable t){ - return "other"; - } - } - - public static OS getOperatingSystem(){ - if (isMac()){ - return OS.MAC; - } - else if (isWindows()){ - return OS.WINDOWS; - } - else if (isUnix()){ - return OS.UNIX; - } - else if (isSolaris()){ - return OS.SOLARIS; - } - else { - return OS.OTHER; - } - } - - public static enum OS { - MAC(1), - WINDOWS(2), - UNIX(3), - SOLARIS(4), - OTHER(0); - - private int mID; - private OS (final int ID){ - this.mID = ID; - } - - public int getID() { - return this.mID; - } - } - -} |