From 86f1765b171f4cc6f163b8027d1330f4e5094e2d Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 28 Sep 2024 13:25:01 +0200 Subject: Remove more reflection + reorganize mixin accessors packages (#3260) Co-authored-by: Martin Robertz Co-authored-by: boubou19 --- .../common/commands/ClearCraftingCache.java | 2 +- .../hooks/BWCoreStaticReplacementMethodes.java | 112 ------ .../CircuitGeneration/CircuitImprintLoader.java | 2 +- .../gtenhancement/PlatinumSludgeOverHaul.java | 2 +- .../loader/NaquadahReworkRecipeLoader.java | 2 +- .../api/interfaces/IRecipeMutableAccess.java | 18 - .../gregtech/api/util/GTRecipeRegistrator.java | 17 +- .../java/gregtech/loaders/preload/GTPreLoad.java | 11 +- src/main/java/gregtech/mixin/Mixin.java | 17 +- .../java/gregtech/mixin/MixinsVariablesHelper.java | 6 - .../hooks/BWCoreStaticReplacementMethodes.java | 112 ++++++ .../mixin/hooks/MixinsVariablesHelper.java | 6 + .../mixin/interfaces/IBlockStemAccesor.java | 8 - .../java/gregtech/mixin/interfaces/PotionExt.java | 7 - .../accessors/EntityPlayerMPAccessor.java | 7 + .../interfaces/accessors/IBlockStemAccessor.java | 8 + .../interfaces/accessors/IRecipeMutableAccess.java | 18 + .../mixin/interfaces/accessors/PotionAccessor.java | 7 + .../accessors/ShapedOreRecipeAccessor.java | 9 + src/main/java/gtPlusPlus/GTplusplus.java | 64 +++- .../java/gtPlusPlus/api/interfaces/IPlugin.java | 41 --- src/main/java/gtPlusPlus/api/objects/Logger.java | 5 +- .../api/objects/minecraft/ShapedRecipe.java | 15 +- .../gtPlusPlus/core/config/ASMConfiguration.java | 11 - .../gtPlusPlus/core/handler/PacketHandler.java | 11 - .../handler/events/PlayerSleepEventHandler.java | 4 +- .../core/util/reflect/ReflectionUtils.java | 396 +-------------------- .../java/gtPlusPlus/everglades/GTPPEverglades.java | 11 +- .../gtPlusPlus/plugin/agrichem/AgrichemCore.java | 56 --- .../plugin/agrichem/block/AgrichemFluids.java | 2 +- .../agrichem/item/algae/ItemAgrichemBase.java | 2 +- .../plugin/agrichem/item/algae/ItemAlgaeBase.java | 8 +- .../plugin/agrichem/logic/AlgaeGeneticData.java | 15 +- .../agrichem/logic/AlgaeGrowthRequirement.java | 4 - .../plugin/fixes/interfaces/IBugFix.java | 6 - .../fixes/vanilla/VanillaBackgroundMusicFix.java | 64 ---- .../plugin/fixes/vanilla/VanillaBedHeightFix.java | 35 +- .../plugin/fixes/vanilla/VanillaFixesCore.java | 101 ------ .../plugin/fixes/vanilla/music/MusicTocker.java | 131 ------- .../gtPlusPlus/plugin/manager/CoreManager.java | 95 ----- .../gregtech/api/enums/GregtechOrePrefixes.java | 42 +-- .../tileentities/generators/MTERTGenerator.java | 25 +- .../common/hatch/MTEHatchBeamlineConnector.java | 11 +- src/main/java/gtnhlanth/loader/RecipeLoader.java | 2 +- .../multiblock/eigbuckets/EIGStemBucket.java | 4 +- .../java/tectech/thing/item/ItemEuMeterGT.java | 12 +- .../hatch/MTEHatchDataConnector.java | 11 +- .../hatch/MTEHatchDataItemsInput.java | 11 +- .../thing/metaTileEntity/hatch/MTEHatchParam.java | 11 +- .../metaTileEntity/hatch/MTEHatchParamText.java | 11 +- .../thing/metaTileEntity/hatch/MTEHatchRack.java | 11 +- .../metaTileEntity/hatch/MTEHatchUncertainty.java | 11 +- .../hatch/MTEHatchWirelessComputationInput.java | 11 - .../hatch/MTEHatchWirelessDataItemsInput.java | 11 +- .../metaTileEntity/multi/MTEResearchStation.java | 9 +- .../metaTileEntity/single/MTEOwnerDetector.java | 17 +- .../thing/metaTileEntity/single/MTETeslaCoil.java | 10 +- src/main/java/tectech/util/TTUtility.java | 1 + 58 files changed, 323 insertions(+), 1346 deletions(-) delete mode 100644 src/main/java/bartworks/hooks/BWCoreStaticReplacementMethodes.java delete mode 100644 src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java delete mode 100644 src/main/java/gregtech/mixin/MixinsVariablesHelper.java create mode 100644 src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java create mode 100644 src/main/java/gregtech/mixin/hooks/MixinsVariablesHelper.java delete mode 100644 src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java delete mode 100644 src/main/java/gregtech/mixin/interfaces/PotionExt.java create mode 100644 src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java create mode 100644 src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java create mode 100644 src/main/java/gregtech/mixin/interfaces/accessors/IRecipeMutableAccess.java create mode 100644 src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java create mode 100644 src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java delete mode 100644 src/main/java/gtPlusPlus/api/interfaces/IPlugin.java delete mode 100644 src/main/java/gtPlusPlus/plugin/agrichem/AgrichemCore.java delete mode 100644 src/main/java/gtPlusPlus/plugin/agrichem/logic/AlgaeGrowthRequirement.java delete mode 100644 src/main/java/gtPlusPlus/plugin/fixes/interfaces/IBugFix.java delete mode 100644 src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java delete mode 100644 src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaFixesCore.java delete mode 100644 src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java delete mode 100644 src/main/java/gtPlusPlus/plugin/manager/CoreManager.java (limited to 'src/main/java') diff --git a/src/main/java/bartworks/common/commands/ClearCraftingCache.java b/src/main/java/bartworks/common/commands/ClearCraftingCache.java index 68172190f6..24f82d90d8 100644 --- a/src/main/java/bartworks/common/commands/ClearCraftingCache.java +++ b/src/main/java/bartworks/common/commands/ClearCraftingCache.java @@ -17,7 +17,7 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; -import bartworks.hooks.BWCoreStaticReplacementMethodes; +import gregtech.mixin.hooks.BWCoreStaticReplacementMethodes; public class ClearCraftingCache extends CommandBase { diff --git a/src/main/java/bartworks/hooks/BWCoreStaticReplacementMethodes.java b/src/main/java/bartworks/hooks/BWCoreStaticReplacementMethodes.java deleted file mode 100644 index 6110d9c32d..0000000000 --- a/src/main/java/bartworks/hooks/BWCoreStaticReplacementMethodes.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.hooks; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.world.World; - -import bartworks.util.NonNullWrappedHashSet; -import bartworks.util.accessprioritylist.AccessPriorityList; -import bartworks.util.accessprioritylist.AccessPriorityListNode; - -public class BWCoreStaticReplacementMethodes { - - private static ThreadLocal> RECENTLYUSEDRECIPES = ThreadLocal - .withInitial(AccessPriorityList::new); - - public static void clearRecentlyUsedRecipes() { - // the easiest way to ensure the cache is flushed without causing synchronization overhead - // is to just replace the whole ThreadLocal instance. - RECENTLYUSEDRECIPES = ThreadLocal.withInitial(AccessPriorityList::new); - } - - public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) { - int i = 0; - ItemStack itemstack = null; - ItemStack itemstack1 = null; - int j; - - for (j = 0; j < inventoryCrafting.getSizeInventory(); ++j) { - ItemStack itemstack2 = inventoryCrafting.getStackInSlot(j); - - if (itemstack2 != null) { - if (i == 0) itemstack = itemstack2; - - if (i == 1) itemstack1 = itemstack2; - - ++i; - } - } - - if (i == 2 && itemstack.getItem() == itemstack1.getItem() - && itemstack.stackSize == 1 - && itemstack1.stackSize == 1 - && itemstack.getItem() - .isRepairable()) { - Item item = itemstack.getItem(); - int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay(); - int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay(); - int l = j1 + k + item.getMaxDamage() * 5 / 100; - int i1 = item.getMaxDamage() - l; - - if (i1 < 0) i1 = 0; - - return new ItemStack(itemstack.getItem(), 1, i1); - - } - IRecipe iPossibleRecipe = null; - AccessPriorityList cache = RECENTLYUSEDRECIPES.get(); - Iterator> it = cache.nodeIterator(); - - while (it.hasNext()) { - AccessPriorityListNode recipeNode = it.next(); - iPossibleRecipe = recipeNode.getELEMENT(); - - if (!iPossibleRecipe.matches(inventoryCrafting, world)) continue; - - cache.addPrioToNode(recipeNode); - return iPossibleRecipe.getCraftingResult(inventoryCrafting); - } - - HashSet recipeSet = new NonNullWrappedHashSet<>(); - List recipeList = CraftingManager.getInstance() - .getRecipeList(); - - for (IRecipe r : recipeList) { - if (r.matches(inventoryCrafting, world)) recipeSet.add(r); - } - - Object[] arr = recipeSet.toArray(); - - if (arr.length == 0) return null; - - IRecipe recipe = (IRecipe) arr[0]; - ItemStack stack = recipe.getCraftingResult(inventoryCrafting); - - if (arr.length != 1) return stack; - - if (stack != null) cache.addLast(recipe); - - return stack; - } - -} diff --git a/src/main/java/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java b/src/main/java/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java index c3a8442397..c75d561e29 100644 --- a/src/main/java/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java +++ b/src/main/java/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java @@ -34,7 +34,6 @@ import com.google.common.collect.HashBiMap; import bartworks.API.recipe.BWNBTDependantCraftingRecipe; import bartworks.API.recipe.BartWorksRecipeMaps; -import bartworks.hooks.BWCoreStaticReplacementMethodes; import bartworks.system.material.WerkstoffLoader; import bartworks.util.BWUtil; import bartworks.util.Pair; @@ -48,6 +47,7 @@ import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; +import gregtech.mixin.hooks.BWCoreStaticReplacementMethodes; public class CircuitImprintLoader { diff --git a/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java b/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java index a21a9b5ae9..e3504a4e9c 100644 --- a/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java +++ b/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java @@ -110,7 +110,6 @@ import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.TierEU; -import gregtech.api.interfaces.IRecipeMutableAccess; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.items.GTGenericBlock; import gregtech.api.items.GTGenericItem; @@ -123,6 +122,7 @@ import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.common.blocks.BlockOresAbstract; +import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess; import gtPlusPlus.core.block.base.BlockBaseModular; import gtPlusPlus.core.item.base.BaseItemComponent; diff --git a/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java b/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java index 56b21238fd..3f43a63523 100644 --- a/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java +++ b/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java @@ -74,7 +74,6 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.Mods; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.TierEU; -import gregtech.api.interfaces.IRecipeMutableAccess; import gregtech.api.recipe.RecipeMaps; import gregtech.api.util.GTLog; import gregtech.api.util.GTOreDictUnificator; @@ -82,6 +81,7 @@ import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.common.items.CombType; import gregtech.loaders.misc.GTBees; +import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.item.chemistry.GenericChem; diff --git a/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java b/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java deleted file mode 100644 index 5c6d931d5a..0000000000 --- a/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java +++ /dev/null @@ -1,18 +0,0 @@ -package gregtech.api.interfaces; - -import net.minecraft.item.ItemStack; - -/** - * Mixed-in interface for recipe classes in Forge and Vanilla that allows mutating the input and output items. - */ -public interface IRecipeMutableAccess { - - /** @return Gets the current output item of the recipe */ - ItemStack gt5u$getRecipeOutputItem(); - - /** Sets a new output item on the recipe */ - void gt5u$setRecipeOutputItem(ItemStack newItem); - - /** @return The raw list or array of recipe inputs, the exact type depends on the underlying recipe type. */ - Object gt5u$getRecipeInputs(); -} diff --git a/src/main/java/gregtech/api/util/GTRecipeRegistrator.java b/src/main/java/gregtech/api/util/GTRecipeRegistrator.java index 919b37e7d9..745a544a52 100644 --- a/src/main/java/gregtech/api/util/GTRecipeRegistrator.java +++ b/src/main/java/gregtech/api/util/GTRecipeRegistrator.java @@ -31,7 +31,6 @@ import static gregtech.api.util.GTRecipeConstants.UniversalArcFurnace; import static gregtech.api.util.GTUtility.calculateRecipeEU; import static gregtech.api.util.GTUtility.getTier; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.IdentityHashMap; @@ -53,7 +52,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.SetMultimap; -import cpw.mods.fml.relauncher.ReflectionHelper; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; @@ -63,6 +61,7 @@ import gregtech.api.enums.TierEU; import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; import gregtech.api.recipe.RecipeCategories; +import gregtech.mixin.interfaces.accessors.ShapedOreRecipeAccessor; import ic2.api.reactor.IReactorComponent; /** @@ -123,8 +122,6 @@ public class GTRecipeRegistrator { new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null), new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null), new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2) }; - public static final Field SHAPED_ORE_RECIPE_WIDTH = ReflectionHelper.findField(ShapedOreRecipe.class, "width"); - public static final Field SHAPED_ORE_RECIPE_HEIGHT = ReflectionHelper.findField(ShapedOreRecipe.class, "height"); private static volatile Map> indexedRecipeListCache; private static final String[][] sShapesA = new String[][] { null, null, null, { "Helmet", s_P + s_P + s_P, s_P + s_H + s_P }, @@ -791,19 +788,11 @@ public class GTRecipeRegistrator { } private static int getRecipeWidth(ShapedOreRecipe r) { - try { - return (int) SHAPED_ORE_RECIPE_WIDTH.get(r); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return ((ShapedOreRecipeAccessor) r).gt5u$getWidth(); } private static int getRecipeHeight(ShapedOreRecipe r) { - try { - return (int) SHAPED_ORE_RECIPE_HEIGHT.get(r); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return ((ShapedOreRecipeAccessor) r).gt5u$getHeight(); } private static int getRecipeHeight(ShapedRecipes r) { diff --git a/src/main/java/gregtech/loaders/preload/GTPreLoad.java b/src/main/java/gregtech/loaders/preload/GTPreLoad.java index 6216f752dc..b3c4c48095 100644 --- a/src/main/java/gregtech/loaders/preload/GTPreLoad.java +++ b/src/main/java/gregtech/loaders/preload/GTPreLoad.java @@ -339,12 +339,9 @@ public class GTPreLoad { try { Objects.requireNonNull(GTUtility.getField("ic2.core.item.ItemScrapbox$Drop", "topChance", true, true)) .set(null, 0); - ((List) Objects.requireNonNull( - GTUtility.getFieldContent( - GTUtility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), - "drops", - true, - true))).clear(); + ((List) Objects + .requireNonNull(GTUtility.getFieldContent(ic2.api.recipe.Recipes.scrapboxDrops, "drops", true, true))) + .clear(); } catch (Throwable e) { if (GTValues.D1) { e.printStackTrace(GTLog.err); @@ -539,7 +536,7 @@ public class GTPreLoad { /** * Clamp value between 0 and 255 - * + * * @param value the value to clamp * @return the clamped value */ diff --git a/src/main/java/gregtech/mixin/Mixin.java b/src/main/java/gregtech/mixin/Mixin.java index 224c7b5f1c..b9ba1db098 100644 --- a/src/main/java/gregtech/mixin/Mixin.java +++ b/src/main/java/gregtech/mixin/Mixin.java @@ -48,16 +48,13 @@ public enum Mixin { .setSide(Side.BOTH)), VanillaAccessors(new Builder("Adds various accessors") .addMixinClasses( - "minecraft.VanillaShapedRecipeMixin", - "minecraft.VanillaShapelessRecipeMixin", - "minecraft.ForgeShapedRecipeMixin", - "minecraft.ForgeShapelessRecipeMixin", - "minecraft.PotionMixin") - .addTargetedMod(VANILLA) - .setApplyIf(() -> true) - .setPhase(Phase.EARLY) - .setSide(Side.BOTH)), - BlockStemMixin(new Builder("Stem Crop Block Accessor").addMixinClasses("minecraft.BlockStemMixin") + "minecraft.accessors.BlockStemMixin", + "minecraft.accessors.VanillaShapedRecipeMixin", + "minecraft.accessors.VanillaShapelessRecipeMixin", + "minecraft.accessors.ForgeShapedRecipeMixin", + "minecraft.accessors.ForgeShapelessRecipeMixin", + "minecraft.accessors.PotionMixin", + "minecraft.accessors.EntityPlayerMPMixin") .addTargetedMod(VANILLA) .setApplyIf(() -> true) .setPhase(Phase.EARLY) diff --git a/src/main/java/gregtech/mixin/MixinsVariablesHelper.java b/src/main/java/gregtech/mixin/MixinsVariablesHelper.java deleted file mode 100644 index 96cc2ee115..0000000000 --- a/src/main/java/gregtech/mixin/MixinsVariablesHelper.java +++ /dev/null @@ -1,6 +0,0 @@ -package gregtech.mixin; - -public class MixinsVariablesHelper { - - public static String currentlyTranslating = null; -} diff --git a/src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java b/src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java new file mode 100644 index 0000000000..9f8f5fb8b4 --- /dev/null +++ b/src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package gregtech.mixin.hooks; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; + +import bartworks.util.NonNullWrappedHashSet; +import bartworks.util.accessprioritylist.AccessPriorityList; +import bartworks.util.accessprioritylist.AccessPriorityListNode; + +public class BWCoreStaticReplacementMethodes { + + private static ThreadLocal> RECENTLYUSEDRECIPES = ThreadLocal + .withInitial(AccessPriorityList::new); + + public static void clearRecentlyUsedRecipes() { + // the easiest way to ensure the cache is flushed without causing synchronization overhead + // is to just replace the whole ThreadLocal instance. + RECENTLYUSEDRECIPES = ThreadLocal.withInitial(AccessPriorityList::new); + } + + public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) { + int i = 0; + ItemStack itemstack = null; + ItemStack itemstack1 = null; + int j; + + for (j = 0; j < inventoryCrafting.getSizeInventory(); ++j) { + ItemStack itemstack2 = inventoryCrafting.getStackInSlot(j); + + if (itemstack2 != null) { + if (i == 0) itemstack = itemstack2; + + if (i == 1) itemstack1 = itemstack2; + + ++i; + } + } + + if (i == 2 && itemstack.getItem() == itemstack1.getItem() + && itemstack.stackSize == 1 + && itemstack1.stackSize == 1 + && itemstack.getItem() + .isRepairable()) { + Item item = itemstack.getItem(); + int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay(); + int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay(); + int l = j1 + k + item.getMaxDamage() * 5 / 100; + int i1 = item.getMaxDamage() - l; + + if (i1 < 0) i1 = 0; + + return new ItemStack(itemstack.getItem(), 1, i1); + + } + IRecipe iPossibleRecipe = null; + AccessPriorityList cache = RECENTLYUSEDRECIPES.get(); + Iterator> it = cache.nodeIterator(); + + while (it.hasNext()) { + AccessPriorityListNode recipeNode = it.next(); + iPossibleRecipe = recipeNode.getELEMENT(); + + if (!iPossibleRecipe.matches(inventoryCrafting, world)) continue; + + cache.addPrioToNode(recipeNode); + return iPossibleRecipe.getCraftingResult(inventoryCrafting); + } + + HashSet recipeSet = new NonNullWrappedHashSet<>(); + List recipeList = CraftingManager.getInstance() + .getRecipeList(); + + for (IRecipe r : recipeList) { + if (r.matches(inventoryCrafting, world)) recipeSet.add(r); + } + + Object[] arr = recipeSet.toArray(); + + if (arr.length == 0) return null; + + IRecipe recipe = (IRecipe) arr[0]; + ItemStack stack = recipe.getCraftingResult(inventoryCrafting); + + if (arr.length != 1) return stack; + + if (stack != null) cache.addLast(recipe); + + return stack; + } + +} diff --git a/src/main/java/gregtech/mixin/hooks/MixinsVariablesHelper.java b/src/main/java/gregtech/mixin/hooks/MixinsVariablesHelper.java new file mode 100644 index 0000000000..7925573f2d --- /dev/null +++ b/src/main/java/gregtech/mixin/hooks/MixinsVariablesHelper.java @@ -0,0 +1,6 @@ +package gregtech.mixin.hooks; + +public class MixinsVariablesHelper { + + public static String currentlyTranslating = null; +} diff --git a/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java b/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java deleted file mode 100644 index 089479f8ad..0000000000 --- a/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java +++ /dev/null @@ -1,8 +0,0 @@ -package gregtech.mixin.interfaces; - -import net.minecraft.block.Block; - -public interface IBlockStemAccesor { - - Block getCropBlock(); -} diff --git a/src/main/java/gregtech/mixin/interfaces/PotionExt.java b/src/main/java/gregtech/mixin/interfaces/PotionExt.java deleted file mode 100644 index 11ae365e5a..0000000000 --- a/src/main/java/gregtech/mixin/interfaces/PotionExt.java +++ /dev/null @@ -1,7 +0,0 @@ -package gregtech.mixin.interfaces; - -public interface PotionExt { - - boolean gt5u$isBadEffect(); - -} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java new file mode 100644 index 0000000000..826c5d1474 --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java @@ -0,0 +1,7 @@ +package gregtech.mixin.interfaces.accessors; + +public interface EntityPlayerMPAccessor { + + String gt5u$getTranslator(); + +} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java new file mode 100644 index 0000000000..da3efa582d --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java @@ -0,0 +1,8 @@ +package gregtech.mixin.interfaces.accessors; + +import net.minecraft.block.Block; + +public interface IBlockStemAccessor { + + Block gt5u$getCropBlock(); +} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/IRecipeMutableAccess.java b/src/main/java/gregtech/mixin/interfaces/accessors/IRecipeMutableAccess.java new file mode 100644 index 0000000000..778e021205 --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/IRecipeMutableAccess.java @@ -0,0 +1,18 @@ +package gregtech.mixin.interfaces.accessors; + +import net.minecraft.item.ItemStack; + +/** + * Mixed-in interface for recipe classes in Forge and Vanilla that allows mutating the input and output items. + */ +public interface IRecipeMutableAccess { + + /** @return Gets the current output item of the recipe */ + ItemStack gt5u$getRecipeOutputItem(); + + /** Sets a new output item on the recipe */ + void gt5u$setRecipeOutputItem(ItemStack newItem); + + /** @return The raw list or array of recipe inputs, the exact type depends on the underlying recipe type. */ + Object gt5u$getRecipeInputs(); +} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java new file mode 100644 index 0000000000..48794c256a --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java @@ -0,0 +1,7 @@ +package gregtech.mixin.interfaces.accessors; + +public interface PotionAccessor { + + boolean gt5u$isBadEffect(); + +} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java new file mode 100644 index 0000000000..9d2980e434 --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java @@ -0,0 +1,9 @@ +package gregtech.mixin.interfaces.accessors; + +public interface ShapedOreRecipeAccessor { + + int gt5u$getWidth(); + + int gt5u$getHeight(); + +} diff --git a/src/main/java/gtPlusPlus/GTplusplus.java b/src/main/java/gtPlusPlus/GTplusplus.java index 893446ea72..5de4fef23b 100644 --- a/src/main/java/gtPlusPlus/GTplusplus.java +++ b/src/main/java/gtPlusPlus/GTplusplus.java @@ -4,12 +4,13 @@ import static gregtech.api.enums.Mods.GTPlusPlus; import static gregtech.api.enums.Mods.Names; import static gregtech.api.enums.Mods.Thaumcraft; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.HashMap; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; import com.gtnewhorizon.gtnhlib.config.ConfigException; @@ -25,7 +26,6 @@ import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.event.FMLServerStoppingEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -44,7 +44,9 @@ import gtPlusPlus.core.handler.Recipes.RegistrationHandler; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.data.LocaleUtils; -import gtPlusPlus.plugin.manager.CoreManager; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.plugin.agrichem.block.AgrichemFluids; +import gtPlusPlus.plugin.fixes.vanilla.VanillaBedHeightFix; import gtPlusPlus.xmod.gregtech.common.MetaGTProxy; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtTools; @@ -76,7 +78,7 @@ import gtPlusPlus.xmod.thaumcraft.commands.CommandDumpAspects; + " after:TGregworks;" + " after:StevesCarts;" + " required-after:gtnhlib@[0.0.10,);") -public class GTplusplus implements ActionListener { +public class GTplusplus { public enum INIT_PHASE { @@ -149,8 +151,6 @@ public class GTplusplus implements ActionListener { @EventHandler public void preInit(final FMLPreInitializationEvent event) { INIT_PHASE.PRE_INIT.setPhaseActive(true); - // Load all class objects within the plugin package. - CoreManager.veryEarlyInit(); PacketHandler.init(); // Give this a go mate. @@ -162,7 +162,9 @@ public class GTplusplus implements ActionListener { proxy.preInit(event); Logger.INFO("Setting up our own GTProxy."); MetaGTProxy.preInit(); - CoreManager.preInit(); + AgrichemFluids.preInit(); + fixVanillaOreDict(); + new VanillaBedHeightFix(); } @EventHandler @@ -171,7 +173,6 @@ public class GTplusplus implements ActionListener { proxy.init(event); proxy.registerNetworkStuff(); MetaGTProxy.init(); - CoreManager.init(); // Used by foreign players to generate .lang files for translation. if (Configuration.debug.dumpItemAndBlockData) { LocaleUtils.generateFakeLocaleFile(); @@ -184,7 +185,6 @@ public class GTplusplus implements ActionListener { proxy.postInit(event); BookHandler.runLater(); MetaGTProxy.postInit(); - CoreManager.postInit(); Logger.INFO("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Logger.INFO( @@ -218,18 +218,9 @@ public class GTplusplus implements ActionListener { if (Thaumcraft.isModLoaded()) { event.registerServerCommand(new CommandDumpAspects()); } - CoreManager.serverStart(); INIT_PHASE.STARTED.setPhaseActive(true); } - @EventHandler - public synchronized void serverStopping(final FMLServerStoppingEvent event) { - CoreManager.serverStop(); - } - - @Override - public void actionPerformed(final ActionEvent arg0) {} - /** * This {@link EventHandler} is called after the {@link FMLPostInitializationEvent} stages of all loaded mods * executes successfully. {@link #onLoadComplete(FMLLoadCompleteEvent)} exists to inject recipe generation after @@ -383,4 +374,39 @@ public class GTplusplus implements ActionListener { mapping.remap(block); Logger.INFO("Remapping block " + mapping.name + " to " + GTPlusPlus.ID + ":" + block.getUnlocalizedName()); } + + private static void fixVanillaOreDict() { + registerToOreDict(ItemUtils.getSimpleStack(Items.blaze_rod), "rodBlaze"); + registerToOreDict(ItemUtils.getSimpleStack(Items.nether_wart), "cropNetherWart"); + registerToOreDict(ItemUtils.getSimpleStack(Items.reeds), "sugarcane"); + registerToOreDict(ItemUtils.getSimpleStack(Items.paper), "paper"); + registerToOreDict(ItemUtils.getSimpleStack(Items.ender_pearl), "enderpearl"); + registerToOreDict(ItemUtils.getSimpleStack(Items.bone), "bone"); + registerToOreDict(ItemUtils.getSimpleStack(Items.gunpowder), "gunpowder"); + registerToOreDict(ItemUtils.getSimpleStack(Items.string), "string"); + registerToOreDict(ItemUtils.getSimpleStack(Items.nether_star), "netherStar"); + registerToOreDict(ItemUtils.getSimpleStack(Items.leather), "leather"); + registerToOreDict(ItemUtils.getSimpleStack(Items.feather), "feather"); + registerToOreDict(ItemUtils.getSimpleStack(Items.egg), "egg"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.end_stone), "endstone"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.vine), "vine"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.cactus), "blockCactus"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.grass), "grass"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.obsidian), "obsidian"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.crafting_table), "workbench"); + } + + private static void registerToOreDict(ItemStack aStack, String aString) { + if (aStack.getItem() == Items.blaze_rod) { + Logger + .INFO("Registering " + aStack.getDisplayName() + " to OreDictionary under the tag '" + aString + "'."); + } else { + Logger.INFO( + "Registering " + aStack.getDisplayName() + + " to OreDictionary under the tag '" + + aString + + "'. (Added to Forge in 1.8.9)"); + } + ItemUtils.addItemToOreDictionary(aStack, aString); + } } diff --git a/src/main/java/gtPlusPlus/api/interfaces/IPlugin.java b/src/main/java/gtPlusPlus/api/interfaces/IPlugin.java deleted file mode 100644 index d70a19925e..0000000000 --- a/src/main/java/gtPlusPlus/api/interfaces/IPlugin.java +++ /dev/null @@ -1,41 +0,0 @@ -package gtPlusPlus.api.interfaces; - -import gtPlusPlus.api.objects.Logger; - -public interface IPlugin { - - /** - * @return A {@link String} object which returns the {@link IPlugin}'s name. - */ - public String getPluginName(); - - /** - * @return A {@link String} object which returns the {@link IPlugin}'s short name. This String should only contain 4 - * Characters. - */ - public String getPluginAbbreviation(); - - /** - * @param message - A {@link String} object which holds a message to be logged to console. - */ - default void log(String message) { - Logger.INFO("[" + getPluginAbbreviation() + "] " + message); - } - - /** - * @param message - A {@link String} object which holds a warning/error message to be logged to console. - */ - default void logDebug(String message) { - Logger.WARNING("[" + getPluginAbbreviation() + "] " + message); - } - - public boolean preInit(); - - public boolean init(); - - public boolean postInit(); - - public boolean serverStart(); - - public boolean serverStop(); -} diff --git a/src/main/java/gtPlusPlus/api/objects/Logger.java b/src/main/java/gtPlusPlus/api/objects/Logger.java index 2214e50e78..6650668894 100644 --- a/src/main/java/gtPlusPlus/api/objects/Logger.java +++ b/src/main/java/gtPlusPlus/api/objects/Logger.java @@ -23,7 +23,7 @@ public class Logger { private static final boolean enabled = !ASMConfiguration.debug.disableAllLogging; - public static final org.apache.logging.log4j.Logger getLogger() { + public static org.apache.logging.log4j.Logger getLogger() { return modLogger; } @@ -38,8 +38,7 @@ public class Logger { public static void MACHINE_INFO(String s, Object... args) { if (enabled) { if (Configuration.debug.MachineInfo || GTCorePlugin.isDevEnv()) { - final String name1 = gtPlusPlus.core.util.reflect.ReflectionUtils.getMethodName(2); - modLogger.info("Machine Info: " + s + " | " + name1, args); + modLogger.info("Machine Info: " + s + " ", args); } } } diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java b/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java index 6852c93f05..867f247b6e 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java @@ -6,7 +6,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.ShapedOreRecipe; -import gregtech.api.interfaces.IRecipeMutableAccess; +import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.util.minecraft.ItemUtils; @@ -25,14 +25,11 @@ public class ShapedRecipe implements IRecipeMutableAccess { } public ShapedRecipe(Object[] aInputs, ItemStack aOutput) { - String aGridWhole = ""; - String aGrid[] = new String[3]; + StringBuilder aGridWhole = new StringBuilder(); + String[] aGrid = new String[3]; char[] aChar = new char[9]; String[] aLoggingInfo = new String[9]; - - if (mBlackList == null) { - mBlackList = new ItemStack[] {}; - } + mBlackList = new ItemStack[] {}; // Just to be safe try { @@ -68,7 +65,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { Object[] mVarags2 = null; Logger.RECIPE("Generating Shaped Crafting Recipe for " + aOutput.getDisplayName()); - if (aInputs.length < 9 || aInputs.length > 9) { + if (aInputs.length != 9) { Logger.RECIPE( "[Fix] Recipe for " + aOutput.getDisplayName() + " has incorrect number of inputs. Size: " @@ -118,7 +115,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { for (Pair h : aRecipePairs) { if (h.getKey() != null) { - aGridWhole += String.valueOf(h.getKey()); + aGridWhole.append(String.valueOf(h.getKey())); Logger.RECIPE("Adding '" + String.valueOf(h.getKey()) + "' to aGridWhole."); } } diff --git a/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java b/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java index a348998ef0..63d65b32c9 100644 --- a/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java +++ b/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java @@ -11,7 +11,6 @@ import gregtech.api.enums.Mods; public class ASMConfiguration { public static Debug debug = new Debug(); - public static General general = new General(); // Debug @Config.Comment("Debug section") @@ -27,14 +26,4 @@ public class ASMConfiguration { } - @Config.Comment("General section") - public static class General { - // General Features - - @Config.Comment("Set to a value greater than 0 to reduce the ticks taken to delay between BGM tracks. Acceptable Values are 1-32767, where 0 is disabled. Vanilla Uses 12,000 & 24,000. 200 is 10s.") - @Config.DefaultInt(0) - @Config.RangeInt(min = 0, max = Short.MAX_VALUE) - public int enableWatchdogBGM; - - } } diff --git a/src/main/java/gtPlusPlus/core/handler/PacketHandler.java b/src/main/java/gtPlusPlus/core/handler/PacketHandler.java index 9c5d6b25d2..504afc55d8 100644 --- a/src/main/java/gtPlusPlus/core/handler/PacketHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/PacketHandler.java @@ -9,12 +9,9 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; -import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.network.handler.AbstractClientMessageHandler; -import gtPlusPlus.core.network.packet.AbstractPacket; import gtPlusPlus.core.network.packet.PacketVolumetricFlaskGui; import gtPlusPlus.core.network.packet.PacketVolumetricFlaskGui2; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class PacketHandler { @@ -37,14 +34,6 @@ public class PacketHandler { private static void registerMessage(Class handlerClass, Class messageClass, Side side) { INSTANCE.registerMessage(handlerClass, messageClass, packetId++, side); - if (AbstractPacket.class.isInstance(messageClass.getClass())) { - AbstractPacket aPacket = ReflectionUtils.createNewInstanceFromConstructor( - ReflectionUtils.getConstructor(messageClass, new Class[] {}), - new Object[] {}); - if (aPacket != null) { - Logger.INFO("Registered Packet: " + aPacket.getPacketName()); - } - } } /** diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index 33649b4ff2..41755d6abc 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -11,7 +11,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import gregtech.mixin.interfaces.PotionExt; +import gregtech.mixin.interfaces.accessors.PotionAccessor; import gtPlusPlus.core.util.math.MathUtils; public class PlayerSleepEventHandler { @@ -43,7 +43,7 @@ public class PlayerSleepEventHandler { final List potionToRemove = new ArrayList<>(); for (PotionEffect potionEffect : player.getActivePotionEffects()) { final Potion potion = Potion.potionTypes[potionEffect.getPotionID()]; - if (potion instanceof PotionExt && ((PotionExt) potion).gt5u$isBadEffect()) { + if (potion instanceof PotionAccessor && ((PotionAccessor) potion).gt5u$isBadEffect()) { potionToRemove.add(potion.id); } } diff --git a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 40b32fed86..5dd9f9f426 100644 --- a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -1,56 +1,19 @@ package gtPlusPlus.core.util.reflect; -import java.io.IOException; -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.HashMap; import java.util.Map; -import org.apache.commons.lang3.ArrayUtils; - -import com.google.common.reflect.ClassPath; import com.gtnewhorizon.gtnhlib.reflect.Fields; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.data.StringUtils; @SuppressWarnings({ "unchecked", "rawtypes" }) public class ReflectionUtils { - public static Map mCachedMethods = new LinkedHashMap<>(); - public static Map mCachedFields = new LinkedHashMap<>(); - public static Map mCachedConstructors = new LinkedHashMap<>(); - public static Map mCachedFieldAccessors = new LinkedHashMap<>(); - - private static class CachedConstructor { - - private final Constructor METHOD; - - public CachedConstructor(Constructor aCons) { - METHOD = aCons; - } - - public Constructor get() { - return METHOD; - } - } - - private static class CachedMethod { - - private final Method METHOD; - - public CachedMethod(Method aMethod, boolean isStatic) { - METHOD = aMethod; - } - - public Method get() { - return METHOD; - } - - } + public static Map mCachedFields = new HashMap<>(); + public static Map mCachedFieldAccessors = new HashMap<>(); private static class CachedField { @@ -73,22 +36,6 @@ public class ReflectionUtils { .getUntypedField(Fields.LookupType.DECLARED_IN_HIERARCHY, field.getName())); } - private static boolean cacheMethod(Class aClass, Method aMethod) { - if (aMethod == null) { - return false; - } - boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); - CachedMethod y = mCachedMethods - .get(aClass.getName() + "." + aMethod.getName() + "." + ArrayUtils.toString(aMethod.getParameterTypes())); - if (y == null) { - mCachedMethods.put( - aClass.getName() + "." + aMethod.getName() + "." + ArrayUtils.toString(aMethod.getParameterTypes()), - new CachedMethod(aMethod, isStatic)); - return true; - } - return false; - } - private static boolean cacheField(Class aClass, Field aField) { if (aField == null) { return false; @@ -102,85 +49,6 @@ public class ReflectionUtils { return false; } - private static void cacheConstructor(Class aClass, Constructor aConstructor) { - if (aConstructor == null) { - return; - } - mCachedConstructors.computeIfAbsent( - aClass.getName() + "." + ArrayUtils.toString(aConstructor.getParameterTypes()), - k -> new CachedConstructor(aConstructor)); - } - - /** - * Returns a cached {@link Constructor} object. - * - * @param aClass - Class containing the Constructor. - * @param aTypes - Varags Class Types for objects constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Constructor getConstructor(Class aClass, Class... aTypes) { - if (aClass == null || aTypes == null) { - return null; - } - - String aMethodKey = ArrayUtils.toString(aTypes); - // Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); - CachedConstructor y = mCachedConstructors.get(aClass.getName() + "." + aMethodKey); - if (y == null) { - Constructor u = getConstructor_Internal(aClass, aTypes); - if (u != null) { - Logger.REFLECTION("Caching Constructor: " + aClass.getName() + "." + aMethodKey); - cacheConstructor(aClass, u); - return u; - } else { - return null; - } - } else { - return y.get(); - } - } - - /** - * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. - * - * @param aObject - Object containing the Method. - * @param aMethodName - Method's name in {@link String} form. - * @param aTypes - Class Array of Types for {@link Method}'s constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Method getMethod(Object aObject, String aMethodName, Class[] aTypes) { - return getMethod(aObject.getClass(), aMethodName, aTypes); - } - - /** - * Returns a cached {@link Method} object. - * - * @param aClass - Class containing the Method. - * @param aMethodName - Method's name in {@link String} form. - * @param aTypes - Varags Class Types for {@link Method}'s constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { - if (aClass == null || aMethodName == null || aMethodName.length() <= 0) { - return null; - } - String aMethodKey = ArrayUtils.toString(aTypes); - // Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); - CachedMethod y = mCachedMethods.get(aClass.getName() + "." + aMethodName + "." + aMethodKey); - if (y == null) { - Method u = getMethod_Internal(aClass, aMethodName, aTypes); - if (u != null) { - Logger.REFLECTION("Caching Method: " + aMethodName + "." + aMethodKey); - cacheMethod(aClass, u); - return u; - } else { - return null; - } - } else { - return y.get(); - } - } - /** * Returns a cached {@link Field} object. * @@ -237,79 +105,6 @@ public class ReflectionUtils { } } - public static void makeMethodAccessible(final Method field) { - if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic( - field.getDeclaringClass() - .getModifiers())) { - field.setAccessible(true); - } - } - - /** - * Get the method name for a depth in call stack.
- * Utility function - * - * @param depth depth in the call stack (0 means current method, 1 means call method, ...) - * @return Method name - */ - public static String getMethodName(final int depth) { - final StackTraceElement[] ste = new Throwable().getStackTrace(); - // System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName()); - if (ste.length < depth) { - return "No valid stack."; - } - return ste[depth + 1].getMethodName(); - } - - /** - * - * @param aPackageName - The full {@link Package} name in {@link String} form. - * @return - {@link Boolean} object. True if loaded > 0 classes. - */ - public static boolean dynamicallyLoadClassesInPackage(String aPackageName) { - ClassLoader classLoader = ReflectionUtils.class.getClassLoader(); - int loaded = 0; - try { - ClassPath path = ClassPath.from(classLoader); - for (ClassPath.ClassInfo info : path.getTopLevelClassesRecursive(aPackageName)) { - Class clazz = Class.forName(info.getName(), true, classLoader); - if (clazz != null) { - loaded++; - Logger.INFO("Found " + clazz.getCanonicalName() + ". [" + loaded + "]"); - } - } - } catch (ClassNotFoundException | IOException e) { - - } - - return loaded > 0; - } - - public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { - Class clazz; - if (object instanceof Class) { - clazz = (Class) object; - } else { - clazz = object.getClass(); - } - while (clazz != null) { - try { - final Field field = getField(clazz, fieldName); - if (field != null) { - setFieldValue_Internal(object, field, fieldValue); - return true; - } - } catch (final NoSuchFieldException e) { - Logger.REFLECTION("setField(" + object + ", " + fieldName + ") failed."); - clazz = clazz.getSuperclass(); - } catch (final Exception e) { - Logger.REFLECTION("setField(" + object + ", " + fieldName + ") failed."); - throw new IllegalStateException(e); - } - } - return false; - } - public static boolean setField(final Object object, final Field field, final Object fieldValue) { if (field == null) return false; Class clazz; @@ -336,51 +131,6 @@ public class ReflectionUtils { return false; } - /** - * Allows to change the state of an immutable instance. Huh?!? - */ - public static void setFinalFieldValue(Class clazz, String fieldName, Object newValue) { - Field nameField = getField(clazz, fieldName); - try { - setFieldValue_Internal(clazz, nameField, newValue); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - public static void setByte(Object clazz, String fieldName, byte newValue) { - Field nameField = getField(clazz.getClass(), fieldName); - cacheAccessor(nameField).setValue(null, newValue); - } - - public static boolean invokeVoid(Object objectInstance, String methodName, Class[] parameters, Object[] values) { - if (objectInstance == null || methodName == null || parameters == null || values == null) { - return false; - } - Class mLocalClass = (objectInstance instanceof Class ? (Class) objectInstance - : objectInstance.getClass()); - Logger.REFLECTION( - "Trying to invoke " + methodName + " on an instance of " + mLocalClass.getCanonicalName() + "."); - try { - Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters); - if (mInvokingMethod != null) { - Logger.REFLECTION(methodName + " was not null."); - mInvokingMethod.invoke(objectInstance, values); - Logger.REFLECTION("Successfully invoked " + methodName + "."); - return true; - } else { - Logger.REFLECTION(methodName + " is null."); - } - } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - Logger.REFLECTION( - "Failed to Dynamically invoke " + methodName + " on an object of type: " + mLocalClass.getName()); - } - - Logger.REFLECTION("Invoke failed or did something wrong."); - return false; - } - /* * Below Code block is used for determining generic types associated with type */ @@ -407,108 +157,6 @@ 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); - } - } catch (Throwable t) { - Logger.REFLECTION("Method: Internal Lookup Failed: " + aMethodName); - try { - m = getMethodRecursively(aClass, aMethodName); - } catch (NoSuchMethodException e) { - Logger.REFLECTION("Unable to find method '" + aMethodName + "'"); - e.printStackTrace(); - dumpClassInfo(aClass); - } - } - return m; - } - - private static Constructor getConstructor_Internal(Class aClass, Class... aTypes) { - Constructor c = null; - try { - Logger.REFLECTION("Constructor: Internal Lookup: " + aClass.getName()); - c = aClass.getDeclaredConstructor(aTypes); - if (c != null) { - c.setAccessible(true); - } - } catch (Throwable t) { - Logger.REFLECTION("Constructor: Internal Lookup Failed: " + aClass.getName()); - try { - c = getConstructorRecursively(aClass, aTypes); - } catch (Exception e) { - Logger.REFLECTION("Unable to find method '" + aClass.getName() + "'"); - e.printStackTrace(); - dumpClassInfo(aClass); - } - } - return c; - } - - private static Constructor getConstructorRecursively(Class aClass, Class... aTypes) throws Exception { - try { - Logger.REFLECTION("Constructor: Recursion Lookup: " + aClass.getName()); - Constructor c = aClass.getConstructor(aTypes); - if (c != null) { - c.setAccessible(true); - } - return c; - } catch (final NoSuchMethodException | IllegalArgumentException e) { - final Class superClass = aClass.getSuperclass(); - if (superClass == null || superClass == Object.class) { - throw e; - } - return getConstructor_Internal(superClass, aTypes); - } - } - - private static Method getMethodRecursively(final Class clazz, final String aMethodName) - throws NoSuchMethodException { - try { - Logger.REFLECTION("Method: Recursion Lookup: " + aMethodName); - Method k = clazz.getDeclaredMethod(aMethodName); - makeMethodAccessible(k); - return k; - } catch (final NoSuchMethodException e) { - final Class superClass = clazz.getSuperclass(); - if (superClass == null || superClass == Object.class) { - throw e; - } - return getMethod_Internal(superClass, aMethodName); - } - } - - private static void dumpClassInfo(Class aClass) { - Logger.INFO( - "We ran into an error processing reflection in " + aClass.getName() + ", dumping all data for debugging."); - // Get the methods - Method[] methods = aClass.getDeclaredMethods(); - Field[] fields = aClass.getDeclaredFields(); - Constructor[] consts = aClass.getDeclaredConstructors(); - - Logger.INFO("Dumping all Methods."); - for (Method method : methods) { - System.out - .println(method.getName() + " | " + StringUtils.getDataStringFromArray(method.getParameterTypes())); - } - Logger.INFO("Dumping all Fields."); - for (Field f : fields) { - System.out.println(f.getName()); - } - Logger.INFO("Dumping all Constructors."); - for (Constructor c : consts) { - System.out.println( - c.getName() + " | " - + c.getParameterCount() - + " | " - + StringUtils.getDataStringFromArray(c.getParameterTypes())); - } - } - /** * * Set the value of a field reflectively. @@ -517,19 +165,6 @@ public class ReflectionUtils { cacheAccessor(field).setValue(owner, value); } - public static boolean doesFieldExist(Class clazz, String string) { - if (clazz != null) { - if (ReflectionUtils.getField(clazz, string) != null) { - return true; - } - } - return false; - } - - public static T getFieldValue(Field field) { - return getFieldValue(field, null); - } - public static T getFieldValue(Field field, Object instance) { try { return (T) field.get(instance); @@ -537,29 +172,4 @@ public class ReflectionUtils { return null; } - public static T createNewInstanceFromConstructor(Constructor aConstructor, Object[] aArgs) { - T aInstance; - try { - aInstance = (T) aConstructor.newInstance(aArgs); - return aInstance; - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - public static Enum getEnum(Class sgtbees, String name) { - if (sgtbees.isEnum()) { - Object[] aValues = sgtbees.getEnumConstants(); - for (Object o : aValues) { - if (o.toString() - .toLowerCase() - .equals(name.toLowerCase())) { - return (Enum) o; - } - } - } - return null; - } } diff --git a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java index d2052afb55..55bb39bd3e 100644 --- a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java +++ b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java @@ -2,9 +2,6 @@ package gtPlusPlus.everglades; import static gregtech.api.enums.Mods.GTPlusPlusEverglades; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - import net.minecraft.block.Block; import net.minecraftforge.common.DimensionManager; @@ -35,7 +32,7 @@ import gtPlusPlus.everglades.gen.gt.WorldGen_Ores; name = Everglades.NAME, version = Everglades.VERSION, dependencies = "required-after:Forge; after:dreamcraft; after:IC2; required-after:gregtech; required-after:miscutils;") -public class GTPPEverglades implements ActionListener { +public class GTPPEverglades { // Mod Instance @Mod.Instance(Mods.Names.G_T_PLUS_PLUS_EVERGLADES) @@ -171,10 +168,4 @@ public class GTPPEverglades implements ActionListener { public static synchronized void setEvergladesBiome(BiomeEverglades darkWorld_Biome) { Everglades_Biome = darkWorld_Biome; } - - @Override - public void actionPerformed(ActionEvent arg0) { - // TODO Auto-generated method stub - - } } diff --git a/src/main/java/gtPlusPlus/plugin/agrichem/AgrichemCore.java b/src/main/java/gtPlusPlus/plugin/agrichem/AgrichemCore.java deleted file mode 100644 index 6e5cc47e3a..0000000000 --- a/src/main/java/gtPlusPlus/plugin/agrichem/AgrichemCore.java +++ /dev/null @@ -1,56 +0,0 @@ -package gtPlusPlus.plugin.agrichem; - -import gtPlusPlus.api.interfaces.IPlugin; -import gtPlusPlus.plugin.agrichem.block.AgrichemFluids; -import gtPlusPlus.plugin.manager.CoreManager; - -// Called by Core_Manager#veryEarlyInit -@SuppressWarnings("unused") -public class AgrichemCore implements IPlugin { - - static f