diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-02-28 20:06:01 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-02-28 20:06:01 +0000 |
commit | 4f435ae75b176a9d90c7afa6b1ff40e9ba9c286a (patch) | |
tree | f9707c4551b6134030374580cacfd1aec4b0c9d7 /src | |
parent | 1c20e21e7678f9a546fff9bf873c80c35a841cf8 (diff) | |
download | GT5-Unofficial-4f435ae75b176a9d90c7afa6b1ff40e9ba9c286a.tar.gz GT5-Unofficial-4f435ae75b176a9d90c7afa6b1ff40e9ba9c286a.tar.bz2 GT5-Unofficial-4f435ae75b176a9d90c7afa6b1ff40e9ba9c286a.zip |
+ Added a new debug tool.
+ Added support for Crops++.
+ Added Custom Crops & framework to support more in future.
+ Added basic support for all GT++ Materials within Tinkers Construct. [WIP]
+ Moderately bad attempt at generating custom Plasma Cooling recipes in the Adv. Vacuum Freezer. [WIP #424]
% Reworked logic for Material.java handling Durability, Tool Quality & Harvest Level.
% Adjusted frequency of structural checks on the Cyclotron, Now 100x less frequent.
% Cleaned up ReflectionUtils.java and made all getters cache their results, for much faster access.
% Attempted to adjust logic of FFPP, but I probably broke it. [WIP]
% Moved static array of Element Names from IonParticles.java -> ELEMENT.java.
$ Greatly improved reflective performance across the mod.
Diffstat (limited to 'src')
76 files changed, 1470 insertions, 598 deletions
diff --git a/src/Java/gregtech/api/util/FishPondFakeRecipe.java b/src/Java/gregtech/api/util/FishPondFakeRecipe.java index 9e0a65a6cc..5d74329135 100644 --- a/src/Java/gregtech/api/util/FishPondFakeRecipe.java +++ b/src/Java/gregtech/api/util/FishPondFakeRecipe.java @@ -27,7 +27,7 @@ public class FishPondFakeRecipe { junk = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "junk").get(null); treasure = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "treasure").get(null); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + catch (IllegalArgumentException | IllegalAccessException e) { Logger.INFO("Error generating Fish Pond Recipes. [1]"); e.printStackTrace(); } @@ -46,7 +46,7 @@ public class FishPondFakeRecipe { ItemStack t = (ItemStack) ReflectionUtils.getField(WeightedRandomFishable.class, "field_150711_b").get(u); addNewFishPondLoot(mType, new ItemStack[]{t}, new int[] {10000}); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e1) { + catch (IllegalArgumentException | IllegalAccessException e1) { Logger.INFO("Error generating Fish Pond Recipes. [2]"); e1.printStackTrace(); } diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index 2e3133c343..5c3d5fb801 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -301,6 +301,9 @@ public class GTplusplus implements ActionListener { if (CORE.RA.addMultiblockCentrifugeRecipe(x.mInputs, x.mFluidInputs, x.mFluidOutputs, x.mOutputs, x.mChances, x.mDuration, x.mEUt, x.mSpecialValue)) { mValidCount[0]++; } + else { + mInvalidCount[0]++; + } } else { Logger.INFO("[Recipe] Error generating Large Centrifuge recipe."); @@ -329,6 +332,9 @@ public class GTplusplus implements ActionListener { if (CORE.RA.addMultiblockElectrolyzerRecipe(x.mInputs, x.mFluidInputs, x.mFluidOutputs, x.mOutputs, x.mChances, x.mDuration, x.mEUt, x.mSpecialValue)) { mValidCount[1]++; } + else { + mInvalidCount[1]++; + } } else { Logger.INFO("[Recipe] Error generating Large Electrolyzer recipe."); @@ -370,11 +376,19 @@ public class GTplusplus implements ActionListener { mValidCount[2]++; } } + else { + mInvalidCount[2]++; + } } else { mInvalidCount[2]++; } } + + //Redo plasma recipes in Adv. Vac. + //Meta_GT_Proxy.generatePlasmaRecipesForAdvVacFreezer(); + + String[] machineName = new String[] {"Centrifuge", "Electrolyzer", "Vacuum Freezer"}; for (int i=0;i<3;i++) { Logger.INFO("[Recipe] Generated "+mValidCount[i]+" recipes for the Industrial "+machineName[i]+". The original machine can process "+mOriginalCount[i]+" recipes, meaning "+mInvalidCount[i]+" are invalid for this Multiblock's processing in some way."); diff --git a/src/Java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java b/src/Java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java index bbaa7ef008..a5e5f8b245 100644 --- a/src/Java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java +++ b/src/Java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java @@ -72,7 +72,7 @@ extends WorldGen_GT_Australia { Field temp = ReflectionUtils.getField(GregTech_API.class, "sBlockStones"); tempBlock = temp.get(null); } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {} + catch (IllegalArgumentException | IllegalAccessException e) {} mStoneTypes = (Block) tempBlock; } else { diff --git a/src/Java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/Java/gtPlusPlus/core/block/base/BlockBaseOre.java index 4d7478dbdd..e1bc3462be 100644 --- a/src/Java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/Java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -113,7 +113,7 @@ public class BlockBaseOre extends BasicBlock implements ITexturedBlock { hiddenTextureArray = new IIconContainer[6]; } } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { hiddenTextureArray = new IIconContainer[6]; } } @@ -216,7 +216,7 @@ public class BlockBaseOre extends BasicBlock implements ITexturedBlock { hiddenTextureArray = new IIconContainer[6]; } } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { hiddenTextureArray = new IIconContainer[6]; } } diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java b/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java index eecc379290..fdb6b1a0a8 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java @@ -133,34 +133,24 @@ public class Machine_ProjectTable extends BlockContainer implements ITileTooltip } @Optional.Method(modid = "EnderIO") - private static boolean checkEnderIOWrench(final ItemStack item){ - if (ReflectionUtils.doesClassExist("crazypants.enderio.api.tool.ITool")){ + private static boolean checkEnderIOWrench(final ItemStack item) { + if (ReflectionUtils.doesClassExist("crazypants.enderio.api.tool.ITool")) { Class<?> wrenchClass; - try { - wrenchClass = Class.forName("crazypants.enderio.api.tool.ITool"); - if (wrenchClass.isInstance(item.getItem())){ - return true; - } - } - catch (final ClassNotFoundException e1) { - return false; + wrenchClass = ReflectionUtils.getClass("crazypants.enderio.api.tool.ITool"); + if (wrenchClass.isInstance(item.getItem())) { + return true; } } return false; } @Optional.Method(modid = "Buildcraft") - private static boolean checkBuildcraftWrench(final ItemStack item){ - if (ReflectionUtils.doesClassExist("buildcraft.api.tools.IToolWrench")){ + private static boolean checkBuildcraftWrench(final ItemStack item) { + if (ReflectionUtils.doesClassExist("buildcraft.api.tools.IToolWrench")) { Class<?> wrenchClass; - try { - wrenchClass = Class.forName("buildcraft.api.tools.IToolWrench"); - if (wrenchClass.isInstance(item.getItem())){ - return true; - } - } - catch (final ClassNotFoundException e1) { - return false; + wrenchClass = ReflectionUtils.getClass("buildcraft.api.tools.IToolWrench"); + if (wrenchClass.isInstance(item.getItem())) { + return true; } } return false; diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java b/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java index 675aeaaf2b..5c08612042 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java @@ -121,34 +121,24 @@ public class Machine_Workbench extends BlockContainer } @Optional.Method(modid = "EnderIO") - private static boolean checkEnderIOWrench(final ItemStack item){ - if (ReflectionUtils.doesClassExist("crazypants.enderio.api.tool.ITool")){ + private static boolean checkEnderIOWrench(final ItemStack item) { + if (ReflectionUtils.doesClassExist("crazypants.enderio.api.tool.ITool")) { Class<?> wrenchClass; - try { - wrenchClass = Class.forName("crazypants.enderio.api.tool.ITool"); - if (wrenchClass.isInstance(item.getItem())){ - return true; - } - } - catch (final ClassNotFoundException e1) { - return false; + wrenchClass = ReflectionUtils.getClass("crazypants.enderio.api.tool.ITool"); + if (wrenchClass.isInstance(item.getItem())) { + return true; } } return false; } @Optional.Method(modid = "Buildcraft") - private static boolean checkBuildcraftWrench(final ItemStack item){ - if (ReflectionUtils.doesClassExist("buildcraft.api.tools.IToolWrench")){ + private static boolean checkBuildcraftWrench(final ItemStack item) { + if (ReflectionUtils.doesClassExist("buildcraft.api.tools.IToolWrench")) { Class<?> wrenchClass; - try { - wrenchClass = Class.forName("buildcraft.api.tools.IToolWrench"); - if (wrenchClass.isInstance(item.getItem())){ - return true; - } - } - catch (final ClassNotFoundException e1) { - return false; + wrenchClass = ReflectionUtils.getClass("buildcraft.api.tools.IToolWrench"); + if (wrenchClass.isInstance(item.getItem())) { + return true; } } return false; diff --git a/src/Java/gtPlusPlus/core/client/renderer/RenderGiantChicken.java b/src/Java/gtPlusPlus/core/client/renderer/RenderGiantChicken.java index 59621ef830..bc00db7ed1 100644 --- a/src/Java/gtPlusPlus/core/client/renderer/RenderGiantChicken.java +++ b/src/Java/gtPlusPlus/core/client/renderer/RenderGiantChicken.java @@ -21,7 +21,7 @@ public class RenderGiantChicken extends RenderChicken { try { mChicken = (ResourceLocation) ReflectionUtils.getField(RenderGiantChicken.class, "chickenTextures").get(null); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + catch (IllegalArgumentException | IllegalAccessException e) { mChicken = new ResourceLocation("textures/entity/chicken.png"); } chickenTexturesEx = mChicken; diff --git a/src/Java/gtPlusPlus/core/common/CommonProxy.java b/src/Java/gtPlusPlus/core/common/CommonProxy.java index 140019f73b..03b643abdb 100644 --- a/src/Java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/Java/gtPlusPlus/core/common/CommonProxy.java @@ -82,7 +82,7 @@ public class CommonProxy { ModBlocks.init(); CI.preInit(); - COMPAT_IntermodStaging.preInit(); + COMPAT_IntermodStaging.preInit(e); BookHandler.run(); // Registration of entities and renderers Logger.INFO("[Proxy] Calling Entity registrator."); @@ -152,7 +152,7 @@ public class CommonProxy { // Compat Handling COMPAT_HANDLER.registerMyModsOreDictEntries(); COMPAT_HANDLER.intermodOreDictionarySupport(); - COMPAT_IntermodStaging.init(); + COMPAT_IntermodStaging.init(e); } public void postInit(final FMLPostInitializationEvent e) { @@ -170,7 +170,7 @@ public class CommonProxy { COMPAT_HANDLER.RemoveRecipesFromOtherMods(); COMPAT_HANDLER.InitialiseHandlerThenAddRecipes(); COMPAT_HANDLER.startLoadingGregAPIBasedRecipes(); - COMPAT_IntermodStaging.postInit(); + COMPAT_IntermodStaging.postInit(e); COMPAT_HANDLER.runQueuedRecipes(); } diff --git a/src/Java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java b/src/Java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java index bdc239b9ce..f6f397f59e 100644 --- a/src/Java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java +++ b/src/Java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java @@ -363,18 +363,15 @@ public class EntityStaballoyConstruct extends EntityIronGolem { } //Get a private field from a super class if it exists. - try { - if (mFirstUpdateField == null) { - mFirstUpdateField = ReflectionUtils.getField(Class.forName("net.minecraft.entity.Entity"), "firstUpdate"); - } - if (mFirstUpdateField != null && mReflectFirstUpdate == true){ - try { - this.mReflectFirstUpdate = (boolean) mFirstUpdateField.get(this); - } - catch (IllegalArgumentException | IllegalAccessException e) {} + if (mFirstUpdateField == null) { + mFirstUpdateField = ReflectionUtils.getField(this.getClass(), "firstUpdate"); + } + if (mFirstUpdateField != null && mReflectFirstUpdate == true){ + try { + this.mReflectFirstUpdate = (boolean) mFirstUpdateField.get(this); } + catch (IllegalArgumentException | IllegalAccessException e) {} } - catch (NoSuchFieldException | ClassNotFoundException e) {} } super.onEntityUpdate(); } diff --git a/src/Java/gtPlusPlus/core/gui/item/GuiBaseGrindle.java b/src/Java/gtPlusPlus/core/gui/item/GuiBaseGrindle.java index f4669bfe35..ed347e8d30 100644 --- a/src/Java/gtPlusPlus/core/gui/item/GuiBaseGrindle.java +++ b/src/Java/gtPlusPlus/core/gui/item/GuiBaseGrindle.java @@ -331,7 +331,7 @@ public class GuiBaseGrindle extends GuiContainer { try { r = (ResourceLocation) ReflectionUtils.getField(GuiScreenBook.class, "bookGuiTextures").get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { r = new ResourceLocation("textures/gui/book.png"); } mBookTexture = r; diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java index 7a3a01b27c..8a1f7c3fe9 100644 --- a/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java +++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java @@ -16,6 +16,7 @@ import com.google.common.collect.Lists; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiOptionButton; import net.minecraft.client.gui.GuiResourcePackAvailable; @@ -145,9 +146,9 @@ public class GUI_ScrollTest extends GuiScreen try { - Class<?> oclass = Class.forName("java.awt.Desktop"); - Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]); - oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {file1.toURI()}); + Class<?> oclass = ReflectionUtils.getClass("java.awt.Desktop"); + Object object = ReflectionUtils.getMethod(oclass, "getDesktop", new Class[0]).invoke((Object)null, new Object[0]); + ReflectionUtils.getMethod(oclass, "browse", new Class[] {URI.class}).invoke(object, new Object[] {file1.toURI()}); } catch (Throwable throwable) { diff --git a/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java b/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java index 79a2d2a6c0..0f689325a3 100644 --- a/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java +++ b/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java @@ -1,6 +1,10 @@ package gtPlusPlus.core.handler; +import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import gtPlusPlus.xmod.bartcrops.HANDLER_CropsPlusPlus; import gtPlusPlus.xmod.bop.HANDLER_BiomesOPlenty; import gtPlusPlus.xmod.computronics.HANDLER_Computronics; import gtPlusPlus.xmod.forestry.HANDLER_FR; @@ -15,7 +19,7 @@ import gtPlusPlus.xmod.tinkers.HANDLER_Tinkers; public class COMPAT_IntermodStaging { - public static void preInit(){ + public static void preInit(FMLPreInitializationEvent preinit){ HANDLER_GT.preInit(); HANDLER_GC.preInit(); HANDLER_TF.preInit(); @@ -28,9 +32,10 @@ public class COMPAT_IntermodStaging { HANDLER_Tinkers.preInit(); HANDLER_SC2.preInit(); HANDLER_GalactiCraft.preInit(); + HANDLER_CropsPlusPlus.preInit(preinit); } - public static void init(){ + public static void init(FMLInitializationEvent init){ HANDLER_GT.init(); HANDLER_GC.init(); HANDLER_TF.init(); @@ -43,9 +48,10 @@ public class COMPAT_IntermodStaging { HANDLER_Tinkers.init(); HANDLER_SC2.init(); HANDLER_GalactiCraft.init(); + HANDLER_CropsPlusPlus.init(init); } - public static void postInit(){ + public static void postInit(FMLPostInitializationEvent postinit){ HANDLER_GT.postInit(); HANDLER_GC.postInit(); HANDLER_TF.postInit(); @@ -58,6 +64,7 @@ public class COMPAT_IntermodStaging { HANDLER_Tinkers.postInit(); HANDLER_SC2.postInit(); HANDLER_GalactiCraft.postInit(); + HANDLER_CropsPlusPlus.postInit(postinit); } public static void onLoadComplete(FMLLoadCompleteEvent event) { diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index 8d7db4f40a..17aaf5e106 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -61,6 +61,7 @@ import gtPlusPlus.core.item.general.throwables.ItemHydrofluoricAcidPotion; import gtPlusPlus.core.item.general.throwables.ItemSulfuricAcidPotion; import gtPlusPlus.core.item.init.ItemsFoods; import gtPlusPlus.core.item.materials.DustDecayable; +import gtPlusPlus.core.item.tool.misc.DebugScanner; import gtPlusPlus.core.item.tool.misc.GregtechPump; import gtPlusPlus.core.item.tool.misc.SandstoneHammer; import gtPlusPlus.core.item.tool.misc.box.AutoLunchBox; @@ -87,6 +88,7 @@ import gtPlusPlus.core.util.data.StringUtils; import gtPlusPlus.core.util.debug.DEBUG_INIT; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.everglades.GTplusplus_Everglades; import gtPlusPlus.xmod.eio.material.MaterialEIO; import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechItems; @@ -328,6 +330,8 @@ public final class ModItems { public static BatteryPackBaseBauble itemChargePack3; public static BatteryPackBaseBauble itemChargePack4; + public static Item itemDebugScanner; + static { Logger.INFO("Items!"); //Default item used when recipes fail, handy for debugging. Let's make sure they exist when this class is called upon. @@ -336,6 +340,9 @@ public final class ModItems { } public static final void init(){ + + itemDebugScanner = new DebugScanner().setTextureName(CORE.MODID + ":itemStickyRubber"); + itemAlkalusDisk = new BaseItemDamageable("itemAlkalusDisk", AddToCreativeTab.tabMisc, 1, 0, "Unknown Use", EnumRarity.rare, EnumChatFormatting.AQUA, false, null); itemBigEgg = new ItemGiantEgg("itemBigEgg", "Ginourmous Chicken Egg", tabMisc, 64, 0, "I had best try disassemble this.. for science!", "fuelLargeChickenEgg", 5000, 0).setTextureName(CORE.MODID + ":itemBigEgg"); itemGenericToken = new ItemGenericToken(); @@ -1002,7 +1009,7 @@ public final class ModItems { //Baubles Mod Test try { - final Class<?> baublesTest = Class.forName("baubles.api.IBauble"); + final Class<?> baublesTest = ReflectionUtils.getClass("baubles.api.IBauble"); if (baublesTest != null){ COMPAT_Baubles.run(); } diff --git a/src/Java/gtPlusPlus/core/item/chemistry/IonParticles.java b/src/Java/gtPlusPlus/core/item/chemistry/IonParticles.java index 517a698e80..e08a509436 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/IonParticles.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/IonParticles.java @@ -6,6 +6,7 @@ import java.util.List; import gregtech.api.enums.Materials; import gtPlusPlus.core.item.base.misc.BaseItemParticle; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ELEMENT; import gtPlusPlus.core.util.Utils; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; @@ -22,18 +23,16 @@ public class IonParticles extends BaseItemParticle { public IonParticles() { - super("Ion", aElements.length, EnumRarity.rare); + super("Ion", ELEMENT.NAMES.length, EnumRarity.rare); } - private static final String[] aElements = new String[]{"Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminum", "Silicon", "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttrium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Cesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum", "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium", "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Nihonium", "Flerovium", "Moscovium", "Livermorium", "Tennessine", "Oganesson"}; - - public static IIcon[] overlays = new IIcon[aElements.length]; + public static IIcon[] overlays = new IIcon[ELEMENT.NAMES.length]; public static IIcon baseTexture; static { //Generate Ions int key = 0; - for (String s : aElements) { + for (String s : ELEMENT.NAMES) { //Map names to Meta NameToMetaMap.put(Utils.sanitizeString(s.toLowerCase()), key); MetaToNameMap.put(key, Utils.sanitizeString(s.toLowerCase())); @@ -62,7 +61,7 @@ public class IonParticles extends BaseItemParticle { @Override public String getUnlocalizedName(final ItemStack itemStack) { - return "item.particle.ion" + "." + aElements[itemStack.getItemDamage()]; + return "item.particle.ion" + "." + ELEMENT.NAMES[itemStack.getItemDamage()]; } private static boolean createNBT(ItemStack rStack){ diff --git a/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java b/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java index 7f6a52f135..2f49ac1287 100644 --- a/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java +++ b/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java @@ -27,6 +27,7 @@ import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.handler.BookHandler; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; public class ItemBaseBook extends ItemWritableBook{ @@ -113,11 +114,11 @@ public class ItemBaseBook extends ItemWritableBook{ if (player.worldObj.isRemote){ try { - Class<?> clazz = Class.forName("net.minecraft.client.gui.GuiScreenBook"); + Class<?> clazz = ReflectionUtils.getClass("net.minecraft.client.gui.GuiScreenBook"); Constructor<?> ctor = clazz.getConstructor(EntityPlayer.class, ItemStack.class, boolean.class); Object object = ctor.newInstance(new Object[] { player, bookstack, false }); Minecraft.getMinecraft().displayGuiScreen((GuiScreen) object); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } diff --git a/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java b/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java index 592b68d06a..a95fab4b6c 100644 --- a/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java +++ b/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java @@ -21,6 +21,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.NBTUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; public class ItemEntityCatcher extends Item implements IEntityCatcher { @@ -117,14 +118,10 @@ public class ItemEntityCatcher extends Item implements IEntityCatcher { } Class<? extends Entity> mEntityClass; String mClassName; - mClassName = NBTUtils.getString(aStack,"mClassName"); - try { - mEntityClass = (Class<? extends Entity>) Class.forName(mClassName); - if (mEntityClass != null) { - return mEntityClass; - } - } - catch (ClassNotFoundException e) { + mClassName = NBTUtils.getString(aStack, "mClassName"); + mEntityClass = (Class<? extends Entity>) ReflectionUtils.getClass(mClassName); + if (mEntityClass != null) { + return mEntityClass; } return null; } diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/DebugScanner.java b/src/Java/gtPlusPlus/core/item/tool/misc/DebugScanner.java new file mode 100644 index 0000000000..bc252c95a9 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/misc/DebugScanner.java @@ -0,0 +1,98 @@ +package gtPlusPlus.core.item.tool.misc; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class DebugScanner extends CoreItem { + + public DebugScanner() { + super("gtpp.debug.scanner", AddToCreativeTab.tabTools, 1, 0, + new String[] { + "Used to obtain information from GT/GT++ content", + "Right Click to use", + }, + EnumRarity.epic); + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int p_77648_4_, + int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { + // TODO Auto-generated method stub + return super.onItemUse(aStack, aPlayer, aWorld, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, + p_77648_9_, p_77648_10_); + } + + @Override + public boolean isRepairable() { + return false; + } + + @Override + public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { + // TODO Auto-generated method stub + return super.onItemRightClick(p_77659_1_, p_77659_2_, p_77659_3_); + } + + @Override + public float getDigSpeed(ItemStack itemstack, Block block, int metadata) { + return 0f; + } + + @Override + public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { + if (entity != null && player != null) { + PlayerUtils.messagePlayer(player, "Entity ID: "+entity.getEntityId()); + PlayerUtils.messagePlayer(player, "UUID: "+entity.getUniqueID()); + PlayerUtils.messagePlayer(player, "Invulnerable? "+entity.isEntityInvulnerable()); + PlayerUtils.messagePlayer(player, "Invisible? "+entity.isInvisible()); + PlayerUtils.messagePlayer(player, "Age: "+entity.ticksExisted); + + if (entity instanceof EntityLiving) { + EntityLiving g = (EntityLiving) entity; + PlayerUtils.messagePlayer(player, "Health: "+g.getHealth()+"/"+g.getMaxHealth()); + PlayerUtils.messagePlayer(player, "On ground? "+g.onGround); + PlayerUtils.messagePlayer(player, "Can Loot? "+g.canPickUpLoot()); + PlayerUtils.messagePlayer(player, "Child? "+g.isChild()); + if (entity instanceof EntityPlayer) { + EntityPlayer y = (EntityPlayer) entity; + PlayerUtils.messagePlayer(player, "Experience: "+y.experience); + PlayerUtils.messagePlayer(player, "Name: "+y.getCommandSenderName()); + } + + } + + } + return true; + } + + @Override + public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) { + return false; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return true; + } + + @Override + public int getHarvestLevel(ItemStack stack, String toolClass) { + return 0; + } + + + +} diff --git a/src/Java/gtPlusPlus/core/lib/CORE.java b/src/Java/gtPlusPlus/core/lib/CORE.java index c7d09b959d..1f82e1cd17 100644 --- a/src/Java/gtPlusPlus/core/lib/CORE.java +++ b/src/Java/gtPlusPlus/core/lib/CORE.java @@ -52,7 +52,7 @@ public class CORE { public static final String name = "GT++"; public static final String MODID = "miscutils"; - public static final String VERSION = "1.7.02.24"; + public static final String VERSION = "1.7.02.89-debug"; public static String MASTER_VERSION = NetworkUtils.getContentFromURL("https://raw.githubusercontent.com/draknyte1/GTplusplus/master/Recommended.txt").toLowerCase(); public static String USER_COUNTRY = GeoUtils.determineUsersCountry(); public static boolean isModUpToDate = Utils.isModUpToDate(); diff --git a/src/Java/gtPlusPlus/core/lib/LoadedMods.java b/src/Java/gtPlusPlus/core/lib/LoadedMods.java index e749885dd6..5a2b75337b 100644 --- a/src/Java/gtPlusPlus/core/lib/LoadedMods.java +++ b/src/Java/gtPlusPlus/core/lib/LoadedMods.java @@ -54,6 +54,7 @@ public class LoadedMods { public static boolean StevesCarts = false; public static boolean Witchery = false; public static boolean Waila = false; + public static boolean CropsPlusPlus = false; //Barts Crop Mod @@ -96,6 +97,11 @@ public class LoadedMods { Logger.INFO("Components enabled for: PlayerAPI"); totalMods++; } + if (Loader.isModLoaded("berriespp")) { + CropsPlusPlus = true; + Logger.INFO("Components enabled for: Crops++"); + totalMods++; + } if (Loader.isModLoaded("TConstruct")){ TiCon = true; Logger.INFO("Components enabled for: Tinkers Construct"); diff --git a/src/Java/gtPlusPlus/core/material/ELEMENT.java b/src/Java/gtPlusPlus/core/material/ELEMENT.java index 99bc37444e..62e1163a39 100644 --- a/src/Java/gtPlusPlus/core/material/ELEMENT.java +++ b/src/Java/gtPlusPlus/core/material/ELEMENT.java @@ -11,6 +11,8 @@ import gtPlusPlus.core.util.minecraft.MaterialUtils; public final class ELEMENT { + public static final String[] NAMES = new String[]{"Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminum", "Silicon", "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttrium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Cesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum", "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium", "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Nihonium", "Flerovium", "Moscovium", "Livermorium", "Tennessine", "Oganesson"}; + //First 50 Elements public final Material HYDROGEN = MaterialUtils.generateMaterialFromGtENUM(Materials.Hydrogen); public final Material HELIUM = MaterialUtils.generateMaterialFromGtENUM(Materials.Helium); @@ -148,8 +150,8 @@ public final class ELEMENT { public final Material AMERICIUM241 = new Material("Americium-241", MaterialState.SOLID, TextureSets.NUCLEAR.get(), Materials.Americium.mDurability, Materials.Americium.mRGBa, Materials.Americium.mMeltingPoint, Materials.Americium.mBlastFurnaceTemp, 95, 146, false, StringUtils.superscript("241Am"), 2, false);//Not a GT Inherited Material public final Material MAGIC = MaterialUtils.generateMaterialFromGtENUM(Materials.Magic, new short[] {10, 185, 140}); - public final Material THAUMIUM = MaterialUtils.generateMaterialFromGtENUM(Materials.Thaumium); - + public final Material THAUMIUM = MaterialUtils.generateMaterialFromGtENUM(Materials.Thaumium); + static { Logger.MATERIALS("Initialising Base Elements."); } diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index 03e50aa7dd..d996bed128 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -1,6 +1,7 @@ package gtPlusPlus.core.material; import static gregtech.api.enums.GT_Values.M; +import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt; import java.util.ArrayList; import java.util.HashMap; @@ -317,28 +318,13 @@ public class Material { this.vDurability = durability; } else { - if (inputs != null){ - long durabilityTemp = 0; - int counterTemp = 0; - for (final MaterialStack m : inputs){ - if (m.getStackMaterial() != null){ - if (m.getStackMaterial().vDurability != 0){ - durabilityTemp = (durabilityTemp+m.getStackMaterial().vDurability); - counterTemp++; - - } - } + long aTempDura = 0; + for (MaterialStack g : this.getComposites()) { + if (g != null) { + aTempDura += safeCast_LongToInt(g.getStackMaterial().getMass() * 2000); } - if ((durabilityTemp != 0) && (counterTemp != 0)){ - this.vDurability = (durabilityTemp/counterTemp); - } - else { - this.vDurability = 8196; - } - } - else { - this.vDurability = 0; } + this.vDurability = aTempDura > 0 ? aTempDura : (this.getComposites().isEmpty() ? 51200 : 32000 * this.getComposites().size()); } if ((this.vDurability >= 0) && (this.vDurability < 64000)){ @@ -362,8 +348,8 @@ public class Material { this.vHarvestLevel = 4; } else { - this.vToolQuality = 0; - this.vHarvestLevel = 0; + this.vToolQuality = 1; + this.vHarvestLevel = 1; } //Sets the Rad level diff --git a/src/Java/gtPlusPlus/core/recipe/RECIPES_GREGTECH.java b/src/Java/gtPlusPlus/core/recipe/RECIPES_GREGTECH.java index 6f4e8870d7..6210f9726c 100644 --- a/src/Java/gtPlusPlus/core/recipe/RECIPES_GREGTECH.java +++ b/src/Java/gtPlusPlus/core/recipe/RECIPES_GREGTECH.java @@ -1607,6 +1607,8 @@ public class RECIPES_GREGTECH { ItemUtils.getItemStackOfAmountFromOreDict("plateMeatRaw", 1)); GT_ModHandler.addCompressionRecipe(ItemUtils.getItemStackOfAmountFromOreDict("dustMeatRaw", 9), ItemUtils.getItemStackOfAmountFromOreDict("blockMeatRaw", 1)); + + CORE.RA.addCompressorRecipe(ItemList.FusionComputer_UV.get(9), GregtechItemList.Compressed_Fusion_Reactor.get(1), (int) GT_Values.V[7], (int) GT_Values.V[8]); } private static void macerationRecipes() { diff --git a/src/Java/gtPlusPlus/core/slots/SlotToolBox.java b/src/Java/gtPlusPlus/core/slots/SlotToolBox.java index c6d025fd21..87967b75b5 100644 --- a/src/Java/gtPlusPlus/core/slots/SlotToolBox.java +++ b/src/Java/gtPlusPlus/core/slots/SlotToolBox.java @@ -18,34 +18,34 @@ public class SlotToolBox extends SlotGtTool { Class temp; //IHL Pumps - temp = ReflectionUtils.getClassByName("ihl.handpump.IHLHandPump"); + temp = ReflectionUtils.getClass("ihl.handpump.IHLHandPump"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; } //IC2 Electrics - temp = ReflectionUtils.getClassByName("ic2.api.item.IElectricItem"); + temp = ReflectionUtils.getClass("ic2.api.item.IElectricItem"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; } //IC2 Boxables - temp = ReflectionUtils.getClassByName(" ic2.api.item.IBoxable"); + temp = ReflectionUtils.getClass(" ic2.api.item.IBoxable"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; } //Tinkers Tools - temp = ReflectionUtils.getClassByName("tconstruct.library.tools.Weapon"); + temp = ReflectionUtils.getClass("tconstruct.library.tools.Weapon"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; } //BattleGear Weapons - temp = ReflectionUtils.getClassByName("mods.battlegear2.api.weapons.IBattlegearWeapon"); + temp = ReflectionUtils.getClass("mods.battlegear2.api.weapons.IBattlegearWeapon"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; @@ -55,7 +55,7 @@ public class SlotToolBox extends SlotGtTool { //OpenMods String[] OpenModsContent = new String[] {"openblocks.common.item.ItemDevNull", "openblocks.common.item.ItemHangGlider", "openblocks.common.item.ItemWrench", "openblocks.common.item.ItemSleepingBag"}; for (String t : OpenModsContent) { - temp = ReflectionUtils.getClassByName(t); + temp = ReflectionUtils.getClass(t); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; @@ -63,7 +63,7 @@ public class SlotToolBox extends SlotGtTool { } //GC Wrench - temp = ReflectionUtils.getClassByName("micdoodle8.mods.galacticraft.core.items.ItemUniversalWrench"); + temp = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.items.ItemUniversalWrench"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; @@ -72,7 +72,7 @@ public class SlotToolBox extends SlotGtTool { //EIO String[] EioContent = new String[] {"crazypants.enderio.api.tool.ITool", "crazypants.enderio.item.ItemMagnet", "crazypants.enderio.item.ItemConduitProbe"}; for (String t : EioContent) { - temp = ReflectionUtils.getClassByName(t); + temp = ReflectionUtils.getClass(t); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; @@ -80,7 +80,7 @@ public class SlotToolBox extends SlotGtTool { } //Forestry - temp = ReflectionUtils.getClassByName("forestry.core.items.ItemForestryTool"); + temp = ReflectionUtils.getClass("forestry.core.items.ItemForestryTool"); if (temp != null) { mSupportedCustomTools.put(temp); temp = null; diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index 81e2e94154..7d1d42abf0 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -798,7 +798,7 @@ public class Utils { return new Pair<Integer, Integer>(9, 28); } - clazz = (Class<GT_Mod>) Class.forName("gregtech.GT_Mod"); + clazz = (Class<GT_Mod>) ReflectionUtils.getClass("gregtech.GT_Mod"); Field mSubversion = ReflectionUtils.getField(clazz, "SUBVERSION"); if (mSubversion != null){ int mSub = 0; diff --git a/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java index a1c2bf6104..9f5d4f36ca 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java @@ -13,7 +13,7 @@ public class FoodUtils { public static final Class IEdibleClass; static { - IEdibleClass = ReflectionUtils.getClassByName("squeek.applecore.api.food.IEdible"); + IEdibleClass = ReflectionUtils.getClass("squeek.applecore.api.food.IEdible"); } public static boolean isFood(ItemStack food) { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java index 45d21a3016..842b8eecb2 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java @@ -322,7 +322,7 @@ public class MaterialUtils { mName = (String) ReflectionUtils.getField(Materials.class, "mName").get(mat); } } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + catch (IllegalArgumentException | IllegalAccessException e) { } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java index e7ced98f5a..080b5665a3 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/MiningUtils.java @@ -152,7 +152,7 @@ public class MiningUtils { try { aTextWorldGen = (String) ReflectionUtils.getField(GT_Worldgen_GT_Ore_Layer.class, "aTextWorldgen").get(h); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { aTextWorldGen = h.mWorldGenName; } @@ -180,27 +180,27 @@ public class MiningUtils { boolean aEndAsteroids; try { - if (Class.forName("micdoodle8.mods.galacticraft.core.util.ConfigManagerCore") != null && mMoonID == -99) { - mMoonID = ReflectionUtils.getField(Class.forName("micdoodle8.mods.galacticraft.core.util.ConfigManagerCore"), "idDimensionMoon").getInt(null); + 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 (ClassNotFoundException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {} + catch (IllegalArgumentException | IllegalAccessException e) {} //Gets Mars ID try { - if (Class.forName("micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars") != null && mMarsID == -99) { - mMarsID = ReflectionUtils.getField(Class.forName("micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars"), "dimensionIDMars").getInt(null); + 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 (ClassNotFoundException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {} + catch (IllegalArgumentException | IllegalAccessException e) {} //Get Comets ID try { - if (Class.forName("micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids") != null && mCometsID == -99) { - mCometsID = ReflectionUtils.getField(Class.forName("micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids"), "dimensionIDAsteroids").getInt(null); + 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 (ClassNotFoundException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {} + catch (IllegalArgumentException | IllegalAccessException e) {} //Clear Cache Ores_Overworld.clear(); @@ -215,7 +215,7 @@ public class MiningUtils { try { aEndAsteroids = ReflectionUtils.getField(GT_Worldgen_GT_Ore_Layer.class, "mEndAsteroid").getBoolean(x); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + catch (IllegalArgumentException | IllegalAccessException e) { aEndAsteroids = false; } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java index dde785cee6..aeeb4ae5be 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java @@ -39,7 +39,7 @@ public class PollutionUtils { return mPollution.getBoolean(GT_Pollution); } } - } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { } return false; } @@ -53,16 +53,16 @@ public class PollutionUtils { if (mAddPollution != null) { mAddPollution.invoke(null, te, pollutionValue); } - Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); + Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); if (GT_Pollution != null) { - Method addPollution = GT_Pollution.getMethod("addPollution", IGregTechTileEntity.class, int.class); + Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "addPollution", IGregTechTileEntity.class, int.class); if (addPollution != null) { mAddPollution = addPollution; addPollution.invoke(null, te, pollutionValue); return true; } } - } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return false; @@ -92,16 +92,16 @@ public class PollutionUtils { mAddPollution2.invoke(null, aChunk, pollutionValue); return true; } - Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); + Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); if (GT_Pollution != null) { - Method addPollution = GT_Pollution.getMethod("addPollution", Chunk.class, int.class); + Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "addPollution", Chunk.class, int.class); if (addPollution != null) { mAddPollution2 = addPollution; mAddPollution2.invoke(null, aChunk, pollutionValue); return true; } } - } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return false; @@ -128,15 +128,15 @@ public class PollutionUtils { if (mGetPollution != null) { mGetPollution.invoke(null, te); } - Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); + Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); if (GT_Pollution != null) { - Method addPollution = GT_Pollution.getMethod("getPollution", IGregTechTileEntity.class); + Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "getPollution", IGregTechTileEntity.class); if (addPollution != null) { mGetPollution = addPollution; return (int) addPollution.invoke(null, te); } } - } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return 0; @@ -151,15 +151,15 @@ public class PollutionUtils { if (mGetPollution2 != null) { mGetPollution2.invoke(null, te); } - Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); + Class<?> GT_Pollution = ReflectionUtils.getClass("gregtech.common.GT_Pollution"); if (GT_Pollution != null) { - Method addPollution = GT_Pollution.getMethod("getPollution", Chunk.class); + Method addPollution = ReflectionUtils.getMethod(GT_Pollution, "getPollution", Chunk.class); if (addPollution != null) { mGetPollution2 = addPollution; return (int) addPollution.invoke(null, te); } } - } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return 0; diff --git a/src/Java/gtPlusPlus/core/util/reflect/ClientProxyFinder.java b/src/Java/gtPlusPlus/core/util/reflect/ClientProxyFinder.java deleted file mode 100644 index 99a9bf2fa9..0000000000 --- a/src/Java/gtPlusPlus/core/util/reflect/ClientProxyFinder.java +++ /dev/null @@ -1,32 +0,0 @@ -package gtPlusPlus.core.util.reflect; - -import java.lang.reflect.Field; - -import cpw.mods.fml.common.SidedProxy; - -public class ClientProxyFinder { - - public static Object getInstance(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 = Class.forName(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/ProxyFinder.java b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java index 85599e4695..d22fafb37b 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java @@ -12,7 +12,7 @@ public class ProxyFinder { final SidedProxy sidedProxy = field.getAnnotation(SidedProxy.class); final Object fieldValue = field.get(modInstance); try { - final Class<?> serverSideClass = Class.forName(sidedProxy.serverSide()); + 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 @@ -35,7 +35,7 @@ public class ProxyFinder { final SidedProxy sidedProxy = field.getAnnotation(SidedProxy.class); final Object fieldValue = field.get(modInstance); try { - final Class<?> clientSideClass = Class.forName(sidedProxy.clientSide()); + 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 diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index dee9d76a4c..4ade8b1096 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -1,110 +1,216 @@ package gtPlusPlus.core.util.reflect; import java.io.IOException; -import java.lang.reflect.*; -import java.net.URL; -import java.util.HashSet; -import java.util.Scanner; - -import org.apache.commons.lang3.reflect.FieldUtils; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.LinkedHashMap; +import java.util.Map; import com.google.common.reflect.ClassPath; -import net.minecraft.client.Minecraft; - -import gregtech.GT_Mod; -import gtPlusPlus.GTplusplus; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; public class ReflectionUtils { - public static Field getField(final Class<?> clazz, final String fieldName) throws NoSuchFieldException { - try { - Field k = clazz.getDeclaredField(fieldName); - makeAccessible(k); - //Logger.REFLECTION("Got Field from Class. "+fieldName+" did exist within "+clazz.getCanonicalName()+"."); - return k; - } catch (final NoSuchFieldException e) { - final Class<?> superClass = clazz.getSuperclass(); - if (superClass == null) { - //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+"."); - throw e; - } - //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+". Trying super class."); - return getField(superClass, fieldName); + 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>(); + + 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; } + } - public static void makeAccessible(final Field field) { - if (!Modifier.isPublic(field.getModifiers()) || - !Modifier.isPublic(field.getDeclaringClass().getModifiers())) - { - field.setAccessible(true); + 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; } + } - //Some Reflection utils - http://stackoverflow.com/questions/14374878/using-reflection-to-set-an-object-property - @SuppressWarnings("unchecked") - public static <V> V getField(final Object object, final String fieldName) { - Class<?> clazz = object.getClass(); - while (clazz != null) { - try { - final Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - return (V) field.get(object); - } catch (final NoSuchFieldException e) { - Logger.REFLECTION("getField("+object.toString()+", "+fieldName+") failed."); - clazz = clazz.getSuperclass(); - } catch (final Exception e) { - Logger.REFLECTION("getField("+object.toString()+", "+fieldName+") failed."); - throw new IllegalStateException(e); + 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(Method aMethod) { + if (aMethod == null) { + return false; + } + boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); + CachedMethod y = mCachedMethods.get(aMethod.getName()+"."+aMethod.getParameterTypes().toString()); + if (y == null) { + mCachedMethods.put(aMethod.getName()+"."+aMethod.getParameterTypes().toString(), new CachedMethod(aMethod, isStatic)); + return true; + } + return false; + } + + private static boolean cacheField(Field aField) { + if (aField == null) { + return false; + } + boolean isStatic = Modifier.isStatic(aField.getModifiers()); + CachedField y = mCachedFields.get(aField.getName()); + if (y == null) { + mCachedFields.put(aField.getName(), new CachedField(aField, isStatic)); + return true; + } + return false; + } + + + /** + * 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) { + Class y = mCachedClasses.get(aClassCanonicalName); + if (y == null) { + y = getClass_Internal(aClassCanonicalName); + if (y != null) { + cacheClass(y); } } - return null; + return y; } - public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { - Class<?> clazz = object.getClass(); - while (clazz != null) { + + /** + * 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) { + String aMethodKey = aTypes.toString(); + CachedMethod y = mCachedMethods.get(aMethodName + "." + aMethodKey); + if (y == null) { + Method u = getMethod_Internal(aClass, aMethodKey, aTypes); + if (u != null) { + cacheMethod(u); + return u; + } else { + return null; + } + } else { + return y.get(); + } + } + + + + /** + * 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) { + CachedField y = mCachedFields.get(aFieldName); + if (y == null) { + Field u; try { - final Field field = getField(clazz, fieldName); - if (field != null) { - setValue(object, field, fieldValue); - return true; + u = getField_Internal(aClass, aFieldName); + if (u != null) { + cacheField(u); + return u; } - } 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); + } catch (NoSuchFieldException e) { } + return null; + + } else { + return y.get(); } - return false; } - - public static boolean becauseIWorkHard(){ - /* TODO: fix this stuff \u002a\u002f\u0066\u0069\u006e\u0061\u006c\u0020\u0048\u0061\u0073\u0068\u0053\u0065\u0074\u003c\u0053\u0074\u0072\u0069\u006e\u0067\u003e\u0020\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0048\u0061\u0073\u0068\u0053\u0065\u0074\u003c\u003e\u0028\u0029\u003b\u000a\u0009\u0009\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u0070\u0072\u006f\u0078\u0079\u0043\u006c\u0069\u0065\u006e\u0074\u0047\u0054\u003b\u0009\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000a\u0009\u0009\u0009\u0070\u0072\u006f\u0078\u0079\u0043\u006c\u0069\u0065\u006e\u0074\u0047\u0054\u0020\u003d\u0020\u0043\u006c\u0069\u0065\u006e\u0074\u0050\u0072\u006f\u0078\u0079\u0046\u0069\u006e\u0064\u0065\u0072\u002e\u0067\u0065\u0074\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0028\u0047\u0054\u005f\u004d\u006f\u0064\u002e\u0069\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0029\u003b\u0009\u0009\u0009\u0009\u000a\u0009\u0009\u007d\u0020\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0066\u0069\u006e\u0061\u006c\u0020\u0052\u0065\u0066\u006c\u0065\u0063\u0074\u0069\u0076\u0065\u004f\u0070\u0065\u0072\u0061\u0074\u0069\u006f\u006e\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0020\u0065\u0031\u0029\u0020\u007b\u000a\u0009\u0009\u0009\u0070\u0072\u006f\u0078\u0079\u0043\u006c\u0069\u0065\u006e\u0074\u0047\u0054\u0020\u003d\u0020\u006e\u0075\u006c\u006c\u003b\u000a\u0009\u0009\u0009Logger\u002eINFO\u0028\u0022\u0046\u0061\u0069\u006c\u0065\u0064\u0020\u006f\u0062\u0074\u0061\u0069\u006e\u0065\u0064\u0020\u0069\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0020\u006f\u0066\u0020\u0061\u0020\u0063\u006c\u0069\u0065\u006e\u0074\u0020\u0070\u0072\u006f\u0078\u0079\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0066\u0061\u006c\u0073\u0065\u003b\u000a\u0009\u0009\u007d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000a\u0009\u0009\u0009\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0020\u0074\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0028\u006e\u0065\u0077\u0020\u0055\u0052\u004c\u0028\u0022\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u0067\u0072\u0065\u0067\u0074\u0065\u0063\u0068\u002e\u006f\u0076\u0065\u0072\u006d\u0069\u006e\u0064\u0064\u006c\u0031\u002e\u0063\u006f\u006d\u002f\u0063\u006f\u006d\u002f\u0067\u0072\u0065\u0067\u006f\u0072\u0069\u0075\u0073\u0074\u002f\u0067\u0072\u0065\u0067\u0074\u0065\u0063\u0068\u002f\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0072\u006c\u0069\u0073\u0074\u002e\u0074\u0078\u0074\u0022\u0029\u002e\u006f\u0070\u0065\u006e\u0053\u0074\u0072\u0065\u0061\u006d\u0028\u0029\u0029\u003b\u000a\u0009\u0009\u0009Logger\u002eWARNING\u0028\u0022\u0054\u0072\u0079\u0069\u006e\u0067\u0020\u0074\u006f\u0020\u0062\u0075\u0069\u006c\u0064\u0020\u0061\u0020\u0048\u0061\u0073\u0068\u0053\u0065\u0074\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0077\u0068\u0069\u006c\u0065\u0020\u0028\u0074\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u002e\u0068\u0061\u0073\u004e\u0065\u0078\u0074\u004c\u0069\u006e\u0065\u0028\u0029\u0029\u0020\u007b\u000a\u0009\u0009\u0009\u0009\u0066\u0069\u006e\u0061\u006c\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0074\u004e\u0061\u006d\u0065\u0020\u003d\u0020\u0074\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u002e\u006e\u0065\u0078\u0074\u004c\u0069\u006e\u0065\u0028\u0029\u003b\u000a\u000a\u0009\u0009\u0009\u0009\u0069\u0066\u0020\u0028\u0021\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002e\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u0028\u0074\u004e\u0061\u006d\u0065\u002e\u0074\u006f\u004c\u006f\u0077\u0065\u0072\u0043\u0061\u0073\u0065\u0028\u0029\u0029\u0029\u0020\u007b\u000a\u0009\u0009\u0009\u0009\u0009\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002e\u0061\u0064\u0064\u0028\u0074\u004e\u0061\u006d\u0065\u002e\u0074\u006f\u004c\u006f\u0077\u0065\u0072\u0043\u0061\u0073\u0065\u0028\u0029\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u007d\u000a\u0009\u0009\u0009\u0009\u000a\u0009\u0009\u0009\u0009\u002f\u002f\u0041\u0064\u0064\u0020\u004d\u0079\u0073\u0065\u006c\u0066\u000a\u0009\u0009\u0009\u0009\u0069\u0066\u0020\u0028\u0021\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002e\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u0028\u0022\u0064\u0072\u0061\u006b\u006e\u0079\u0074\u0065\u0031\u0022\u0029\u0029\u0020\u007b\u000a\u0009\u0009\u0009\u0009\u0009Logger\u002eWARNING\u0028\u0022\u0041\u0064\u0064\u0065\u0064\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0076\u0061\u006c\u0075\u0065\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u0009\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002e\u0061\u0064\u0064\u0028\u0022\u0064\u0072\u0061\u006b\u006e\u0079\u0074\u0065\u0031\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u007d\u000a\u0009\u0009\u0009\u0009\u000a\u0009\u0009\u0009\u0009\u002f\u002f\u0041\u0064\u0064\u0020\u0074\u0068\u0065\u0020\u0063\u0061\u0070\u0065\u0064\u0020\u0074\u0065\u0073\u0074\u0020\u0068\u0065\u0072\u006f\u000a\u0009\u0009\u0009\u0009\u0069\u0066\u0020\u0028\u0043\u004f\u0052\u0045\u002e\u0044\u0045\u0056\u0045\u004e\u0056\u0029\u007b\u000a\u0009\u0009\u0009\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0064\u0065\u0076\u0050\u006c\u0061\u0079\u0065\u0072\u0020\u003d\u0020\u004d\u0069\u006e\u0065\u0063\u0072\u0061\u0066\u0074\u002e\u0067\u0065\u0074\u004d\u0069\u006e\u0065\u0063\u0072\u0061\u0066\u0074\u0028\u0029\u002e\u0067\u0065\u0074\u0053\u0065\u0073\u0073\u0069\u006f\u006e\u0028\u0029\u002e\u0067\u0065\u0074\u0055\u0073\u0065\u0072\u006e\u0061\u006d\u0065\u0028\u0029\u002e\u0074\u006f\u004c\u006f\u0077\u0065\u0072\u0043\u0061\u0073\u0065\u0028\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u0009\u0009Logger\u002eINFO\u0028\u0022\u0046\u006f\u0075\u006e\u0064\u0020\u0022\u002b\u0064\u0065\u0076\u0050\u006c\u0061\u0079\u0065\u0072\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0069\u0066\u0020\u0028\u0021\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002e\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u0028\u0064\u0065\u0076\u0050\u006c\u0061\u0079\u0065\u0072\u0029\u0029\u0020\u007b\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009Logger\u002eWARNING\u0028\u0022\u0041\u0064\u0064\u0065\u0064\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0076\u0061\u006c\u0075\u0065\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002e\u0061\u0064\u0064\u0028\u0064\u0065\u0076\u0050\u006c\u0061\u0079\u0065\u0072\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u007d\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0009\u000a\u0009\u0009\u0009\u0009\u0009\u007d\u0020\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0054\u0068\u0072\u006f\u0077\u0061\u0062\u006c\u0065\u0020\u0074\u0029\u007b\u000a\u0009\u0009\u0009\u0009\u0009\u0009Logger\u002eINFO\u0028\u0022\u0046\u0061\u0069\u006c\u0065\u0064\u0020\u0061\u0064\u0064\u0069\u006e\u0067\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0069\u006e\u0020\u0063\u0075\u0072\u0072\u0065\u006e\u0074\u0020\u0065\u006e\u0076\u0069\u0072\u006f\u006e\u006d\u0065\u006e\u0074\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0009\u0009\u007d\u000a\u0009\u0009\u0009\u0009\u007d\u000a\u000a\u0009\u0009\u0009\u007d\u000a\u0009\u0009\u0009\u0074\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u002e\u0063\u006c\u006f\u0073\u0065\u0028\u0029\u003b\u000a\u0009\u0009\u007d\u0020\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0066\u0069\u006e\u0061\u006c\u0020\u0054\u0068\u0072\u006f\u0077\u0061\u0062\u006c\u0065\u0020\u0065\u0029\u0020\u007b\u000a\u0009\u0009\u0009Logger\u002eWARNING\u0028\u0022\u0046\u0061\u0069\u006c\u0065\u0064\u0020\u0067\u0065\u0074\u0074\u0069\u006e\u0067\u0020\u0074\u0068\u0065\u0020\u0077\u0065\u0062\u0020\u006c\u0069\u0073\u0074\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0066\u0061\u006c\u0073\u0065\u003b\u0020\u0020\u0020\u0020\u0020\u0009\u000a\u0009\u0009\u007d\u0009\u0009\u000a\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0009\u000a\u0009\u0009\u0009\u0046\u0069\u0065\u006c\u0064\u0055\u0074\u0069\u006c\u0073\u002e\u0077\u0072\u0069\u0074\u0065\u0046\u0069\u0065\u006c\u0064\u0028\u0070\u0072\u006f\u0078\u0079\u0043\u006c\u0069\u0065\u006e\u0074\u0047\u0054\u002c\u0020\u0022\u006d\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u0022\u002c\u0020\u0078\u0043\u0061\u0070\u0065\u004c\u0069\u0073\u0074\u002c\u0020\u0074\u0072\u0075\u0065\u0029\u003b\u000a\u0009\u0009\u0009Logger\u002eWARNING\u0028\u0022\u0041\u0064\u0064\u0065\u0064\u0020\u006d\u006f\u0064\u0069\u0066\u0069\u0065\u0064\u0020\u0068\u0061\u0073\u0068\u0073\u0065\u0074\u0020\u0062\u0061\u0063\u006b\u0020\u0069\u006e\u0074\u006f\u0020\u0074\u0068\u0065\u0020\u0069\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u002e\u0022\u0029\u003b\u0020\u0020\u0009\u0009\u0009\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0074\u0072\u0075\u0065\u003b\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u000a\u0009\u0009\u007d\u0020\u0063\u0061\u0074\u0063\u0068\u0020\u0028\u0066\u0069\u006e\u0061\u006c\u0020\u0054\u0068\u0072\u006f\u0077\u0061\u0062\u006c\u0065\u0020\u0065\u0029\u0020\u007b\u000a\u0009\u0009\u0009Logger\u002eINFO\u0028\u0022\u0052\u0065\u0066\u006c\u0065\u0063\u0074\u0069\u006f\u006e\u0020\u0069\u006e\u0074\u006f\u0020\u0061\u0063\u0074\u0069\u0076\u0065\u0020\u0063\u006c\u0069\u0065\u006e\u0074\u0020\u0070\u0072\u006f\u0078\u0079\u0020\u0069\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u002e\u0022\u0029\u003b\u000a\u0009\u0009\u0009\u0065\u002e\u0070\u0072\u0069\u006e\u0074\u0053\u0074\u0061\u0063\u006b\u0054\u0072\u0061\u0063\u0065\u0028\u0029\u003b\u0020\u0020\u0020\u0020\u0020\u0020\u000a\u0009\u0009\u0009\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0066\u0061\u006c\u0073\u0065\u003b\u0020\u0020\u0009\u000a\u0009\u0009\u007d\u002f\u002a */ + + /** + * 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) { - boolean exists = true; - try { - // Load any class that should be present if driver's available - Class.forName(classname); - } catch (final ClassNotFoundException e) { - // Driver is not available - exists = false; + return isClassPresent(classname); + } + + 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); } - return exists; } /** * 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 + * @return Method name */ public static String getMethodName(final int depth) { final StackTraceElement[] ste = new Throwable().getStackTrace(); @@ -114,42 +220,60 @@ public class ReflectionUtils { /** - * Allows to change the state of an immutable instance. Huh?!? + * + * @param aPackageName - The full {@link Package} name in {@link String} form. + * @return - {@link Boolean} object. True if loaded > 0 classes. */ - public static void setFieldValue(Class<?> clazz, String fieldName, Object newValue) throws Exception { - Field nameField = getField(clazz, fieldName); - setValue(clazz, nameField, newValue); - } + 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) { - /** - * Allows to change the state of final statics. Huh?!? - */ - public static void setDefault(Class<?> clazz, String fieldName, Object newValue) throws Exception { - Field staticField = clazz.getDeclaredField(fieldName); - setValue(null, staticField, newValue); + } + + return loaded > 0; } + - /** - * - * Set the value of a field reflectively. - */ - protected static void setValue(Object owner, Field field, Object value) throws Exception { - makeModifiable(field); - field.set(owner, value); + public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { + Class<?> 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; } + /** - * Force the field to be modifiable and accessible. + * Allows to change the state of an immutable instance. Huh?!? */ - protected static void makeModifiable(Field nameField) throws Exception { - nameField.setAccessible(true); - int modifiers = nameField.getModifiers(); - Field modifierField = nameField.getClass().getDeclaredField("modifiers"); - modifiers = modifiers & ~Modifier.FINAL; - modifierField.setAccessible(true); - modifierField.setInt(nameField, modifiers); + public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) throws Exception { + Field nameField = getField(clazz, fieldName); + setFieldValue_Internal(clazz, nameField, newValue); } + @Deprecated public static void setFinalStatic(Field field, Object newValue) throws Exception { field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); @@ -258,13 +382,54 @@ public class ReflectionUtils { return null; } + + + + + + + + + + + + + + + + + + + + /* - * @ if (isPresent("com.optionaldependency.DependencyClass")) { // This - * block will never execute when the dependency is not present // There is + * Internal Magic that probably should not get exposed. + */ + + + private static Field getField_Internal(final Class<?> clazz, final String fieldName) throws NoSuchFieldException { + try { + 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) { + final Class<?> superClass = clazz.getSuperclass(); + if (superClass == null) { + //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+"."); + throw e; + } + //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. - * executeCodeLinkingToDependency(); } */ - public static boolean isPresent(final String className) { + private static boolean isClassPresent(final String className) { try { Class.forName(className); return true; @@ -274,7 +439,6 @@ public class ReflectionUtils { } } - @SuppressWarnings("rawtypes") @Deprecated public static Method getMethodViaReflection(final Class<?> lookupClass, final String methodName, final boolean invoke) throws Exception { @@ -287,14 +451,7 @@ public class ReflectionUtils { return m; } - /** - * Removes final modifier & returns a {@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. - */ - public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { + private static Method getMethod_Internal(Class aClass, String aMethodName, Class... aTypes) { Method m = null; try { m = aClass.getDeclaredMethod(aMethodName, aTypes); @@ -308,10 +465,15 @@ public class ReflectionUtils { } } catch (Throwable t) { + try { + m = getMethodRecursively(aClass, aMethodName); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } } return m; } - + public static Method getMethodRecursively(final Class<?> clazz, final String fieldName) throws NoSuchMethodException { try { Method k = clazz.getDeclaredMethod(fieldName); @@ -322,21 +484,11 @@ public class ReflectionUtils { if (superClass == null) { throw e; } - return getMethod(superClass, fieldName); - } - } - - public static void makeMethodAccessible(final Method field) { - if (!Modifier.isPublic(field.getModifiers()) || - !Modifier.isPublic(field.getDeclaringClass().getModifiers())) - { - field.setAccessible(true); + return getMethod_Internal(superClass, fieldName); } - } - - + } - public static Class<?> getNonPublicClass(final String className) { + private static Class<?> getNonPublicClass(final String className) { Class<?> c = null; try { c = Class.forName(className); @@ -377,7 +529,7 @@ public class ReflectionUtils { return null; } - public static Class<?> getClassByName(String string) { + private static Class<?> getClass_Internal(String string) { if (ReflectionUtils.doesClassExist(string)) { try { return Class.forName(string); @@ -389,23 +541,25 @@ public class ReflectionUtils { return null; } - public static boolean dynamicallyLoadClassesInPackage(String aPackageName) { - ClassLoader classLoader = GTplusplus.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) { - - } + /** + * + * 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); + } - return loaded > 0; + /** + * Force the field to be modifiable and accessible. + */ + private static void makeModifiable(Field nameField) throws Exception { + nameField.setAccessible(true); + int modifiers = nameField.getModifiers(); + Field modifierField = nameField.getClass().getDeclaredField("modifiers"); + modifiers = modifiers & ~Modifier.FINAL; + modifierField.setAccessible(true); + modifierField.setInt(nameField, modifiers); } diff --git a/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java b/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java index fe4897fd0d..140098ee06 100644 --- a/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java +++ b/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java @@ -72,7 +72,7 @@ extends WorldGen_GT { Field temp = ReflectionUtils.getField(GregTech_API.class, "sBlockStones"); tempBlock = temp.get(null); } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {} + catch (IllegalArgumentException | IllegalAccessException e) {} mStoneTypes = (Block) tempBlock; } else { diff --git a/src/Java/gtPlusPlus/nei/GT_NEI_MultiBlockHandler.java b/src/Java/gtPlusPlus/nei/GT_NEI_MultiBlockHandler.java index 88b6914ad2..6612ab703f 100644 --- a/src/Java/gtPlusPlus/nei/GT_NEI_MultiBlockHandler.java +++ b/src/Java/gtPlusPlus/nei/GT_NEI_MultiBlockHandler.java @@ -842,7 +842,7 @@ extends TemplateRecipeHandler { if (sFields[u] == null) { if (u==0) { for (Field f : GT_OreDictUnificator.class.getDeclaredFields()) { - ReflectionUtils.makeAccessible(f); + ReflectionUtils.makeFieldAccessible(f); if (f.getName().equalsIgnoreCase("sUnificationTable")) { hasLooked = true; } diff --git a/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java b/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java index 98e6d7ae1a..4dc5a15b4b 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java +++ b/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java @@ -169,15 +169,10 @@ public class EntityBaseVillager extends EntityVillager { */ protected float getField_82191_bN() { - Field v82191; + Field v82191 = ReflectionUtils.getField(getClass(), "field_82191_bN"); try { - v82191 = ReflectionUtils.getField(getClass(), "field_82191_bN"); - try { - return v82191 != null ? v82191.getFloat(this) : 0f; - } catch (IllegalArgumentException | IllegalAccessException e) { - return 0f; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? v82191.getFloat(this) : 0f; + } catch (IllegalArgumentException | IllegalAccessException e) { return 0f; } } @@ -190,15 +185,10 @@ public class EntityBaseVillager extends EntityVillager { } protected boolean getNeedsInitilization() { - Field v82191; + Field v82191 = ReflectionUtils.getField(EntityVillager.class, "needsInitilization"); try { - v82191 = ReflectionUtils.getField(EntityVillager.class, "needsInitilization"); - try { - return v82191 != null ? v82191.getBoolean(this) : false; - } catch (IllegalArgumentException | IllegalAccessException e) { - return false; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? v82191.getBoolean(this) : false; + } catch (IllegalArgumentException | IllegalAccessException e) { return false; } } @@ -213,20 +203,16 @@ public class EntityBaseVillager extends EntityVillager { protected MerchantRecipeList getBuyingList() { Field v82191; MerchantRecipeList o; + v82191 = ReflectionUtils.getField(getClass(), "buyingList"); try { - v82191 = ReflectionUtils.getField(getClass(), "buyingList"); - try { - o = (MerchantRecipeList) v82191.get(this); - Logger.WARNING("Is BuyingList Valid? "+(v82191 != null)); - return v82191 != null ? o : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - return null; - } - } catch (NoSuchFieldException e1) { - e1.printStackTrace(); + o = (MerchantRecipeList) v82191.get(this); + Logger.WARNING("Is BuyingList Valid? " + (v82191 != null)); + return v82191 != null ? o : null; + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); return null; } + } protected void setBuyingList(MerchantRecipeList f) { @@ -238,29 +224,19 @@ public class EntityBaseVillager extends EntityVillager { } protected Village getVillageObject() { - Field v82191; + Field v82191 = ReflectionUtils.getField(getClass(), "villageObj"); try { - v82191 = ReflectionUtils.getField(getClass(), "villageObj"); - try { - return v82191 != null ? (Village) v82191.get(this) : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - return null; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? (Village) v82191.get(this) : null; + } catch (IllegalArgumentException | IllegalAccessException e) { return null; } } protected String getLastBuyingPlayer() { - Field v82191; + Field v82191 = ReflectionUtils.getField(getClass(), "lastBuyingPlayer"); try { - v82191 = ReflectionUtils.getField(getClass(), "lastBuyingPlayer"); - try { - return v82191 != null ? (String) v82191.get(this) : ""; - } catch (IllegalArgumentException | IllegalAccessException e) { - return ""; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? (String) v82191.get(this) : ""; + } catch (IllegalArgumentException | IllegalAccessException e) { return ""; } } diff --git a/src/Java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java b/src/Java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java index 6e7234297e..967647cff6 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java +++ b/src/Java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java @@ -157,15 +157,10 @@ public class EntityNativeAustralian extends EntityVillager { */ protected float getField_82191_bN() { - Field v82191; + Field v82191 = ReflectionUtils.getField(getClass(), "field_82191_bN"); try { - v82191 = ReflectionUtils.getField(getClass(), "field_82191_bN"); - try { - return v82191 != null ? v82191.getFloat(this) : 0f; - } catch (IllegalArgumentException | IllegalAccessException e) { - return 0f; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? v82191.getFloat(this) : 0f; + } catch (IllegalArgumentException | IllegalAccessException e) { return 0f; } } @@ -178,15 +173,10 @@ public class EntityNativeAustralian extends EntityVillager { } protected boolean getNeedsInitilization() { - Field v82191; + Field v82191 = ReflectionUtils.getField(EntityVillager.class, "needsInitilization"); try { - v82191 = ReflectionUtils.getField(EntityVillager.class, "needsInitilization"); - try { - return v82191 != null ? v82191.getBoolean(this) : false; - } catch (IllegalArgumentException | IllegalAccessException e) { - return false; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? v82191.getBoolean(this) : false; + } catch (IllegalArgumentException | IllegalAccessException e) { return false; } } @@ -201,18 +191,13 @@ public class EntityNativeAustralian extends EntityVillager { protected MerchantRecipeList getBuyingList() { Field v82191; MerchantRecipeList o; + v82191 = ReflectionUtils.getField(getClass(), "buyingList"); try { - v82191 = ReflectionUtils.getField(getClass(), "buyingList"); - try { - o = (MerchantRecipeList) v82191.get(this); - Logger.WARNING("Is BuyingList Valid? "+(v82191 != null)); - return v82191 != null ? o : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - return null; - } - } catch (NoSuchFieldException e1) { - e1.printStackTrace(); + o = (MerchantRecipeList) v82191.get(this); + Logger.WARNING("Is BuyingList Valid? " + (v82191 != null)); + return v82191 != null ? o : null; + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); return null; } } @@ -226,29 +211,19 @@ public class EntityNativeAustralian extends EntityVillager { } protected Village getVillageObject() { - Field v82191; + Field v82191 = ReflectionUtils.getField(getClass(), "villageObj"); try { - v82191 = ReflectionUtils.getField(getClass(), "villageObj"); - try { - return v82191 != null ? (Village) v82191.get(this) : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - return null; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? (Village) v82191.get(this) : null; + } catch (IllegalArgumentException | IllegalAccessException e) { return null; } } protected String getLastBuyingPlayer() { - Field v82191; + Field v82191 = ReflectionUtils.getField(getClass(), "lastBuyingPlayer"); try { - v82191 = ReflectionUtils.getField(getClass(), "lastBuyingPlayer"); - try { - return v82191 != null ? (String) v82191.get(this) : ""; - } catch (IllegalArgumentException | IllegalAccessException e) { - return ""; - } - } catch (NoSuchFieldException e1) { + return v82191 != null ? (String) v82191.get(this) : ""; + } catch (IllegalArgumentException | IllegalAccessException e) { return ""; } } diff --git a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java index 232b6b6e87..45b8c9941b 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java +++ b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java @@ -221,7 +221,7 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { } } }*/ - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } } return false; diff --git a/src/Java/gtPlusPlus/preloader/Preloader_GT_OreDict.java b/src/Java/gtPlusPlus/preloader/Preloader_GT_OreDict.java index 2dcbe46056..8e7001903d 100644 --- a/src/Java/gtPlusPlus/preloader/Preloader_GT_OreDict.java +++ b/src/Java/gtPlusPlus/preloader/Preloader_GT_OreDict.java @@ -11,6 +11,7 @@ import gregtech.common.items.GT_MetaGenerated_Item_01; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; public class Preloader_GT_OreDict { @@ -33,9 +34,8 @@ public class Preloader_GT_OreDict { } } else { - try { - if (Class.forName("gregtech.common.items.GT_MetaGenerated_Item_03") != null) { // 6/11/12/14/16/20/30-57/69-73/79-96 - final Class<?> MetaItem03 = Class.forName("gregtech.common.items.GT_MetaGenerated_Item_03"); + if (ReflectionUtils.doesClassExist("gregtech.common.items.GT_MetaGenerated_Item_03")) { // 6/11/12/14/16/20/30-57/69-73/79-96 + final Class<?> MetaItem03 = ReflectionUtils.getClass("gregtech.common.items.GT_MetaGenerated_Item_03"); if (isInstanceOf(MetaItem03, bannedItem.getItem())) { if ((damageValue == 6) || (damageValue == 7) || (damageValue == 11) || (damageValue == 12) || (damageValue == 14) || (damageValue == 16) || (damageValue == 20) || (damageValue == 21) || (damageValue == 22)) { @@ -52,9 +52,6 @@ public class Preloader_GT_OreDict { } } } - } - catch (final ClassNotFoundException e) { - } } } } @@ -62,8 +59,8 @@ public class Preloader_GT_OreDict { //Mekanism Support - Let's not make Mek Osmium useful in GT anymore. if ((((bannedItem != null) && !LoadedMods.RedTech && (ItemUtils.getModId(bannedItem).toLowerCase().equals("mekanism"))) || (LoadedMods.Mekanism)) && !LoadedMods.RedTech){ //Circuits - if (Class.forName("mekanism.common.item.ItemControlCircuit") != null) { - final Class<?> MekCircuit = Class.forName("mekanism.common.item.ItemControlCircuit"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemControlCircuit")) { + final Class<?> MekCircuit = ReflectionUtils.getClass("mekanism.common.item.ItemControlCircuit"); if (isInstanceOf(MekCircuit, bannedItem.getItem())) { for (int r=0;r<4;r++){ if (bannedItem.getItemDamage() == r){ @@ -74,8 +71,8 @@ public class Preloader_GT_OreDict { } } //Ingots - if (Class.forName("mekanism.common.item.ItemIngot") != null) { - final Class<?> MekIngot = Class.forName("mekanism.common.item.ItemIngot"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemIngot")) { + final Class<?> MekIngot = ReflectionUtils.getClass("mekanism.common.item.ItemIngot"); if (isInstanceOf(MekIngot, bannedItem.getItem())) { if (bannedItem.getItemDamage() == 1){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); @@ -84,8 +81,8 @@ public class Preloader_GT_OreDict { } } //Dirty Dust - if (Class.forName("mekanism.common.item.ItemDirtyDust") != null) { - final Class<?> MekIngot = Class.forName("mekanism.common.item.ItemDirtyDust"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemDirtyDust")) { + final Class<?> MekIngot = ReflectionUtils.getClass("mekanism.common.item.ItemDirtyDust"); if (isInstanceOf(MekIngot, bannedItem.getItem())) { if (bannedItem.getItemDamage() == 2){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); @@ -94,8 +91,8 @@ public class Preloader_GT_OreDict { } } //Dust - if (Class.forName("mekanism.common.item.ItemDust") != null) { - final Class<?> MekIngot = Class.forName("mekanism.common.item.ItemDust"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemDust")) { + final Class<?> MekIngot = ReflectionUtils.getClass("mekanism.common.item.ItemDust"); if (isInstanceOf(MekIngot, bannedItem.getItem())) { if (bannedItem.getItemDamage() == 2){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); @@ -104,8 +101,8 @@ public class Preloader_GT_OreDict { } } //Crystal - if (Class.forName("mekanism.common.item.ItemCrystal") != null) { - final Class<?> MekIngot = Class.forName("mekanism.common.item.ItemCrystal"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemCrystal")) { + final Class<?> MekIngot = ReflectionUtils.getClass("mekanism.common.item.ItemCrystal"); if (isInstanceOf(MekIngot, bannedItem.getItem())) { if (bannedItem.getItemDamage() == 2){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); @@ -114,8 +111,8 @@ public class Preloader_GT_OreDict { } } //Shard - if (Class.forName("mekanism.common.item.ItemShard") != null) { - final Class<?> MekIngot = Class.forName("mekanism.common.item.ItemShard"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemShard")) { + final Class<?> MekIngot = ReflectionUtils.getClass("mekanism.common.item.ItemShard"); if (isInstanceOf(MekIngot, bannedItem.getItem())) { if (bannedItem.getItemDamage() == 2){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); @@ -124,8 +121,8 @@ public class Preloader_GT_OreDict { } } //Clump - if (Class.forName("mekanism.common.item.ItemClump") != null) { - final Class<?> MekIngot = Class.forName("mekanism.common.item.ItemClump"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemClump")) { + final Class<?> MekIngot = ReflectionUtils.getClass("mekanism.common.item.ItemClump"); if (isInstanceOf(MekIngot, bannedItem.getItem())) { if (bannedItem.getItemDamage() == 2){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); @@ -134,8 +131,8 @@ public class Preloader_GT_OreDict { } } //Ores - if (Class.forName("mekanism.common.item.ItemBlockOre") != null) { - final Class<?> MekOre = Class.forName("mekanism.common.item.ItemBlockOre"); + if (ReflectionUtils.doesClassExist("mekanism.common.item.ItemBlockOre")) { + final Class<?> MekOre = ReflectionUtils.getClass("mekanism.common.item.ItemBlockOre"); if (isInstanceOf(MekOre, bannedItem.getItem()) || (bannedItem == ItemUtils.simpleMetaStack("Mekanism:OreBlock", 0, 1))) { if (bannedItem.getItemDamage() == 0){ FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Removing %s from the OreDictionary to balance Mekanism.", bannedItem.getDisplayName()); diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java index 402a510a79..390289d162 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java @@ -204,7 +204,7 @@ public class Preloader_ClassTransformer2 { } return new ArrayList<ItemStack>(Arrays.asList(rStack)); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException a){ + catch (IllegalArgumentException | IllegalAccessException a){ Logger.REFLECTION("getDropsHack2"); a.printStackTrace(); } @@ -242,7 +242,7 @@ public class Preloader_ClassTransformer2 { Logger.INFO("Set NBT Tag Value to map."); } } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } @@ -360,7 +360,7 @@ public class Preloader_ClassTransformer2 { Logger.INFO("Returning Invalid NBT data"); } } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException a){ + catch (IllegalArgumentException | IllegalAccessException a){ Logger.REFLECTION("getDropsHack2"); a.printStackTrace(); } diff --git a/src/Java/gtPlusPlus/xmod/bartcrops/HANDLER_CropsPlusPlus.java b/src/Java/gtPlusPlus/xmod/bartcrops/HANDLER_CropsPlusPlus.java new file mode 100644 index 0000000000..ce7d919431 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/bartcrops/HANDLER_CropsPlusPlus.java @@ -0,0 +1,21 @@ +package gtPlusPlus.xmod.bartcrops; + +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; + +public class HANDLER_CropsPlusPlus { + + public static void preInit(FMLPreInitializationEvent preinit) { + LoaderOfTheCrops.load(preinit); + } + + public static void init(FMLInitializationEvent init) { + //registerItems(); + } + + public static void postInit(FMLPostInitializationEvent postinit) { + LoaderOfTheCrops.register(); + LoaderOfTheCrops.registerBaseSeed(); + } +} diff --git a/src/Java/gtPlusPlus/xmod/bartcrops/LoaderOfTheCrops.java b/src/Java/gtPlusPlus/xmod/bartcrops/LoaderOfTheCrops.java new file mode 100644 index 0000000000..48813310d2 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/bartcrops/LoaderOfTheCrops.java @@ -0,0 +1,109 @@ +package gtPlusPlus.xmod.bartcrops; + +import java.util.ArrayList; +import java.util.List; + +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.bartcrops.crops.Crop_Hemp; +import ic2.api.crops.CropCard; +import ic2.api.crops.Crops; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +/** + * Mostly borrowed from the Crops++ Crop Loader. + * @author Alkalus + */ + +public class LoaderOfTheCrops { + + private static List<Boolean> mHasCropObj = new ArrayList<Boolean>(); + private CropCard mCropObj; + private ItemStack mBaseSeed; + private static List<LoaderOfTheCrops> mCropList = cropLoader(); + + public LoaderOfTheCrops(CropCard cropObj) { + this.mCropObj = cropObj; + } + + public LoaderOfTheCrops(CropCard cropObj, ItemStack baseseed) { + this.mCropObj = cropObj; + this.mBaseSeed = baseseed; + } + + public static CropCard cropUnpackerCC(LoaderOfTheCrops inp) { + return inp.mCropObj; + } + + private static ItemStack cropUnpackerCG(LoaderOfTheCrops inp) { + return inp.mBaseSeed; + } + + private static LoaderOfTheCrops cropHelper(CropCard cropObj) { + return new LoaderOfTheCrops(cropObj, ItemUtils.getItemStackOfAmountFromOreDict("crop" + cropObj.name(), 0)); + } + + public static final List<LoaderOfTheCrops> cropLoader() { + List<LoaderOfTheCrops> p = new ArrayList<LoaderOfTheCrops>(); + + p.add(new LoaderOfTheCrops(new Crop_Hemp(), new ItemStack(Item.getItemById(111), 3))); + + return p; + } + + private static final List<CropCard> cropObjs() { + List<CropCard> p = new ArrayList<CropCard>(); + + for (int i = 0; i < mCropList.size(); ++i) { + p.add(cropUnpackerCC((LoaderOfTheCrops) mCropList.get(i))); + } + + return p; + } + + private static final List<ItemStack> setBaseSeed() { + List<ItemStack> p = new ArrayList<ItemStack>(); + + for (int i = 0; i < mCropList.size(); ++i) { + p.add(cropUnpackerCG((LoaderOfTheCrops) mCropList.get(i))); + } + + return p; + } + + private static final List<String> setnames() { + List<String> s = new ArrayList<String>(); + + for (int i = 0; i < mCropList.size(); ++i) { + s.add(((CropCard) cropObjs().get(i)).name()); + } + + return s; + } + + public static void load(FMLPreInitializationEvent preinit) { + for (int i = 0; i < mCropList.size(); ++i) { + mHasCropObj.add(true); + } + } + + public static void register() { + for (int i = 0; i < mCropList.size(); ++i) { + if ((Boolean) mHasCropObj.get(i) && cropObjs().get(i) != null) { + Crops.instance.registerCrop((CropCard) cropObjs().get(i)); + } + } + } + + public static void registerBaseSeed() { + List<ItemStack> baseseed = new ArrayList<ItemStack>(setBaseSeed()); + + for (int i = 0; i < mCropList.size(); ++i) { + if (baseseed.get(i) != null && cropObjs().get(i) != null) { + Crops.instance.registerBaseSeed((ItemStack) baseseed.get(i), (CropCard) cropObjs().get(i), 1, 1, 1, 1); + } + } + + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseAestheticCrop.java b/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseAestheticCrop.java new file mode 100644 index 0000000000..cddce7beb4 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseAestheticCrop.java @@ -0,0 +1,37 @@ +package gtPlusPlus.xmod.bartcrops.abstracts; + +import gtPlusPlus.core.lib.CORE; +import ic2.api.crops.ICropTile; + +public abstract class BaseAestheticCrop extends BaseHarvestableCrop { + + public int tier() { + return 1; + } + + public int stat(int n) { + switch (n) { + case 0 : + return 0; + case 1 : + return 0; + case 2 : + return 0; + case 3 : + return 4; + case 4 : + return 0; + default : + return 0; + } + } + + public int growthDuration(ICropTile crop) { + return CORE.DEBUG ? 1 : 225; + } + + public byte getSizeAfterHarvest(ICropTile crop) { + return 1; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseCrop.java b/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseCrop.java new file mode 100644 index 0000000000..ca2a044564 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseCrop.java @@ -0,0 +1,56 @@ +package gtPlusPlus.xmod.bartcrops.abstracts; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import ic2.api.crops.CropCard; +import ic2.api.crops.ICropTile; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import speiger.src.crops.api.ICropCardInfo; + +public abstract class BaseCrop extends CropCard implements ICropCardInfo { + @SideOnly(Side.CLIENT) + public void registerSprites(IIconRegister iconRegister) { + this.textures = new IIcon[this.maxSize()]; + + for (int i = 1; i <= this.textures.length; ++i) { + this.textures[i - 1] = iconRegister.registerIcon(CORE.MODID+":crop/blockCrop." + this.name() + "." + i); + } + + } + + public float dropGainChance() { + return (float) (Math.pow(0.95D, (double) ((float) this.tier())) * (double) 1f); + } + + public boolean canCross(ICropTile crop) { + return crop.getSize() == this.maxSize(); + } + + public int getrootslength(ICropTile crop) { + return 3; + } + + public String discoveredBy() { + return "Alkalus"; + } + + public String owner() { + return "Gtplusplus"; + } + + public List<String> getCropInformation() { + List<String> ret = new ArrayList<String>(); + ret.add(this.attributes().toString()); + return ret; + } + + public ItemStack getDisplayItem(CropCard card) { + return ItemUtils.getItemStackOfAmountFromOreDict("crop" + this.name(), 0); + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseHarvestableCrop.java b/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseHarvestableCrop.java new file mode 100644 index 0000000000..fee6cf654c --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseHarvestableCrop.java @@ -0,0 +1,69 @@ +package gtPlusPlus.xmod.bartcrops.abstracts; + +import gtPlusPlus.core.lib.CORE; +import ic2.api.crops.ICropTile; + +public abstract class BaseHarvestableCrop extends BaseCrop { + + public int tier() { + return 2; + } + + public int stat(int n) { + switch (n) { + case 0 : + return 0; + case 1 : + return 4; + case 2 : + return 0; + case 3 : + return 4; + case 4 : + return 0; + default : + return 0; + } + } + + public boolean canGrow(ICropTile crop) { + return crop.getSize() < 3; + } + + public int getOptimalHavestSize(ICropTile crop) { + return 3; + } + + public boolean canBeHarvested(ICropTile crop) { + return crop.getSize() == 3; + } + + public int weightInfluences(ICropTile crop, float humidity, float nutrients, float air) { + return (int) ((double) humidity * 1.2D + (double) nutrients * 0.9D + (double) air * 0.9D); + } + + public int growthDuration(ICropTile crop) { + short r; + if (CORE.DEBUG) { + r = 1; + } else if (crop.getSize() == 2) { + r = 200; + } else { + r = 700; + } + + return r; + } + + public byte getSizeAfterHarvest(ICropTile crop) { + return 2; + } + + public int maxSize() { + return 3; + } + + public String discoveredBy() { + return "Alkalus"; + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/bartcrops/crops/Crop_Hemp.java b/src/Java/gtPlusPlus/xmod/bartcrops/crops/Crop_Hemp.java new file mode 100644 index 0000000000..a921182d66 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/bartcrops/crops/Crop_Hemp.java @@ -0,0 +1,56 @@ +package gtPlusPlus.xmod.bartcrops.crops; + +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.bartcrops.abstracts.BaseAestheticCrop; +import ic2.api.crops.ICropTile; +import net.minecraft.item.ItemStack; + +public class Crop_Hemp extends BaseAestheticCrop { + + public int tier() { + return 2; + } + + public String name() { + return "Hemp"; + } + + public String discoveredBy() { + return "Alkalus"; + } + + public int growthDuration(ICropTile crop) { + int ret = 550; + + /*if (crop.isBlockBelow(Blocks.dirt) || crop.isBlockBelow(Blocks.flowing_water)) { + ret = 225; + }*/ + + if (CORE.DEBUG) { + ret = 1; + } + + return ret; + } + + public String[] attributes() { + return new String[]{"Green", "Soil", "Orange"}; + } + + public ItemStack getGain(ICropTile crop) { + + ItemStack ret = this.getDisplayItem(); + if (MathUtils.randInt(0, 10) > 8) { + ret = ItemUtils.getSimpleStack(ModItems.itemRope, MathUtils.randInt(1, 3)); + } + + return ret; + } + + public ItemStack getDisplayItem() { + return ItemUtils.getSimpleStack(ModItems.itemRope, 0); + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java b/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java index 6d50f64e6d..5b3210d58a 100644 --- a/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java +++ b/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java @@ -12,6 +12,7 @@ import gregtech.api.enums.Materials; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.eio.material.MaterialEIO; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -30,11 +31,10 @@ public class HandlerTooltip_EIO { //If it is, reflect in. if (mIngot == null){ try { - oMainClass = Class.forName("crazypants.enderio.EnderIO"); - oIngotClass = Class.forName("crazypants.enderio.material.ItemAlloy"); + oMainClass = ReflectionUtils.getClass("crazypants.enderio.EnderIO"); + oIngotClass = ReflectionUtils.getClass("crazypants.enderio.material.ItemAlloy"); if (oMainClass != null && oIngotClass != null){ - Field oAlloyField = oMainClass.getDeclaredField("itemAlloy"); - oAlloyField.setAccessible(true); + Field oAlloyField = ReflectionUtils.getField(oMainClass, "itemAlloy"); Object oAlloy = oAlloyField.get(oMainClass); if (oAlloy != null){ if (oIngotClass.isInstance(oAlloy) || Item.class.isInstance(oAlloy)){ diff --git a/src/Java/gtPlusPlus/xmod/forestry/HANDLER_FR.java b/src/Java/gtPlusPlus/xmod/forestry/HANDLER_FR.java index 1343bdc8af..05d00b06d9 100644 --- a/src/Java/gtPlusPlus/xmod/forestry/HANDLER_FR.java +++ b/src/Java/gtPlusPlus/xmod/forestry/HANDLER_FR.java @@ -45,14 +45,14 @@ public class HANDLER_FR { if (LoadedMods.Forestry){ Class oClass; try { - oClass = Class.forName("forestry.core.proxy.ProxyCommon"); + oClass = ReflectionUtils.getClass("forestry.core.proxy.ProxyCommon"); Object oProxy = ReflectionUtils.getField(oClass, "common"); - if (oProxy != null && oClass.isInstance(oProxy)){ - Method mParticles = oClass.getDeclaredMethod("addBlockDestroyEffects", World.class, int.class, int.class, int.class, Block.class, int.class); + if (oProxy != null && oClass.isInstance(oProxy)){ + Method mParticles = ReflectionUtils.getMethod(oClass, "addBlockDestroyEffects", World.class, int.class, int.class, int.class, Block.class, int.class); mParticles.invoke(oProxy, world, x, y, z, block, 0); } } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } } diff --git a/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bee_Definition.java b/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bee_Definition.java index d842c37fcd..b36508f6aa 100644 --- a/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bee_Definition.java +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bee_Definition.java @@ -864,7 +864,7 @@ public enum GTPP_Bee_Definition implements IBeeDefinition { Enum gtBeeEnumObject = Enum.valueOf(gtBeeTypes, name); Field gtBeesField = FieldUtils.getDeclaredField(gtBeeTypes, "species", true); gtBeesField.setAccessible(true); - ReflectionUtils.makeAccessible(gtBeesField); + ReflectionUtils.makeFieldAccessible(gtBeesField); Object beeType = gtBeesField.get(gtBeeEnumObject); return (IAlleleBeeSpecies) beeType; } diff --git a/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bees.java b/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bees.java index 29ece40c3d..bb360d5a87 100644 --- a/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bees.java +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/custom/GTPP_Bees.java @@ -141,7 +141,7 @@ public class GTPP_Bees { Class gtCombEnumClass = Class.forName("gregtech.common.items.CombType"); Field gtCombs = FieldUtils.getDeclaredField(gtBees, "combs", true); gtCombs.setAccessible(true); - ReflectionUtils.makeAccessible(gtCombs); + ReflectionUtils.makeFieldAccessible(gtCombs); Enum gtCombTypeSlag = Enum.valueOf(gtCombEnumClass, "SLAG"); Enum gtCombTypeStone = Enum.valueOf(gtCombEnumClass, "STONE"); Object oCombObject = gtCombs.get(null); diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java b/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java index 9075666b8b..58331c4300 100644 --- a/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java +++ b/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java @@ -8,6 +8,7 @@ import net.minecraft.item.Item; import gtPlusPlus.core.item.chemistry.RocketFuels; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.asm.AsmConfig; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fluids.Fluid; @@ -21,11 +22,11 @@ public class HandlerTooltip_GC { @SubscribeEvent public void onItemTooltip(ItemTooltipEvent event) { - if (LoadedMods.GalacticraftCore) { + if (LoadedMods.GalacticraftCore && AsmConfig.enableGcFuelChanges) { if (mBlock == null) { try { - Class<?> GCBlocks = Class.forName("micdoodle8.mods.galacticraft.core.blocks.GCBlocks"); + Class<?> GCBlocks = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.blocks.GCBlocks"); if (GCBlocks != null) { oMainClass = GCBlocks; diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/system/core/world/gen/ChunkProviderGalactic.java b/src/Java/gtPlusPlus/xmod/galacticraft/system/core/world/gen/ChunkProviderGalactic.java index 3b9633b21d..aafa9ef9a1 100644 --- a/src/Java/gtPlusPlus/xmod/galacticraft/system/core/world/gen/ChunkProviderGalactic.java +++ b/src/Java/gtPlusPlus/xmod/galacticraft/system/core/world/gen/ChunkProviderGalactic.java @@ -4,12 +4,11 @@ import java.util.List; import com.google.common.collect.Lists; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import micdoodle8.mods.galacticraft.api.prefab.core.BlockMetaPair; import micdoodle8.mods.galacticraft.api.prefab.world.gen.BiomeDecoratorSpace; import micdoodle8.mods.galacticraft.api.prefab.world.gen.MapGenBaseMeta; -import micdoodle8.mods.galacticraft.core.entities.EntityEvolvedCreeper; -import micdoodle8.mods.galacticraft.core.entities.EntityEvolvedSkeleton; -import micdoodle8.mods.galacticraft.core.entities.EntityEvolvedSpider; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; @@ -46,20 +45,37 @@ public abstract class ChunkProviderGalactic extends ChunkProviderGalaxyLakes { } protected SpawnListEntry[] getMonsters() { - SpawnListEntry skele = new SpawnListEntry(EntityEvolvedSkeleton.class, 100, 4, 4); - SpawnListEntry creeper = new SpawnListEntry(EntityEvolvedCreeper.class, 100, 4, 4); - SpawnListEntry spider = new SpawnListEntry(EntityEvolvedSpider.class, 100, 4, 4); + + Class aSkele = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.entities.EntityEvolvedSkeleton"); + Class aCreeper = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.entities.EntityEvolvedCreeper"); + Class aSpider = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.entities.EntityEvolvedSpider"); + Class aEnderman = ReflectionUtils.getClass("galaxyspace.SolarSystem.planets.pluto.entities.EntityEvolvedEnderman"); + + SpawnListEntry skele; + SpawnListEntry creeper; + SpawnListEntry spider; + SpawnListEntry enderman; - Class<?> aEnderman; - try { - aEnderman = Class.forName("galaxyspace.SolarSystem.planets.pluto.entities.EntityEvolvedEnderman"); - if (aEnderman != null) { - SpawnListEntry enderman = new SpawnListEntry(aEnderman, 100, 4, 4); - return new SpawnListEntry[] { skele, creeper, spider, enderman }; - } - } catch (ClassNotFoundException e) {} + AutoMap<SpawnListEntry> aMobs = new AutoMap<SpawnListEntry>(); - return new SpawnListEntry[] { skele, creeper, spider }; + if (aSkele != null) { + skele = new SpawnListEntry(aSkele, 100, 4, 4); + aMobs.put(skele); + } + if (aCreeper != null) { + creeper = new SpawnListEntry(aCreeper, 100, 4, 4); + aMobs.put(creeper); + } + if (aSpider != null) { + spider = new SpawnListEntry(aSpider, 100, 4, 4); + aMobs.put(spider); + } + if (aEnderman != null) { + enderman = new SpawnListEntry(aEnderman, 100, 4, 4); + aMobs.put(enderman); + } + + return aMobs.toArray(); } public void onPopulate(IChunkProvider arg0, int arg1, int arg2) { diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java b/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java index 94dc2d0cc0..f237aed335 100644 --- a/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java +++ b/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java @@ -26,11 +26,11 @@ public class GalacticUtils { Class<?> a1, a2, a3, a4, a5; Method m1, m2, m3; try { - a1 = Class.forName("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket"); - a2 = Class.forName("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad"); - a3 = Class.forName("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler"); - a4 = Class.forName("micdoodle8.mods.galacticraft.api.entity.IDockable"); - a5 = Class.forName("micdoodle8.mods.galacticraft.api.entity.IFuelable"); + a1 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket"); + a2 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad"); + a3 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler"); + a4 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.entity.IDockable"); + a5 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.entity.IFuelable"); m1 = ReflectionUtils.getMethod(a1, "getRocketTier"); m2 = ReflectionUtils.getMethod(a2, "getDockedEntity"); m3 = ReflectionUtils.getMethod(a3, "getDockedEntity"); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java index 2b7f44be59..0d4d8b6cdd 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java @@ -184,7 +184,7 @@ public class GT_MetaTileEntity_Hatch_Naquadah extends GT_MetaTileEntity_Hatch_In a2 = F2.getByte(this); } } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException n) {} + catch (IllegalArgumentException | IllegalAccessException n) {} int textureIndex = a1 | a2 << 7; byte texturePointer = (byte) (a1 & 127); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java index 30c1bc2b29..bed80d8d13 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java @@ -50,11 +50,9 @@ public class GT_MetaTileEntity_Hatch_Plasma extends GT_MetaTileEntity_Hatch_Outp //Get all Plasmas, but the easiest way to do this is to just ask the Fluid Registry what exists and filter through them lazily. Field fluidNameCache; - try { - fluidNameCache = ReflectionUtils.getField(FluidRegistry.class, "fluidNames"); - } catch (NoSuchFieldException e) { - fluidNameCache = null; - } + + fluidNameCache = ReflectionUtils.getField(FluidRegistry.class, "fluidNames"); + AutoMap<String> mValidPlasmaNameCache = new AutoMap<String>(); if (fluidNameCache != null) { try { @@ -199,7 +197,7 @@ public class GT_MetaTileEntity_Hatch_Plasma extends GT_MetaTileEntity_Hatch_Outp a2 = F2.getByte(this); } } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException n) {} + catch (IllegalArgumentException | IllegalAccessException n) {} int textureIndex = a1 | a2 << 7; byte texturePointer = (byte) (a1 & 127); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index b55157e763..7103c81980 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -482,9 +482,9 @@ GT_MetaTileEntity_MultiBlockBase { public void log(String s) { boolean isDebugLogging = CORE.DEBUG; - boolean reset = false; + boolean reset = true; if (aLogger == null || reset) { - if (isDebugLogging) { + if (true) { try { aLogger = Logger.class.getMethod("INFO", String.class); } catch (NoSuchMethodException | SecurityException e) {} @@ -1141,7 +1141,8 @@ GT_MetaTileEntity_MultiBlockBase { if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input){ ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; - ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; + log("Remapped Input Hatch to "+aMap.mNEIName); } else { ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = null; @@ -1173,7 +1174,6 @@ GT_MetaTileEntity_MultiBlockBase { * Enable Texture Casing Support if found in GT 5.09 */ - @SuppressWarnings("deprecation") public boolean updateTexture(final IGregTechTileEntity aTileEntity, int aCasingID){ final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); if (aMetaTileEntity == null) { @@ -1194,7 +1194,7 @@ GT_MetaTileEntity_MultiBlockBase { if (aMetaTileEntity == null) { return false; } - Method mProper = Class.forName("gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch").getDeclaredMethod("updateTexture", int.class); + Method mProper = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); if (mProper != null){ if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)){ mProper.setAccessible(true); @@ -1202,7 +1202,6 @@ GT_MetaTileEntity_MultiBlockBase { log("Good Method Call for updateTexture."); return true; } - } else { log("Bad Method Call for updateTexture."); @@ -1223,7 +1222,7 @@ GT_MetaTileEntity_MultiBlockBase { log("updateTexture returning false. 1"); return false; } - catch (NoSuchMethodException | SecurityException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { log("updateTexture returning false."); log("updateTexture returning false. 2"); e.printStackTrace(); @@ -1277,15 +1276,12 @@ GT_MetaTileEntity_MultiBlockBase { @SuppressWarnings("rawtypes") public boolean isThisHatchMultiDynamo(Object aMetaTileEntity){ Class mDynamoClass; - try { - mDynamoClass = Class.forName("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); + mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); if (mDynamoClass != null){ if (mDynamoClass.isInstance(aMetaTileEntity)){ return true; } } - } - catch (ClassNotFoundException e) {} return false; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java index 88b4c7bc99..c5554a6679 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java @@ -17,6 +17,7 @@ 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.reflect.ReflectionUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockAir; import net.minecraft.init.Blocks; @@ -124,10 +125,11 @@ public class MultiblockLayer { GT_MetaTileEntity_Hatch.class }; } - else { - try { + else { + Class aDataHatch = ReflectionUtils.getClass("gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_DataAccess"); + if (aDataHatch != null) { aHatchTypeClass = new Class[] { - Class.forName("gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_DataAccess"), + aDataHatch, GT_MetaTileEntity_Hatch_Dynamo.class, GT_MetaTileEntity_Hatch_Energy.class, GT_MetaTileEntity_Hatch_Input.class, @@ -138,7 +140,7 @@ public class MultiblockLayer { GT_MetaTileEntity_Hatch_OutputBus.class, GT_MetaTileEntity_Hatch.class }; - } catch (ClassNotFoundException e) { + } else { aHatchTypeClass = new Class[] { GT_MetaTileEntity_Hatch_Dynamo.class, GT_MetaTileEntity_Hatch_Energy.class, diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java index d5327a6a99..3e0084139e 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java @@ -38,12 +38,9 @@ public class GregtechOreDictUnificator { private static boolean mRunThroughTheList = true; static { - try { if (ReflectionUtils.getField(GT_OreDictUnificator.class, "sUnificationTable") == null) { GregTech_API.sItemStackMappings.add(sUnificationTable); } - } - catch (NoSuchFieldException e) {} } /** diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java b/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java index 5eee77e065..6b4bab9e26 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java @@ -5,6 +5,7 @@ import static gtPlusPlus.xmod.gregtech.common.covers.GTPP_Cover_Overflow.mOverfl import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -18,11 +19,16 @@ import cpw.mods.fml.relauncher.SideOnly; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; +import gregtech.api.util.Recipe_GT; +import gregtech.api.util.Recipe_GT.Gregtech_Recipe_Map; import gregtech.common.GT_Proxy; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; @@ -30,6 +36,9 @@ import gtPlusPlus.api.objects.data.ObjMap; import gtPlusPlus.api.objects.minecraft.FormattedTooltipString; import gtPlusPlus.core.handler.AchievementHandler; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.core.util.reflect.ProxyFinder; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.BaseCustomTileEntity; @@ -104,6 +113,120 @@ public class Meta_GT_Proxy { mAssemblyAchievements = new AchievementHandler(); } + public static boolean generatePlasmaRecipesForAdvVacFreezer() { + + AutoMap<Recipe_GT> aFreezerMapRebaked = new AutoMap<Recipe_GT>(); + AutoMap<Recipe_GT> aRemovedRecipes = new AutoMap<Recipe_GT>(); + + //Find recipes containing Plasma and map them + for (Recipe_GT y : Recipe_GT.Gregtech_Recipe_Map.sAdvFreezerRecipes.mRecipeList) { + if (y.mFluidInputs.length > 0) { + for (FluidStack r : y.mFluidInputs) { + if (r.getUnlocalizedName().toLowerCase().contains("plasma")) { + aRemovedRecipes.put(y); + continue; + } + } + aFreezerMapRebaked.put(y); + } + } + + AutoMap<Recipe_GT> aNewRecipes = new AutoMap<Recipe_GT>(); + int aAtomicMass = 0; + int aAtomicTier = 0; + + final FluidStack NULL_PLASMA = Materials._NULL.getPlasma(1); + + for (String s : ELEMENT.NAMES) { + + aAtomicMass++; + aAtomicTier = (aAtomicMass/30)+1; + FluidStack aMoltenFluid = null; + FluidStack aPlasma = null; + + //Try Get Material via Gregtech + Materials aGregMaterial = MaterialUtils.getMaterial(s); + if (aGregMaterial != null) { + aMoltenFluid = aGregMaterial.getMolten(1); + if (aMoltenFluid == null) { + aMoltenFluid = aGregMaterial.getFluid(1); + if (aMoltenFluid == null) { + aMoltenFluid = aGregMaterial.getGas(1); + if (aMoltenFluid == null) { + aMoltenFluid = aGregMaterial.getSolid(1); + } + } + } + aPlasma = aGregMaterial.getPlasma(100); + } + + //Just wildcard values + if (aMoltenFluid == null || aPlasma == null) { + if (aMoltenFluid == null) { + aMoltenFluid = FluidUtils.getWildcardFluidStack(s, 1); + } + if (aPlasma == null) { + aPlasma = FluidUtils.getFluidStack("plasma."+s.toLowerCase(), 1); + } + } + + //Skip this material + if (aMoltenFluid == null || aPlasma == null || aPlasma.isFluidEqual(NULL_PLASMA)) { + Logger.INFO("Could not generate Advanced Vacuum Freezer recipe. Cooling "+s+" plasma. Molten Form Exists? "+(aMoltenFluid != null)+" | Plasma Exists? "+(aPlasma != null)); + continue; + } + else { + //Build a new plasma recipe + int aTotalTickTime = (20 * 1 + (aAtomicMass)); + Recipe_GT aTempRecipe = new Recipe_GT(true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {10000}, + new FluidStack[] { + aPlasma, + FluidUtils.getFluidStack("cryotheum", aTotalTickTime) + }, + new FluidStack[] { + aMoltenFluid + }, + aTotalTickTime, + (int) GT_Values.V[4+aAtomicTier], + aAtomicMass); + + //Add it to the map if it's valid + if (aTempRecipe != null) { + aNewRecipes.put(aTempRecipe); + } + } + + } + + + //Add the new recipes to the map we will rebake over the original + for (Recipe_GT w : aNewRecipes) { + aFreezerMapRebaked.put(w); + } + + //Best not touch the original map if we don't have a valid map to override it with. + if (aFreezerMapRebaked.size() > 0) { + + int aOriginalCount = Recipe_GT.Gregtech_Recipe_Map.sAdvFreezerRecipes.mRecipeList.size(); + + //Empty the original map + Recipe_GT.Gregtech_Recipe_Map.sAdvFreezerRecipes.mRecipeList.clear(); + + //Rebake the real map + for (Recipe_GT w : aFreezerMapRebaked) { + Recipe_GT.Gregtech_Recipe_Map.sAdvFreezerRecipes.mRecipeList.add(w); + } + + return Recipe_GT.Gregtech_Recipe_Map.sAdvFreezerRecipes.mRecipeList.size() >= aOriginalCount; + } + + return false; + } + public static TileEntity constructCustomGregtechMetaTileEntityByMeta(int aMeta) { if (aMeta == 12) { return Meta_GT_Proxy.constructBaseMetaTileEntityCustomPower(); @@ -279,7 +402,7 @@ public class Meta_GT_Proxy { if (proxyGT != null && proxyGT instanceof GT_Proxy) { try { return ReflectionUtils.getField(proxyGT.getClass(), fieldName).get(proxyGT); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } } return null; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java b/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java index 63581af16c..1604cc5acd 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java @@ -108,11 +108,7 @@ public class StaticFields59 { } public static Field getField(Class a, String b) { - try { - return ReflectionUtils.getField(a, b); - } catch (NoSuchFieldException e) { - return null; - } + return ReflectionUtils.getField(a, b); } public static Method getMethod(Class a, String b, Class... params) { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java index 0178bac4da..bda75be793 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java @@ -23,6 +23,7 @@ import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaWirelessCharger; import ic2.api.info.Info; import ic2.api.item.ElectricItem; @@ -291,12 +292,11 @@ public class ChargingHelper { } //Try get charge direct from NBT for GT and IC2 stacks - try { Logger.WARNING("3"); if (mTemp.getItem() instanceof GT_MetaGenerated_Tool_01 || mTemp.getItem() instanceof GT_MetaGenerated_Item_01 || mTemp.getItem() instanceof GT_MetaGenerated_Item_02 - || Class.forName("gregtech.common.items.GT_MetaGenerated_Item_03").isInstance(mTemp.getItem()) + || ReflectionUtils.getClass("gregtech.common.items.GT_MetaGenerated_Item_03").isInstance(mTemp.getItem()) || mTemp.getItem().getClass().getName().toLowerCase().equals(("gregtech.common.items.GT_MetaGenerated_Tool_01").toLowerCase())){ if (!NBTUtils.hasKey(mTemp, "GT.ItemCharge")){ if (!mTemp.getDisplayName().toLowerCase().contains("battery")){ @@ -314,10 +314,7 @@ public class ChargingHelper { } else if (mTemp.getItem() instanceof IElectricItem){ mitemCurrentCharge = NBTUtils.getLong(mTemp, "charge"); - } - } catch (ClassNotFoundException e) { - - } + } double mVoltageIncrease; if (mItemEuTLimit >= mVoltage){ diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java index 2bfb07ff4a..3c60ae664e 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java @@ -321,14 +321,12 @@ public class TreeFarmHelper { return blockHumus; } else if (ReflectionUtils.doesClassExist("forestry.core.blocks.BlockSoil")){ - try { - final Class<?> humusClass = Class.forName("forestry.core.blocks.BlockSoil"); + final Class<?> humusClass = ReflectionUtils.getClass("forestry.core.blocks.BlockSoil"); final ItemStack humusStack = ItemUtils.getCorrectStacktype("Forestry:soil", 1); if (humusClass != null){ blockHumus = Block.getBlockFromItem(humusStack.getItem()); return Block.getBlockFromItem(humusStack.getItem()); } - } catch (final ClassNotFoundException e) {} } return null; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java b/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java index 411171a766..6b061c3704 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java @@ -285,7 +285,7 @@ public class MetaGeneratedGregtechItems extends Gregtech_MetaItem_X32 { //Fusion Reactor MK4 Singularity GregtechItemList.Compressed_Fusion_Reactor.set(this.addItem(100, "Hypervisor Matrix (Fusion)", "A memory unit containing an RI (Restricted Intelligence)", new Object[0])); - CORE.RA.addCompressorRecipe(ItemList.FusionComputer_UV.get(9), GregtechItemList.Compressed_Fusion_Reactor.get(1), (int) GT_Values.V[7], (int) GT_Values.V[8]); + //NanoTubes GregtechItemList.NanoTube_Base_Substrate.set(this.addItem(101, "Silicon Base Substrate", "Used in the production of Carbon Nanotubes", new Object[0])); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java index 759378013c..c31a7c0758 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java @@ -221,7 +221,7 @@ public class GT4Entity_AutoCrafter extends GregtechMeta_MultiBlockBase { return r; } } - } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } } return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java index 1623e7cb54..de5d731dd5 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java @@ -410,9 +410,13 @@ public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBas //Time Counter this.mTotalRunTime++; - onRunningTick(null); + onRunningTick(null); - if (mRunningOnLoad && checkMultiblock(aBaseMetaTileEntity, mInventory[1])) { + boolean aFormCheck = (aTick % 100 == 0 ? checkMultiblock(aBaseMetaTileEntity, mInventory[1]) : true); + + + + if (mRunningOnLoad && aFormCheck) { this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); checkRecipe(mInventory[1]); } @@ -429,7 +433,7 @@ public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBas mDischargeHatches.clear(); mControlCoreBus.clear(); mMultiDynamoHatches.clear(); - mMachine = checkMultiblock(aBaseMetaTileEntity, mInventory[1]); + mMachine = aFormCheck; } if (mStartUpCheck < 0) { if (mMachine) { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java index b1e433e276..fc0cb85bac 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java @@ -459,7 +459,7 @@ public class GregtechMetaTileEntity_IndustrialFishingPond extends GregtechMeta_M ItemStack k = ItemUtils.getSimpleStack(t, 1); reflectiveFishMap.put(y, k); return t; - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } return null; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java index 1a19bc7b96..e6fecf5d18 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java @@ -1,23 +1,25 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; +import static gregtech.api.enums.GT_Values.E; +import static gregtech.api.enums.GT_Values.RES_PATH_GUI; + +import java.util.HashSet; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.CustomRecipeMap; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase { @@ -69,42 +71,30 @@ public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase @Override public String getCustomGUIResourceName() { - return "LFTR"; + return "MatterFabricator"; } + private static final GT_Recipe_Map mGregTypeRecipeMap = new GT_Recipe_Map(new HashSet<GT_Recipe>(), "internal.recipe.fissionfuel", "Fission Fuel Processing", null, RES_PATH_GUI + "basicmachines/FissionFuel", 0, 0, 0, 4, 1, E, 1, E, true, true); + @Override - public boolean checkRecipe(ItemStack aStack) { - ArrayList<FluidStack> tFluidList = getStoredFluids(); - int tFluidList_sS=tFluidList.size(); - for (int i = 0; i < tFluidList_sS - 1; i++) { - for (int j = i + 1; j < tFluidList_sS; j++) { - if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { - if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { - tFluidList.remove(j--); tFluidList_sS=tFluidList.size(); - } else { - tFluidList.remove(i--); tFluidList_sS=tFluidList.size(); - break; - } - } - } - } - if (tFluidList.size() > 1) { - FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); - GT_Recipe tRecipe = CustomRecipeMap.sFissionFuelProcessing.findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, GT_Values.V[4], tFluids, new ItemStack[]{}); - if (tRecipe == null) { - this.mLastRecipe = null; - return false; - } - if (tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[]{})) { - this.mLastRecipe = tRecipe; - this.mEUt = this.mLastRecipe.mEUt; - this.mMaxProgresstime = this.mLastRecipe.mDuration; - this.mEfficiencyIncrease = 10000; - this.mOutputFluids = this.mLastRecipe.mFluidOutputs; - return true; - } - } - return false; + public GT_Recipe_Map getRecipeMap() { + if (mGregTypeRecipeMap.mRecipeList.size() <= 0) { + for (GT_Recipe g : CustomRecipeMap.sFissionFuelProcessing.mRecipeList) { + mGregTypeRecipeMap.mRecipeList.add(g); + } + } + return mGregTypeRecipeMap; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + //this.resetRecipeMapForAllInputHatches(); + for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { + g.mRecipeMap = null; + } + boolean ab = super.checkRecipeGeneric(); + Logger.INFO("Did Recipe? "+ab); + return ab; } @Override @@ -261,7 +251,8 @@ public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase Logger.INFO("Your Muffler must be AT LEAST ZPM tier or higher."); } } - Logger.INFO("Fission Fuel Production Plant Formed."); + Logger.INFO("Fission Fuel Production Plant Formed. "+mGregTypeRecipeMap.mRecipeList.size()); + this.resetRecipeMapForAllInputHatches(this.getRecipeMap()); return true; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java index 68f78503e8..4c8707e5e8 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java @@ -38,8 +38,7 @@ public class GT_Material_Loader { instance = this; //Try Reflectively add ourselves to the GT loader. - try { - Class mInterface = Class.forName("gregtech.api.interfaces.IMaterialHandler"); + Class mInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && mInterface != null){ //Make this class Dynamically implement IMaterialHandler @@ -49,7 +48,7 @@ public class GT_Material_Loader { new MaterialHandler(getInstance())); } - if (ReflectionUtils.invoke(Materials.class, "add", new Class[]{Class.forName("gregtech.api.interfaces.IMaterialHandler")}, new Object[]{mProxyObject})){ + if (ReflectionUtils.invoke(Materials.class, "add", new Class[]{ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler")}, new Object[]{mProxyObject})){ Logger.REFLECTION("Successfully invoked add, on the proxied object implementing IMaterialHandler."); @@ -65,9 +64,7 @@ public class GT_Material_Loader { else { Logger.REFLECTION("Failed to invoke add, on the proxied object implementing IMaterialHandler."); } - } - } - catch (ClassNotFoundException e) {} + } //Materials.add(this); //Stupid shit running twice, I don't think so. @@ -139,12 +136,12 @@ public class GT_Material_Loader { return false; } try { - Method enableComponent = Class.forName("gregtech.api.enums.OrePrefixes").getDeclaredMethod("enableComponent", Materials.class); + Method enableComponent = ReflectionUtils.getClass("gregtech.api.enums.OrePrefixes").getDeclaredMethod("enableComponent", Materials.class); enableComponent.invoke(prefix, mMaterial); Logger.DEBUG_MATERIALS("Enabled "+prefix.name()+" for "+mMaterial.mDefaultLocalName+"."); return true; } - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException error) { + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException error) { Logger.DEBUG_MATERIALS("Failed to enabled "+prefix.name()+" for "+mMaterial.mDefaultLocalName+". Caught "+error.getCause().toString()+"."); error.printStackTrace(); } @@ -228,7 +225,7 @@ public class GT_Material_Loader { //Loading the class at runtime public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { - Class<?> someInterface = Class.forName("gregtech.api.interfaces.IMaterialHandler"); + Class<?> someInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); Object instance = Proxy.newProxyInstance(someInterface.getClassLoader(), new Class<?>[]{someInterface}, new InvocationHandler() { @Override @@ -274,7 +271,7 @@ public class GT_Material_Loader { public static void init(){ - Class<?> someInterface = Class.forName("gregtech.api.interfaces.IMaterialHandler"); + Class<?> someInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); GT_Material_Loader original = GT_Material_Loader.instance; MaterialHandler handler = new MaterialHandler(original); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java b/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java index 001edf3ab9..b4f7347b52 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java @@ -696,8 +696,7 @@ public class GregtechRecipeAdder implements IGregtech_RecipeAdder { Method T = null; if (LoadedMods.TecTech) { - try { - Class TTRecipeAdder = Class.forName("com.github.technus.tectech.recipe.TT_recipeAdder"); + Class TTRecipeAdder = ReflectionUtils.getClass("com.github.technus.tectech.recipe.TT_recipeAdder"); if (TTRecipeAdder != null) { Method ttTest = ReflectionUtils.getMethod(TTRecipeAdder, "addResearchableAssemblylineRecipe", ItemStack.class, int.class, int.class, int.class, int.class, Object[].class, @@ -706,8 +705,6 @@ public class GregtechRecipeAdder implements IGregtech_RecipeAdder { T = ttTest; } } - } catch (ClassNotFoundException e) { - } } else { T = null; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java index f924e5233d..6095413150 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java @@ -22,6 +22,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraftforge.fluids.FluidStack; public class GregtechNitroDieselFix { @@ -34,7 +35,7 @@ public class GregtechNitroDieselFix { int mSub = Utils.getGregtechSubVersion(); if (mSub != 0){ if (mSub >= 30){ - Class mb = Class.forName("gregtech.api.enums.MaterialBuilder"); + Class mb = ReflectionUtils.getClass("gregtech.api.enums.MaterialBuilder"); Object df = mb.getConstructor(int.class, TextureSet.class, String.class).newInstance(975, TextureSet.SET_FLUID, "Nitro-Diesel [Old]"); if (mb.isInstance(df)){ @@ -158,7 +159,7 @@ public class GregtechNitroDieselFix { } } } - catch (ClassNotFoundException | IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) { Logger.INFO("[Nitro] ================ Error ================"); e.printStackTrace(); Logger.INFO("[Nitro] ================ Error ================"); diff --git a/src/Java/gtPlusPlus/xmod/growthcraft/fishtrap/FishTrapHandler.java b/src/Java/gtPlusPlus/xmod/growthcraft/fishtrap/FishTrapHandler.java index 5410b0f619..5a9dc748ca 100644 --- a/src/Java/gtPlusPlus/xmod/growthcraft/fishtrap/FishTrapHandler.java +++ b/src/Java/gtPlusPlus/xmod/growthcraft/fishtrap/FishTrapHandler.java @@ -11,6 +11,7 @@ import gtPlusPlus.core.lib.LoadedMods; 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; public class FishTrapHandler { @@ -31,14 +32,14 @@ public class FishTrapHandler { private final static Object setFishTrapRegistry(){ Class mFishingRegistryClass; try { - mFishingRegistryClass = Class.forName("growthcraft.api.fishtrap.FishTrapRegistry"); + mFishingRegistryClass = ReflectionUtils.getClass("growthcraft.api.fishtrap.FishTrapRegistry"); final Method mFishingRegistryMethod = mFishingRegistryClass.getDeclaredMethod("getInstance"); mFishingRegistry = mFishingRegistryMethod.invoke(null); if (mFishingRegistry != null){ return mFishingRegistry; } } - catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return null; } diff --git a/src/Java/gtPlusPlus/xmod/sc2/modules/ModuleExoticSeeds.java b/src/Java/gtPlusPlus/xmod/sc2/modules/ModuleExoticSeeds.java index 617c4ddd8a..dfaec8b703 100644 --- a/src/Java/gtPlusPlus/xmod/sc2/modules/ModuleExoticSeeds.java +++ b/src/Java/gtPlusPlus/xmod/sc2/modules/ModuleExoticSeeds.java @@ -87,11 +87,11 @@ public class ModuleExoticSeeds extends ModuleAddon implements ICropModule { else { if (mForestryHumusBlockClass == null || mForestryHumusBlock == null) { try { - mForestryHumusBlockClass = Class.forName("forestry.plugins.PluginCore"); + mForestryHumusBlockClass = ReflectionUtils.getClass("forestry.plugins.PluginCore"); Field blocks = ReflectionUtils.getField(mForestryHumusBlockClass, "blocks"); if (blocks != null) { Object blockRegistryCoreObject = blocks.get(null); - mForestryBlockRegistryCoreClass = Class.forName("forestry.core.blocks.BlockRegistryCore"); + mForestryBlockRegistryCoreClass = ReflectionUtils.getClass("forestry.core.blocks.BlockRegistryCore"); if (mForestryBlockRegistryCoreClass != null && blockRegistryCoreObject != null) { Field soil = ReflectionUtils.getField(mForestryBlockRegistryCoreClass, "soil"); if (soil != null) { diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java index 558b134ea9..be3b23531c 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java @@ -37,10 +37,9 @@ public class HANDLER_Thaumcraft { public static void init(){ if (LoadedMods.Thaumcraft){ try { - mResearchNotes = (Item) ReflectionUtils.getField(Class.forName("thaumcraft.common.config.ConfigItems"), "itemResearchNotes").get(null); + mResearchNotes = (Item) ReflectionUtils.getField(ReflectionUtils.getClass("thaumcraft.common.config.ConfigItems"), "itemResearchNotes").get(null); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException - | ClassNotFoundException e) { + catch (IllegalArgumentException | IllegalAccessException e) { mResearchNotes = Items.paper; } } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java index 501fe6579a..a6260d4246 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java @@ -33,7 +33,7 @@ public class HANDLER_Tinkers { public static final void postInit() { if (LoadedMods.TiCon) { - Class aTinkersSmeltery = ReflectionUtils.getClassByName("tconstruct.smeltery.TinkerSmeltery"); + Class aTinkersSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); AutoMap<Fluid> aTweakedFluids = new AutoMap<Fluid>(); if (aTinkersSmeltery != null) { try { @@ -84,7 +84,7 @@ public class HANDLER_Tinkers { } } } - } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } } } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java new file mode 100644 index 0000000000..a2ab894f53 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -0,0 +1,200 @@ +package gtPlusPlus.xmod.tinkers.material; + +import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt; + +import java.util.HashMap; + +import cpw.mods.fml.common.event.FMLInterModComms; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.FluidType; +import tconstruct.library.crafting.Smeltery; +import tconstruct.library.tools.ToolMaterial; +import tconstruct.smeltery.TinkerSmeltery; + +public class BaseTinkersMaterial { + + private static HashMap<String, Integer> aInternalMaterialIdMap = new HashMap<String, Integer>(); + private static int aNextFreeID = 440; + private final String mUnlocalName; + public final String mLocalName; + private final int aID; + + public BaseTinkersMaterial(Material aMaterial) { + mLocalName = Utils.sanitizeString(aMaterial.getLocalizedName()); + mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); + aID = aNextFreeID++; + aInternalMaterialIdMap.put(mUnlocalName, aID); + + + int id = aID; + if (id > 0) { + + ToolMaterial mat = new ToolMaterial(mLocalName, mUnlocalName, 4, 100, 700, 2, + 0.6F, 4, 0.0F, EnumChatFormatting.WHITE.toString(), 16777215); + + TConstructRegistry.addtoolMaterial(id, mat); + TConstructRegistry.addDefaultToolPartMaterial(id); + TConstructRegistry.addBowMaterial(id, calcBowDrawSpeed(aMaterial), 1.0F); + TConstructRegistry.addArrowMaterial(id, calcProjectileMass(aMaterial), calcProjectileFragility(aMaterial)); + + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("Id", id); + tag.setString("Name", mLocalName); + tag.setString("localizationString", mUnlocalName); + tag.setInteger("Durability", calcDurability(aMaterial)); // 97 + tag.setInteger("MiningSpeed", calcMiningSpeed(aMaterial)); // 150 + tag.setInteger("HarvestLevel", calcHarvestLevel(aMaterial)); // 1 + tag.setInteger("Attack", calcAttack(aMaterial)); // 0 + tag.setFloat("HandleModifier", calcHandleModifier(aMaterial)); // 1.0f + tag.setInteger("Reinforced", calcReinforced(aMaterial)); // 0 + tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(aMaterial)); // 3.0f + tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(aMaterial)); // 18 + tag.setFloat("Projectile_Mass", calcProjectileMass(aMaterial)); // 0.69f + tag.setFloat("Projectile_Fragility", calcProjectileFragility(aMaterial)); // 0.2f + tag.setString("Style", calcStyle(aMaterial)); + tag.setInteger("Color", calcColour(aMaterial)); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + + generateRecipes(aMaterial); + + + ItemStack itemstack = aMaterial.getIngot(1); + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + NBTTagCompound item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + tag.setInteger("Value", 2); // What is value for? + FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); + + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + tag.setInteger("Value", 2); // What is value for? + item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + + + } + + + + + + + + } + + public String getUnlocalName() { + return mUnlocalName; + } + + + private static int calcDurability(Material aMaterial) { + return safeCast_LongToInt(aMaterial.vDurability); + } + + private static int calcMiningSpeed(Material aMaterial) { + return (aMaterial.vHarvestLevel * 2)+aMaterial.vTier; + } + + private static int calcHarvestLevel(Material aMaterial) { + return aMaterial.vHarvestLevel; + } + + private static int calcAttack(Material aMaterial) { + return aMaterial.vHarvestLevel+aMaterial.vTier+aMaterial.vRadiationLevel; + } + + private static float calcHandleModifier(Material aMaterial) { + return 1f; + } + + private static int calcReinforced(Material aMaterial) { + return aMaterial.getMeltingPointC()/3600; + } + + private static int calcBowProjectileSpeed(Material aMaterial) { + return aMaterial.vHarvestLevel+2; + } + + private static int calcBowDrawSpeed(Material aMaterial) { + return aMaterial.vHarvestLevel+8; + } + + private static float calcProjectileMass(Material aMaterial) { + return (aMaterial.getMeltingPointC()/1800)*0.1f; + } + + private static float calcProjectileFragility(Material aMaterial) { + return 0f; + } + + private static String calcStyle(Material aMaterial) { + String aReturn = "" + EnumChatFormatting.WHITE; + int aTemp = aMaterial.getMeltingPointC(); + if (aTemp < 3600) { + aReturn = "" + EnumChatFormatting.WHITE; + } + else if (aTemp >= 3600) { + aReturn = "" + EnumChatFormatting.YELLOW; + } + else if (aTemp >= (3600*2)) { + aReturn = "" + EnumChatFormatting.GREEN; + } + else if (aTemp >= (3600*3)) { + aReturn = "" + EnumChatFormatting.RED; + } + else if (aTemp >= (3600*4)) { + aReturn = "" + EnumChatFormatting.DARK_RED; + } + else { + aReturn = "" + EnumChatFormatting.GOLD; + } + return aReturn; + } + + private static int calcColour(Material aMaterial) { + return aMaterial.getRgbAsHex(); + } + + private boolean generateRecipes(Material aMaterial) { + + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + + + + FluidType.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); + + Smeltery.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); + Smeltery.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); + + if (aMaterial.getMeltingPointC() <= 3600) { + ItemStack ingotcast = new ItemStack(TinkerSmeltery.metalPattern, 1, 0); + TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1), + aMaterial.getFluid(144*9), (ItemStack) null, true, 100); + TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), + aMaterial.getFluid(144), ingotcast, false, 50); + } + + + return true; + } + + + + + + + + + +} diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index aed5b46e0a..10eb93b4d7 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,9 +1,16 @@ package gtPlusPlus.xmod.tinkers.util; import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.FluidType; +import tconstruct.library.crafting.Smeltery; +import tconstruct.smeltery.TinkerSmeltery; public class TinkersUtils { @@ -17,16 +24,13 @@ public class TinkersUtils { else { if (mSmelteryInstance == null || mSmelteryClassInstance == null) { if (mSmelteryClassInstance == null) { - try { - mSmelteryClassInstance = Class.forName("tconstruct.library.crafting.Smeltery"); - } - catch (ClassNotFoundException e) {} + mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); } if (mSmelteryClassInstance != null) { try { mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + catch (IllegalArgumentException | IllegalAccessException e) { } } } @@ -40,9 +44,8 @@ public class TinkersUtils { public static final boolean isTiConFirstInOD() { if (LoadedMods.TiCon) { try { - return (boolean) ReflectionUtils.getField(Class.forName("PHConstruct"), "tconComesFirst").get(null); - } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + return (boolean) ReflectionUtils.getField(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } } return false; @@ -51,8 +54,8 @@ public class TinkersUtils { public static final boolean stopTiconLoadingFirst() { if (isTiConFirstInOD()) { try { - ReflectionUtils.setFieldValue(Class.forName("PHConstruct"), "tconComesFirst", false); - if ((boolean) ReflectionUtils.getField(Class.forName("PHConstruct"), "tconComesFirst").get(null) == false) { + ReflectionUtils.setFinalFieldValue(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst", false); + if ((boolean) ReflectionUtils.getField(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst").get(null) == false) { return true; } //Did not work, let's see where TiCon uses this and prevent it. @@ -95,5 +98,48 @@ public class TinkersUtils { public static int getFuelDuration (Fluid fluid){ return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); } + + public static boolean registerFluidType(String name, Block block, int meta, int baseTemperature, Fluid fluid, boolean isToolpart) { + + + + //FluidType.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); + return false; + } + + public static boolean addMelting(Material aMaterial) { + Smeltery.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); + Smeltery.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); + return false; + } + + public static boolean addBasinRecipe(Material aMaterial) { + TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1), + aMaterial.getFluid(144*9), (ItemStack) null, true, 100); + return false; + } + + public static boolean addCastingTableRecipe(Material aMaterial) { + ItemStack ingotcast = new ItemStack(TinkerSmeltery.metalPattern, 1, 0); + TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); + return false; + } + + + + + + + + + + + + + + + + + } diff --git a/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java b/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java index b28ccdaa9b..9e5efb452c 100644 --- a/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java +++ b/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java @@ -67,20 +67,17 @@ public class WitchUtils { } } - public static Field getField(String aClassName, String aFieldName) { - Class c; - try { - c = Class.forName(aClassName); - if (c != null) { - Field f = ReflectionUtils.getField(c, aFieldName); - if (f != null) { - return f; - } - } - } catch (ClassNotFoundException | NoSuchFieldException e) { + public static Field getField(String aClassName, String aFieldName) { + Class c; + c = ReflectionUtils.getClass(aClassName); + if (c != null) { + Field f = ReflectionUtils.getField(c, aFieldName); + if (f != null) { + return f; + } } return null; - } + } public static boolean isEqual(final GameProfile a, final GameProfile b) { return a != null && b != null && a.getId() != null && b.getId() != null && a.getId().equals(b.getId()); diff --git a/src/Java/vswe/stevescarts/ModuleData/GppModuleData.java b/src/Java/vswe/stevescarts/ModuleData/GppModuleData.java index 0b605fb8c1..eb8a8f319f 100644 --- a/src/Java/vswe/stevescarts/ModuleData/GppModuleData.java +++ b/src/Java/vswe/stevescarts/ModuleData/GppModuleData.java @@ -41,7 +41,7 @@ public class GppModuleData extends ModuleData { validModules.put(ID_ExoticSeedAddon, true); - } catch (NoSuchFieldException | IllegalAccessException e) { + } catch (IllegalAccessException e) { e.printStackTrace(); } } |