aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util
diff options
context:
space:
mode:
author‭huajijam <strhuaji@gmail.com>2019-05-17 23:26:41 +0800
committer‭huajijam <strhuaji@gmail.com>2019-05-17 23:26:41 +0800
commit5920c6db3ff62d89ba41db4eda59cc6d70ddce3b (patch)
treed4d6d5036e8cb95d2232066f0ee257f59b5aa967 /src/Java/gtPlusPlus/core/util
parent787c31758d2ea3259f8da9c5c7ffd4b28429eb9a (diff)
parentcacc2915ef0039e3460817e4f116d44cf8e44e5f (diff)
downloadGT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.tar.gz
GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.tar.bz2
GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.zip
Automatic synchronization
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
-rw-r--r--src/Java/gtPlusPlus/core/util/math/MathUtils.java9
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java4
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java75
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java52
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java49
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java59
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java4
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java52
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java61
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java232
10 files changed, 530 insertions, 67 deletions
diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
index 3cef3c511f..bda722b47e 100644
--- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java
+++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
@@ -7,6 +7,7 @@ import gregtech.api.enums.GT_Values;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
@@ -227,7 +228,7 @@ public class MathUtils {
* @param x Value A.
* @return boolean Whether or not it divides evenly.
*/
- public static boolean isNumberEven(final int x){
+ public static boolean isNumberEven(final long x){
if ((x % 2) == 0)
{
return true;
@@ -696,5 +697,11 @@ public class MathUtils {
int aAmount = Math.max(Math.min(i, aMax), aMin);
return aAmount;
}
+
+ public static Pair<Integer, Integer> splitLongIntoIntegers(long aLong){
+ int aIntMaxInLong = (int) Math.min(Integer.MAX_VALUE, Math.floor(aLong/Integer.MAX_VALUE));
+ int aRemainder = (int) (aLong - (aIntMaxInLong * Integer.MAX_VALUE));
+ return new Pair<Integer, Integer>(aIntMaxInLong, aRemainder);
+ }
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java
index ef68436f21..7daefbcc23 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java
@@ -1,9 +1,7 @@
package gtPlusPlus.core.util.minecraft;
-import gregtech.api.enums.GT_Values;
import gregtech.api.util.GT_ModHandler;
import gtPlusPlus.api.objects.Logger;
-import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItem;
import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem;
@@ -40,7 +38,7 @@ public class EnergyUtils {
if (isElectricItem(aStack)) {
int tTier = ((IElectricItem) aStack.getItem()).getTier(aStack);
int aDischargeValue = GT_ModHandler.dischargeElectricItem(aStack, aEnergyToDrain, tTier, true, false, false);
- Logger.INFO("Trying to drain "+aDischargeValue);
+ //Logger.INFO("Trying to drain "+aDischargeValue);
return aDischargeValue > 0;
}
else {
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
index 8c5a9f6581..49aa3a1306 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
@@ -11,6 +11,7 @@ import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.minecraft.AABB;
import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.core.handler.events.EntityDeathHandler;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import ic2.core.IC2Potion;
import ic2.core.item.armor.ItemArmorHazmat;
@@ -20,6 +21,7 @@ import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@@ -87,7 +89,7 @@ public class EntityUtils {
}
return false;
}
-
+
public static boolean applyHeatDamageToEntity(final int heatLevel, final World world, final Entity entityHolding){
if (!world.isRemote){
if ((heatLevel > 0) && (entityHolding instanceof EntityLivingBase)) {
@@ -113,11 +115,7 @@ public class EntityUtils {
*/
public synchronized static boolean doFireDamage(Entity entity, int amount){
if (dealFireDamage == null){
- try {
- dealFireDamage = Entity.class.getDeclaredMethod("dealFireDamage", int.class);
- dealFireDamage.setAccessible(true);
- }
- catch (NoSuchMethodException | SecurityException e) {}
+ dealFireDamage = ReflectionUtils.getMethod(Entity.class, "dealFireDamage", int.class);
}
else {
try {
@@ -131,42 +129,41 @@ public class EntityUtils {
public static void doDamage(Entity entity, DamageSource dmg, int i) {
entity.attackEntityFrom(dmg, i);
}
-
+
public static boolean isTileEntityRegistered(Class aTileClass, String aTileName) {
Field aRegistry = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "nameToClassMap");
Field aRegistry2 = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "classToNameMap");
try {
Object o = aRegistry.get(null);
if (o != null) {
- Map nameToClassMap = (Map) o;
- if (!nameToClassMap.containsKey(aTileName)) {
- o = aRegistry2.get(null);
- if (o != null) {
- Map classToNameMap = (Map) o;
- if (!classToNameMap.containsKey(aTileClass)) {
- return false;
- }
- else {
- return true;
- }
- }
- }
- else {
- return true;
- }
+ Map nameToClassMap = (Map) o;
+ if (!nameToClassMap.containsKey(aTileName)) {
+ o = aRegistry2.get(null);
+ if (o != null) {
+ Map classToNameMap = (Map) o;
+ if (!classToNameMap.containsKey(aTileClass)) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ }
+ else {
+ return true;
+ }
}
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
-
+
public static double getDistance(Entity p1, Entity p2) {
- return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2));
+ return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2));
}
-
+
public static AutoMap<Entity> getEntitiesWithinBoundingBoxExcluding(Entity aExclusion, AABB aBoundingBox){
-
if (aExclusion == null) {
return new AutoMap<Entity>();
}
@@ -175,9 +172,8 @@ public class EntityUtils {
return new AutoMap<Entity>(aEntities);
}
}
-
+
public static AutoMap<Entity> getEntitiesWithinBoundingBox(Class aEntityType, AABB aBoundingBox){
-
if (aEntityType == null) {
return new AutoMap<Entity>();
}
@@ -186,5 +182,26 @@ public class EntityUtils {
return new AutoMap<Entity>(aEntities);
}
}
+
+ /**
+ * Provides the ability to provide custom drops upon the death of EntityLivingBase objects. Simplified function with static Max drop size of 1.
+ * @param aMobClass - The Base Class you want to drop this item.
+ * @param aStack - The ItemStack, stack size is not respected.
+ * @param aChance - Chance out of 10000, where 100 is 1%. (1 = 0.01% - this is ok)
+ */
+ public static void registerDropsForMob(Class aMobClass, ItemStack aStack, int aChance) {
+ registerDropsForMob(aMobClass, aStack, 1, aChance);
+ }
+
+ /**
+ * Provides the ability to provide custom drops upon the death of EntityLivingBase objects.
+ * @param aMobClass - The Base Class you want to drop this item.
+ * @param aStack - The ItemStack, stack size is not respected.
+ * @param aMaxAmount - The maximum size of the ItemStack which drops.
+ * @param aChance - Chance out of 10000, where 100 is 1%. (1 = 0.01% - this is ok)
+ */
+ public static void registerDropsForMob(Class aMobClass, ItemStack aStack, int aMaxAmount, int aChance) {
+ EntityDeathHandler.registerDropsForMob(aMobClass, aStack, aMaxAmount, aChance);
+ }
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java
index 0ae751a20b..09263bb639 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java
@@ -25,14 +25,64 @@ public class FluidUtils {
return FluidUtils.getFluidStack("water", amount);
}
- public static FluidStack getlava(final int amount){
+ public static FluidStack getDistilledWater(final int amount){
+ return FluidUtils.getFluidStack("ic2distilledwater", amount);
+ }
+
+ public static FluidStack getHotWater(final int amount) {
+ return FluidUtils.getFluidStack("ic2hotwater", amount);
+ }
+
+ public static FluidStack getLava(final int amount){
return FluidUtils.getFluidStack("lava", amount);
}
+ public static FluidStack getPahoehoeLava(final int amount){
+ return FluidUtils.getFluidStack("ic2pahoehoelava", amount);
+ }
+
public static FluidStack getMilk(final int amount){
return FluidUtils.getFluidStack("milk", amount);
}
+ public static FluidStack getColdCoolant(final int amount){
+ return FluidUtils.getFluidStack("ic2coolant", amount);
+ }
+
+ public static FluidStack getHotCoolant(final int amount){
+ return FluidUtils.getFluidStack("ic2hotcoolant", amount);
+ }
+
+ public static FluidStack getSteam(final int amount){
+ return FluidUtils.getFluidStack("steam", amount);
+ }
+
+ public static FluidStack getIC2Steam(final int amount){
+ return FluidUtils.getFluidStack("ic2steam", amount);
+ }
+
+ public static FluidStack getSuperHeatedSteam(final int amount){
+ return FluidUtils.getFluidStack("ic2superheatedsteam", amount);
+ }
+
+ @Deprecated
+ /**
+ * Do not use - Gives third tier steam - Not implemented
+ * @param amount
+ * @return
+ */
+ public static FluidStack getHyperSteam(final int amount){
+ return FluidUtils.getFluidStack("water", amount);
+ }
+
+ public static FluidStack getUUA(final int amount){
+ return FluidUtils.getFluidStack("uuamplifier", amount);
+ }
+
+ public static FluidStack getUUM(final int amount){
+ return FluidUtils.getFluidStack("ic2uumatter", amount);
+ }
+
public static FluidStack getFluidStack(final String fluidName, final int amount){
Logger.WARNING("Trying to get a fluid stack of "+fluidName);
try {
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
index ae799baa2b..adeaf8c8ad 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
@@ -15,6 +15,7 @@ import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.api.objects.minecraft.BlockPos;
import gtPlusPlus.core.item.ModItems;
@@ -34,6 +35,8 @@ import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool;
import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration;
import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
@@ -479,20 +482,27 @@ public class ItemUtils {
return new BaseItemPlate_OLD(internalName, displayName, mFormula, rgb, radioactivity);
}
+
public static Item[] generateSpecialUseDusts(final Material material, final boolean onlyLargeDust) {
+ return generateSpecialUseDusts(material, onlyLargeDust, false);
+ }
+
+ public static Item[] generateSpecialUseDusts(final Material material, final boolean onlyLargeDust, final boolean disableExtraRecipes) {
final String materialName = material.getLocalizedName();
final String unlocalizedName = Utils.sanitizeString(materialName);
final int Colour = material.getRgbAsHex();
+ final String aChemForm = material.vChemicalFormula;
+ final boolean isChemFormvalid = (aChemForm != null && aChemForm.length() > 0);
Item[] output = null;
if (onlyLargeDust == false) {
- output = new Item[] { new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, Colour, "Dust"),
- new BaseItemDustUnique("itemDustSmall" + unlocalizedName, materialName, Colour, "Small"),
- new BaseItemDustUnique("itemDustTiny" + unlocalizedName, materialName, Colour, "Tiny") };
+ output = new Item[] { new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, isChemFormvalid ? aChemForm : "", Colour, "Dust"),
+ new BaseItemDustUnique("itemDustSmall" + unlocalizedName, materialName, isChemFormvalid ? aChemForm : "", Colour, "Small"),
+ new BaseItemDustUnique("itemDustTiny" + unlocalizedName, materialName, isChemFormvalid ? aChemForm : "", Colour, "Tiny") };
} else {
output = new Item[] { new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, Colour, "Dust") };
}
- new RecipeGen_DustGeneration(material);
+ new RecipeGen_DustGeneration(material, disableExtraRecipes);
return output;
}
@@ -1179,4 +1189,35 @@ public class ItemUtils {
return false;
}
+ public static ItemStack[] cleanItemStackArray(ItemStack[] input) {
+ int aArraySize = input.length;
+ ItemStack[] aOutput = new ItemStack[aArraySize];
+ AutoMap<ItemStack> aCleanedItems = new AutoMap<ItemStack>();
+ for (ItemStack checkStack : input) {
+ if (ItemUtils.checkForInvalidItems(checkStack)) {
+ aCleanedItems.put(checkStack);
+ }
+ }
+ for (int i=0;i<aArraySize;i++) {
+ ItemStack aMappedStack = aCleanedItems.get(i);
+ if (aMappedStack != null){
+ aOutput[i] = aMappedStack;
+ }
+ }
+ return aOutput;
+ }
+
+ public static ItemStack getEnchantedBook(Enchantment aEnch, int aLevel) {
+ return enchantItem(new ItemStack(Items.enchanted_book), aEnch, aLevel);
+ }
+
+ public static ItemStack enchantItem(ItemStack aStack, Enchantment aEnch, int aLevel) {
+ Items.enchanted_book.addEnchantment(aStack, new EnchantmentData(aEnch, aLevel));
+ return aStack;
+ }
+
+ public static boolean doesOreDictHaveEntryFor(String string) {
+ return OreDictionary.doesOreNameExist(string);
+ }
+
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java
index 743e4bedf1..364430b07d 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java
@@ -15,6 +15,9 @@ import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.data.TypeCounter;
import gtPlusPlus.core.client.CustomTextureSet.TextureSets;
+import gtPlusPlus.core.item.base.BaseItemComponent;
+import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes;
+import gtPlusPlus.core.item.base.plates.BaseItemPlateHeavy;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.material.MaterialStack;
@@ -23,6 +26,7 @@ import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.data.EnumUtils;
import gtPlusPlus.core.util.data.StringUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -439,6 +443,61 @@ public class MaterialUtils {
}
return resultList;
}
+
+ public static void generateComponentAndAssignToAMaterial(ComponentTypes aType, Material aMaterial) {
+ generateComponentAndAssignToAMaterial(aType, aMaterial, true);
+ }
+
+ public static void generateComponentAndAssignToAMaterial(ComponentTypes aType, Material aMaterial, boolean generateRecipes) {
+ Item aGC;
+ if (aType == ComponentTypes.PLATEHEAVY) {
+ aGC = new BaseItemPlateHeavy(aMaterial);
+ }
+ else {
+ aGC = new BaseItemComponent(aMaterial, aType);
+ }
+ if (aGC != null) {
+ String aFormattedLangName = aType.getName();
+
+ if (!aFormattedLangName.startsWith(" ")) {
+ if (aFormattedLangName.contains("@")) {
+ String[] aSplit = aFormattedLangName.split("@");
+ aFormattedLangName = aSplit[0] + " " + aMaterial.getLocalizedName() + " " + aSplit[1];
+ }
+ }
+
+ if (aFormattedLangName.equals(aType.getName())) {
+ aFormattedLangName = aMaterial.getLocalizedName() + aFormattedLangName;
+
+ }
+
+
+
+ Logger.MATERIALS("[Lang] "+aGC.getUnlocalizedName()+".name="+aFormattedLangName);
+ aMaterial.registerComponentForMaterial(aType, ItemUtils.getSimpleStack(aGC));
+ }
+ }
+
+
+
+
+
+
+
+
+ public static void generateSpecialDustAndAssignToAMaterial(Material aMaterial) {
+ generateSpecialDustAndAssignToAMaterial(aMaterial, true);
+ }
+
+ public static void generateSpecialDustAndAssignToAMaterial(Material aMaterial, boolean generateMixerRecipes) {
+ Item[] aDusts = ItemUtils.generateSpecialUseDusts(aMaterial, false, Utils.invertBoolean(generateMixerRecipes));
+ if (aDusts != null && aDusts.length > 0) {
+ aMaterial.registerComponentForMaterial(OrePrefixes.dust, ItemUtils.getSimpleStack(aDusts[0]));
+ aMaterial.registerComponentForMaterial(OrePrefixes.dustSmall, ItemUtils.getSimpleStack(aDusts[1]));
+ aMaterial.registerComponentForMaterial(OrePrefixes.dustTiny, ItemUtils.getSimpleStack(aDusts[2]));
+ }
+
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java
index 7dd127203e..2fb7344a28 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java
@@ -174,4 +174,8 @@ public class PlayerUtils {
return false;
}
+ public static void messageAllPlayers(String string) {
+ Utils.sendServerMessage(string);
+ }
+
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
index 774c8b6f13..13bc0c9382 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
@@ -6,8 +6,11 @@ import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.enums.Materials;
+import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
import gregtech.api.util.GT_ModHandler;
+import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gtPlusPlus.GTplusplus;
import gtPlusPlus.api.interfaces.RunnableWithInfo;
@@ -23,6 +26,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
+import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
@@ -579,7 +583,53 @@ public static int mInvalidID = 1;
return aRecipeMap.mRecipeList.remove(aRecipeToRemove);
}
return false;
- }
+ }
+
+ public static boolean addGtRecipe(GT_Recipe aRecipeToAdd, GT_Recipe_Map aRecipeMap) {
+ if (!aRecipeMap.mRecipeList.contains(aRecipeToAdd)) {
+ return aRecipeMap.mRecipeList.add(aRecipeToAdd);
+ }
+ return false;
+ }
+
+ public static boolean removeRecipeByOutput(ItemStack aOutput) {
+ return removeRecipeByOutput(aOutput, true, false, false);
+ }
+
+ public static boolean removeRecipeByOutput(ItemStack aOutput, boolean aIgnoreNBT,
+ boolean aNotRemoveShapelessRecipes, boolean aOnlyRemoveNativeHandlers) {
+ if (aOutput == null) {
+ return false;
+ } else {
+ boolean rReturn = false;
+ ArrayList<IRecipe> tList = (ArrayList) CraftingManager.getInstance().getRecipeList();
+ aOutput = GT_OreDictUnificator.get(aOutput);
+ int tList_sS = tList.size();
+
+ for (int i = 0; i < tList_sS; ++i) {
+ IRecipe tRecipe = (IRecipe) tList.get(i);
+ if (!aNotRemoveShapelessRecipes
+ || !(tRecipe instanceof ShapelessRecipes) && !(tRecipe instanceof ShapelessOreRecipe)) {
+ if (aOnlyRemoveNativeHandlers) {
+ if (!gregtech.api.util.GT_ModHandler.sNativeRecipeClasses.contains(tRecipe.getClass().getName())) {
+ continue;
+ }
+ } else if (gregtech.api.util.GT_ModHandler.sSpecialRecipeClasses.contains(tRecipe.getClass().getName())) {
+ continue;
+ }
+
+ ItemStack tStack = tRecipe.getRecipeOutput();
+ if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get(tStack), aOutput, aIgnoreNBT)) {
+ tList.remove(i--);
+ tList_sS = tList.size();
+ rReturn = true;
+ }
+ }
+ }
+
+ return rReturn;
+ }
+ }
diff --git a/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java b/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java
index fcb8c42197..0b22ea3acc 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java
@@ -7,13 +7,72 @@ import net.minecraft.item.ItemStack;
import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.internal.IGT_RecipeAdder;
-
+import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.recipe.common.CI;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import net.minecraftforge.fluids.FluidStack;
public final class AddGregtechRecipe {
+
+
+ public static boolean importPyroRecipe(GT_Recipe aRecipe) {
+
+ int aModifiedTime = (int) (aRecipe.mDuration * 0.8);
+
+ if (aRecipe.mInputs == null || aRecipe.mFluidInputs == null || aRecipe.mFluidOutputs == null || aRecipe.mOutputs == null) {
+ return false;
+ }
+
+ if (aRecipe.mInputs.length > 2 || aRecipe.mFluidInputs.length > 1 || aRecipe.mFluidOutputs.length > 1 || aRecipe.mOutputs.length > 1) {
+ return false;
+ }
+ else if (aRecipe.mInputs.length <= 0 || aRecipe.mFluidInputs.length <= 0 || aRecipe.mFluidOutputs.length <= 0 || aRecipe.mOutputs.length <= 0) {
+ return false;
+ }
+
+ int aCircuitNumber = -1;
+ int aItemSlot = -1;
+
+ int aSlot = 0;
+ for (ItemStack a : aRecipe.mInputs) {
+ if (a != null && a.getItem() != CI.getNumberedCircuit(1).getItem()) {
+ aItemSlot = aSlot;
+ }
+ else {
+ aSlot++;
+ }
+ }
+
+ for (int i=0;i<25;i++) {
+ ItemStack aTest = CI.getNumberedCircuit(i);
+ for (ItemStack a : aRecipe.mInputs) {
+ if (a != null && GT_Utility.areStacksEqual(a, aTest)) {
+ aCircuitNumber = i;
+ break;
+ }
+ }
+ }
+
+ if (aCircuitNumber < 0) {
+ return false;
+ }
+
+
+ return CORE.RA.addCokeOvenRecipe(
+ aRecipe.mInputs[aItemSlot],
+ ItemUtils.getGregtechCircuit(aCircuitNumber),
+ aRecipe.mFluidInputs[0],
+ aRecipe.mFluidOutputs[0],
+ aRecipe.mOutputs[0],
+ aModifiedTime,
+ aRecipe.mEUt);
+
+
+ }
+
public static boolean addCokeAndPyrolyseRecipes(
ItemStack input1, int circuitNumber,
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index 722a4f3ff7..2371753fe6 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -3,10 +3,17 @@ package gtPlusPlus.core.util.reflect;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
@@ -133,8 +140,8 @@ public class ReflectionUtils {
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.
@@ -193,7 +200,7 @@ public class ReflectionUtils {
return y.get();
}
}
-
+
/**
* Returns a cached {@link Field} object.
* @param aInstance - {@link Object} to get the field instance from.
@@ -219,6 +226,20 @@ public class ReflectionUtils {
return isClassPresent(classname);
}
+
+ /**
+ * Returns the class of the objects type parameter
+ * @param o - Object to examine paramters on
+ * @return - a Class<?> or null
+ */
+ public static Class<?> getTypeOfGenericObject(Object o) {
+ Class<?> aTypeParam = findSuperClassParameterType(o, o.getClass(), 0);
+ if (aTypeParam == null) {
+ aTypeParam = findSubClassParameterType(o, o.getClass(), 0);
+ }
+ return aTypeParam;
+ }
+
public static void makeFieldAccessible(final Field field) {
if (!Modifier.isPublic(field.getModifiers()) ||
!Modifier.isPublic(field.getDeclaringClass().getModifiers()))
@@ -271,6 +292,7 @@ public class ReflectionUtils {
return loaded > 0;
}
+
public static boolean setField(final Object object, final String fieldName, final Object fieldValue) {
@@ -291,15 +313,42 @@ public class ReflectionUtils {
}
}
return false;
+
+
+ }
+
+ public static boolean setField(final Object object, final Field field, final Object fieldValue) {
+ Class<?> clazz = object.getClass();
+ while (clazz != null) {
+ try {
+ final Field field2 = getField(clazz, field.getName());
+ if (field2 != null) {
+ setFieldValue_Internal(object, field, fieldValue);
+ return true;
+ }
+ } catch (final NoSuchFieldException e) {
+ Logger.REFLECTION("setField("+object.toString()+", "+field.getName()+") failed.");
+ clazz = clazz.getSuperclass();
+ } catch (final Exception e) {
+ Logger.REFLECTION("setField("+object.toString()+", "+field.getName()+") failed.");
+ throw new IllegalStateException(e);
+ }
+ }
+ return false;
}
/**
* Allows to change the state of an immutable instance. Huh?!?
*/
- public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) throws Exception {
+ public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) {
Field nameField = getField(clazz, fieldName);
- setFieldValue_Internal(clazz, nameField, newValue);
+ try {
+ setFieldValue_Internal(clazz, nameField, newValue);
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ }
}
@Deprecated
@@ -414,13 +463,27 @@ public class ReflectionUtils {
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /*
+ * Internal Magic that probably should not get exposed.
+ */
+
@@ -429,11 +492,126 @@ public class ReflectionUtils {
+ /*
+ *
+ * Below Code block is used for determining generic types associated with type<E>
+ *
+ */
+
+
+ //https://xebia.com/blog/acessing-generic-types-at-runtime-in-java/
+ //https://www.javacodegeeks.com/2013/12/advanced-java-generics-retreiving-generic-type-arguments.html
+ public static Class<?> findSuperClassParameterType(Object instance, Class<?> classOfInterest, int parameterIndex) {
+ Class<?> subClass = instance.getClass();
+ while (classOfInterest != subClass.getSuperclass()) {
+ // instance.getClass() is no subclass of classOfInterest or instance is a direct instance of classOfInterest
+ subClass = subClass.getSuperclass();
+ if (subClass == null) {
+ return null;
+ }
+ }
+ ParameterizedType parameterizedType = (ParameterizedType) subClass.getGenericSuperclass();
+ Class<?> aReturn;
+ aReturn = (Class<?>) parameterizedType.getActualTypeArguments()[parameterIndex];
+ return aReturn;
+ }
+
+ public static Class<?> findSubClassParameterType(Object instance, Class<?> classOfInterest, int parameterIndex) {
+ Map<Type, Type> typeMap = new HashMap<Type, Type>();
+ Class<?> instanceClass = instance.getClass();
+ while (classOfInterest != instanceClass.getSuperclass()) {
+ extractTypeArguments(typeMap, instanceClass);
+ instanceClass = instanceClass.getSuperclass();
+ if (instanceClass == null) {
+ return null;
+ }
+ }
+
+ ParameterizedType parameterizedType = (ParameterizedType) instanceClass.getGenericSuperclass();
+ Type actualType = parameterizedType.getActualTypeArguments()[parameterIndex];
+ if (typeMap.containsKey(actualType)) {
+ actualType = typeMap.get(actualType);
+ }
+ if (actualType instanceof Class) {
+ return (Class<?>) actualType;
+ } else if (actualType instanceof TypeVariable) {
+ return browseNestedTypes(instance, (TypeVariable<?>) actualType);
+ } else {
+ return null;
+ }
+ }
+
+ private static void extractTypeArguments(Map<Type, Type> typeMap, Class<?> clazz) {
+ Type genericSuperclass = clazz.getGenericSuperclass();
+ if (!(genericSuperclass instanceof ParameterizedType)) {
+ return;
+ }
+
+ ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
+ Type[] typeParameter = ((Class<?>) parameterizedType.getRawType()).getTypeParameters();
+ Type[] actualTypeArgument = parameterizedType.getActualTypeArguments();
+ for (int i = 0; i < typeParameter.length; i++) {
+ if(typeMap.containsKey(actualTypeArgument[i])) {
+ actualTypeArgument[i] = typeMap.get(actualTypeArgument[i]);
+ }
+ typeMap.put(typeParameter[i], actualTypeArgument[i]);
+ }
+ }
+
+ private static Class<?> browseNestedTypes(Object instance, TypeVariable<?> actualType) {
+ Class<?> instanceClass = instance.getClass();
+ List<Class<?>> nestedOuterTypes = new LinkedList<Class<?>>();
+ for (Class<?> enclosingClass = instanceClass
+ .getEnclosingClass(); enclosingClass != null; enclosingClass = enclosingClass.getEnclosingClass()) {
+ try {
+ Field this$0 = instanceClass.getDeclaredField("this$0");
+ Object outerInstance = this$0.get(instance);
+ Class<?> outerClass = outerInstance.getClass();
+ nestedOuterTypes.add(outerClass);
+ Map<Type, Type> outerTypeMap = new HashMap<Type, Type>();
+ extractTypeArguments(outerTypeMap, outerClass);
+ for (Map.Entry<Type, Type> entry : outerTypeMap.entrySet()) {
+ if (!(entry.getKey() instanceof TypeVariable)) {
+ continue;
+ }
+ TypeVariable<?> foundType = (TypeVariable<?>) entry.getKey();
+ if (foundType.getName().equals(actualType.getName())
+ && isInnerClass(foundType.getGenericDeclaration(), actualType.getGenericDeclaration())) {
+ if (entry.getValue() instanceof Class) {
+ return (Class<?>) entry.getValue();
+ }
+ actualType = (TypeVariable<?>) entry.getValue();
+ }
+ }
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+
+ }
+
+ }
+ return null;
+ }
+
+ private static boolean isInnerClass(GenericDeclaration outerDeclaration, GenericDeclaration innerDeclaration) {
+ if (!(outerDeclaration instanceof Class) || !(innerDeclaration instanceof Class)) {
+ return false;
+ }
+ Class<?> outerClass = (Class<?>) outerDeclaration;
+ Class<?> innerClass = (Class<?>) innerDeclaration;
+ while ((innerClass = innerClass.getEnclosingClass()) != null) {
+ if (innerClass == outerClass) {
+ return true;
+ }
+ }
+ return false;
+ }
/*
- * Internal Magic that probably should not get exposed.
- */
+ *
+ * End of Generics Block
+ *
+ */
+
private static Field getField_Internal(final Class<?> clazz, final String fieldName) throws NoSuchFieldException {
@@ -525,26 +703,26 @@ public class ReflectionUtils {
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();
+ 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()));
- }
+ 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());
- }
+ 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()));
- }
+ for (Constructor c : consts) {
+ System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes()));
+ }
}
private static Class<?> getNonPublicClass(final String className) {