From 82604eadb847335e4b4ddf2e90a28b325786837b Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 7 Sep 2024 05:40:03 +0200 Subject: Remove a bunch more reflection (#3074) Co-authored-by: boubou19 --- dependencies.gradle | 1 + .../bwcrossmod/galacticgreg/MTEVoidMinerBase.java | 4 +- .../blocks/tileEntity/MTEYottaFluidTank.java | 2 +- src/main/java/gregtech/GTMod.java | 2 +- .../implementations/MTEWirelessEnergy.java | 2 +- .../multi/purification/MTEPurificationPlant.java | 2 +- .../java/gregtech/loaders/preload/GTPreLoad.java | 2 +- .../java/gtPlusPlus/api/objects/data/AutoMap.java | 30 +- .../gtPlusPlus/core/block/base/BlockBaseOre.java | 27 +- .../gtPlusPlus/core/gui/widget/GuiValueField.java | 8 +- .../gtPlusPlus/core/handler/PacketHandler.java | 17 +- .../core/item/chemistry/AgriculturalChem.java | 45 +-- .../core/item/chemistry/MilledOreProcessing.java | 11 +- .../core/item/tool/misc/ItemGregtechPump.java | 2 +- src/main/java/gtPlusPlus/core/lib/GTPPCore.java | 34 +- .../gtPlusPlus/core/material/MaterialStack.java | 7 +- .../machines/TileEntityPestKiller.java | 9 +- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 7 +- .../core/util/minecraft/MiningUtils.java | 76 ++--- .../core/util/reflect/ReflectionUtils.java | 22 +- .../agrichem/item/algae/ItemAgrichemBase.java | 22 -- .../plugin/fixes/vanilla/VanillaBedHeightFix.java | 1 + .../gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java | 169 +--------- .../forestry/bees/registry/GTPP_BeeDefinition.java | 59 ++-- .../xmod/forestry/bees/registry/GTPP_Bees.java | 17 +- .../implementations/MTEHatchNaquadah.java | 40 ++- .../implementations/base/GTPPMultiBlockBase.java | 43 +-- .../gregtech/loaders/RecipeGenFluidCanning.java | 9 +- .../xmod/gregtech/loaders/RecipeGenRecycling.java | 13 +- .../gtPlusPlus/xmod/tinkers/HandlerTinkers.java | 5 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 19 +- .../xmod/tinkers/util/TinkersDryingRecipe.java | 91 ++---- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 356 +++------------------ .../java/gtnhlanth/common/tileentity/MTELINAC.java | 2 +- 34 files changed, 231 insertions(+), 925 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 686bc508d1..ee1ded31a4 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -99,6 +99,7 @@ dependencies { compileOnly("com.github.GTNewHorizons:BloodMagic:1.6.5:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:CraftTweaker:3.4.0:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:BetterLoadingScreen:1.7.0-GTNH:dev") { transitive = false } + compileOnly rfg.deobf("curse.maven:biomes-o-plenty-220318:2499612") compileOnly('com.github.GTNewHorizons:SC2:2.2.0:dev') {transitive=false} compileOnly('com.github.GTNewHorizons:Binnie:2.4.1:dev') {transitive = false} diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java index 1eb6d8e312..3744d26aa4 100644 --- a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -290,10 +290,10 @@ public abstract class MTEVoidMinerBase extends MTEDrillerBase { final List inputOres = this.getStoredInputs() .stream() .filter(GTUtility::isOre) - .collect(Collectors.toList());; + .collect(Collectors.toList()); final ItemStack output = this.nextOre(); output.stackSize = multiplier; - if (inputOres.size() == 0 || this.mBlacklist && inputOres.stream() + if (inputOres.isEmpty() || this.mBlacklist && inputOres.stream() .noneMatch(is -> GTUtility.areStacksEqual(is, output)) || !this.mBlacklist && inputOres.stream() .anyMatch(is -> GTUtility.areStacksEqual(is, output))) diff --git a/src/main/java/goodgenerator/blocks/tileEntity/MTEYottaFluidTank.java b/src/main/java/goodgenerator/blocks/tileEntity/MTEYottaFluidTank.java index 1d8620ad4d..ccac1e3fb6 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/MTEYottaFluidTank.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/MTEYottaFluidTank.java @@ -472,7 +472,7 @@ public class MTEYottaFluidTank extends MTETooltipMultiBlockBaseEM implements ICo if (tFluid == null) continue; if (isFluidLocked) { if (mLockedFluid != null) { - if (!tFluid.isFluidEqual(mLockedFluid)) continue;; + if (!tFluid.isFluidEqual(mLockedFluid)) continue; } else { mLockedFluid = tFluid.copy(); mLockedFluid.amount = 1; diff --git a/src/main/java/gregtech/GTMod.java b/src/main/java/gregtech/GTMod.java index 87b5b154d9..4b3bae4056 100644 --- a/src/main/java/gregtech/GTMod.java +++ b/src/main/java/gregtech/GTMod.java @@ -238,7 +238,7 @@ public class GTMod implements IGTMod { clientSide = "gregtech.common.GTClient", serverSide = "gregtech.common.GTServer") public static GTProxy gregtechproxy; - public static final boolean DEBUG = Boolean.getBoolean("gt.debug");; + public static final boolean DEBUG = Boolean.getBoolean("gt.debug"); public static int MAX_IC2 = 2147483647; public static GTAchievements achievements; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEWirelessEnergy.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEWirelessEnergy.java index e195b4ab08..517fa18636 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEWirelessEnergy.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEWirelessEnergy.java @@ -134,7 +134,7 @@ public class MTEWirelessEnergy extends MTEHatchEnergy implements IWirelessEnergy // UUID of the owner. owner_uuid = aBaseMetaTileEntity.getOwnerUuid(); - SpaceProjectManager.checkOrCreateTeam(owner_uuid);; + SpaceProjectManager.checkOrCreateTeam(owner_uuid); tryFetchingEnergy(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/purification/MTEPurificationPlant.java b/src/main/java/gregtech/common/tileentities/machines/multi/purification/MTEPurificationPlant.java index 6933a18dc2..9c0b530164 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/purification/MTEPurificationPlant.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/purification/MTEPurificationPlant.java @@ -680,7 +680,7 @@ public class MTEPurificationPlant extends MTEExtendedPowerMultiBlockBase implements Iterable, Cloneable, Serializable, Collect /** * Generates an AutoMap from the List. - * + * * @param aList - Data to be inserted into the AutoMap. */ public AutoMap(List aList) { mInternalMap = new LinkedHashMap<>(); mInternalNameMap = new LinkedHashMap<>(); - if (aList != null && aList.size() > 0) { + if (aList != null && !aList.isEmpty()) { for (V obj : aList) { add(obj); } @@ -56,13 +56,13 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect /** * Generates an AutoMap from a Set. - * + * * @param aList - Data to be inserted into the AutoMap. */ public AutoMap(Set aList) { mInternalMap = new LinkedHashMap<>(); mInternalNameMap = new LinkedHashMap<>(); - if (aList != null && aList.size() > 0) { + if (aList != null && !aList.isEmpty()) { for (V obj : aList) { add(obj); } @@ -71,13 +71,13 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect /** * Generates an AutoMap from a Collection. - * + * * @param aList - Data to be inserted into the AutoMap. */ public AutoMap(Collection aList) { mInternalMap = new LinkedHashMap<>(); mInternalNameMap = new LinkedHashMap<>(); - if (aList != null && aList.size() > 0) { + if (aList != null && !aList.isEmpty()) { for (V obj : aList) { add(obj); } @@ -86,13 +86,13 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect /** * Generates an AutoMap from a Array. - * + * * @param aArray - Data to be inserted into the AutoMap. */ public AutoMap(V[] aArray) { mInternalMap = new LinkedHashMap<>(); mInternalNameMap = new LinkedHashMap<>(); - if (aArray != null && aArray.length > 0) { + if (aArray != null) { for (V obj : aArray) { add(obj); } @@ -107,12 +107,8 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect public synchronized boolean setValue(V object) { int mOriginalID = this.mInternalID; put(object); - if (this.mInternalMap.get(mOriginalID) - .equals(object) || mOriginalID > this.mInternalID) { - return true; - } else { - return false; - } + return this.mInternalMap.get(mOriginalID) + .equals(object) || mOriginalID > this.mInternalID; } public synchronized V put(V object) { @@ -168,7 +164,6 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect this.mInternalID = 0; this.mInternalMap.clear(); this.mInternalNameMap.clear(); - return; } @Override @@ -322,7 +317,6 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect for (V of : mInternalMap.values()) { if (of != o) { aCount++; - continue; } else { return aCount; } @@ -353,9 +347,7 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect AutoMap aNewSubList = new AutoMap<>(); for (int slot = fromIndex; slot <= toIndex; slot++) { V obj = mInternalMap.get(slot); - if (obj == null) { - continue; - } else { + if (obj != null) { aNewSubList.put(obj); } } diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index b0ee1c0c77..7ba3e7e474 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -1,6 +1,5 @@ package gtPlusPlus.core.block.base; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Random; @@ -21,7 +20,6 @@ import cpw.mods.fml.common.registry.GameRegistry; import gregtech.GTMod; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.Textures; -import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; import gregtech.api.util.GTOreDictUnificator; import gtPlusPlus.api.interfaces.ITexturedBlock; @@ -30,7 +28,6 @@ import gtPlusPlus.core.item.base.itemblock.ItemBlockOre; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.objects.GTPPCopiedBlockTexture; import gtPlusPlus.xmod.gregtech.api.objects.GTPPRenderedTexture; @@ -100,13 +97,6 @@ public class BlockBaseOre extends BasicBlock implements ITexturedBlock { return Blocks.stone.getIcon(0, 0); } - /** - * GT Texture Handler - */ - - // .08 compat - public static IIconContainer[] hiddenTextureArray; - @Override public ITexture[] getTexture(ForgeDirection side) { return getTexture(null, side); @@ -120,21 +110,8 @@ public class BlockBaseOre extends BasicBlock implements ITexturedBlock { this.blockMaterial.getRGBA()); return new ITexture[] { new GTPPCopiedBlockTexture(Blocks.stone, 0, 0), aIconSet }; } - - if (hiddenTextureArray == null) { - try { - Field o = ReflectionUtils.getField(Textures.BlockIcons.class, "STONES"); - if (o != null) { - hiddenTextureArray = (IIconContainer[]) o.get(Textures.BlockIcons.class); - } - if (hiddenTextureArray == null) { - hiddenTextureArray = new IIconContainer[6]; - } - } catch (IllegalArgumentException | IllegalAccessException e) { - hiddenTextureArray = new IIconContainer[6]; - } - } - return new ITexture[] { new GTPPRenderedTexture(hiddenTextureArray[0], new short[] { 240, 240, 240, 0 }) }; + return new ITexture[] { + new GTPPRenderedTexture(Textures.BlockIcons.STONES[0], new short[] { 240, 240, 240, 0 }) }; } @Override diff --git a/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java b/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java index 26e7d907d3..8f549364c1 100644 --- a/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java +++ b/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java @@ -31,13 +31,7 @@ public class GuiValueField extends GuiTextField { } public boolean isBackgroundDrawingEnabled() { - Field enableBackgroundDrawing = ReflectionUtils.getField( - GuiTextField.class, - !PreloaderCore.DEV_ENVIRONMENT ? "field_146215_m" : "enableBackgroundDrawing"); - if (enableBackgroundDrawing != null) { - return ReflectionUtils.getFieldValue(enableBackgroundDrawing, this); - } - return true; + return this.getEnableBackgroundDrawing(); } public int getLineScrollOffset() { diff --git a/src/main/java/gtPlusPlus/core/handler/PacketHandler.java b/src/main/java/gtPlusPlus/core/handler/PacketHandler.java index 735d381706..9c5d6b25d2 100644 --- a/src/main/java/gtPlusPlus/core/handler/PacketHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/PacketHandler.java @@ -22,7 +22,7 @@ public class PacketHandler { private static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(GTPlusPlus.ID); - public static final void init() { + public static void init() { registerMessage(PacketVolumetricFlaskGui.class, PacketVolumetricFlaskGui.class); registerMessage(PacketVolumetricFlaskGui2.class, PacketVolumetricFlaskGui2.class); } @@ -50,30 +50,29 @@ public class PacketHandler { /** * Send this message to the specified player. See {@link SimpleNetworkWrapper#sendTo(IMessage, EntityPlayerMP)} */ - public static final void sendTo(IMessage message, EntityPlayerMP player) { + public static void sendTo(IMessage message, EntityPlayerMP player) { INSTANCE.sendTo(message, player); } /** * Send this message to everyone within a certain range of a point. See - * {@link SimpleNetworkWrapper#sendToDimension(IMessage, NetworkRegistry.TargetPoint)} + * {@link SimpleNetworkWrapper#sendToAllAround(IMessage, NetworkRegistry.TargetPoint)} */ - public static final void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) { + public static void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) { INSTANCE.sendToAllAround(message, point); } /** * Sends a message to everyone within a certain range of the coordinates in the same dimension. */ - public static final void sendToAllAround(IMessage message, int dimension, double x, double y, double z, - double range) { + public static void sendToAllAround(IMessage message, int dimension, double x, double y, double z, double range) { sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, x, y, z, range)); } /** * Sends a message to everyone within a certain range of the player provided. */ - public static final void sendToAllAround(IMessage message, EntityPlayer player, double range) { + public static void sendToAllAround(IMessage message, EntityPlayer player, double range) { sendToAllAround(message, player.worldObj.provider.dimensionId, player.posX, player.posY, player.posZ, range); } @@ -81,14 +80,14 @@ public class PacketHandler { * Send this message to everyone within the supplied dimension. See * {@link SimpleNetworkWrapper#sendToDimension(IMessage, int)} */ - public static final void sendToDimension(IMessage message, int dimensionId) { + public static void sendToDimension(IMessage message, int dimensionId) { INSTANCE.sendToDimension(message, dimensionId); } /** * Send this message to the server. See {@link SimpleNetworkWrapper#sendToServer(IMessage)} */ - public static final void sendToServer(IMessage message) { + public static void sendToServer(IMessage message) { INSTANCE.sendToServer(message); } } diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java b/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java index 4bbf29c88f..4c7dc05804 100644 --- a/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java +++ b/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java @@ -1,7 +1,6 @@ package gtPlusPlus.core.item.chemistry; import static gregtech.api.enums.Mods.BiomesOPlenty; -import static gregtech.api.enums.Mods.Forestry; import static gregtech.api.enums.Mods.TinkerConstruct; import static gregtech.api.recipe.RecipeMaps.centrifugeRecipes; import static gregtech.api.recipe.RecipeMaps.compressorRecipes; @@ -12,7 +11,6 @@ import static gregtech.api.util.GTRecipeConstants.UniversalChemical; import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes; import static gtPlusPlus.api.recipe.GTPPRecipeMaps.semiFluidFuels; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; @@ -23,8 +21,12 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; +import forestry.core.items.ItemForestryBonemeal; +import forestry.core.items.ItemRegistryCore; +import forestry.plugins.PluginCore; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; +import gregtech.api.enums.Mods; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.TierEU; import gregtech.api.util.GTOreDictUnificator; @@ -37,7 +39,6 @@ import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.plugin.agrichem.BioRecipes; import gtPlusPlus.plugin.agrichem.item.algae.ItemAgrichemBase; import gtPlusPlus.plugin.agrichem.item.algae.ItemAlgaeBase; @@ -543,33 +544,19 @@ public class AgriculturalChem extends ItemPackage { ItemStack aManureByprod = ItemUtils.getSimpleStack(dustManureByproducts, 1); // Dehydrate Organise Fert to Normal Fert. + if (Mods.Forestry.isModLoaded()) { + ItemRegistryCore aItemRegInstance = PluginCore.items; + if (aItemRegInstance != null) { + ItemForestryBonemeal fertilizerCompound = aItemRegInstance.fertilizerCompound; + aFertForestry = ItemUtils.getSimpleStack(fertilizerCompound); - /* - * Forestry Support - */ - if (Forestry.isModLoaded()) { - Field aItemField = ReflectionUtils - .getField(ReflectionUtils.getClass("forestry.plugins.PluginCore"), "items"); - try { - Object aItemRegInstance = aItemField != null ? aItemField.get(aItemField) : null; - if (aItemRegInstance != null) { - Field aFertField = ReflectionUtils.getField(aItemRegInstance.getClass(), "fertilizerCompound"); - Object aItemInstance = aFertField.get(aItemRegInstance); - if (aItemInstance instanceof Item aForestryFert) { - aFertForestry = ItemUtils.getSimpleStack((Item) aItemInstance); - - GTValues.RA.stdBuilder() - .itemInputs( - GTUtility.getIntegratedCircuit(11), - ItemUtils.getSimpleStack(aDustOrganicFert, 4)) - .itemOutputs(ItemUtils.getSimpleStack(aForestryFert, 3), aManureByprod, aManureByprod) - .outputChances(100_00, 20_00, 20_00) - .eut(240) - .duration(20 * SECONDS) - .addTo(chemicalDehydratorRecipes); - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { + GTValues.RA.stdBuilder() + .itemInputs(GTUtility.getIntegratedCircuit(11), ItemUtils.getSimpleStack(aDustOrganicFert, 4)) + .itemOutputs(ItemUtils.getSimpleStack(fertilizerCompound, 3), aManureByprod, aManureByprod) + .outputChances(100_00, 20_00, 20_00) + .eut(240) + .duration(20 * SECONDS) + .addTo(chemicalDehydratorRecipes); } } diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java b/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java index 078dcdee88..4909d269cc 100644 --- a/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java +++ b/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java @@ -14,6 +14,8 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; +import biomesoplenty.api.content.BOPCBlocks; +import biomesoplenty.api.content.BOPCItems; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; import gregtech.api.enums.TierEU; @@ -33,7 +35,6 @@ import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.core.util.minecraft.NBTUtils; -import gtPlusPlus.xmod.bop.BiomesOPlentyHandler; import gtPlusPlus.xmod.bop.blocks.BOPBlockRegistrator; import gtPlusPlus.xmod.gregtech.common.helpers.FlotationRecipeHandler; @@ -654,10 +655,10 @@ public class MilledOreProcessing extends ItemPackage { aPinecones.add(ItemUtils.getSimpleStack(AgriculturalChem.mPinecone, 1)); if (BiomesOPlenty.isModLoaded()) { - aLogs.add(BiomesOPlentyHandler.getStack(BiomesOPlentyHandler.logs4, 0, 1)); - aLeaves.add(BiomesOPlentyHandler.getStack(BiomesOPlentyHandler.colorizedLeaves2, 1, 1)); - aSaplings.add(BiomesOPlentyHandler.getStack(BiomesOPlentyHandler.colorizedSaplings, 5, 1)); - aPinecones.add(ItemUtils.simpleMetaStack(BiomesOPlentyHandler.mPineCone, 13, 1)); + aLogs.add(ItemUtils.simpleMetaStack(BOPCBlocks.logs4, 0, 1)); + aLeaves.add(ItemUtils.simpleMetaStack(BOPCBlocks.colorizedLeaves2, 1, 1)); + aSaplings.add(ItemUtils.simpleMetaStack(BOPCBlocks.colorizedSaplings, 5, 1)); + aPinecones.add(ItemUtils.simpleMetaStack(BOPCItems.misc, 13, 1)); } if (Forestry.isModLoaded()) { ItemStack aForestryLog = ItemUtils.getItemStackFromFQRN("Forestry:logs", 1); diff --git a/src/main/java/gtPlusPlus/core/item/tool/misc/ItemGregtechPump.java b/src/main/java/gtPlusPlus/core/item/tool/misc/ItemGregtechPump.java index 082f74ad2b..1c896e8497 100644 --- a/src/main/java/gtPlusPlus/core/item/tool/misc/ItemGregtechPump.java +++ b/src/main/java/gtPlusPlus/core/item/tool/misc/ItemGregtechPump.java @@ -1238,7 +1238,7 @@ public class ItemGregtechPump extends Item implements ISpecialElectricItem, IEle if (aTileEntity == null) { return null; } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();; + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); if (aMetaTileEntity == null || aMetaTileEntity instanceof MTEHatchMultiInput) { // blacklist multiinput hatch as it's too complex return null; diff --git a/src/main/java/gtPlusPlus/core/lib/GTPPCore.java b/src/main/java/gtPlusPlus/core/lib/GTPPCore.java index c78d734cb6..af6bedfa61 100644 --- a/src/main/java/gtPlusPlus/core/lib/GTPPCore.java +++ b/src/main/java/gtPlusPlus/core/lib/GTPPCore.java @@ -6,23 +6,17 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.UUID; -import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; -import net.minecraft.world.World; - -import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.GT_Version; import gregtech.api.objects.XSTR; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.Pair; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.preloader.PreloaderCore; import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; import gtPlusPlus.xmod.gregtech.common.tileentities.automation.MTETesseractGenerator; @@ -30,8 +24,6 @@ import gtPlusPlus.xmod.gregtech.common.tileentities.automation.MTETesseractTermi public class GTPPCore { - public static Map PlayerCache; - // Math Related public static final float PI = (float) Math.PI; public static volatile Random RANDOM = new XSTR(); @@ -48,11 +40,6 @@ public class GTPPCore { public static int turbineCutoffBase = 75000; - // GT++ Fake Player Profile - public static final GameProfile gameProfile = new GameProfile( - UUID.nameUUIDFromBytes("gtplusplus.core".getBytes()), - "[GT++]"); - public static final WeakHashMap fakePlayerCache = new WeakHashMap<>(); // Tooltips; public static final Supplier GT_Tooltip = () -> StatCollector.translateToLocal("GTPP.core.GT_Tooltip"); public static final Supplier GT_Tooltip_Builder = () -> StatCollector @@ -202,34 +189,19 @@ public class GTPPCore { public static final String VERSION = GT_Version.VERSION; } - public static final void crash() { + public static void crash() { crash("Generic Crash"); } - public static final void crash(String aReason) { + public static void crash(String aReason) { try { Logger.INFO("=========================================================="); Logger.INFO("[GT++ CRASH]"); Logger.INFO("=========================================================="); Logger.INFO("Oooops..."); - Logger.INFO("This should only happy in a development environment or when something really bad happens."); + Logger.INFO("This should only happen in a development environment or when something really bad happens."); Logger.INFO("Reason: " + aReason); Logger.INFO("=========================================================="); - Logger.INFO("Called from: " + ReflectionUtils.getMethodName(1)); - Logger.INFO(ReflectionUtils.getMethodName(2)); - Logger.INFO(ReflectionUtils.getMethodName(3)); - Logger.INFO(ReflectionUtils.getMethodName(4)); - Logger.INFO(ReflectionUtils.getMethodName(5)); - Logger.INFO(ReflectionUtils.getMethodName(6)); - Logger.INFO(ReflectionUtils.getMethodName(7)); - Logger.INFO(ReflectionUtils.getMethodName(8)); - Logger.INFO(ReflectionUtils.getMethodName(9)); - Logger.INFO(ReflectionUtils.getMethodName(10)); - Logger.INFO(ReflectionUtils.getMethodName(11)); - Logger.INFO(ReflectionUtils.getMethodName(12)); - Logger.INFO(ReflectionUtils.getMethodName(13)); - Logger.INFO(ReflectionUtils.getMethodName(14)); - Logger.INFO(ReflectionUtils.getMethodName(15)); } catch (Throwable t) { t.printStackTrace(); } diff --git a/src/main/java/gtPlusPlus/core/material/MaterialStack.java b/src/main/java/gtPlusPlus/core/material/MaterialStack.java index d4d11781c5..aeb23a9455 100644 --- a/src/main/java/gtPlusPlus/core/material/MaterialStack.java +++ b/src/main/java/gtPlusPlus/core/material/MaterialStack.java @@ -8,7 +8,6 @@ import net.minecraft.item.ItemStack; import gregtech.api.enums.OrePrefixes; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.bartworks.BWUtils; public class MaterialStack { @@ -69,11 +68,7 @@ public class MaterialStack { public Material getStackMaterial() { if (this.stackMaterial == null) { - Logger.MATERIALS("Tried getStackMaterial, got an invalid material."); - Logger.MATERIALS(ReflectionUtils.getMethodName(0)); - Logger.MATERIALS(ReflectionUtils.getMethodName(1)); - Logger.MATERIALS(ReflectionUtils.getMethodName(2)); - Logger.MATERIALS(ReflectionUtils.getMethodName(3)); + Logger.modLogger.error("Tried getStackMaterial, got an invalid material.", new Exception()); return null; } return this.stackMaterial; diff --git a/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityPestKiller.java b/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityPestKiller.java index 66378f0f7a..c91476f556 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityPestKiller.java +++ b/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityPestKiller.java @@ -1,7 +1,5 @@ package gtPlusPlus.core.tileentities.machines; -import static gregtech.api.enums.Mods.Forestry; - import java.util.ArrayList; import java.util.List; @@ -27,6 +25,8 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; +import forestry.lepidopterology.entities.EntityButterfly; +import gregtech.api.enums.Mods; import gregtech.api.util.GTUtility; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.BTF_FluidTank; @@ -36,7 +36,6 @@ import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.EntityUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class TileEntityPestKiller extends TileEntity implements ISidedInventory, IFluidHandler { @@ -56,8 +55,8 @@ public class TileEntityPestKiller extends TileEntity implements ISidedInventory, static { mEntityMap.put(EntityBat.class); - if (Forestry.isModLoaded()) { - mEntityMap.put(ReflectionUtils.getClass("forestry.lepidopterology.entities.EntityButterfly")); + if (Mods.Forestry.isModLoaded()) { + mEntityMap.put(EntityButterfly.class); } } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 1e211290cd..26d7783b78 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -46,7 +46,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.preloader.PreloaderCore; import gtPlusPlus.xmod.gregtech.api.items.GTMetaTool; import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; @@ -309,11 +308,7 @@ public class ItemUtils { public static ItemStack getItemStackOfAmountFromOreDictNoBroken(String oredictName, final int amount) { if (PreloaderCore.DEBUG_MODE) { - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(1)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(2)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(3)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(4)); - Logger.WARNING("Looking up: " + oredictName + " - from method: " + ReflectionUtils.getMethodName(5)); + Logger.modLogger.warn("Looking up: " + oredictName + " - from : ", new Exception()); } try { diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/MiningUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/MiningUtils.java index 16e5652e82..8845409da9 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/MiningUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/MiningUtils.java @@ -2,10 +2,14 @@ package gtPlusPlus.core.util.minecraft; import java.util.HashMap; +import gregtech.api.enums.Mods; import gregtech.common.WorldgenGTOreLayer; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore; +import micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids; +import micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars; public class MiningUtils { @@ -48,42 +52,17 @@ public class MiningUtils { public static boolean findAndMapOreTypesFromGT() { // Gets Moon ID - boolean aEndAsteroids; - try { - if (ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.util.ConfigManagerCore") != null - && mMoonID == -99) { - mMoonID = ReflectionUtils - .getField( - ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.util.ConfigManagerCore"), - "idDimensionMoon") - .getInt(null); + if (Mods.GalacticraftCore.isModLoaded()) { + if (mMoonID == -99) { + mMoonID = ConfigManagerCore.idDimensionMoon; } - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - - // Gets Mars ID - try { - if (ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars") != null - && mMarsID == -99) { - mMarsID = ReflectionUtils - .getField( - ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars"), - "dimensionIDMars") - .getInt(null); + if (mMarsID == -99) { + mMarsID = ConfigManagerMars.dimensionIDMars; } - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - - // Get Comets ID - try { - if (ReflectionUtils.getClass("micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids") - != null && mCometsID == -99) { - mCometsID = ReflectionUtils - .getField( - ReflectionUtils - .getClass("micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids"), - "dimensionIDAsteroids") - .getInt(null); + if (mCometsID == -99) { + mCometsID = ConfigManagerAsteroids.dimensionIDAsteroids; } - } catch (IllegalArgumentException | IllegalAccessException ignored) {} + } // Clear Cache Ores_Overworld.clear(); @@ -91,32 +70,23 @@ public class MiningUtils { Ores_End.clear(); Ores_Misc.clear(); - for (WorldgenGTOreLayer x : WorldgenGTOreLayer.sList) { - if (x.mEnabled) { - - try { - aEndAsteroids = ReflectionUtils.getField(WorldgenGTOreLayer.class, "mEndAsteroid") - .getBoolean(x); - } catch (IllegalArgumentException | IllegalAccessException e) { - aEndAsteroids = false; + for (WorldgenGTOreLayer gtOreLayer : WorldgenGTOreLayer.sList) { + if (gtOreLayer.mEnabled) { + if (gtOreLayer.mOverworld) { + Ores_Overworld.put(gtOreLayer); } - - if (x.mOverworld) { - Ores_Overworld.put(x); - } - if (x.mNether) { - Ores_Nether.put(x); + if (gtOreLayer.mNether) { + Ores_Nether.put(gtOreLayer); } - if (x.mEnd || aEndAsteroids) { - Ores_End.put(x); + if (gtOreLayer.mEnd || gtOreLayer.mEndAsteroid) { + Ores_End.put(gtOreLayer); } - if (x.mOverworld || x.mNether || (x.mEnd || aEndAsteroids)) { + if (gtOreLayer.mOverworld || gtOreLayer.mNether || (gtOreLayer.mEnd || gtOreLayer.mEndAsteroid)) { continue; } - - Ores_Misc.put(x); + Ores_Misc.put(gtOreLayer); } else { - Ores_Comets.put(x); + Ores_Comets.put(gtOreLayer); } } diff --git a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 078cef6ea8..576c236de6 100644 --- a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -126,7 +126,7 @@ public class ReflectionUtils { /** * 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}. @@ -155,7 +155,7 @@ public class ReflectionUtils { /** * Returns a cached {@link Class} object. - * + * * @param aClassCanonicalName - The canonical name of the underlying class. * @return - Valid, {@link Class} object, or {@link null}. */ @@ -176,7 +176,7 @@ 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. @@ -188,7 +188,7 @@ public class ReflectionUtils { /** * 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. @@ -217,7 +217,7 @@ public class ReflectionUtils { /** * 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}. @@ -246,7 +246,7 @@ public class ReflectionUtils { /** * 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}. @@ -286,7 +286,7 @@ public class ReflectionUtils { /** * 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 */ @@ -323,14 +323,6 @@ public class ReflectionUtils { return loaded > 0; } - public static void loadClass(String aClassName) { - try { - Class.forName(aClassName, true, ReflectionUtils.class.getClassLoader()); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { Class clazz; if (object instanceof Class) { diff --git a/src/main/java/gtPlusPlus/plugin/agrichem/item/algae/ItemAgrichemBase.java b/src/main/java/gtPlusPlus/plugin/agrichem/item/algae/ItemAgrichemBase.java index 8a6d189898..b7784580fd 100644 --- a/src/main/java/gtPlusPlus/plugin/agrichem/item/algae/ItemAgrichemBase.java +++ b/src/main/java/gtPlusPlus/plugin/agrichem/item/algae/ItemAgrichemBase.java @@ -2,12 +2,9 @@ package gtPlusPlus.plugin.agrichem.item.algae; import static gregtech.api.enums.Mods.GTPlusPlus; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -23,7 +20,6 @@ import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.OreDictUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class ItemAgrichemBase extends Item { @@ -150,24 +146,6 @@ public class ItemAgrichemBase extends Item { } } - private boolean isTextureValid(String aPath) { - if (aPath == null) { - return false; - } else if (aPath.indexOf(92) == -1) { - Constructor aTextureAtlasSprite = ReflectionUtils.getConstructor(TextureAtlasSprite.class, String.class); - if (aTextureAtlasSprite != null) { - try { - TextureAtlasSprite aTestAtlas = (TextureAtlasSprite) aTextureAtlasSprite.newInstance(aPath); - if (aTestAtlas != null) { - return true; - } - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) {} - } - } - return false; - } - @Override public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { return this.base[damage]; diff --git a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java index bf69ead5e2..31c0a2e41c 100644 --- a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java +++ b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java @@ -15,6 +15,7 @@ import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.plugin.fixes.interfaces.IBugFix; import gtPlusPlus.preloader.PreloaderCore; +// TODO move this as a mixin in hodgepodge public class VanillaBedHeightFix implements IBugFix { private final Method mSleepInBedAt; diff --git a/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java b/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java index b1e97782af..272b2dacf5 100644 --- a/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java +++ b/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java @@ -1,178 +1,27 @@ package gtPlusPlus.xmod.bop; -import static gregtech.api.enums.Mods.BiomesOPlenty; - -import java.lang.reflect.Field; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import biomesoplenty.api.content.BOPCItems; +import gregtech.api.enums.Mods; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.bop.blocks.BOPBlockRegistrator; public class BiomesOPlentyHandler { - public static Item mPineCone; - - public static Block logs1; - public static Block logs2; - public static Block logs3; - public static Block logs4; - - public static Block leaves1; - public static Block leaves2; - public static Block leaves3; - public static Block leaves4; - - public static Block colorizedLeaves1; - public static Block colorizedLeaves2; - - public static Block saplings; - public static Block colorizedSaplings; - public static void preInit() { BOPBlockRegistrator.run(); - if (BiomesOPlenty.isModLoaded()) { - setFields(); - registerPineconeToOreDict(); + if (Mods.BiomesOPlenty.isModLoaded()) { + if (BOPCItems.misc != null) { + ItemStack aPinecone = ItemUtils.simpleMetaStack(BOPCItems.misc, 13, 1); + if (aPinecone != null) { + ItemUtils.addItemToOreDictionary(aPinecone, "pinecone"); + } + } } } public static void postInit() { BOPBlockRegistrator.recipes(); } - - private static void registerPineconeToOreDict() { - if (mPineCone != null) { - ItemStack aPinecone = ItemUtils.simpleMetaStack(mPineCone, 13, 1); - if (aPinecone != null) { - ItemUtils.addItemToOreDictionary(aPinecone, "pinecone"); - } - } - } - - public static ItemStack getStack(Block aBlock, int aMeta, int aSize) { - return ItemUtils.simpleMetaStack(aBlock, aMeta, aSize); - } - - // BOPCBlocks.logs4 - 0 - // BOPCBlocks.colorizedLeaves2 - 1 - - private static void setFields() { - Field aBopMiscItem = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCItems"), "misc"); - - Field aBopBlock1 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs1"); - Field aBopBlock2 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs2"); - Field aBopBlock3 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs3"); - Field aBopBlock4 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs4"); - - Field aBopLeaves1 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves1"); - Field aBopLeaves2 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves2"); - Field aBopLeaves3 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves3"); - Field aBopLeaves4 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves4"); - - Field aBopColouredLeaves1 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedLeaves1"); - Field aBopColouredLeaves2 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedLeaves2"); - - Field aBopSapling = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "saplings"); - Field aBopColouredSapling = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedSaplings"); - - if (aBopMiscItem != null) { - Item aMiscItem = ReflectionUtils.getFieldValue(aBopMiscItem); - if (aMiscItem != null) { - mPineCone = aMiscItem; - } - } - - if (aBopBlock1 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock1); - if (aBlock != null) { - logs1 = aBlock; - } - } - if (aBopBlock2 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock2); - if (aBlock != null) { - logs2 = aBlock; - } - } - if (aBopBlock3 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock3); - if (aBlock != null) { - logs3 = aBlock; - } - } - if (aBopBlock4 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock4); - if (aBlock != null) { - logs4 = aBlock; - } - } - - if (aBopLeaves1 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves1); - if (aBlock != null) { - leaves1 = aBlock; - } - } - if (aBopLeaves2 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves2); - if (aBlock != null) { - leaves2 = aBlock; - } - } - if (aBopLeaves3 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves3); - if (aBlock != null) { - leaves3 = aBlock; - } - } - if (aBopLeaves4 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves4); - if (aBlock != null) { - leaves4 = aBlock; - } - } - - if (aBopColouredLeaves1 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopColouredLeaves1); - if (aBlock != null) { - colorizedLeaves1 = aBlock; - } - } - if (aBopColouredLeaves2 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopColouredLeaves2); - if (aBlock != null) { - colorizedLeaves2 = aBlock; - } - } - - if (aBopSapling != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopSapling); - if (aBlock != null) { - saplings = aBlock; - } - } - if (aBopColouredSapling != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopColouredSapling); - if (aBlock != null) { - colorizedSaplings = aBlock; - } - } - } } diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java index 11397e3ef3..95813e45bd 100644 --- a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java +++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java @@ -8,7 +8,6 @@ import static forestry.api.apiculture.EnumBeeChromosome.TEMPERATURE_TOLERANCE; import static forestry.api.core.EnumHumidity.ARID; import static gregtech.api.enums.Mods.Forestry; -import java.lang.reflect.Field; import java.util.Arrays; import java.util.Locale; import java.util.function.Consumer; @@ -47,7 +46,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.MaterialsElements.STANDALONE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.forestry.bees.handler.GTPPCombType; public enum GTPP_BeeDefinition implements IBeeDefinition { @@ -65,7 +63,11 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { AlleleHelper.instance.set(template, TEMPERATURE_TOLERANCE, Tolerance.BOTH_3); AlleleHelper.instance.set(template, HUMIDITY_TOLERANCE, Tolerance.BOTH_3); }, dis -> { - IBeeMutationCustom tMutation = dis.registerMutation("DRAGONESSENCE", "NEUTRONIUM", 2); + IBeeMutationCustom tMutation = dis.registerMutation( + GTBeeDefinition.DRAGONESSENCE.getSpecies(), + GTBeeDefinition.NEUTRONIUM.getSpecies(), + 2, + 1f); tMutation.restrictHumidity(ARID); tMutation.requireResource(STANDALONE.DRAGON_METAL.getBlock(), 1); tMutation.addMutationCondition(new GTBees.DimensionMutationCondition(1, "End")); // End Dim @@ -84,7 +86,8 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { AlleleHelper.instance.set(template, TEMPERATURE_TOLERANCE, Tolerance.BOTH_1); AlleleHelper.instance.set(template, HUMIDITY_TOLERANCE, Tolerance.BOTH_1); }, dis -> { - IBeeMutationCustom tMutation = dis.registerMutation("STEEL", "GOLD", 10); + IBeeMutationCustom tMutation = dis + .registerMutation(GTBeeDefinition.STEEL.getSpecies(), GTBeeDefinition.GOLD.getSpecies(), 10, 1f); tMutation.restrictHumidity(ARID); tMutation.restrictBiomeType(BiomeDictionary.Type.HOT); }),; @@ -185,15 +188,15 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { return ret; } - private final void setSpeciesProperties(GTPPAlleleBeeSpecies species2) { + private void setSpeciesProperties(GTPPAlleleBeeSpecies species2) { this.mSpeciesProperties.accept(species2); } - private final void setAlleles(IAllele[] template) { + private void setAlleles(IAllele[] template) { this.mAlleles.accept(template); } - private final void registerMutations() { + private void registerMutations() { this.mMutations.accept(this); } @@ -209,59 +212,47 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { BeeManager.beeRoot.registerTemplate(template); } - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, - int chance) { + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, - int chance) { + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, - int chance) { + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, - int chance) { + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(String parent1, String parent2, int chance) { - return registerMutation(getGregtechBeeType(parent1), getGregtechBeeType(parent2), chance, 1f); - } - /** * Diese neue Funtion erlaubt Mutationsraten unter 1%. Setze dazu die Mutationsrate als Bruch mit chance / * chancedivider This new function allows Mutation percentages under 1%. Set them as a fraction with chance / * chancedivider */ - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, int chance, + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, int chance, float chancedivider) { return new GTPPBeeMutation(parent1, parent2, this.getTemplate(), chance, chancedivider); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, int chance, + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, int chance, float chancedivider) { return registerMutation(parent1.species, parent2, chance, chancedivider); } - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, int chance, + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, int chance, float chancedivider) { return registerMutation(parent1, parent2.species, chance, chancedivider); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, - int chance, float chancedivider) { + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, int chance, + float chancedivider) { return registerMutation(parent1.species, parent2, chance, chancedivider); } - private final IBeeMutationCustom registerMutation(String parent1, String parent2, int chance, float chancedivider) { - return registerMutation(getGregtechBeeType(parent1), getGregtechBeeType(parent2), chance, chancedivider); - } - @Override public final IAllele[] getTemplate() { return Arrays.copyOf(template, template.length); @@ -285,16 +276,4 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { public final IBeeDefinition getRainResist() { return new BeeVariation.RainResist(this); } - - public static IAlleleBeeSpecies getGregtechBeeType(String name) { - try { - // This is still cursed, but the species field is private and I don't want to go modify that right now - GTBeeDefinition aBeeObject = GTBeeDefinition.valueOf(name); - Field gtBeesField = ReflectionUtils.getField(GTBeeDefinition.class, "species"); - return ReflectionUtils.getFieldValue(gtBeesField, aBeeObject); - } catch (Throwable t) { - t.printStackTrace(); - return null; - } - } } diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java index bfdddcca8b..7ba5bc326a 100644 --- a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java +++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java @@ -7,7 +7,6 @@ import java.util.HashMap; import gregtech.GTMod; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.forestry.bees.handler.GTPPCombType; import gtPlusPlus.xmod.forestry.bees.handler.GTPPDropType; import gtPlusPlus.xmod.forestry.bees.handler.GTPPPollenType; @@ -45,7 +44,12 @@ public class GTPP_Bees { combs = new GTPPComb(); Logger.BEES("Loading types."); - initTypes(); + // call values() to force initialization of enum entries + GTPP_BeeDefinition.values(); + GTPPCombType.values(); + GTPPDropType.values(); + GTPPPollenType.values(); + GTPPPropolisType.values(); Logger.BEES("Adding recipes."); GTPPDrop.initDropsRecipes(); @@ -58,13 +62,4 @@ public class GTPP_Bees { Logger.BEES("Done!"); } } - - private static void initTypes() { - // This is stupid - ReflectionUtils.loadClass(GTPP_BeeDefinition.class.getName()); - ReflectionUtils.loadClass(GTPPCombType.class.getName()); - ReflectionUtils.loadClass(GTPPDropType.class.getName()); - ReflectionUtils.loadClass(GTPPPollenType.class.getName()); - ReflectionUtils.loadClass(GTPPPropolisType.class.getName()); - } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java index 43e43a1d4e..90db739be7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java @@ -120,30 +120,26 @@ public class MTEHatchNaquadah extends MTEHatchInput { private static String[] aDescCache = new String[3]; - private String formatFluidString(FluidStack f) { - FluidStack mLockedStack = f; - Integer mLockedTemp = 0;; - String mTempMod = "" + EnumChatFormatting.RESET; - mLockedTemp = mLockedStack.getFluid() + private String formatFluidString(FluidStack fluidStack) { + String mTempMod = EnumChatFormatting.RESET.toString(); + int mLockedTemp = fluidStack.getFluid() .getTemperature(); - if (mLockedTemp != null) { - if (mLockedTemp <= -3000) { - mTempMod = "" + EnumChatFormatting.DARK_PURPLE; - } else if (mLockedTemp >= -2999 && mLockedTemp <= -500) { - mTempMod = "" + EnumChatFormatting.DARK_BLUE; - } else if (mLockedTemp >= -499 && mLockedTemp <= -50) { - mTempMod = "" + EnumChatFormatting.BLUE; - } else if (mLockedTemp >= 30 && mLockedTemp <= 300) { - mTempMod = "" + EnumChatFormatting.AQUA; - } else if (mLockedTemp >= 301 && mLockedTemp <= 800) { - mTempMod = "" + EnumChatFormatting.YELLOW; - } else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { - mTempMod = "" + EnumChatFormatting.GOLD; - } else if (mLockedTemp >= 1501) { - mTempMod = "" + EnumChatFormatting.RED; - } + if (mLockedTemp <= -3000) { + mTempMod = "" + EnumChatFormatting.DARK_PURPLE; + } else if (mLockedTemp <= -500) { + mTempMod = "" + EnumChatFormatting.DARK_BLUE; + } else if (mLockedTemp <= -50) { + mTempMod = "" + EnumChatFormatting.BLUE; + } else if (mLockedTemp >= 30 && mLockedTemp <= 300) { + mTempMod = "" + EnumChatFormatting.AQUA; + } else if (mLockedTemp >= 301 && mLockedTemp <= 800) { + mTempMod = "" + EnumChatFormatting.YELLOW; + } else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { + mTempMod = "" + EnumChatFormatting.GOLD; + } else if (mLockedTemp >= 1501) { + mTempMod = "" + EnumChatFormatting.RED; } - return mTempMod + mLockedStack.getLocalizedName(); + return mTempMod + fluidStack.getLocalizedName(); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java index 738afb0d90..b1af2451aa 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java @@ -2,7 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; import static gregtech.api.util.GTUtility.filterValidMTEs; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -208,7 +207,7 @@ public abstract class GTPPMultiBlockBase aMap) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java index 8fe051dd71..305422ccea 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java @@ -28,7 +28,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.state.MaterialState; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class RecipeGenRecycling implements Runnable { @@ -252,11 +251,7 @@ public class RecipeGenRecycling implements Runnable { public static ItemStack get(final Object aName, final ItemStack aReplacement, final long aAmount, final boolean aMentionPossibleTypos, final boolean aNoInvalidAmounts) { if (aNoInvalidAmounts && (aAmount < 1L)) { - Logger.WARNING("Returning Null. Method: " + ReflectionUtils.getMethodName(0)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(1)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(2)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(3)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(4)); + Logger.modLogger.warn("Returning Null. Method: ", new Exception()); return null; } if (!mNameMap.containsKey(aName.toString()) && aMentionPossibleTypos) { @@ -269,11 +264,7 @@ public class RecipeGenRecycling implements Runnable { public static ItemStack getFirstOre(final Object aName, final long aAmount) { if (GTUtility.isStringInvalid(aName)) { - Logger.WARNING("Returning Null. Method: " + ReflectionUtils.getMethodName(0)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(1)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(2)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(3)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(4)); + Logger.modLogger.warn("Returning Null. Method: ", new Exception()); return null; } final ItemStack tStack = mNameMap.get(aName.toString()); diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java b/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java index 5dbde33493..faa94542b9 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java @@ -1,10 +1,9 @@ package gtPlusPlus.xmod.tinkers; -import static gregtech.api.enums.Mods.TinkerConstruct; - import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; +import gregtech.api.enums.Mods; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import gtPlusPlus.xmod.tinkers.util.TinkersDryingRecipe; @@ -15,7 +14,7 @@ public class HandlerTinkers { public static AutoMap mTinkerMaterials = new AutoMap<>(); public static void postInit() { - if (TinkerConstruct.isModLoaded()) { + if (Mods.TinkerConstruct.isModLoaded()) { Fluid pyrotheumFluid = FluidRegistry.getFluid("pyrotheum"); if (pyrotheumFluid != null) { diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 5a4984a898..68685b7b8b 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -165,20 +165,12 @@ public class BaseTinkersMaterial { private boolean generateRecipes(Material aMaterial, int aID) { - Block aMatBlock; - Integer aMelt; - Fluid aFluid; - - try { - aMatBlock = aMaterial.getBlock(); - aMelt = aMaterial.getMeltingPointC(); - aFluid = aMaterial.getFluidStack(0) - .getFluid(); - } catch (Throwable t) { - return false; - } + Block aMatBlock = aMaterial.getBlock(); + int aMelt = aMaterial.getMeltingPointC(); + Fluid aFluid = aMaterial.getFluidStack(0) + .getFluid(); - if (aMatBlock == null || aMelt == null || aFluid == null) { + if (aMatBlock == null || aFluid == null) { return false; } @@ -192,7 +184,6 @@ public class BaseTinkersMaterial { TinkersUtils .addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluidStack(144), ingotcast, false, 50); } - TinkersUtils.generateCastingRecipes(aMaterial, aID); return true; diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java index 4adac363e8..4136b54309 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java @@ -1,9 +1,7 @@ package gtPlusPlus.xmod.tinkers.util; -import static gregtech.api.enums.Mods.TinkerConstruct; import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes; -import java.lang.reflect.Field; import java.util.List; import net.minecraft.item.ItemStack; @@ -14,7 +12,7 @@ import gregtech.api.enums.TierEU; import gregtech.api.util.GTUtility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.util.reflect.ReflectionUtils; +import tconstruct.library.crafting.DryingRackRecipes; public class TinkersDryingRecipe { @@ -24,20 +22,25 @@ public class TinkersDryingRecipe { public final ItemStack input; public final ItemStack result; + public TinkersDryingRecipe(final ItemStack input, final int time, final ItemStack result) { + this.time = time; + this.input = input; + this.result = result; + Logger.INFO( + "Generating Drying Recipe. Input: " + input.getDisplayName() + ", Output: " + result.getDisplayName()); + } + public static void generateAllDryingRecipes() { - List aRecipes = TinkersUtils.getDryingRecipes(); - if (aRecipes != null && aRecipes.size() > 0) { - for (Object o : aRecipes) { + List aRecipes = TinkersDryingRecipe.getDryingRecipes(); + if (!aRecipes.isEmpty()) { + for (DryingRackRecipes.DryingRecipe recipe : aRecipes) { Logger.INFO( - "Trying to generate recipe using object of type " + o.getClass() + "Trying to generate recipe using object of type " + recipe.getClass() .getSimpleName()); - generateFromTinkersRecipeObject(o); + generateFromTinkersRecipe(recipe); } } else { - Logger.INFO( - "Error generating Drying recipes, map was either null or empty. Null? " + (aRecipes != null) - + ", Size: " - + aRecipes.size()); + Logger.INFO("Error generating Drying recipes, map was empty. Size: " + aRecipes.size()); } if (!recipes.isEmpty()) { Logger.INFO("Adding " + recipes.size() + " drying rack recipes to the dehydrator."); @@ -52,61 +55,19 @@ public class TinkersDryingRecipe { } } - public static TinkersDryingRecipe generateFromTinkersRecipeObject(Object o) { - Field aTime; - Field aInput; - Field aOutput; - Class aTinkerClass = ReflectionUtils.getClass("tconstruct.library.crafting.DryingRackRecipes.DryingRecipe"); // o.getClass(); - if (aTinkerClass == null || TinkerConstruct.isModLoaded()) { - Logger.INFO( - "Error generating Drying Recipe, could not find class. Exists? " - + ReflectionUtils.doesClassExist("tconstruct.library.crafting.DryingRackRecipes.DryingRecipe")); - Class clazz = ReflectionUtils.getClass("tconstruct.library.crafting.DryingRackRecipes"); - Class[] y = clazz.getDeclaredClasses(); - if (y == null || y.length <= 0) { - Logger.INFO("No hidden inner classes."); - return null; - } else { - boolean found = false; - for (Class h : y) { - Logger.INFO("Found hidden inner class: " + h.getCanonicalName()); - if (h.getSimpleName() - .toLowerCase() - .equals("dryingrecipe")) { - Logger.INFO("Found correct recipe. Caching at correct location."); - ReflectionUtils.mCachedClasses - .put("tconstruct.library.crafting.DryingRackRecipes.DryingRecipe", h); - aTinkerClass = h; - found = true; - break; - } - } - if (!found) { - return null; - } - } - } - aTime = ReflectionUtils.getField(aTinkerClass, "time"); - aInput = ReflectionUtils.getField(aTinkerClass, "input"); - aOutput = ReflectionUtils.getField(aTinkerClass, "result"); - try { - int time_internal = aTime.getInt(o); - ItemStack input_internal = (ItemStack) aInput.get(o); - ItemStack result_internal = (ItemStack) aOutput.get(o); - return new TinkersDryingRecipe(input_internal, time_internal, result_internal); - } catch (Throwable b) { - b.printStackTrace(); - } - return null; + private static void generateFromTinkersRecipe(DryingRackRecipes.DryingRecipe recipe) { + recipes.add(new TinkersDryingRecipe(recipe.input, recipe.time, recipe.result)); } - public TinkersDryingRecipe(final ItemStack input, final int time, final ItemStack result) { - this.time = time; - this.input = input; - this.result = result; - Logger.INFO( - "Generating Drying Recipe. Input: " + input.getDisplayName() + ", Output: " + result.getDisplayName()); - recipes.add(this); + private static List getDryingRecipes() { + AutoMap aData = new AutoMap<>(); + int aCount = 0; + for (DryingRackRecipes.DryingRecipe recipe : DryingRackRecipes.recipes) { + aData.put(recipe); + aCount++; + } + Logger.INFO("Found " + aCount + " Tinkers drying rack recipes."); + return aData; } public boolean matches(ItemStack input) { diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index 8b173d5b62..09633f5810 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,339 +1,89 @@ package gtPlusPlus.xmod.tinkers.util; -import static gregtech.api.enums.Mods.TinkerConstruct; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import net.minecraft.block.Block; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -import gregtech.api.enums.Materials; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.CastingRecipe; +import tconstruct.library.crafting.FluidType; +import tconstruct.library.crafting.LiquidCasting; +import tconstruct.library.crafting.Smeltery; +import tconstruct.library.tools.DynamicToolPart; +import tconstruct.library.util.IPattern; +import tconstruct.smeltery.TinkerSmeltery; public class TinkersUtils { - private static final Class mClass_Smeltery; - private static final Class mClass_TConstructRegistry; - private static final Class mClass_ToolMaterial; - private static final Class mClass_IPattern; - private static final Class mClass_DynamicToolPart; - private static final Class mClass_FluidType; - private static final Class mClass_CastingRecipe; - private static final Class mClass_TinkerSmeltery; - - private static final Field mField_MoltenIronFluid; - - private static final Method mMethod_getFluidType; - private static final Method mMethod_getCastingRecipes; - - private static Object mSmelteryInstance; - private static Object mTinkersRegistryInstance; - - private static final HashMap mMethodCache = new LinkedHashMap<>(); - - static { - mClass_Smeltery = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); - mClass_TConstructRegistry = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); - - mClass_ToolMaterial = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); - mClass_IPattern = ReflectionUtils.getClass("tconstruct.library.util.IPattern"); - mClass_DynamicToolPart = ReflectionUtils.getClass("tconstruct.library.tools.DynamicToolPart"); - mClass_FluidType = ReflectionUtils.getClass("tconstruct.library.crafting.FluidType"); - mClass_CastingRecipe = ReflectionUtils.getClass("tconstruct.library.crafting.CastingRecipe"); - mClass_TinkerSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); - - mField_MoltenIronFluid = ReflectionUtils.getField(mClass_TinkerSmeltery, "moltenIronFluid"); - - mMethod_getFluidType = ReflectionUtils.getMethod(mClass_FluidType, "getFluidType", String.class); - mMethod_getCastingRecipes = ReflectionUtils - .getMethod(getCastingInstance(0), "getCastingRecipes", new Class[] {}); - } - - private static void setTiConDataInstance() { - if (!TinkerConstruct.isModLoaded()) { - return; - } - - if (mSmelteryInstance == null) { - if (mClass_Smeltery != null) { - try { - mSmelteryInstance = ReflectionUtils.getField(mClass_Smeltery, "instance") - .get(null); - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - } - } - if (mTinkersRegistryInstance == null) { - if (mClass_TConstructRegistry != null) { - try { - mTinkersRegistryInstance = ReflectionUtils.getField(mClass_TConstructRegistry, "instance") - .get(null); - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - } - } - } - /** * Add a new fluid as a valid Smeltery fuel. - * + * * @param fluid The fluid. * @param power The temperature of the fluid. This also influences the melting speed. Lava is 1000. * @param duration How long one "portion" of liquid fuels the smeltery. Lava is 10. */ public static void addSmelteryFuel(Fluid fluid, int power, int duration) { - setTiConDataInstance(); - ReflectionUtils.invokeVoid( - mSmelteryInstance, - "addSmelteryFuel", - new Class[] { Fluid.class, int.class, int.class }, - new Object[] { fluid, power, duration }); + Smeltery.addSmelteryFuel(fluid, power, duration); } public static boolean registerFluidType(String name, Block block, int meta, int baseTemperature, Fluid fluid, boolean isToolpart) { - 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; - } + FluidType.registerFluidType(name, block, meta, baseTemperature, fluid, isToolpart); + return true; } public static void addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) { - if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils.getMethod( - mClass_Smeltery, - "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); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + Smeltery.addMelting(input, block, metadata, temperature, liquid); } - public static void addMelting(Object type, ItemStack input, int temperatureDifference, int fluidAmount) { - if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils - .getMethod(mClass_Smeltery, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); - mMethodCache.put("addMelting", m); - } - try { - mMethodCache.get("addMelting") - .invoke(null, type, input, temperatureDifference, fluidAmount); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + public static void addMelting(FluidType type, ItemStack input, int temperatureDifference, int fluidAmount) { + Smeltery.addMelting(type, input, temperatureDifference, fluidAmount); } public static void 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); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + LiquidCasting tableCasting = TConstructRegistry.getTableCasting(); + tableCasting.addCastingRecipe(output, metal, cast, consume, delay); } public static void 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"), - "addCastingRecipe", - 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); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + LiquidCasting basinCasting = TConstructRegistry.getBasinCasting(); + basinCasting.addCastingRecipe(output, metal, cast, consume, delay); } - /** - * 0 For Table, 1 For Basin. - * - * @param aType - Casting Type - * @return - The casting instance. - */ - public static Object getCastingInstance(int aType) { - - setTiConDataInstance(); - - Method m = null; - if (aType == 0) { - m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getTableCasting", new Class[] {}); - } else if (aType == 1) { - m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getBasinCasting", new Class[] {}); - } // return null; - - if (m != null) { - try { - return m.invoke(mTinkersRegistryInstance, new Object[] {}); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - } - return null; - } - - private static Item mTinkerMetalPattern; - - public static ItemStack getPattern(int aType) { - if (mTinkerMetalPattern == null) { - Field m = ReflectionUtils.getField(mClass_TinkerSmeltery, "metalPattern"); - if (m != null) { - try { - mTinkerMetalPattern = (Item) m.get(null); - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - } - } - if (mTinkerMetalPattern != null) { - return new ItemStack(mTinkerMetalPattern, aType, 0); - } - return ItemUtils.getErrorStack(1, "Bad Tinkers Pattern"); - } - - private static AutoMap mDryingRackRecipes; - - public static List getDryingRecipes() { - if (mDryingRackRecipes != null) { - return mDryingRackRecipes; - } - AutoMap aData = new AutoMap<>(); - int aCount = 0; - try { - ArrayList recipes = (ArrayList) ReflectionUtils - .getField(ReflectionUtils.getClass("tconstruct.library.crafting.DryingRackRecipes"), "recipes") - .get(null); - if (recipes != null) { - for (Object o : recipes) { - aData.put(o); - aCount++; - } - Logger.INFO("Found " + aCount + " Tinkers drying rack recipes."); - } else { - Logger.INFO("Failed to find any Tinkers drying rack recipes."); - } - } catch (IllegalArgumentException | IllegalAccessException e) { - Logger.INFO("Failed to find any Tinkers drying rack recipes."); - } - mDryingRackRecipes = aData; - return aData; - } - - public static List getTableCastingRecipes() { - Object aCastingTableHandlerInstance = getCastingInstance(0); - List aTemp; - try { - aTemp = (List) mMethod_getCastingRecipes.invoke(aCastingTableHandlerInstance, new Object[] {}); - return aTemp; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - return new ArrayList<>(); + public static List getTableCastingRecipes() { + LiquidCasting tableCasting = TConstructRegistry.getTableCasting(); + return tableCasting.getCastingRecipes(); } public static void generateCastingRecipes(Material aMaterial, int aID) { - - List newRecipies = new LinkedList<>(); - - Iterator iterator1 = getTableCastingRecipes().iterator(); - Fluid aMoltenIron = null; - if (aMoltenIron == null) { - try { - aMoltenIron = (Fluid) mField_MoltenIronFluid.get(null); - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - aMoltenIron = Materials.Iron.getMolten(0) - .getFluid(); - } - } - while (iterator1.hasNext()) { - CastingRecipeHandler recipe = new CastingRecipeHandler(iterator1.next()); - if (recipe == null || !recipe.valid) { - continue; - } - try { - if (recipe.castingMetal.getFluid() == aMoltenIron && recipe.cast != null - && mClass_IPattern.isInstance(recipe.cast.getItem()) - && mClass_DynamicToolPart.isInstance( - recipe.getResult() - .getItem())) { - newRecipies.add(recipe); - } - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return; - } - } - - Object ft; - try { - ft = mMethod_getFluidType.invoke(null, aMaterial.getLocalizedName()); - for (CastingRecipeHandler newRecipy : newRecipies) { - CastingRecipeHandler recipe = new CastingRecipeHandler(newRecipy); - if (!recipe.valid) { - continue; - } - // CastingRecipe recipe = (CastingRecipe) i$.next(); - ItemStack output = recipe.getResult() + Fluid aMoltenIron = TinkerSmeltery.moltenIronFluid; + FluidType fluidType = FluidType.getFluidType(aMaterial.getLocalizedName()); + for (CastingRecipe recipe : getTableCastingRecipes()) { + CastingRecipeHandler newRecipe = new CastingRecipeHandler(recipe); + if (newRecipe.castingMetal.getFluid() == aMoltenIron && newRecipe.cast != null + && newRecipe.cast.getItem() instanceof IPattern + && newRecipe.getResult() + .getItem() instanceof DynamicToolPart) { + ItemStack output = newRecipe.getResult() .copy(); output.setItemDamage(aID); - FluidStack liquid2 = new FluidStack( + FluidStack liquid = new FluidStack( aMaterial.getFluidStack(0) .getFluid(), - recipe.castingMetal.amount); - addCastingTableRecipe(output, liquid2, recipe.cast, recipe.consumeCast, recipe.coolTime); - addMelting(ft, output, 0, liquid2.amount / 2); + newRecipe.castingMetal.amount); + addCastingTableRecipe(output, liquid, newRecipe.cast, newRecipe.consumeCast, newRecipe.coolTime); + addMelting(fluidType, output, 0, liquid.amount / 2); } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); } + } + public static ItemStack getPattern(int aType) { + return new ItemStack(TinkerSmeltery.metalPattern, aType, 0); } private static class CastingRecipeHandler { @@ -344,30 +94,12 @@ public class TinkersUtils { public boolean consumeCast; public int coolTime; - public boolean valid; - - public CastingRecipeHandler(Object aCastingRecipe) { - if (mClass_CastingRecipe.isInstance(aCastingRecipe)) { - try { - Field aF_output = ReflectionUtils.getField(mClass_CastingRecipe, "output"); - Field aF_castingMetal = ReflectionUtils.getField(mClass_CastingRecipe, "castingMetal"); - Field aF_cast = ReflectionUtils.getField(mClass_CastingRecipe, "cast"); - Field aF_consumeCast = ReflectionUtils.getField(mClass_CastingRecipe, "consumeCast"); - Field aF_coolTime = ReflectionUtils.getField(mClass_CastingRecipe, "coolTime"); - - output = (ItemStack) aF_output.get(aCastingRecipe); - castingMetal = (FluidStack) aF_castingMetal.get(aCastingRecipe); - cast = (ItemStack) aF_cast.get(aCastingRecipe); - consumeCast = (boolean) aF_consumeCast.get(aCastingRecipe); - coolTime = (int) aF_coolTime.get(aCastingRecipe); - valid = true; - } catch (Throwable t) { - t.printStackTrace(); - valid = false; - } - } else { - valid = false; - } + public CastingRecipeHandler(CastingRecipe castingRecipe) { + this.output = castingRecipe.output; + this.castingMetal = castingRecipe.castingMetal; + this.cast = castingRecipe.cast; + this.consumeCast = castingRecipe.consumeCast; + this.coolTime = castingRecipe.coolTime; } public ItemStack getResult() { diff --git a/src/main/java/gtnhlanth/common/tileentity/MTELINAC.java b/src/main/java/gtnhlanth/common/tileentity/MTELINAC.java index 78ea9c7846..94571d10e0 100644 --- a/src/main/java/gtnhlanth/common/tileentity/MTELINAC.java +++ b/src/main/java/gtnhlanth/common/tileentity/MTELINAC.java @@ -213,7 +213,7 @@ public class MTELINAC extends MTEEnhancedMultiBlockBase implements ISu .addOtherStructurePart("Beamline Input Hatch", addDotText(3)) .addOtherStructurePart("Beamline Output Hatch", addDotText(4)) - .toolTipFinisher("GTNH: Lanthanides");; + .toolTipFinisher("GTNH: Lanthanides"); return tt; } -- cgit