From 5507b8c0e7b2117a33dfb1fedbd14b3c30f6a01b Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 5 Feb 2019 20:02:33 +0000 Subject: + Added recipe for Nano Healer. + Added recipe for Strange Dust. + Added recipe for Slow Builders Ring. + Added recipes for Charge Packs. + Added recipes to make obtaining Zirconium a little earlier. + Added packager recipes for all ore materials. + Added lathe recipes for all materials -> rods. Closes #411. + Added way to process Silicon Carbide into Synthetic Graphite. Closes #407. + Added proper achievement localization for all new AL recipes. + Added more INIT_PHASE's. - Removed ways to obtain Trinium dust in GTNH. (Leave handling to GT instead). % Adjusted recipes for Cyclotron and Casings, it's now assembled instead of shape crafted. % Adjusted circuits used in lower tier dehydrator recipes for consistency. Closes #364. % Adjusted a few materials having '-' in their name within en_US.lang. % Adjusted power capacity of the Gem Batteries. % Adjusted tiering for Large Auto-Assembler, it has been reduced by one. % Adjusted composition of Pikyonium to now require Yttrium, instead of the rare Ytterbium. % Adjusted composition of DEEP_EARTH_REACTOR_FUEL_DEPOSIT to be slightly more balanced. % Adjusted smelting point of Zirconium Carbide. $ Fixed an NPE in GeneralTooltipEventHandler.java. $ Fixed weird invisible recipes. Closes #304. $ Confirmed Large Mixer is now working correctly. Closes #366. (Closed in previous commit https://github.com/draknyte1/GTplusplus/commit/918d763dabd82d47db739a1b0a51c01f0803adc0). $ Confirmed Matter Fabricator is now working correctly. Closes #360. + Auto Doors. Closes #338. (Closed in previous commit https://github.com/draknyte1/GTplusplus/commit/22c6a05a8a3a00294bcb8890a1e2a0fdc9196de8). % Changed Energy Buffer Recipes. Closes #52. (Closed in previous commit https://github.com/draknyte1/GTplusplus/commit/499411aa21ac4a742b6d51ef3ce9c4046d0a22c1). $ Invalid Recipe. Closes #241. (Closed in unknown, previous commit). --- src/Java/gtPlusPlus/core/material/ALLOY.java | 6 +++--- src/Java/gtPlusPlus/core/material/ORES.java | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Java/gtPlusPlus/core/material') diff --git a/src/Java/gtPlusPlus/core/material/ALLOY.java b/src/Java/gtPlusPlus/core/material/ALLOY.java index c7397962ad..4edd36c51f 100644 --- a/src/Java/gtPlusPlus/core/material/ALLOY.java +++ b/src/Java/gtPlusPlus/core/material/ALLOY.java @@ -524,11 +524,11 @@ public final class ALLOY { "Zirconium Carbide", //Material Name MaterialState.SOLID, //State new short[]{222, 202, 180, 0}, //Material Colour - 1855, //Melting Point in C + 1555, //Melting Point in C -1, -1, -1, - true, //Uses Blast furnace? + false, //Uses Blast furnace? //Material Stacks with Percentage of required elements. new MaterialStack[]{ new MaterialStack(ELEMENT.getInstance().ZIRCONIUM, 50), @@ -787,7 +787,7 @@ public final class ALLOY { new MaterialStack(ELEMENT.getInstance().CERIUM, 6), new MaterialStack(ELEMENT.getInstance().ANTIMONY, 4), new MaterialStack(ELEMENT.getInstance().PLATINUM, 4), - new MaterialStack(ELEMENT.getInstance().YTTERBIUM, 2), + new MaterialStack(ELEMENT.getInstance().YTTRIUM, 2), new MaterialStack(ALLOY.TUNGSTENSTEEL, 8) }); diff --git a/src/Java/gtPlusPlus/core/material/ORES.java b/src/Java/gtPlusPlus/core/material/ORES.java index a8b86a142c..801e4924b3 100644 --- a/src/Java/gtPlusPlus/core/material/ORES.java +++ b/src/Java/gtPlusPlus/core/material/ORES.java @@ -807,15 +807,15 @@ public final class ORES { -1, 4, //Radiation new MaterialStack[]{// Na3AlF6 - new MaterialStack(ELEMENT.getInstance().RADON, 3), - new MaterialStack(ELEMENT.getInstance().RADIUM, 2), + new MaterialStack(ELEMENT.getInstance().RADON, 2), + new MaterialStack(ELEMENT.getInstance().RADIUM, 1), new MaterialStack(ELEMENT.getInstance().URANIUM235, 1), - new MaterialStack(ELEMENT.getInstance().URANIUM238, 13), - new MaterialStack(ELEMENT.getInstance().THORIUM, 28), - new MaterialStack(ELEMENT.getInstance().THORIUM232, 5), - new MaterialStack(FLUORCAPHITE, 4), - new MaterialStack(SAMARSKITE_Y, 6), - new MaterialStack(TITANITE, 2) + new MaterialStack(ELEMENT.getInstance().URANIUM238, 10), + new MaterialStack(ELEMENT.getInstance().THORIUM, 25), + new MaterialStack(ELEMENT.getInstance().THORIUM232, 4), + new MaterialStack(FLUORCAPHITE, 6), + new MaterialStack(SAMARSKITE_Y, 8), + new MaterialStack(TITANITE, 4) }); -- cgit From 4f435ae75b176a9d90c7afa6b1ff40e9ba9c286a Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:06:01 +0000 Subject: + 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. --- src/Java/gregtech/api/util/FishPondFakeRecipe.java | 4 +- src/Java/gtPlusPlus/GTplusplus.java | 14 + .../gen/gt/WorldGen_GT_Australia_Ore_Layer.java | 2 +- .../gtPlusPlus/core/block/base/BlockBaseOre.java | 4 +- .../core/block/machine/Machine_ProjectTable.java | 30 +- .../core/block/machine/Machine_Workbench.java | 30 +- .../core/client/renderer/RenderGiantChicken.java | 2 +- src/Java/gtPlusPlus/core/common/CommonProxy.java | 6 +- .../entity/monster/EntityStaballoyConstruct.java | 17 +- .../gtPlusPlus/core/gui/item/GuiBaseGrindle.java | 2 +- .../core/gui/machine/GUI_ScrollTest.java | 7 +- .../core/handler/COMPAT_IntermodStaging.java | 13 +- src/Java/gtPlusPlus/core/item/ModItems.java | 9 +- .../core/item/chemistry/IonParticles.java | 11 +- .../core/item/general/books/ItemBaseBook.java | 5 +- .../item/general/capture/ItemEntityCatcher.java | 13 +- .../core/item/tool/misc/DebugScanner.java | 98 +++++ src/Java/gtPlusPlus/core/lib/CORE.java | 2 +- src/Java/gtPlusPlus/core/lib/LoadedMods.java | 6 + src/Java/gtPlusPlus/core/material/ELEMENT.java | 6 +- src/Java/gtPlusPlus/core/material/Material.java | 30 +- .../gtPlusPlus/core/recipe/RECIPES_GREGTECH.java | 2 + src/Java/gtPlusPlus/core/slots/SlotToolBox.java | 18 +- src/Java/gtPlusPlus/core/util/Utils.java | 2 +- .../gtPlusPlus/core/util/minecraft/FoodUtils.java | 2 +- .../core/util/minecraft/MaterialUtils.java | 2 +- .../core/util/minecraft/MiningUtils.java | 22 +- .../util/minecraft/gregtech/PollutionUtils.java | 26 +- .../core/util/reflect/ClientProxyFinder.java | 32 -- .../gtPlusPlus/core/util/reflect/ProxyFinder.java | 4 +- .../core/util/reflect/ReflectionUtils.java | 438 ++++++++++++++------- .../everglades/gen/gt/WorldGen_GT_Ore_Layer.java | 2 +- .../gtPlusPlus/nei/GT_NEI_MultiBlockHandler.java | 2 +- .../villagers/entity/EntityBaseVillager.java | 62 +-- .../villagers/entity/EntityNativeAustralian.java | 61 +-- .../villagers/tile/TileEntityGenericSpawner.java | 2 +- .../gtPlusPlus/preloader/Preloader_GT_OreDict.java | 41 +- .../transformers/Preloader_ClassTransformer2.java | 6 +- .../xmod/bartcrops/HANDLER_CropsPlusPlus.java | 21 + .../xmod/bartcrops/LoaderOfTheCrops.java | 109 +++++ .../bartcrops/abstracts/BaseAestheticCrop.java | 37 ++ .../xmod/bartcrops/abstracts/BaseCrop.java | 56 +++ .../bartcrops/abstracts/BaseHarvestableCrop.java | 69 ++++ .../gtPlusPlus/xmod/bartcrops/crops/Crop_Hemp.java | 56 +++ .../xmod/eio/handler/HandlerTooltip_EIO.java | 8 +- src/Java/gtPlusPlus/xmod/forestry/HANDLER_FR.java | 8 +- .../forestry/bees/custom/GTPP_Bee_Definition.java | 2 +- .../xmod/forestry/bees/custom/GTPP_Bees.java | 2 +- .../galacticraft/handler/HandlerTooltip_GC.java | 5 +- .../core/world/gen/ChunkProviderGalactic.java | 46 ++- .../xmod/galacticraft/util/GalacticUtils.java | 10 +- .../GT_MetaTileEntity_Hatch_Naquadah.java | 2 +- .../GT_MetaTileEntity_Hatch_Plasma.java | 10 +- .../base/GregtechMeta_MultiBlockBase.java | 18 +- .../xmod/gregtech/api/objects/MultiblockLayer.java | 10 +- .../api/util/GregtechOreDictUnificator.java | 3 - .../xmod/gregtech/common/Meta_GT_Proxy.java | 125 +++++- .../xmod/gregtech/common/StaticFields59.java | 6 +- .../gregtech/common/helpers/ChargingHelper.java | 9 +- .../gregtech/common/helpers/TreeFarmHelper.java | 4 +- .../common/items/MetaGeneratedGregtechItems.java | 2 +- .../multi/production/GT4Entity_AutoCrafter.java | 2 +- .../GregtechMetaTileEntity_Cyclotron.java | 10 +- ...egtechMetaTileEntity_IndustrialFishingPond.java | 2 +- .../GregtechMetaTileEntity_Refinery.java | 67 ++-- .../xmod/gregtech/loaders/GT_Material_Loader.java | 17 +- .../xmod/gregtech/recipes/GregtechRecipeAdder.java | 5 +- .../gregtech/GregtechNitroDieselFix.java | 5 +- .../xmod/growthcraft/fishtrap/FishTrapHandler.java | 5 +- .../xmod/sc2/modules/ModuleExoticSeeds.java | 4 +- .../xmod/thaumcraft/HANDLER_Thaumcraft.java | 5 +- .../gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java | 4 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 200 ++++++++++ .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 66 +++- src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java | 21 +- .../vswe/stevescarts/ModuleData/GppModuleData.java | 2 +- 76 files changed, 1470 insertions(+), 598 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/DebugScanner.java delete mode 100644 src/Java/gtPlusPlus/core/util/reflect/ClientProxyFinder.java create mode 100644 src/Java/gtPlusPlus/xmod/bartcrops/HANDLER_CropsPlusPlus.java create mode 100644 src/Java/gtPlusPlus/xmod/bartcrops/LoaderOfTheCrops.java create mode 100644 src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseAestheticCrop.java create mode 100644 src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseCrop.java create mode 100644 src/Java/gtPlusPlus/xmod/bartcrops/abstracts/BaseHarvestableCrop.java create mode 100644 src/Java/gtPlusPlus/xmod/bartcrops/crops/Crop_Hemp.java create mode 100644 src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java (limited to 'src/Java/gtPlusPlus/core/material') 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) ReflectionUtils.getField(FishingHooks.class, "junk").get(null); treasure = (ArrayList) 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 mEntityClass; String mClassName; - mClassName = NBTUtils.getString(aStack,"mClassName"); - try { - mEntityClass = (Class) Class.forName(mClassName); - if (mEntityClass != null) { - return mEntityClass; - } - } - catch (ClassNotFoundException e) { + mClassName = NBTUtils.getString(aStack, "mClassName"); + mEntityClass = (Class) 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(9, 28); } - clazz = (Class) Class.forName("gregtech.GT_Mod"); + clazz = (Class) 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 mCachedClasses = new LinkedHashMap(); + public static Map mCachedMethods = new LinkedHashMap(); + public static Map mCachedFields = new LinkedHashMap(); + + 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 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 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.
* 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"); @@ -257,14 +381,55 @@ public class ReflectionUtils { Logger.REFLECTION("Invoke failed or did something wrong."); 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(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 mHasCropObj = new ArrayList(); + private CropCard mCropObj; + private ItemStack mBaseSeed; + private static List 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 cropLoader() { + List p = new ArrayList(); + + p.add(new LoaderOfTheCrops(new Crop_Hemp(), new ItemStack(Item.getItemById(111), 3))); + + return p; + } + + private static final List cropObjs() { + List p = new ArrayList(); + + for (int i = 0; i < mCropList.size(); ++i) { + p.add(cropUnpackerCC((LoaderOfTheCrops) mCropList.get(i))); + } + + return p; + } + + private static final List setBaseSeed() { + List p = new ArrayList(); + + for (int i = 0; i < mCropList.size(); ++i) { + p.add(cropUnpackerCG((LoaderOfTheCrops) mCropList.get(i))); + } + + return p; + } + + private static final List setnames() { + List s = new ArrayList(); + + 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 baseseed = new ArrayList(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 getCropInformation() { + List ret = new ArrayList(); + 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 aMobs = new AutoMap(); - 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 mValidPlasmaNameCache = new AutoMap(); 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 aFreezerMapRebaked = new AutoMap(); + AutoMap aRemovedRecipes = new AutoMap(); + + //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 aNewRecipes = new AutoMap(); + 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(), "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 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 aTweakedFluids = new AutoMap(); 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 aInternalMaterialIdMap = new HashMap(); + 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(); } } -- cgit From 5ffa0957e9d936ec999ee5157be771ff4b315aac Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 28 Feb 2019 23:49:40 +0000 Subject: + Enabled Tinkers compat for GT++ Materials. $ Migrated lots of TiCon code to be reflective. $ Upload missing class ItemDummyResearch.java. --- .../core/item/crafting/ItemDummyResearch.java | 111 +++++++ src/Java/gtPlusPlus/core/material/Material.java | 8 + .../gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java | 10 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 185 ++++++------ .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 330 ++++++++++++++++++--- 5 files changed, 516 insertions(+), 128 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java (limited to 'src/Java/gtPlusPlus/core/material') diff --git a/src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java b/src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java new file mode 100644 index 0000000000..1c28f99ff8 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java @@ -0,0 +1,111 @@ +package gtPlusPlus.core.item.crafting; + +import java.util.LinkedHashMap; +import java.util.Map; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.general.ItemGenericToken; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +public class ItemDummyResearch extends ItemGenericToken { + + public static enum ASSEMBLY_LINE_RESEARCH { + + + RESEARCH_1_CONTAINMENT("Containment Fields", "Advanced scientific study"), + RESEARCH_2_BASIC_CHEM("Basic Chemistry", "Time to start at the beginning"), + RESEARCH_3_ADV_CHEM("Advanced Chemistry", "Best learn more than chemical equations"), + RESEARCH_4_BASIC_PHYSICS("Basic Physics", "Fundamental laws of motion"), + RESEARCH_5_ADV_PHYSICS("Advanced Physics", "Advanced knowledge!"), + RESEARCH_6_BASIC_METALLURGY("Basic Metallurgy", "Information about material smelting"), + RESEARCH_7_ADV_METALLURGY("Advanced Metallurgy", "Advanced Material Sciences!"); + + + + + + + + + + + + + + + + + + + private String mName; + private String mDesc; + + private ASSEMBLY_LINE_RESEARCH(String aName, String aDesc) { + mName = aName; + mDesc = aDesc; + ModItems.itemDummyResearch.register(mName, mDesc); + } + + } + + + + + + + + + + + private static Map mInternalNameToIdMap = new LinkedHashMap(); + + public static ItemStack getResearchStack(ASSEMBLY_LINE_RESEARCH aResearchName, int aStacksize) { + Integer aMeta = mInternalNameToIdMap.get(Utils.sanitizeString(aResearchName.mName)); + if (aMeta == null) { + aMeta = 0; + } + return ItemUtils.simpleMetaStack(ModItems.itemDummyResearch, aMeta, aStacksize); + } + + private int aID = 0; + public ItemDummyResearch() { + super("dummyResearch", "Research", new String[] {"This object requires some further study"}, "research"); + + + + } + + /** + * + * @param aResearchType - What is the research for? + * @param aDescriptThe - tooltip for this research + * @return - Did we register a custom research item? + */ + public boolean register(String aResearchType, String aDescript) { + int aNewID = aID++; + mInternalNameToIdMap.put(Utils.sanitizeString(aResearchType), aNewID); + return register(aNewID, "Research on "+aResearchType, 1, aDescript); + } + + @Override + public boolean register(int id, String aLocalName, int aMaxStack, String aDescript) { + return register(id, aLocalName, 1, new String[] {aDescript, EnumChatFormatting.DARK_GRAY+"Used to further your knowledge"}, EnumRarity.common, EnumChatFormatting.LIGHT_PURPLE); + } + + @Override + @SideOnly(Side.CLIENT) + public final void registerIcons(final IIconRegister aIconRegister) { + for (int i = 0, j = mLocalNames.size(); i < j; i++) { + mIcons.put(i, aIconRegister.registerIcon(CORE.MODID + ":" + "research" + "/" + "note")); + } + } + +} diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index d996bed128..f0a2eb7152 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -15,6 +15,7 @@ import gregtech.api.enums.TextureSet; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.item.base.cell.BaseItemCell; +import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.state.MaterialState; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.data.StringUtils; @@ -23,6 +24,7 @@ import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects; +import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -77,6 +79,8 @@ public class Material { public int vHarvestLevel; private GTPP_Aspects[] vAspects; + + public BaseTinkersMaterial vTiConHandler; public static AutoMap invalidMaterials = new AutoMap(); @@ -492,6 +496,10 @@ public class Material { } this.textureSet = setTextureSet(set, vTier); + + if (LoadedMods.TiCon) { + this.vTiConHandler = new BaseTinkersMaterial(this); + } Logger.MATERIALS("Creating a Material instance for "+materialName); Logger.MATERIALS("Formula: "+this.vChemicalFormula + " Smallest Stack: "+this.smallestStackSizeWhenProcessing+" Smallest Ratio:"+ratio); diff --git a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java index a6260d4246..9ba10fc40e 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java @@ -6,6 +6,7 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import gtPlusPlus.xmod.tinkers.util.TinkersUtils; import net.minecraft.block.Block; import net.minecraftforge.fluids.Fluid; @@ -13,6 +14,8 @@ import net.minecraftforge.fluids.FluidRegistry; public class HANDLER_Tinkers { + public static AutoMap mTinkerMaterials = new AutoMap(); + public static final void preInit() { if (LoadedMods.TiCon) { @@ -31,8 +34,13 @@ public class HANDLER_Tinkers { } } - public static final void postInit() { + public static final void postInit() { if (LoadedMods.TiCon) { + + for (BaseTinkersMaterial y : mTinkerMaterials) { + y.generate(); + } + Class aTinkersSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); AutoMap aTweakedFluids = new AutoMap(); if (aTinkersSmeltery != null) { diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index a2ab894f53..0730f5baba 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -5,98 +5,38 @@ import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt; import java.util.HashMap; import cpw.mods.fml.common.event.FMLInterModComms; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.tinkers.HANDLER_Tinkers; +import gtPlusPlus.xmod.tinkers.util.TinkersUtils; 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 aInternalMaterialIdMap = new HashMap(); private static int aNextFreeID = 440; - private final String mUnlocalName; + public final String mLocalName; - private final int aID; + + private final String mUnlocalName; + private final int mID; + private final Material mMaterial; 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); - - - } - - - - - - - + mMaterial = aMaterial; + mID = aNextFreeID++; + aInternalMaterialIdMap.put(mUnlocalName, mID); + HANDLER_Tinkers.mTinkerMaterials.put(this); } public String getUnlocalName() { return mUnlocalName; - } - + } private static int calcDurability(Material aMaterial) { return safeCast_LongToInt(aMaterial.vDurability); @@ -166,22 +106,95 @@ public class BaseTinkersMaterial { return aMaterial.getRgbAsHex(); } - private boolean generateRecipes(Material aMaterial) { - - //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + public Object generateToolMaterial(Material aMaterial) { + int level, dura, speed, dmg, reinf, primColour; + float handle, stonebound; + level = calcHarvestLevel(aMaterial); + dura = calcDurability(aMaterial); + speed = calcMiningSpeed(aMaterial); + dmg = calcAttack(aMaterial); + reinf = calcReinforced(aMaterial); + primColour = calcColour(aMaterial); + handle = calcHandleModifier(aMaterial); + //stonebound = calcHarvestLevel(aMaterial); + stonebound = 0; + return TinkersUtils.generateToolMaterial(aMaterial.getLocalizedName(), aMaterial.getUnlocalizedName(), level, dura, speed, dmg, handle, reinf, stonebound, calcStyle(aMaterial), primColour); + } + public void generate() { + + Logger.INFO("Trying to generate TiCon Material: "+mLocalName); + int id = mID; + if (id > 0) { + + Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); + Logger.INFO("Created TiCon Material: "+mLocalName); + + TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); + TinkersUtils.addDefaultToolPartMaterial(id); + TinkersUtils.addBowMaterial(id, calcBowDrawSpeed(mMaterial), 1.0F); + TinkersUtils.addArrowMaterial(id, calcProjectileMass(mMaterial), calcProjectileFragility(mMaterial)); + + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("Id", id); + tag.setString("Name", mLocalName); + tag.setString("localizationString", mUnlocalName); + tag.setInteger("Durability", calcDurability(mMaterial)); // 97 + tag.setInteger("MiningSpeed", calcMiningSpeed(mMaterial)); // 150 + tag.setInteger("HarvestLevel", calcHarvestLevel(mMaterial)); // 1 + tag.setInteger("Attack", calcAttack(mMaterial)); // 0 + tag.setFloat("HandleModifier", calcHandleModifier(mMaterial)); // 1.0f + tag.setInteger("Reinforced", calcReinforced(mMaterial)); // 0 + tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(mMaterial)); // 3.0f + tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(mMaterial)); // 18 + tag.setFloat("Projectile_Mass", calcProjectileMass(mMaterial)); // 0.69f + tag.setFloat("Projectile_Fragility", calcProjectileFragility(mMaterial)); // 0.2f + tag.setString("Style", calcStyle(mMaterial)); + tag.setInteger("Color", calcColour(mMaterial)); + + Logger.INFO("Sending IMC to TConstruct: addMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + + generateRecipes(mMaterial); + + + ItemStack itemstack = mMaterial.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? + + Logger.INFO("Sending IMC to TConstruct: addPartBuilderMaterial - "+mLocalName+"."); + 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); + + Logger.INFO("Sending IMC to TConstruct: addMaterialItem - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + + + } - - 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)); - + } + + private boolean generateRecipes(Material aMaterial) { + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + TinkersUtils.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); + TinkersUtils.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); + TinkersUtils.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), + ItemStack ingotcast = TinkersUtils.getPattern(1); + TinkersUtils.addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100); - TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), + TinkersUtils.addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); } @@ -195,6 +208,4 @@ public class BaseTinkersMaterial { - - } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index 10eb93b4d7..b902e38a1e 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,44 +1,112 @@ package gtPlusPlus.xmod.tinkers.util; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.LinkedHashMap; + 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.Item; 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; +import net.minecraftforge.fluids.FluidStack; public class TinkersUtils { private static Object mSmelteryInstance; private static Class mSmelteryClassInstance; + + private static Object mTinkersRegistryInstance; + private static Class mTinkersRegistryClass; + + private static final Class mToolMaterialClass; - public static Object getSmelteryInstance() { + private static final HashMap mMethodCache = new LinkedHashMap(); + + + static { + setRegistries(); + mToolMaterialClass = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); + } + + + /** + * + * @param aSwitch - The Registry to return + */ + private static Object getTiConDataInstance(int aSwitch) { if (!LoadedMods.TiCon) { return null; } else { - if (mSmelteryInstance == null || mSmelteryClassInstance == null) { - if (mSmelteryClassInstance == null) { - mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); - } - if (mSmelteryClassInstance != null) { - try { - mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); + + if (mTinkersRegistryClass == null || mSmelteryClassInstance == null) { + setRegistries(); + } + + // getSmelteryInstance + if (aSwitch == 0) { + + //Set Smeltery Instance + if (mSmelteryInstance == null || mSmelteryClassInstance == null) { + if (mSmelteryClassInstance == null) { + mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); } - catch (IllegalArgumentException | IllegalAccessException e) { + if (mSmelteryClassInstance != null) { + try { + mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); + } + catch (IllegalArgumentException | IllegalAccessException e) { + } } } - } - } - if (mSmelteryInstance != null) { - return mSmelteryInstance; - } - return null; + + //Return Smeltery Instance + if (mSmelteryInstance != null) { + return mSmelteryInstance; + } + } + + // getTableCastingInstance || getBasinCastingInstance + else if (aSwitch == 1) { + if (mTinkersRegistryClass == null || mTinkersRegistryInstance == null) { + if (mTinkersRegistryClass == null) { + mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + } + if (mTinkersRegistryClass != null) { + if (mTinkersRegistryInstance == null) { + try { + mTinkersRegistryInstance = ReflectionUtils.getField(mTinkersRegistryClass, "instance").get(null); + } + catch (IllegalArgumentException | IllegalAccessException e) { + } + } + } + } + + //Return Smeltery Instance + if (mTinkersRegistryInstance != null) { + return mTinkersRegistryInstance; + } + } + + return null; + } + } + + private static void setRegistries() { + if (mTinkersRegistryClass == null) { + mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + } + if (mSmelteryClassInstance == null) { + mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + } } public static final boolean isTiConFirstInOD() { @@ -75,56 +143,100 @@ public class TinkersUtils { * @param duration How long one "portion" of liquid fuels the smeltery. Lava is 10. */ public static void addSmelteryFuel (Fluid fluid, int power, int duration){ - ReflectionUtils.invokeVoid(getSmelteryInstance(), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration}); + ReflectionUtils.invokeVoid(getTiConDataInstance(0), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration}); } /** * Returns true if the liquid is a valid smeltery fuel. */ public static boolean isSmelteryFuel (Fluid fluid){ - return ReflectionUtils.invoke(getSmelteryInstance(), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid}); + return ReflectionUtils.invoke(getTiConDataInstance(0), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid}); } /** * Returns the power of a smeltery fuel or 0 if it's not a fuel. */ public static int getFuelPower (Fluid fluid){ - return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid}); + return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid}); } /** * Returns the duration of a smeltery fuel or 0 if it's not a fuel. */ public static int getFuelDuration (Fluid fluid){ - return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); + return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "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; + if (mMethodCache.get("registerFluidType") == null) { + Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.FluidType"), "registerFluidType", String.class, Block.class, int.class, int.class, Fluid.class, boolean.class); + mMethodCache.put("registerFluidType", m); + } + try { + mMethodCache.get("registerFluidType").invoke(null, name, block, meta, baseTemperature, fluid, isToolpart); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + 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 addBaseMeltingRecipes(Material aMaterial) { + return addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)) && + addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); } - 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 addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) { + if (mMethodCache.get("addMelting") == null) { + Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "addMelting", ItemStack.class, Block.class, int.class, int.class, FluidStack.class); + mMethodCache.put("addMelting", m); + } + try { + mMethodCache.get("addMelting").invoke(null, input, block, metadata, temperature, liquid); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + 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; + + + + + + + + + + + public static boolean addBaseBasinRecipes(Material aMaterial) { + return addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100); } + public static boolean addBasinRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) { + if (mMethodCache.get("addBasinRecipe") == null) { + Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), "addCastingRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class); + mMethodCache.put("addBasinRecipe", m); + } + try { + mMethodCache.get("addBasinRecipe").invoke(getCastingInstance(0), output, metal, cast, consume, delay); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } + } @@ -132,6 +244,24 @@ public class TinkersUtils { + public static boolean addBaseCastingRecipes(Material aMaterial) { + ItemStack ingotcast = getPattern(1); + return addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); + } + + public static boolean addCastingTableRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) { + if (mMethodCache.get("addCastingTableRecipe") == null) { + Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), "addBasinRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class); + mMethodCache.put("addCastingTableRecipe", m); + } + try { + mMethodCache.get("addCastingTableRecipe").invoke(getCastingInstance(1), output, metal, cast, consume, delay); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } + } + @@ -139,7 +269,127 @@ public class TinkersUtils { + public static Object getCastingInstance(int aType) { + if (aType == 0) { + return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); + } + else if (aType == 1) { + return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); + } + else { + return null; + } + } + + private static Item mTinkerMetalPattern; + public static ItemStack getPattern(int aType) { + if (mTinkerMetalPattern == null) { + Field m = ReflectionUtils.getField(ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"), "metalPattern"); + if (m != null) { + try { + mTinkerMetalPattern = (Item) m.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + } + } + } + if (mTinkerMetalPattern != null) { + ItemStack ingotCast = new ItemStack(mTinkerMetalPattern, aType, 0); + return ingotCast; + } + return ItemUtils.getErrorStack(1, "Bad Tinkers Pattern"); + + + + + + + + } + /** + * Generates Tinkers {@link ToolMaterial}'s reflectively. + * @param name + * @param localizationString + * @param level + * @param durability + * @param speed + * @param damage + * @param handle + * @param reinforced + * @param stonebound + * @param style + * @param primaryColor + * @return + */ + public static Object generateToolMaterial(String name, String localizationString, int level, int durability, int speed, int damage, float handle, int reinforced, float stonebound, String style, int primaryColor) { + try { + Constructor constructor = mToolMaterialClass.getConstructor(String.class, String.class, int.class, int.class, int.class, int.class, float.class, int.class, float.class, String.class, int.class); + Object myObject = constructor.newInstance(name, localizationString, level, durability, speed, damage, handle, reinforced, stonebound, style, primaryColor); + return myObject; + } catch (Throwable t) { + t.printStackTrace(); + return null; + } + } + + + + + + + + + + + + public static void addToolMaterial(int id, Object aToolMaterial) { + setRegistries(); + if (mMethodCache.get("addToolMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addToolMaterial", int.class, mToolMaterialClass); + mMethodCache.put("addToolMaterial", m); + } + try { + mMethodCache.get("addToolMaterial").invoke(mTinkersRegistryClass, id, aToolMaterial); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + + } + } + + public static void addDefaultToolPartMaterial(int id) { + setRegistries(); + if (mMethodCache.get("addDefaultToolPartMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addDefaultToolPartMaterial", int.class); + mMethodCache.put("addDefaultToolPartMaterial", m); + } + try { + mMethodCache.get("addDefaultToolPartMaterial").invoke(mTinkersRegistryClass, id); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { + setRegistries(); + if (mMethodCache.get("addBowMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addBowMaterial", int.class, int.class, float.class); + mMethodCache.put("addBowMaterial", m); + } + try { + mMethodCache.get("addBowMaterial").invoke(mTinkersRegistryClass, id, drawspeed, maxSpeed); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static void addArrowMaterial(int id, float mass, float fragility) { + setRegistries(); + if (mMethodCache.get("addArrowMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addArrowMaterial", int.class, float.class, float.class); + mMethodCache.put("addArrowMaterial", m); + } + try { + mMethodCache.get("addArrowMaterial").invoke(mTinkersRegistryClass, id, mass, fragility); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } } -- cgit From a5f5766e189593f8cfe7fbef862b1bb77207720e Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 1 Mar 2019 00:39:20 +0000 Subject: + Added some reflection logging to assist in debugging. % Only solid GT++ Mats will generates TiCon equivs. --- src/Java/gtPlusPlus/core/material/Material.java | 2 +- .../core/util/reflect/ReflectionUtils.java | 30 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/Java/gtPlusPlus/core/material') diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index f0a2eb7152..01503a1fc5 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -497,7 +497,7 @@ public class Material { this.textureSet = setTextureSet(set, vTier); - if (LoadedMods.TiCon) { + if (LoadedMods.TiCon && this.materialState == MaterialState.SOLID) { this.vTiConHandler = new BaseTinkersMaterial(this); } diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 4ade8b1096..372bf81fe9 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -108,6 +108,7 @@ public class ReflectionUtils { if (y == null) { y = getClass_Internal(aClassCanonicalName); if (y != null) { + Logger.REFLECTION("Caching Class: "+aClassCanonicalName); cacheClass(y); } } @@ -128,6 +129,7 @@ public class ReflectionUtils { if (y == null) { Method u = getMethod_Internal(aClass, aMethodKey, aTypes); if (u != null) { + Logger.REFLECTION("Caching Method: "+aMethodName + "." + aMethodKey); cacheMethod(u); return u; } else { @@ -153,6 +155,7 @@ public class ReflectionUtils { try { u = getField_Internal(aClass, aFieldName); if (u != null) { + Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getCanonicalName()); cacheField(u); return u; } @@ -468,25 +471,48 @@ public class ReflectionUtils { try { m = getMethodRecursively(aClass, aMethodName); } catch (NoSuchMethodException e) { + Logger.REFLECTION("Unable to find method '"+aMethodName+"'"); e.printStackTrace(); + dumpClassInfo(aClass); } } return m; } - public static Method getMethodRecursively(final Class clazz, final String fieldName) throws NoSuchMethodException { + private static Method getMethodRecursively(final Class clazz, final String fieldName) throws NoSuchMethodException { try { Method k = clazz.getDeclaredMethod(fieldName); makeMethodAccessible(k); return k; } catch (final NoSuchMethodException e) { final Class superClass = clazz.getSuperclass(); - if (superClass == null) { + if (superClass == null || superClass == Object.class) { throw e; } return getMethod_Internal(superClass, fieldName); } } + + private static void dumpClassInfo(Class aClass) { + Logger.INFO("We ran into an error processing reflection in "+aClass.getCanonicalName()+", dumping all data for debugging."); + // Get the methods + Method[] methods = aClass.getDeclaredMethods(); + Field[] fields = aClass.getDeclaredFields(); + Constructor[] consts = aClass.getDeclaredConstructors(); + + Logger.INFO("Dumping all Methods."); + for (Method method : methods) { + System.out.println(method.getName()); + } + Logger.INFO("Dumping all Fields."); + for (Field f : fields) { + System.out.println(f.getName()); + } + Logger.INFO("Dumping all Constructors."); + for (Constructor c : consts) { + System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+c.getParameterTypes().toString()); + } + } private static Class getNonPublicClass(final String className) { Class c = null; -- cgit From 35522722af5dddea144c841a71f4fa9087e68966 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 1 Mar 2019 03:00:51 +0000 Subject: % More work on TiCon Compat. --- src/Java/gtPlusPlus/core/material/Material.java | 10 ++- .../gtPlusPlus/core/util/data/StringUtils.java | 15 ++++ .../core/util/reflect/ReflectionUtils.java | 29 +++++-- .../xmod/tinkers/material/BaseTinkersMaterial.java | 93 ++++++++++++++-------- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 27 +++++-- 5 files changed, 128 insertions(+), 46 deletions(-) (limited to 'src/Java/gtPlusPlus/core/material') diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index 01503a1fc5..ba572efe90 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -498,7 +498,9 @@ public class Material { this.textureSet = setTextureSet(set, vTier); if (LoadedMods.TiCon && this.materialState == MaterialState.SOLID) { - this.vTiConHandler = new BaseTinkersMaterial(this); + if (this.getProtons() >= 98 || this.getComposites().size() > 1 || this.getMeltingPointC() >= 3600) { + this.vTiConHandler = new BaseTinkersMaterial(this); + } } Logger.MATERIALS("Creating a Material instance for "+materialName); @@ -753,7 +755,11 @@ public class Material { } final public Block getBlock(){ - return Block.getBlockFromItem(getBlock(1).getItem()); + Block b = Block.getBlockFromItem(getBlock(1).getItem()); + if (b == null) { + Logger.INFO("[ERROR] Tried to get invalid block for "+this.getLocalizedName()+", returning debug block instead."); + } + return b != null ? b : Blocks.lit_furnace; } public final ItemStack getBlock(final int stacksize){ diff --git a/src/Java/gtPlusPlus/core/util/data/StringUtils.java b/src/Java/gtPlusPlus/core/util/data/StringUtils.java index e58b68665a..b64266b5d4 100644 --- a/src/Java/gtPlusPlus/core/util/data/StringUtils.java +++ b/src/Java/gtPlusPlus/core/util/data/StringUtils.java @@ -116,4 +116,19 @@ public class StringUtils { String restLetters = data.substring(1).toLowerCase(); return firstLetter + restLetters; } + + public static String getDataStringFromArray(V[] parameterTypes) { + if (parameterTypes == null || parameterTypes.length == 0) { + return "empty/null"; + } + else { + String aData = ""; + for (V y : parameterTypes) { + if (y != null) { + aData += ", "+y.toString(); + } + } + return aData; + } + } } diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 372bf81fe9..88175b0a82 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -12,6 +12,7 @@ import java.util.Map; import com.google.common.reflect.ClassPath; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.data.StringUtils; public class ReflectionUtils { @@ -116,6 +117,19 @@ public class ReflectionUtils { } + + /** + * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. + * @param aObject - Object containing the Method. + * @param aMethodName - Method's name in {@link String} form. + * @param aTypes - Class Array of Types for {@link Method}'s constructor. + * @return - Valid, non-final, {@link Method} object, or {@link null}. + */ + public static Method getMethod(Object aObject, String aMethodName, Class[] aTypes) { + return getMethod(aObject.getClass(), aMethodName, aTypes); + } + + /** * Returns a cached {@link Method} object. * @param aClass - Class containing the Method. @@ -127,7 +141,7 @@ public class ReflectionUtils { String aMethodKey = aTypes.toString(); CachedMethod y = mCachedMethods.get(aMethodName + "." + aMethodKey); if (y == null) { - Method u = getMethod_Internal(aClass, aMethodKey, aTypes); + Method u = getMethod_Internal(aClass, aMethodName, aTypes); if (u != null) { Logger.REFLECTION("Caching Method: "+aMethodName + "." + aMethodKey); cacheMethod(u); @@ -457,6 +471,7 @@ public class ReflectionUtils { private static Method getMethod_Internal(Class aClass, String aMethodName, Class... aTypes) { Method m = null; try { + Logger.REFLECTION("Method: Internal Lookup: "+aMethodName); m = aClass.getDeclaredMethod(aMethodName, aTypes); if (m != null) { m.setAccessible(true); @@ -468,6 +483,7 @@ public class ReflectionUtils { } } catch (Throwable t) { + Logger.REFLECTION("Method: Internal Lookup Failed: "+aMethodName); try { m = getMethodRecursively(aClass, aMethodName); } catch (NoSuchMethodException e) { @@ -479,9 +495,10 @@ public class ReflectionUtils { return m; } - private static Method getMethodRecursively(final Class clazz, final String fieldName) throws NoSuchMethodException { + private static Method getMethodRecursively(final Class clazz, final String aMethodName) throws NoSuchMethodException { try { - Method k = clazz.getDeclaredMethod(fieldName); + Logger.REFLECTION("Method: Recursion Lookup: "+aMethodName); + Method k = clazz.getDeclaredMethod(aMethodName); makeMethodAccessible(k); return k; } catch (final NoSuchMethodException e) { @@ -489,7 +506,7 @@ public class ReflectionUtils { if (superClass == null || superClass == Object.class) { throw e; } - return getMethod_Internal(superClass, fieldName); + return getMethod_Internal(superClass, aMethodName); } } @@ -502,7 +519,7 @@ public class ReflectionUtils { Logger.INFO("Dumping all Methods."); for (Method method : methods) { - System.out.println(method.getName()); + System.out.println(method.getName()+" | "+StringUtils.getDataStringFromArray(method.getParameterTypes())); } Logger.INFO("Dumping all Fields."); for (Field f : fields) { @@ -510,7 +527,7 @@ public class ReflectionUtils { } Logger.INFO("Dumping all Constructors."); for (Constructor c : consts) { - System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+c.getParameterTypes().toString()); + System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes())); } } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 0730f5baba..19ff630a92 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -10,14 +10,18 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.xmod.tinkers.HANDLER_Tinkers; import gtPlusPlus.xmod.tinkers.util.TinkersUtils; +import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.Fluid; public class BaseTinkersMaterial { + + private static HashMap aInternalMaterialIdMap = new HashMap(); - private static int aNextFreeID = 440; + private static int aNextFreeID; public final String mLocalName; @@ -25,11 +29,16 @@ public class BaseTinkersMaterial { private final int mID; private final Material mMaterial; + static { + aNextFreeID = Short.MAX_VALUE+420; + } + public BaseTinkersMaterial(Material aMaterial) { mLocalName = Utils.sanitizeString(aMaterial.getLocalizedName()); mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); mMaterial = aMaterial; mID = aNextFreeID++; + Logger.INFO("[TiCon] Assigning ID "+mID+" to "+mLocalName+"."); aInternalMaterialIdMap.put(mUnlocalName, mID); HANDLER_Tinkers.mTinkerMaterials.put(this); } @@ -123,12 +132,12 @@ public class BaseTinkersMaterial { public void generate() { - Logger.INFO("Trying to generate TiCon Material: "+mLocalName); + Logger.INFO("[TiCon] Trying to generate Material: "+mLocalName); int id = mID; if (id > 0) { Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); - Logger.INFO("Created TiCon Material: "+mLocalName); + Logger.INFO("[TiCon] Created Material: "+mLocalName); TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); TinkersUtils.addDefaultToolPartMaterial(id); @@ -152,33 +161,34 @@ public class BaseTinkersMaterial { tag.setString("Style", calcStyle(mMaterial)); tag.setInteger("Color", calcColour(mMaterial)); - Logger.INFO("Sending IMC to TConstruct: addMaterial - "+mLocalName+"."); - FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); - - - generateRecipes(mMaterial); - - ItemStack itemstack = mMaterial.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? - - Logger.INFO("Sending IMC to TConstruct: addPartBuilderMaterial - "+mLocalName+"."); - 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); + boolean generate = generateRecipes(mMaterial); - Logger.INFO("Sending IMC to TConstruct: addMaterialItem - "+mLocalName+"."); - FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + if (generate) { + Logger.INFO("[TiCon] Sending IMC: addMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + ItemStack itemstack = mMaterial.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? + + Logger.INFO("[TiCon] Sending IMC: addPartBuilderMaterial - "+mLocalName+"."); + 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); + + Logger.INFO("[TiCon] Sending IMC: addMaterialItem - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + } } @@ -186,11 +196,30 @@ public class BaseTinkersMaterial { } private boolean generateRecipes(Material aMaterial) { + + Block aMatBlock; + Integer aMelt; + Fluid aFluid; + + try { + aMatBlock = aMaterial.getBlock(); + aMelt = aMaterial.getMeltingPointC(); + aFluid = aMaterial.getFluid(0).getFluid(); + } + catch (Throwable t) { + return false; + } + + if (aMatBlock == null || aMelt == null || aFluid == null) { + return false; + } + + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); - TinkersUtils.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); - TinkersUtils.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); - TinkersUtils.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); - if (aMaterial.getMeltingPointC() <= 3600) { + TinkersUtils.registerFluidType(mLocalName, aMatBlock, 0, aMelt, aFluid, true); + TinkersUtils.addMelting(aMaterial.getBlock(1), aMatBlock, 0, aMelt, aMaterial.getFluid(144*9)); + TinkersUtils.addMelting(aMaterial.getIngot(1), aMatBlock, 0, aMelt, aMaterial.getFluid(144)); + if (aMelt <= 3600) { ItemStack ingotcast = TinkersUtils.getPattern(1); TinkersUtils.addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100); diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index b902e38a1e..450111a113 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -251,7 +251,7 @@ public class TinkersUtils { public static boolean addCastingTableRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) { if (mMethodCache.get("addCastingTableRecipe") == null) { - Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), "addBasinRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class); + Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), "addCastingRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class); mMethodCache.put("addCastingTableRecipe", m); } try { @@ -270,15 +270,30 @@ public class TinkersUtils { public static Object getCastingInstance(int aType) { + + + + Method m = null; if (aType == 0) { - return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); + m = ReflectionUtils.getMethod(getTiConDataInstance(1), "getTableCasting", new Class[] {}); + //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); } else if (aType == 1) { - return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); + m = ReflectionUtils.getMethod(getTiConDataInstance(1), "getBasinCasting", new Class[] {}); + //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); } else { - return null; - } + //return null; + } + + if (m != null) { + try { + return m.invoke(getTiConDataInstance(1), new Object[] {}); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + return null; } @@ -346,7 +361,7 @@ public class TinkersUtils { public static void addToolMaterial(int id, Object aToolMaterial) { setRegistries(); if (mMethodCache.get("addToolMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addToolMaterial", int.class, mToolMaterialClass); + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addtoolMaterial", int.class, mToolMaterialClass); mMethodCache.put("addToolMaterial", m); } try { -- cgit From 94f842fa9223d1d0fa233266495a20a00eafa030 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 4 Mar 2019 21:05:08 +0000 Subject: % Final touches to TC aspects. The 5 custom ones added by GT++ now have names and proper handling. --- .../core/item/base/BaseItemComponent.java | 7 +- .../core/item/base/ore/BaseOreComponent.java | 7 +- src/Java/gtPlusPlus/core/material/Material.java | 4 +- .../core/util/reflect/ReflectionUtils.java | 9 + .../xmod/thaumcraft/HANDLER_Thaumcraft.java | 2 +- .../xmod/thaumcraft/aspect/GTPP_AspectCompat.java | 58 +++- .../xmod/thaumcraft/aspect/GTPP_AspectStack.java | 2 + .../thaumcraft/aspect/TC_AspectList_Wrapper.java | 40 --- .../xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java | 308 -------------------- .../thaumcraft/aspect/TC_PageType_Wrapper.java | 17 -- .../aspect/TC_ResearchCategories_Wrapper.java | 89 ------ .../aspect/TC_ResearchCategoryList_Wrapper.java | 21 -- .../thaumcraft/aspect/TC_ResearchItem_Wrapper.java | 244 ---------------- .../aspect/TC_ResearchNoteData_Wrapper.java | 14 - .../thaumcraft/aspect/TC_ResearchPage_Wrapper.java | 227 --------------- .../wrapper/aspect/TC_AspectList_Wrapper.java | 40 +++ .../objects/wrapper/aspect/TC_Aspect_Wrapper.java | 314 +++++++++++++++++++++ .../wrapper/research/TC_PageType_Wrapper.java | 17 ++ .../research/TC_ResearchCategories_Wrapper.java | 89 ++++++ .../research/TC_ResearchCategoryList_Wrapper.java | 21 ++ .../wrapper/research/TC_ResearchItem_Wrapper.java | 246 ++++++++++++++++ .../research/TC_ResearchNoteData_Wrapper.java | 14 + .../wrapper/research/TC_ResearchPage_Wrapper.java | 228 +++++++++++++++ .../xmod/thaumcraft/util/ThaumcraftUtils.java | 14 +- .../miscutils/textures/aspects/Sagrausten.png | Bin 0 -> 2997 bytes .../assets/miscutils/textures/aspects/Slusium.png | Bin 0 -> 697 bytes .../assets/miscutils/textures/aspects/Xablum.png | Bin 0 -> 563 bytes .../assets/miscutils/textures/aspects/Xenil.png | Bin 0 -> 1000 bytes .../assets/miscutils/textures/aspects/Zetralt.png | Bin 0 -> 1461 bytes 29 files changed, 1047 insertions(+), 985 deletions(-) delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java delete mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_PageType_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategories_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategoryList_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchItem_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchNoteData_Wrapper.java create mode 100644 src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchPage_Wrapper.java create mode 100644 src/resources/assets/miscutils/textures/aspects/Sagrausten.png create mode 100644 src/resources/assets/miscutils/textures/aspects/Slusium.png create mode 100644 src/resources/assets/miscutils/textures/aspects/Xablum.png create mode 100644 src/resources/assets/miscutils/textures/aspects/Xenil.png create mode 100644 src/resources/assets/miscutils/textures/aspects/Zetralt.png (limited to 'src/Java/gtPlusPlus/core/material') diff --git a/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java b/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java index 4dbb5851f2..522b7e900e 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java @@ -8,6 +8,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TC_Aspects; import gregtech.api.enums.TextureSet; import gregtech.api.util.GT_OreDictUnificator; import gtPlusPlus.api.objects.Logger; @@ -21,7 +22,7 @@ import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.EntityUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.sys.KeyboardUtils; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; @@ -66,9 +67,9 @@ public class BaseItemComponent extends Item{ GT_OreDictUnificator.registerOre(componentType.getOreDictName()+material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); if (LoadedMods.Thaumcraft) { - ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), GTPP_Aspects.METALLUM, 1); + ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), TC_Aspect_Wrapper.generate(TC_Aspects.METALLUM.mAspect), 1); if (componentMaterial.isRadioactive) { - ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), GTPP_Aspects.RADIO, 2); + ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), TC_Aspect_Wrapper.generate(TC_Aspects.RADIO.mAspect), componentMaterial.vRadiationLevel); } } registerComponent(); diff --git a/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java b/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java index 2b3f477c56..de47ed8225 100644 --- a/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java +++ b/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java @@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TC_Aspects; import gregtech.api.util.GT_OreDictUnificator; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.creative.AddToCreativeTab; @@ -26,7 +27,7 @@ import gtPlusPlus.core.material.state.MaterialState; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.EntityUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; public class BaseOreComponent extends Item{ @@ -57,9 +58,9 @@ public class BaseOreComponent extends Item{ registerComponent(); GT_OreDictUnificator.registerOre(componentType.getComponent()+material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); if (LoadedMods.Thaumcraft) { - ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), GTPP_Aspects.METALLUM, 2); + ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), TC_Aspect_Wrapper.generate(TC_Aspects.METALLUM.mAspect), 1); if (componentMaterial.isRadioactive) { - ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), GTPP_Aspects.RADIO, 4); + ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), TC_Aspect_Wrapper.generate(TC_Aspects.RADIO.mAspect), componentMaterial.vRadiationLevel); } } diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index ba572efe90..58a7f68afe 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -23,7 +23,7 @@ import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -78,7 +78,7 @@ public class Material { public int vToolQuality; public int vHarvestLevel; - private GTPP_Aspects[] vAspects; + private TC_Aspect_Wrapper[] vAspects; public BaseTinkersMaterial vTiConHandler; diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 617728cdec..722a4f3ff7 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -107,6 +107,9 @@ public class ReflectionUtils { * @return - Valid, {@link Class} object, or {@link null}. */ public static Class getClass(String aClassCanonicalName) { + if (aClassCanonicalName == null || aClassCanonicalName.length() <= 0) { + return null; + } Class y = mCachedClasses.get(aClassCanonicalName); if (y == null) { y = getClass_Internal(aClassCanonicalName); @@ -140,6 +143,9 @@ public class ReflectionUtils { * @return - Valid, non-final, {@link Method} object, or {@link null}. */ public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { + if (aClass == null || aMethodName == null || aMethodName.length() <= 0) { + return null; + } String aMethodKey = ArrayUtils.toString(aTypes); //Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethodName + "." + aMethodKey); @@ -166,6 +172,9 @@ public class ReflectionUtils { * @return - Valid, non-final, {@link Field} object, or {@link null}. */ public static Field getField(final Class aClass, final String aFieldName) { + if (aClass == null || aFieldName == null || aFieldName.length() <= 0) { + return null; + } CachedField y = mCachedFields.get(aClass.getName()+"."+aFieldName); if (y == null) { Field u; diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java index b02ba40392..35e608b0ca 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java @@ -45,7 +45,7 @@ public class HANDLER_Thaumcraft { //sThaumcraftCompat = (IThaumcraftCompat) GT_Utility.callConstructor("gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectCompat", 0, null, GT_Values.D1, new Object[0]); sThaumcraftCompat = new GTPP_AspectCompat(); - if (!sItemsToGetAspects.isEmpty()) { + if (!sItemsToGetAspects.isEmpty() && false) { for (Pair j : sItemsToGetAspects) { if (j .getKey() != null && (j.getValue() != null && j.getValue().length > 0)) { List list = Arrays.asList(j.getValue()); diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java index ea4c97fbfc..d5a19a91fc 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java @@ -10,6 +10,9 @@ import gregtech.api.enums.TC_Aspects; import gregtech.api.util.GT_LanguageManager; import gregtech.common.GT_ThaumcraftCompat; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_AspectList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; import net.minecraft.util.ResourceLocation; public class GTPP_AspectCompat { @@ -99,8 +102,8 @@ public class GTPP_AspectCompat { // Custom Aspects ASPECT_BALANCE = new TC_Aspect_Wrapper( - "Purity", - 15647411, + "Sagrausten", + Utils.rgbtoHexValue(125, 125, 125), new TC_Aspect_Wrapper[]{ get(TC_Aspects.GELUM), get(TC_Aspects.IGNIS) @@ -108,10 +111,11 @@ public class GTPP_AspectCompat { new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.RADIO.name() + ".png"), false, 1); + ASPECT_LUST = new TC_Aspect_Wrapper( - "Vengeance", - 15647411, + "Slusium", + Utils.rgbtoHexValue(175, 125, 25), new TC_Aspect_Wrapper[]{ get(TC_Aspects.CORPUS), get(TC_Aspects.ORDO) @@ -119,6 +123,42 @@ public class GTPP_AspectCompat { new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.NEBRISUM.name() + ".png"), false, 1); + + ASPECT_STARBOUND = + new TC_Aspect_Wrapper( + "Xenil", + Utils.rgbtoHexValue(25, 25, 25), + new TC_Aspect_Wrapper[]{ + get(TC_Aspects.ALIENIS), + ASPECT_BALANCE + }, + new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.NEBRISUM.name() + ".png"), + false, + 1); + + ASPECT_TOXIC = + new TC_Aspect_Wrapper( + "Xablum", + Utils.rgbtoHexValue(25, 185, 25), + new TC_Aspect_Wrapper[]{ + get(TC_Aspects.CORPUS), + ASPECT_LUST + }, + new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.NEBRISUM.name() + ".png"), + false, + 1); + + ASPECT_HEAVEN = + new TC_Aspect_Wrapper( + "Zetralt", + Utils.rgbtoHexValue(225, 225, 225), + new TC_Aspect_Wrapper[]{ + get(TC_Aspects.COGNITIO), + ASPECT_BALANCE + }, + new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.NEBRISUM.name() + ".png"), + false, + 1); @@ -131,11 +171,11 @@ public class GTPP_AspectCompat { new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.RADIO.name() + ".png"), 1); GTPP_Aspects.CUSTOM_5.mAspect = new Aspect("custom4", 12648384, new Aspect[]{Aspect.LIGHT, Aspect.SOUL}, new ResourceLocation("gregtech:textures/aspects/" + TC_Aspects.RADIO.name() + ".png"), 1);*/ - GT_LanguageManager.addStringLocalization("tc.aspect.Purity", "Balance"); - GT_LanguageManager.addStringLocalization("tc.aspect.Vengeance", "Lust"); - GT_LanguageManager.addStringLocalization("tc.aspect.custom3", "Starbound"); - GT_LanguageManager.addStringLocalization("tc.aspect.custom4", "Toxic"); - GT_LanguageManager.addStringLocalization("tc.aspect.custom5", "Heaven"); + GT_LanguageManager.addStringLocalization("tc.aspect.Sagrausten", "Balance"); + GT_LanguageManager.addStringLocalization("tc.aspect.Slusium", "Lust"); + GT_LanguageManager.addStringLocalization("tc.aspect.Xenil", "Starbound"); + GT_LanguageManager.addStringLocalization("tc.aspect.Xablum", "Toxic"); + GT_LanguageManager.addStringLocalization("tc.aspect.Zetralt", "Zetralt"); } private TC_Aspect_Wrapper get(TC_Aspects aGtObjects) { diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java index d7cfa7d326..23e9035f40 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java @@ -1,5 +1,7 @@ package gtPlusPlus.xmod.thaumcraft.aspect; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; + public class GTPP_AspectStack { public final TC_Aspect_Wrapper mAspect; diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java deleted file mode 100644 index 0a7f2d6a3c..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java +++ /dev/null @@ -1,40 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import net.minecraft.item.ItemStack; - -public class TC_AspectList_Wrapper { - - - //thaumcraft.api.aspects.Aspect; - //thaumcraft.api.aspects.AspectList; - - public TC_AspectList_Wrapper() { - - } - - public TC_AspectList_Wrapper(ItemStack stack) { - - } - - public TC_AspectList_Wrapper(Object invoke) { - // TODO Auto-generated constructor stub - } - - public int size() { - // TODO Auto-generated method stub - return 0; - } - - public Object getVanillaAspectList() { - // TODO Auto-generated method stub - return null; - } - - public void add(TC_Aspect_Wrapper mAspect, int mAmount) { - // TODO Auto-generated method stub - - } - - - -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java deleted file mode 100644 index 78c2a670bb..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java +++ /dev/null @@ -1,308 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.LinkedHashMap; -import java.util.Map; - -import gregtech.api.enums.TC_Aspects; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import net.minecraft.util.ResourceLocation; - -/** - * Wrapper class for Thaumcraft Aspects. - * Used to avoid compile time dependencies. - * @author Alkalus - * - */ -public class TC_Aspect_Wrapper { - - private static Class mClass_Aspect; - private static Field mField_Aspects; - - private final String tag; - private final TC_Aspect_Wrapper[] components; - private final int color; - private String chatcolor; - private final ResourceLocation image; - private final int blend; - - public final Object mAspect; - - /** - * May be null, but links back to the TC_Aspects class from GT for convinience. - */ - public final TC_Aspects mGtEnumField; - - - - - /** - * Statically set the Class objects - */ - static { - mClass_Aspect = ReflectionUtils.getClass("thaumcraft.api.aspects.Aspect"); - } - - /** - * Gets the total aspect list from Thaumcraft, which should contain all other registered aspects. - * @return - A LinkedHashMap(String, Aspect); - */ - public static LinkedHashMap getVanillaAspectList() { - try { - if (mField_Aspects == null) { - mField_Aspects = ReflectionUtils.getField(mClass_Aspect, "aspects"); - } - return (LinkedHashMap) mField_Aspects.get(null); - } catch (IllegalArgumentException | IllegalAccessException e) { - Logger.REFLECTION("Failed configuring TC Aspect compatibility."); - return new LinkedHashMap(); - } - } - - public static Object getVanillaAspectObject(String aAspectName) { - return getVanillaAspectList().get(aAspectName); - } - - - - - - - - - - - - - - - /** - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param chatcolor - * @param blend - */ - public TC_Aspect_Wrapper(String tag, int color, String chatcolor, int blend) { - this(tag, color, (TC_Aspect_Wrapper[]) null, blend); - this.chatcolor = chatcolor; - } - - /** - * - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param components - */ - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components) { - this(tag, color, components, false, 1); - } - - /** - * - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param components - * @param blend - */ - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, int blend) { - this(tag, color, components, false, blend); - } - - - /** - * - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param components - * @param image - * @param blend - */ - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, boolean vanilla, int blend) { - this(tag, color, components, vanilla ? new ResourceLocation("thaumcraft", "textures/aspects/" + tag.toLowerCase() + ".png") : new ResourceLocation(CORE.MODID, "textures/aspects/" + tag.toLowerCase() + ".png"), vanilla, blend); - } - - - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, ResourceLocation image, boolean vanilla, int blend) { - if (getAspectList().containsKey(tag.toLowerCase())) { - throw new IllegalArgumentException(tag + " already registered!"); - } else { - this.tag = tag.toLowerCase(); - this.components = components; - this.color = color; - this.image = image; - this.blend = blend; - this.mAspect = vanilla ? getVanillaAspectObject(this.tag) : this.generateTcAspect(); - - //Set GT Type if exists - TC_Aspects y = null; - for (TC_Aspects e : TC_Aspects.values()) { - TC_Aspect_Wrapper g; - try { - g = generate(e.mAspect); - if (g != null) { - if (g.tag.equals(this.tag)) { - y = e; - break; - } - } - } catch (IllegalArgumentException e1) { - e1.printStackTrace(); - } - } - mGtEnumField = y; - - - Logger.INFO("[Thaumcraft++] Adding support for Aspect: "+tag); - } - } - - - - /** - * Generates a TC_Aspect from an object, presummed to be a TC Aspect. - * @param aBaseAspect - The TC Aspect to generate from. - * @return - * @throws IllegalArgumentException - * @throws IllegalAccessException - */ - @SuppressWarnings("unused") - public static TC_Aspect_Wrapper generate(Object aBaseAspect) { - try { - Field aTagF = ReflectionUtils.getField(mClass_Aspect, "tag"); - if (aTagF == null) { - return null; - } - String aTafB = (String) aTagF.get(aBaseAspect); - if (aTafB == null) { - return null; - } - String aTag = aTafB.toLowerCase(); - if (aTag != null && getAspectList().containsKey(aTag.toLowerCase())) { - return getAspect(aTag); - } else { - TC_Aspect_Wrapper aTemp = new TC_Aspect_Wrapper( - aTag, - (int) ReflectionUtils.getField(mClass_Aspect, "color").get(aBaseAspect), - generateAspectArrayInternal(ReflectionUtils.getField(mClass_Aspect, "components"), (aBaseAspect)), - (ResourceLocation) ReflectionUtils.getField(mClass_Aspect, "image").get(aBaseAspect), - true, - (int) ReflectionUtils.getField(mClass_Aspect, "blend").get(aBaseAspect) - ); - if (aTemp != null) { - aTemp.chatcolor = (String) ReflectionUtils.getField(mClass_Aspect, "chatcolor").get(aBaseAspect); - return aTemp; - } - else { - return null; - } - } - } - catch (Throwable t) { - t.printStackTrace(); - return null; - } - } - - - /** - * Internal Map containing all the TC_Aspects. - */ - private static Map mInternalAspectCache = new LinkedHashMap(); - - /** - * Public getter for all TC_Aspects - * @param aAspectName - Aspect Name - * @return - A GT++ Aspect wrapper or null. (TC_Aspect) - */ - public static TC_Aspect_Wrapper getAspect(String aAspectName) { - String aName = aAspectName.toLowerCase(); - TC_Aspect_Wrapper g = mInternalAspectCache.get(aName); - if (g != null) { - return g; - } - else { - try { - TC_Aspect_Wrapper aTemp = generate(getVanillaAspectList().get(aName)); - if (aTemp != null) { - mInternalAspectCache.put(aName, aTemp); - return aTemp; - } - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } - } - return null; - } - - public static Map getAspectList(){ - return mInternalAspectCache; - } - - - private static TC_Aspect_Wrapper[] generateAspectArrayInternal(Field aField, Object aInstance) { - //thaumcraft.api.aspects.Aspect.Aspect() - Object[] components; - TC_Aspect_Wrapper[] aAspectArray; - try { - components = (Object[]) aField.get(aInstance); - aAspectArray = new TC_Aspect_Wrapper[components.length]; - if (components.length > 0) { - int i = 0; - for (Object g : components) { - aAspectArray[i] = getAspect((String) ReflectionUtils.getField(mClass_Aspect, "tag").get(g)); - i++; - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - aAspectArray = new TC_Aspect_Wrapper[0]; - } - return aAspectArray; - } - - /** - * Tasty code to generate TC Aspects reflectively. - * @return - */ - public Object generateTcAspect() { - try { - //thaumcraft.api.aspects.Aspect.Aspect() - Object aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, 1); - if (components.length > 0) { - aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, components.length); - int i = 0; - for (TC_Aspect_Wrapper g : components) { - ((Object[]) aAspectArray)[i++] = g.mAspect; - } - } - Constructor constructor = mClass_Aspect.getConstructor(String.class, int.class, aAspectArray.getClass(), ResourceLocation.class, int.class); - Object myObject = constructor.newInstance(tag, color, aAspectArray, image, blend); - - //Set chat colour - if (chatcolor != null && chatcolor.length() > 0) { - Method setChatColour = ReflectionUtils.getMethod(mClass_Aspect, "setChatcolor", String.class); - if (setChatColour != null) { - setChatColour.invoke(myObject, chatcolor); - } - } - return myObject; - } catch (Throwable t) { - t.printStackTrace(); - return null; - } - } - - public static boolean isObjectAnAspect(Object aAspect) { - return mClass_Aspect.isInstance(aAspect); - } - -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java deleted file mode 100644 index 5a608e290f..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java +++ /dev/null @@ -1,17 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -public class TC_PageType_Wrapper { - - public static final TC_PageType_Wrapper TEXT = null; - public static final TC_PageType_Wrapper TEXT_CONCEALED = null; - public static final TC_PageType_Wrapper NORMAL_CRAFTING = null; - public static final TC_PageType_Wrapper ARCANE_CRAFTING = null; - public static final TC_PageType_Wrapper CRUCIBLE_CRAFTING = null; - public static final TC_PageType_Wrapper INFUSION_CRAFTING = null; - public static final TC_PageType_Wrapper COMPOUND_CRAFTING = null; - public static final TC_PageType_Wrapper SMELTING = null; - public static final TC_PageType_Wrapper INFUSION_ENCHANTMENT = null; - public static final TC_PageType_Wrapper IMAGE = null; - public static final TC_PageType_Wrapper ASPECTS = null; - -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java deleted file mode 100644 index 3392dbcff9..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java +++ /dev/null @@ -1,89 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import cpw.mods.fml.common.FMLLog; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashMap; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; - -import org.apache.logging.log4j.Level; - -public class TC_ResearchCategories_Wrapper { - - public static LinkedHashMap researchCategories = new LinkedHashMap(); - - public static TC_ResearchCategoryList_Wrapper getResearchList(String key) { - return (TC_ResearchCategoryList_Wrapper) researchCategories.get(key); - } - - public static String getCategoryName(String key) { - return StatCollector.translateToLocal("tc.research_category." + key); - } - - public static TC_ResearchItem_Wrapper getResearch(String key) { - Collection rc = researchCategories.values(); - Iterator i$ = rc.iterator(); - - while (i$.hasNext()) { - Object cat = i$.next(); - Collection rl = ((TC_ResearchCategoryList_Wrapper) cat).research.values(); - Iterator i$1 = rl.iterator(); - - while (i$1.hasNext()) { - Object ri = i$1.next(); - if (((TC_ResearchItem_Wrapper) ri).key.equals(key)) { - return (TC_ResearchItem_Wrapper) ri; - } - } - } - - return null; - } - - public static void registerCategory(String key, ResourceLocation icon, ResourceLocation background) { - if (getResearchList(key) == null) { - TC_ResearchCategoryList_Wrapper rl = new TC_ResearchCategoryList_Wrapper(icon, background); - researchCategories.put(key, rl); - } - - } - - public static void addResearch(TC_ResearchItem_Wrapper ri) { - TC_ResearchCategoryList_Wrapper rl = getResearchList(ri.category); - if (rl != null && !rl.research.containsKey(ri.key)) { - if (!ri.isVirtual()) { - Iterator i$ = rl.research.values().iterator(); - - while (i$.hasNext()) { - TC_ResearchItem_Wrapper rr = (TC_ResearchItem_Wrapper) i$.next(); - if (rr.displayColumn == ri.displayColumn && rr.displayRow == ri.displayRow) { - FMLLog.log(Level.FATAL, - "[Thaumcraft] Research [" + ri.getName() - + "] not added as it overlaps with existing research [" + rr.getName() + "]", - new Object[0]); - return; - } - } - } - - rl.research.put(ri.key, ri); - if (ri.displayColumn < rl.minDisplayColumn) { - rl.minDisplayColumn = ri.displayColumn; - } - - if (ri.displayRow < rl.minDisplayRow) { - rl.minDisplayRow = ri.displayRow; - } - - if (ri.displayColumn > rl.maxDisplayColumn) { - rl.maxDisplayColumn = ri.displayColumn; - } - - if (ri.displayRow > rl.maxDisplayRow) { - rl.maxDisplayRow = ri.displayRow; - } - } - - } -} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java deleted file mode 100644 index 4c9102648a..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import java.util.HashMap; -import java.util.Map; - -import net.minecraft.util.ResourceLocation; - -public class TC_ResearchCategoryList_Wrapper { - public int minDisplayColumn; - public int minDisplayRow; - public int maxDisplayColumn; - public int maxDisplayRow; - public ResourceLocation icon; - public ResourceLocation background; - public Map research = new HashMap(); - - public TC_ResearchCategoryList_Wrapper(ResourceLocation icon, ResourceLocation background) { - this.icon = icon; - this.background = background; - } -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java deleted file mode 100644 index 399ec5ad09..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java +++ /dev/null @@ -1,244 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; - -public class TC_ResearchItem_Wrapper { - - public final String key; - public final String category; - public final TC_AspectList_Wrapper tags; - public String[] parents = null; - public String[] parentsHidden = null; - public String[] siblings = null; - public final int displayColumn; - public final int displayRow; - public final ItemStack icon_item; - public final ResourceLocation icon_resource; - private int complexity; - private boolean isSpecial; - private boolean isSecondary; - private boolean isRound; - private boolean isStub; - private boolean isVirtual; - private boolean isConcealed; - private boolean isHidden; - private boolean isLost; - private boolean isAutoUnlock; - private ItemStack[] itemTriggers; - private String[] entityTriggers; - private TC_Aspect_Wrapper[] aspectTriggers; - private Object[] pages = null; - - public TC_ResearchItem_Wrapper(String key, String category) { - this.key = key; - this.category = category; - this.tags = new TC_AspectList_Wrapper(); - this.icon_resource = null; - this.icon_item = null; - this.displayColumn = 0; - this.displayRow = 0; - this.setVirtual(); - } - - public TC_ResearchItem_Wrapper(String key, String category, TC_AspectList_Wrapper tags, int col, int row, int complex, - ResourceLocation icon) { - this.key = key; - this.category = category; - this.tags = tags; - this.icon_resource = icon; - this.icon_item = null; - this.displayColumn = col; - this.displayRow = row; - this.complexity = complex; - if (this.complexity < 1) { - this.complexity = 1; - } - - if (this.complexity > 3) { - this.complexity = 3; - } - - } - - public TC_ResearchItem_Wrapper(String key, String category, TC_AspectList_Wrapper tags, int col, int row, int complex, ItemStack icon) { - this.key = key; - this.category = category; - this.tags = tags; - this.icon_item = icon; - this.icon_resource = null; - this.displayColumn = col; - this.displayRow = row; - this.complexity = complex; - if (this.complexity < 1) { - this.complexity = 1; - } - - if (this.complexity > 3) { - this.complexity = 3; - } - - } - - public TC_ResearchItem_Wrapper setSpecial() { - this.isSpecial = true; - return this; - } - - public TC_ResearchItem_Wrapper setStub() { - this.isStub = true; - return this; - } - - public TC_ResearchItem_Wrapper setLost() { - this.isLost = true; - return this; - } - - public TC_ResearchItem_Wrapper setConcealed() { - this.isConcealed = true; - return this; - } - - public TC_ResearchItem_Wrapper setHidden() { - this.isHidden = true; - return this; - } - - public TC_ResearchItem_Wrapper setVirtual() { - this.isVirtual = true; - return this; - } - - public TC_ResearchItem_Wrapper setParents(String... par) { - this.parents = par; - return this; - } - - public TC_ResearchItem_Wrapper setParentsHidden(String... par) { - this.parentsHidden = par; - return this; - } - - public TC_ResearchItem_Wrapper setSiblings(String... sib) { - this.siblings = sib; - return this; - } - - public TC_ResearchItem_Wrapper setPages(Object... par) { - this.pages = par; - return this; - } - - public Object[] getPages() { - return this.pages; - } - - public TC_ResearchItem_Wrapper setItemTriggers(ItemStack... par) { - this.itemTriggers = par; - return this; - } - - public TC_ResearchItem_Wrapper setEntityTriggers(String... par) { - this.entityTriggers = par; - return this; - } - - public TC_ResearchItem_Wrapper setAspectTriggers(TC_Aspect_Wrapper... par) { - this.aspectTriggers = par; - return this; - } - - public ItemStack[] getItemTriggers() { - return this.itemTriggers; - } - - public String[] getEntityTriggers() { - return this.entityTriggers; - } - - public TC_Aspect_Wrapper[] getAspectTriggers() { - return this.aspectTriggers; - } - - public TC_ResearchItem_Wrapper registerResearchItem() { - ThaumcraftUtils.addResearch(this); - return this; - } - - public String getName() { - return StatCollector.translateToLocal("tc.research_name." + this.key); - } - - public String getText() { - return StatCollector.translateToLocal("tc.research_text." + this.key); - } - - public boolean isSpecial() { - return this.isSpecial; - } - - public boolean isStub() { - return this.isStub; - } - - public boolean isLost() { - return this.isLost; - } - - public boolean isConcealed() { - return this.isConcealed; - } - - public boolean isHidden() { - return this.isHidden; - } - - public boolean isVirtual() { - return this.isVirtual; - } - - public boolean isAutoUnlock() { - return this.isAutoUnlock; - } - - public TC_ResearchItem_Wrapper setAutoUnlock() { - this.isAutoUnlock = true; - return this; - } - - public boolean isRound() { - return this.isRound; - } - - public TC_ResearchItem_Wrapper setRound() { - this.isRound = true; - return this; - } - - public boolean isSecondary() { - return this.isSecondary; - } - - public TC_ResearchItem_Wrapper setSecondary() { - this.isSecondary = true; - return this; - } - - public int getComplexity() { - return this.complexity; - } - - public TC_ResearchItem_Wrapper setComplexity(int complexity) { - this.complexity = complexity; - return this; - } - - public TC_Aspect_Wrapper getResearchPrimaryTag() { - //TODO - return null; - } - -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java deleted file mode 100644 index dbec20cdb8..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -public class TC_ResearchNoteData_Wrapper { - - public TC_ResearchNoteData_Wrapper(Object researchNoteData) { - // TODO Auto-generated constructor stub - } - - public Object getResearchNoteData() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java deleted file mode 100644 index 23d3a9f575..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java +++ /dev/null @@ -1,227 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import java.util.List; - -import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_CrucibleRecipe_Wrapper; -import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_IArcaneRecipe_Wrapper; -import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionEnchantmentRecipe_Wrapper; -import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionRecipe_Wrapper; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.FurnaceRecipes; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; - -public class TC_ResearchPage_Wrapper { - public TC_PageType_Wrapper type; - public String text; - public String research; - public ResourceLocation image; - public TC_AspectList_Wrapper aspects; - public Object recipe; - public ItemStack recipeOutput; - - public TC_ResearchPage_Wrapper(String text) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.TEXT; - this.text = text; - } - - public TC_ResearchPage_Wrapper(String research, String text) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.TEXT_CONCEALED; - this.research = research; - this.text = text; - } - - public TC_ResearchPage_Wrapper(IRecipe recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.NORMAL_CRAFTING; - this.recipe = recipe; - this.recipeOutput = recipe.getRecipeOutput(); - } - - public TC_ResearchPage_Wrapper(IRecipe[] recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.NORMAL_CRAFTING; - this.recipe = recipe; - } - - public TC_ResearchPage_Wrapper(TC_IArcaneRecipe_Wrapper[] recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.ARCANE_CRAFTING; - this.recipe = recipe; - } - - public TC_ResearchPage_Wrapper(TC_CrucibleRecipe_Wrapper[] recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.CRUCIBLE_CRAFTING; - this.recipe = recipe; - } - - public TC_ResearchPage_Wrapper(TC_InfusionRecipe_Wrapper[] recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.INFUSION_CRAFTING; - this.recipe = recipe; - } - - public TC_ResearchPage_Wrapper(List recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.COMPOUND_CRAFTING; - this.recipe = recipe; - } - - public TC_ResearchPage_Wrapper(TC_IArcaneRecipe_Wrapper recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.ARCANE_CRAFTING; - this.recipe = recipe; - this.recipeOutput = recipe.getRecipeOutput(); - } - - public TC_ResearchPage_Wrapper(TC_CrucibleRecipe_Wrapper recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.CRUCIBLE_CRAFTING; - this.recipe = recipe; - this.recipeOutput = recipe.getRecipeOutput(); - } - - public TC_ResearchPage_Wrapper(ItemStack input) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.SMELTING; - this.recipe = input; - this.recipeOutput = FurnaceRecipes.smelting().getSmeltingResult(input); - } - - public TC_ResearchPage_Wrapper(TC_InfusionRecipe_Wrapper recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.INFUSION_CRAFTING; - this.recipe = recipe; - if (recipe.getRecipeOutput() instanceof ItemStack) { - this.recipeOutput = (ItemStack) recipe.getRecipeOutput(); - } else { - this.recipeOutput = recipe.getRecipeInput(); - } - - } - - public TC_ResearchPage_Wrapper(TC_InfusionEnchantmentRecipe_Wrapper recipe) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.INFUSION_ENCHANTMENT; - this.recipe = recipe; - } - - public TC_ResearchPage_Wrapper(ResourceLocation image, String caption) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.IMAGE; - this.image = image; - this.text = caption; - } - - public TC_ResearchPage_Wrapper(TC_AspectList_Wrapper as) { - this.type = TC_PageType_Wrapper.TEXT; - this.text = null; - this.research = null; - this.image = null; - this.aspects = null; - this.recipe = null; - this.recipeOutput = null; - this.type = TC_PageType_Wrapper.ASPECTS; - this.aspects = as; - } - - public String getTranslatedText() { - String ret = ""; - if (this.text != null) { - ret = StatCollector.translateToLocal(this.text); - if (ret.isEmpty()) { - ret = this.text; - } - } - - return ret; - } -} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java new file mode 100644 index 0000000000..9df38ca384 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java @@ -0,0 +1,40 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect; + +import net.minecraft.item.ItemStack; + +public class TC_AspectList_Wrapper { + + + //thaumcraft.api.aspects.Aspect; + //thaumcraft.api.aspects.AspectList; + + public TC_AspectList_Wrapper() { + + } + + public TC_AspectList_Wrapper(ItemStack stack) { + + } + + public TC_AspectList_Wrapper(Object invoke) { + // TODO Auto-generated constructor stub + } + + public int size() { + // TODO Auto-generated method stub + return 0; + } + + public Object getVanillaAspectList() { + // TODO Auto-generated method stub + return null; + } + + public void add(TC_Aspect_Wrapper mAspect, int mAmount) { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java new file mode 100644 index 0000000000..ba448442d2 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java @@ -0,0 +1,314 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect; + +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.Map; + +import gregtech.api.enums.TC_Aspects; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; +import net.minecraft.util.ResourceLocation; + +/** + * Wrapper class for Thaumcraft Aspects. + * Used to avoid compile time dependencies. + * @author Alkalus + * + */ +public class TC_Aspect_Wrapper { + + private static Class mClass_Aspect; + private static Field mField_Aspects; + + private final String tag; + private final TC_Aspect_Wrapper[] components; + private final int color; + private String chatcolor; + private final ResourceLocation image; + private final int blend; + + public final Object mAspect; + + /** + * May be null, but links back to the TC_Aspects class from GT for convinience. + */ + public final TC_Aspects mGtEnumField; + + + + + /** + * Statically set the Class objects + */ + static { + mClass_Aspect = ReflectionUtils.getClass("thaumcraft.api.aspects.Aspect"); + } + + /** + * Gets the total aspect list from Thaumcraft, which should contain all other registered aspects. + * @return - A LinkedHashMap(String, Aspect); + */ + public static LinkedHashMap getVanillaAspectList() { + try { + if (mField_Aspects == null) { + mField_Aspects = ReflectionUtils.getField(mClass_Aspect, "aspects"); + } + return (LinkedHashMap) mField_Aspects.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + Logger.REFLECTION("Failed configuring TC Aspect compatibility."); + return new LinkedHashMap(); + } + } + + public static Object getVanillaAspectObject(String aAspectName) { + return getVanillaAspectList().get(aAspectName); + } + + + + + + + + + + + + + + + /** + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param chatcolor + * @param blend + */ + public TC_Aspect_Wrapper(String tag, int color, String chatcolor, int blend) { + this(tag, color, (TC_Aspect_Wrapper[]) null, blend); + this.chatcolor = chatcolor; + } + + /** + * + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param components + */ + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components) { + this(tag, color, components, false, 1); + } + + /** + * + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param components + * @param blend + */ + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, int blend) { + this(tag, color, components, false, blend); + } + + + /** + * + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param components + * @param image + * @param blend + */ + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, boolean vanilla, int blend) { + this(tag, color, components, vanilla ? new ResourceLocation("thaumcraft", "textures/aspects/" + tag.toLowerCase() + ".png") : new ResourceLocation(CORE.MODID, "textures/aspects/" + tag.toLowerCase() + ".png"), vanilla, blend); + } + + + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, ResourceLocation image, boolean vanilla, int blend) { + if (getAspectList().containsKey(tag.toLowerCase())) { + this.tag = tag.toLowerCase(); + this.components = components; + this.color = color; + this.image = image; + this.blend = blend; + this.mAspect = null; + this.mGtEnumField = null; + } else { + this.tag = tag.toLowerCase(); + this.components = components; + this.color = color; + this.image = image; + this.blend = blend; + this.mAspect = vanilla ? getVanillaAspectObject(this.tag) : this.generateTcAspect(); + + //Set GT Type if exists + TC_Aspects y = null; + for (TC_Aspects e : TC_Aspects.values()) { + TC_Aspect_Wrapper g; + try { + String gtTag = ThaumcraftUtils.getTagFromAspectObject(e.mAspect); + if (gtTag != null) { + if (gtTag.equals(this.tag)) { + y = e; + break; + } + } + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } + } + this.mGtEnumField = y; + mInternalAspectCache.put(this.tag, this); + Logger.INFO("[Thaumcraft++] Adding support for Aspect: "+tag); + } + } + + + + /** + * Generates a TC_Aspect from an object, presummed to be a TC Aspect. + * @param aBaseAspect - The TC Aspect to generate from. + * @return + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + @SuppressWarnings("unused") + public static TC_Aspect_Wrapper generate(Object aBaseAspect) { + try { + Field aTagF = ReflectionUtils.getField(mClass_Aspect, "tag"); + if (aTagF == null) { + return null; + } + String aTafB = (String) aTagF.get(aBaseAspect); + if (aTafB == null) { + return null; + } + String aTag = aTafB.toLowerCase(); + if (aTag != null && getAspectList().containsKey(aTag.toLowerCase())) { + return getAspect(aTag); + } else { + TC_Aspect_Wrapper aTemp = new TC_Aspect_Wrapper( + aTag, + (int) ReflectionUtils.getField(mClass_Aspect, "color").get(aBaseAspect), + generateAspectArrayInternal(ReflectionUtils.getField(mClass_Aspect, "components"), (aBaseAspect)), + (ResourceLocation) ReflectionUtils.getField(mClass_Aspect, "image").get(aBaseAspect), + true, + (int) ReflectionUtils.getField(mClass_Aspect, "blend").get(aBaseAspect) + ); + if (aTemp != null) { + aTemp.chatcolor = (String) ReflectionUtils.getField(mClass_Aspect, "chatcolor").get(aBaseAspect); + return aTemp; + } + else { + return null; + } + } + } + catch (Throwable t) { + t.printStackTrace(); + return null; + } + } + + + /** + * Internal Map containing all the TC_Aspects. + */ + private static Map mInternalAspectCache = new LinkedHashMap(); + + /** + * Public getter for all TC_Aspects + * @param aAspectName - Aspect Name + * @return - A GT++ Aspect wrapper or null. (TC_Aspect) + */ + public static TC_Aspect_Wrapper getAspect(String aAspectName) { + String aName = aAspectName.toLowerCase(); + TC_Aspect_Wrapper g = mInternalAspectCache.get(aName); + if (g != null) { + return g; + } + else { + try { + TC_Aspect_Wrapper aTemp = generate(getVanillaAspectList().get(aName)); + if (aTemp != null) { + mInternalAspectCache.put(aName, aTemp); + return aTemp; + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + return null; + } + + public static Map getAspectList(){ + return mInternalAspectCache; + } + + + private static TC_Aspect_Wrapper[] generateAspectArrayInternal(Field aField, Object aInstance) { + //thaumcraft.api.aspects.Aspect.Aspect() + Object[] components; + TC_Aspect_Wrapper[] aAspectArray; + try { + components = (Object[]) aField.get(aInstance); + aAspectArray = new TC_Aspect_Wrapper[components == null ? 0 : components.length]; + if (aAspectArray.length > 0) { + int i = 0; + for (Object g : components) { + aAspectArray[i] = getAspect((String) ReflectionUtils.getField(mClass_Aspect, "tag").get(g)); + i++; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + aAspectArray = new TC_Aspect_Wrapper[0]; + } + return aAspectArray; + } + + /** + * Tasty code to generate TC Aspects reflectively. + * @return + */ + public Object generateTcAspect() { + try { + //thaumcraft.api.aspects.Aspect.Aspect() + Object aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, 1); + if (components.length > 0) { + aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, components.length); + int i = 0; + for (TC_Aspect_Wrapper g : components) { + ((Object[]) aAspectArray)[i++] = g.mAspect; + } + } + Constructor constructor = mClass_Aspect.getConstructor(String.class, int.class, aAspectArray.getClass(), ResourceLocation.class, int.class); + Object myObject = constructor.newInstance(tag, color, aAspectArray, image, blend); + + //Set chat colour + if (chatcolor != null && chatcolor.length() > 0) { + Method setChatColour = ReflectionUtils.getMethod(mClass_Aspect, "setChatcolor", String.class); + if (setChatColour != null) { + setChatColour.invoke(myObject, chatcolor); + } + } + return myObject; + } catch (Throwable t) { + t.printStackTrace(); + return null; + } + } + + public static boolean isObjectAnAspect(Object aAspect) { + return mClass_Aspect.isInstance(aAspect); + } + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_PageType_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_PageType_Wrapper.java new file mode 100644 index 0000000000..d6c7f66988 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_PageType_Wrapper.java @@ -0,0 +1,17 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.research; + +public class TC_PageType_Wrapper { + + public static final TC_PageType_Wrapper TEXT = null; + public static final TC_PageType_Wrapper TEXT_CONCEALED = null; + public static final TC_PageType_Wrapper NORMAL_CRAFTING = null; + public static final TC_PageType_Wrapper ARCANE_CRAFTING = null; + public static final TC_PageType_Wrapper CRUCIBLE_CRAFTING = null; + public static final TC_PageType_Wrapper INFUSION_CRAFTING = null; + public static final TC_PageType_Wrapper COMPOUND_CRAFTING = null; + public static final TC_PageType_Wrapper SMELTING = null; + public static final TC_PageType_Wrapper INFUSION_ENCHANTMENT = null; + public static final TC_PageType_Wrapper IMAGE = null; + public static final TC_PageType_Wrapper ASPECTS = null; + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategories_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategories_Wrapper.java new file mode 100644 index 0000000000..93869cb8d8 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategories_Wrapper.java @@ -0,0 +1,89 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.research; + +import cpw.mods.fml.common.FMLLog; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +import org.apache.logging.log4j.Level; + +public class TC_ResearchCategories_Wrapper { + + public static LinkedHashMap researchCategories = new LinkedHashMap(); + + public static TC_ResearchCategoryList_Wrapper getResearchList(String key) { + return (TC_ResearchCategoryList_Wrapper) researchCategories.get(key); + } + + public static String getCategoryName(String key) { + return StatCollector.translateToLocal("tc.research_category." + key); + } + + public static TC_ResearchItem_Wrapper getResearch(String key) { + Collection rc = researchCategories.values(); + Iterator i$ = rc.iterator(); + + while (i$.hasNext()) { + Object cat = i$.next(); + Collection rl = ((TC_ResearchCategoryList_Wrapper) cat).research.values(); + Iterator i$1 = rl.iterator(); + + while (i$1.hasNext()) { + Object ri = i$1.next(); + if (((TC_ResearchItem_Wrapper) ri).key.equals(key)) { + return (TC_ResearchItem_Wrapper) ri; + } + } + } + + return null; + } + + public static void registerCategory(String key, ResourceLocation icon, ResourceLocation background) { + if (getResearchList(key) == null) { + TC_ResearchCategoryList_Wrapper rl = new TC_ResearchCategoryList_Wrapper(icon, background); + researchCategories.put(key, rl); + } + + } + + public static void addResearch(TC_ResearchItem_Wrapper ri) { + TC_ResearchCategoryList_Wrapper rl = getResearchList(ri.category); + if (rl != null && !rl.research.containsKey(ri.key)) { + if (!ri.isVirtual()) { + Iterator i$ = rl.research.values().iterator(); + + while (i$.hasNext()) { + TC_ResearchItem_Wrapper rr = (TC_ResearchItem_Wrapper) i$.next(); + if (rr.displayColumn == ri.displayColumn && rr.displayRow == ri.displayRow) { + FMLLog.log(Level.FATAL, + "[Thaumcraft] Research [" + ri.getName() + + "] not added as it overlaps with existing research [" + rr.getName() + "]", + new Object[0]); + return; + } + } + } + + rl.research.put(ri.key, ri); + if (ri.displayColumn < rl.minDisplayColumn) { + rl.minDisplayColumn = ri.displayColumn; + } + + if (ri.displayRow < rl.minDisplayRow) { + rl.minDisplayRow = ri.displayRow; + } + + if (ri.displayColumn > rl.maxDisplayColumn) { + rl.maxDisplayColumn = ri.displayColumn; + } + + if (ri.displayRow > rl.maxDisplayRow) { + rl.maxDisplayRow = ri.displayRow; + } + } + + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategoryList_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategoryList_Wrapper.java new file mode 100644 index 0000000000..3e6f5b78f2 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchCategoryList_Wrapper.java @@ -0,0 +1,21 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.research; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.util.ResourceLocation; + +public class TC_ResearchCategoryList_Wrapper { + public int minDisplayColumn; + public int minDisplayRow; + public int maxDisplayColumn; + public int maxDisplayRow; + public ResourceLocation icon; + public ResourceLocation background; + public Map research = new HashMap(); + + public TC_ResearchCategoryList_Wrapper(ResourceLocation icon, ResourceLocation background) { + this.icon = icon; + this.background = background; + } +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchItem_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchItem_Wrapper.java new file mode 100644 index 0000000000..6372cc0371 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchItem_Wrapper.java @@ -0,0 +1,246 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.research; + +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_AspectList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; +import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +public class TC_ResearchItem_Wrapper { + + public final String key; + public final String category; + public final TC_AspectList_Wrapper tags; + public String[] parents = null; + public String[] parentsHidden = null; + public String[] siblings = null; + public final int displayColumn; + public final int displayRow; + public final ItemStack icon_item; + public final ResourceLocation icon_resource; + private int complexity; + private boolean isSpecial; + private boolean isSecondary; + private boolean isRound; + private boolean isStub; + private boolean isVirtual; + private boolean isConcealed; + private boolean isHidden; + private boolean isLost; + private boolean isAutoUnlock; + private ItemStack[] itemTriggers; + private String[] entityTriggers; + private TC_Aspect_Wrapper[] aspectTriggers; + private Object[] pages = null; + + public TC_ResearchItem_Wrapper(String key, String category) { + this.key = key; + this.category = category; + this.tags = new TC_AspectList_Wrapper(); + this.icon_resource = null; + this.icon_item = null; + this.displayColumn = 0; + this.displayRow = 0; + this.setVirtual(); + } + + public TC_ResearchItem_Wrapper(String key, String category, TC_AspectList_Wrapper tags, int col, int row, int complex, + ResourceLocation icon) { + this.key = key; + this.category = category; + this.tags = tags; + this.icon_resource = icon; + this.icon_item = null; + this.displayColumn = col; + this.displayRow = row; + this.complexity = complex; + if (this.complexity < 1) { + this.complexity = 1; + } + + if (this.complexity > 3) { + this.complexity = 3; + } + + } + + public TC_ResearchItem_Wrapper(String key, String category, TC_AspectList_Wrapper tags, int col, int row, int complex, ItemStack icon) { + this.key = key; + this.category = category; + this.tags = tags; + this.icon_item = icon; + this.icon_resource = null; + this.displayColumn = col; + this.displayRow = row; + this.complexity = complex; + if (this.complexity < 1) { + this.complexity = 1; + } + + if (this.complexity > 3) { + this.complexity = 3; + } + + } + + public TC_ResearchItem_Wrapper setSpecial() { + this.isSpecial = true; + return this; + } + + public TC_ResearchItem_Wrapper setStub() { + this.isStub = true; + return this; + } + + public TC_ResearchItem_Wrapper setLost() { + this.isLost = true; + return this; + } + + public TC_ResearchItem_Wrapper setConcealed() { + this.isConcealed = true; + return this; + } + + public TC_ResearchItem_Wrapper setHidden() { + this.isHidden = true; + return this; + } + + public TC_ResearchItem_Wrapper setVirtual() { + this.isVirtual = true; + return this; + } + + public TC_ResearchItem_Wrapper setParents(String... par) { + this.parents = par; + return this; + } + + public TC_ResearchItem_Wrapper setParentsHidden(String... par) { + this.parentsHidden = par; + return this; + } + + public TC_ResearchItem_Wrapper setSiblings(String... sib) { + this.siblings = sib; + return this; + } + + public TC_ResearchItem_Wrapper setPages(Object... par) { + this.pages = par; + return this; + } + + public Object[] getPages() { + return this.pages; + } + + public TC_ResearchItem_Wrapper setItemTriggers(ItemStack... par) { + this.itemTriggers = par; + return this; + } + + public TC_ResearchItem_Wrapper setEntityTriggers(String... par) { + this.entityTriggers = par; + return this; + } + + public TC_ResearchItem_Wrapper setAspectTriggers(TC_Aspect_Wrapper... par) { + this.aspectTriggers = par; + return this; + } + + public ItemStack[] getItemTriggers() { + return this.itemTriggers; + } + + public String[] getEntityTriggers() { + return this.entityTriggers; + } + + public TC_Aspect_Wrapper[] getAspectTriggers() { + return this.aspectTriggers; + } + + public TC_ResearchItem_Wrapper registerResearchItem() { + ThaumcraftUtils.addResearch(this); + return this; + } + + public String getName() { + return StatCollector.translateToLocal("tc.research_name." + this.key); + } + + public String getText() { + return StatCollector.translateToLocal("tc.research_text." + this.key); + } + + public boolean isSpecial() { + return this.isSpecial; + } + + public boolean isStub() { + return this.isStub; + } + + public boolean isLost() { + return this.isLost; + } + + public boolean isConcealed() { + return this.isConcealed; + } + + public boolean isHidden() { + return this.isHidden; + } + + public boolean isVirtual() { + return this.isVirtual; + } + + public boolean isAutoUnlock() { + return this.isAutoUnlock; + } + + public TC_ResearchItem_Wrapper setAutoUnlock() { + this.isAutoUnlock = true; + return this; + } + + public boolean isRound() { + return this.isRound; + } + + public TC_ResearchItem_Wrapper setRound() { + this.isRound = true; + return this; + } + + public boolean isSecondary() { + return this.isSecondary; + } + + public TC_ResearchItem_Wrapper setSecondary() { + this.isSecondary = true; + return this; + } + + public int getComplexity() { + return this.complexity; + } + + public TC_ResearchItem_Wrapper setComplexity(int complexity) { + this.complexity = complexity; + return this; + } + + public TC_Aspect_Wrapper getResearchPrimaryTag() { + //TODO + return null; + } + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchNoteData_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchNoteData_Wrapper.java new file mode 100644 index 0000000000..5adf0150d9 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchNoteData_Wrapper.java @@ -0,0 +1,14 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.research; + +public class TC_ResearchNoteData_Wrapper { + + public TC_ResearchNoteData_Wrapper(Object researchNoteData) { + // TODO Auto-generated constructor stub + } + + public Object getResearchNoteData() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchPage_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchPage_Wrapper.java new file mode 100644 index 0000000000..998f37bf8c --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/research/TC_ResearchPage_Wrapper.java @@ -0,0 +1,228 @@ +package gtPlusPlus.xmod.thaumcraft.objects.wrapper.research; + +import java.util.List; + +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_AspectList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_CrucibleRecipe_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_IArcaneRecipe_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionEnchantmentRecipe_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionRecipe_Wrapper; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +public class TC_ResearchPage_Wrapper { + public TC_PageType_Wrapper type; + public String text; + public String research; + public ResourceLocation image; + public TC_AspectList_Wrapper aspects; + public Object recipe; + public ItemStack recipeOutput; + + public TC_ResearchPage_Wrapper(String text) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.TEXT; + this.text = text; + } + + public TC_ResearchPage_Wrapper(String research, String text) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.TEXT_CONCEALED; + this.research = research; + this.text = text; + } + + public TC_ResearchPage_Wrapper(IRecipe recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.NORMAL_CRAFTING; + this.recipe = recipe; + this.recipeOutput = recipe.getRecipeOutput(); + } + + public TC_ResearchPage_Wrapper(IRecipe[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.NORMAL_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(TC_IArcaneRecipe_Wrapper[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.ARCANE_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(TC_CrucibleRecipe_Wrapper[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.CRUCIBLE_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(TC_InfusionRecipe_Wrapper[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.INFUSION_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(List recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.COMPOUND_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(TC_IArcaneRecipe_Wrapper recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.ARCANE_CRAFTING; + this.recipe = recipe; + this.recipeOutput = recipe.getRecipeOutput(); + } + + public TC_ResearchPage_Wrapper(TC_CrucibleRecipe_Wrapper recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.CRUCIBLE_CRAFTING; + this.recipe = recipe; + this.recipeOutput = recipe.getRecipeOutput(); + } + + public TC_ResearchPage_Wrapper(ItemStack input) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.SMELTING; + this.recipe = input; + this.recipeOutput = FurnaceRecipes.smelting().getSmeltingResult(input); + } + + public TC_ResearchPage_Wrapper(TC_InfusionRecipe_Wrapper recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.INFUSION_CRAFTING; + this.recipe = recipe; + if (recipe.getRecipeOutput() instanceof ItemStack) { + this.recipeOutput = (ItemStack) recipe.getRecipeOutput(); + } else { + this.recipeOutput = recipe.getRecipeInput(); + } + + } + + public TC_ResearchPage_Wrapper(TC_InfusionEnchantmentRecipe_Wrapper recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.INFUSION_ENCHANTMENT; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(ResourceLocation image, String caption) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.IMAGE; + this.image = image; + this.text = caption; + } + + public TC_ResearchPage_Wrapper(TC_AspectList_Wrapper as) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.ASPECTS; + this.aspects = as; + } + + public String getTranslatedText() { + String ret = ""; + if (this.text != null) { + ret = StatCollector.translateToLocal(this.text); + if (ret.isEmpty()) { + ret = this.text; + } + } + + return ret; + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java b/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java index c60a140819..8beaa8df5e 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java @@ -19,17 +19,17 @@ import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.thaumcraft.HANDLER_Thaumcraft; import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectStack; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_AspectList_Wrapper; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_Aspect_Wrapper; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchCategories_Wrapper; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchCategoryList_Wrapper; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchItem_Wrapper; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchNoteData_Wrapper; -import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchPage_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_AspectList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper; import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_CrucibleRecipe_Wrapper; import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_IArcaneRecipe_Wrapper; import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionEnchantmentRecipe_Wrapper; import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionRecipe_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchCategories_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchCategoryList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchItem_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchNoteData_Wrapper; +import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchPage_Wrapper; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; diff --git a/src/resources/assets/miscutils/textures/aspects/Sagrausten.png b/src/resources/assets/miscutils/textures/aspects/Sagrausten.png new file mode 100644 index 0000000000..a2c461f94e Binary files /dev/null and b/src/resources/assets/miscutils/textures/aspects/Sagrausten.png differ diff --git a/src/resources/assets/miscutils/textures/aspects/Slusium.png b/src/resources/assets/miscutils/textures/aspects/Slusium.png new file mode 100644 index 0000000000..fd2c42414d Binary files /dev/null and b/src/resources/assets/miscutils/textures/aspects/Slusium.png differ diff --git a/src/resources/assets/miscutils/textures/aspects/Xablum.png b/src/resources/assets/miscutils/textures/aspects/Xablum.png new file mode 100644 index 0000000000..a19d64039a Binary files /dev/null and b/src/resources/assets/miscutils/textures/aspects/Xablum.png differ diff --git a/src/resources/assets/miscutils/textures/aspects/Xenil.png b/src/resources/assets/miscutils/textures/aspects/Xenil.png new file mode 100644 index 0000000000..e3b5ecda82 Binary files /dev/null and b/src/resources/assets/miscutils/textures/aspects/Xenil.png differ diff --git a/src/resources/assets/miscutils/textures/aspects/Zetralt.png b/src/resources/assets/miscutils/textures/aspects/Zetralt.png new file mode 100644 index 0000000000..001edf8ea3 Binary files /dev/null and b/src/resources/assets/miscutils/textures/aspects/Zetralt.png differ -- cgit