Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/alex/reflection' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Sep 20, 2024
2 parents 55f5648 + 0e6e19f commit f8f53f5
Show file tree
Hide file tree
Showing 32 changed files with 290 additions and 737 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,7 @@ private static void removeOldRecipesFromRegistries() {
BWCoreStaticReplacementMethodes.clearRecentlyUsedRecipes();
RecipeMaps.slicerRecipes.getBackend()
.removeRecipes(gtrecipeWorldCache);
recipeWorldCache.forEach(r -> {
try {
BWUtil.getGTBufferedRecipeList()
.remove(r);
} catch (Exception e) {
e.printStackTrace();
}
});
GTModHandler.sBufferRecipeList.removeAll(recipeWorldCache);
recipeWorldCache.clear();
gtrecipeWorldCache.clear();
}
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/bartworks/util/BWUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static gregtech.api.enums.GTValues.VN;
import static gregtech.api.enums.GTValues.W;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -39,8 +38,6 @@
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;

import org.apache.commons.lang3.reflect.FieldUtils;

import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
Expand Down Expand Up @@ -362,20 +359,6 @@ public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, Ite
};
}

private static Field sBufferedRecipeList;

@SuppressWarnings("unchecked")
public static List<IRecipe> getGTBufferedRecipeList()
throws SecurityException, IllegalArgumentException, IllegalAccessException {
if (sBufferedRecipeList == null) {
sBufferedRecipeList = FieldUtils.getDeclaredField(GTModHandler.class, "sBufferRecipeList", true);
}
if (sBufferedRecipeList == null) {
sBufferedRecipeList = FieldUtils.getField(GTModHandler.class, "sBufferRecipeList", true);
}
return (List<IRecipe>) sBufferedRecipeList.get(null);
}

public static ShapedOreRecipe createGTCraftingRecipe(ItemStack aResult, long aBitMask, Object[] aRecipe) {
return createGTCraftingRecipe(
aResult,
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/gregtech/api/enums/TAE.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package gregtech.api.enums;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;

import gregtech.api.interfaces.ITexture;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.lib.GTPPCore;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.api.objects.GTPPCopiedBlockTexture;

public class TAE {
Expand Down Expand Up @@ -77,38 +75,6 @@ public static void finalizeTAE() {
Logger.INFO("Finalised TAE.");
}

private static boolean registerTextures(GTPPCopiedBlockTexture GTPPCopiedBlockTexture) {
try {
// Handle page 2.
Logger.INFO("[TAE} Registering Texture, Last used casing ID is " + gtPPLastUsedIndex + ".");
if (gtPPLastUsedIndex >= 128) {
Field x = ReflectionUtils.getField(Textures.BlockIcons.class, "casingTexturePages");
if (x != null) {
ITexture[][] h = (ITexture[][]) x.get(null);
if (h != null) {
h[64][secondaryIndex++] = GTPPCopiedBlockTexture;
x.set(null, h);
Logger
.INFO("[TAE} Registered Texture with ID " + (secondaryIndex - 1) + " in secondary index.");
return true;
}
}
}

// set to page 1.
else {
Textures.BlockIcons.setCasingTextureForId(gtPPLastUsedIndex, GTPPCopiedBlockTexture);
Logger.INFO("[TAE} Registered Texture with ID " + (gtPPLastUsedIndex) + " in main index.");
gtPPLastUsedIndex++;
return true;
}
} catch (Throwable t) {
t.printStackTrace();
}
Logger.INFO("[TAE} Failed to register texture, Last used casing ID is " + gtPPLastUsedIndex + ".");
return false;
}

public static ITexture getTexture(int index) {
if (gtPPLastUsedIndex >= 128) {
return Textures.BlockIcons.getCasingTextureForId(((64 * 128) + index));
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gregtech/api/items/ItemEnergyArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import gregtech.api.GregTechAPI;
import gregtech.api.util.GTLanguageManager;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;

public class ItemEnergyArmor extends ItemArmor implements ISpecialArmor {

Expand Down Expand Up @@ -126,11 +125,11 @@ public void onArmorTick(World aWorld, EntityPlayer aPlayer, ItemStack aStack) {

if ((mSpecials & 8) != 0) {
if (GTModHandler.canUseElectricItem(aStack, 10000) && aPlayer.isPotionActive(Potion.poison)) {
GTUtility.removePotion(aPlayer, Potion.poison.id);
aPlayer.removePotionEffect(Potion.poison.id);
GTModHandler.useElectricItem(aStack, 10000, aPlayer);
}
if (GTModHandler.canUseElectricItem(aStack, 100000) && aPlayer.isPotionActive(Potion.wither)) {
GTUtility.removePotion(aPlayer, Potion.wither.id);
aPlayer.removePotionEffect(Potion.wither.id);
GTModHandler.useElectricItem(aStack, 100000, aPlayer);
}
}
Expand Down
80 changes: 37 additions & 43 deletions src/main/java/gregtech/api/util/FishPondFakeRecipe.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gregtech.api.util;

import static gregtech.api.util.GTRecipeBuilder.SECONDS;
import static gtPlusPlus.api.recipe.GTPPRecipeMaps.fishPondRecipes;

import java.lang.reflect.Field;
import java.util.ArrayList;

import net.minecraft.item.ItemStack;
Expand All @@ -11,61 +11,55 @@

import gregtech.api.enums.GTValues;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.api.recipe.GTPPRecipeMaps;
import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.MTEIndustrialFishingPond;

public class FishPondFakeRecipe {

public static ArrayList<WeightedRandomFishable> fish = new ArrayList<>();
public static ArrayList<WeightedRandomFishable> junk = new ArrayList<>();
public static ArrayList<WeightedRandomFishable> treasure = new ArrayList<>();
public static final ArrayList<ItemStack> fish = new ArrayList<>();
public static final ArrayList<ItemStack> junk = new ArrayList<>();
public static final ArrayList<ItemStack> treasure = new ArrayList<>();

@SuppressWarnings("unchecked")
public static boolean generateFishPondRecipes() {

public static void generateFishPondRecipes() {
try {
fish = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "fish")
ArrayList<WeightedRandomFishable> fishList = (ArrayList<WeightedRandomFishable>) GTUtility
.getField(FishingHooks.class, "fish")
.get(null);
junk = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "junk")
ArrayList<WeightedRandomFishable> junkList = (ArrayList<WeightedRandomFishable>) GTUtility
.getField(FishingHooks.class, "junk")
.get(null);
treasure = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "treasure")
ArrayList<WeightedRandomFishable> treasureList = (ArrayList<WeightedRandomFishable>) GTUtility
.getField(FishingHooks.class, "treasure")
.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
Logger.INFO("Error generating Fish Pond Recipes. [1]");
final Field stackField = GTUtility.getField(WeightedRandomFishable.class, "field_150711_b");
generateRecipesFor(MTEIndustrialFishingPond.FISH_MODE, fish, fishList, stackField);
generateRecipesFor(MTEIndustrialFishingPond.JUNK_MODE, junk, junkList, stackField);
generateRecipesFor(MTEIndustrialFishingPond.TREASURE_MODE, treasure, treasureList, stackField);
} catch (Exception e) {
Logger.INFO("Error reading the vanilla fishing loot table.");
e.printStackTrace();
}
}

ArrayList<ArrayList<WeightedRandomFishable>> mega = new ArrayList<>();
mega.add(fish);
mega.add(junk);
mega.add(treasure);

int mType = 14;
for (ArrayList<WeightedRandomFishable> f : mega) {
for (WeightedRandomFishable weightedRandomFishable : f) {
if (weightedRandomFishable != null) {
WeightedRandomFishable u = weightedRandomFishable;
try {
ItemStack t = (ItemStack) ReflectionUtils
.getField(WeightedRandomFishable.class, "field_150711_b")
.get(u);
GTValues.RA.stdBuilder()
.itemInputs(GTUtility.getIntegratedCircuit(mType))
.itemOutputs(t)
.duration(5 * SECONDS)
.eut(0)
.ignoreCollision()
.addTo(fishPondRecipes);
Logger.INFO("Fishing [" + mType + "]: " + ItemUtils.getArrayStackNames(new ItemStack[] { t }));
} catch (IllegalArgumentException | IllegalAccessException e1) {
Logger.INFO("Error generating Fish Pond Recipes. [2]");
e1.printStackTrace();
}
}
private static void generateRecipesFor(int circuitType, ArrayList<ItemStack> listToFill,
ArrayList<WeightedRandomFishable> lootTable, Field stackField) {
for (WeightedRandomFishable fishable : lootTable) {
try {
ItemStack stack = (ItemStack) stackField.get(fishable);
listToFill.add(stack.copy());
GTValues.RA.stdBuilder()
.itemInputs(GTUtility.getIntegratedCircuit(circuitType))
.itemOutputs(stack)
.duration(5 * SECONDS)
.eut(0)
.ignoreCollision()
.addTo(GTPPRecipeMaps.fishPondRecipes);
} catch (IllegalArgumentException | IllegalAccessException e1) {
Logger.INFO("Error generating Fish Pond Recipes");
e1.printStackTrace();
}
mType++;
}

return true;
listToFill.trimToSize();
}
}
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/util/GTOreDictUnificator.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,8 @@ public static List<ItemStack> getOresImmutable(@Nullable Object aOreName) {
return GTUtility.isStringValid(aName) ? Collections.unmodifiableList(OreDictionary.getOres(aName))
: Collections.emptyList();
}

public static Map<String, ItemStack> getName2StackMap() {
return sName2StackMap;
}
}
65 changes: 5 additions & 60 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.item.EntityItem;
Expand Down Expand Up @@ -364,21 +363,6 @@ public static Object callMethod(Object aObject, String aMethod, boolean aPrivate
return null;
}

public static Object callConstructor(String aClass, int aConstructorIndex, Object aReplacementObject,
boolean aLogErrors, Object... aParameters) {
try {
return callConstructor(
Class.forName(aClass),
aConstructorIndex,
aReplacementObject,
aLogErrors,
aParameters);
} catch (Throwable e) {
if (aLogErrors) e.printStackTrace(GTLog.err);
}
return aReplacementObject;
}

public static Object callConstructor(Class<?> aClass, int aConstructorIndex, Object aReplacementObject,
boolean aLogErrors, Object... aParameters) {
if (aConstructorIndex < 0) {
Expand All @@ -401,31 +385,12 @@ public static Object callConstructor(Class<?> aClass, int aConstructorIndex, Obj
return aReplacementObject;
}

public static String capitalizeString(String aString) {
if (aString != null && aString.length() > 0) return aString.substring(0, 1)
.toUpperCase() + aString.substring(1);
return E;
}

public static boolean getPotion(EntityLivingBase aPlayer, int aPotionIndex) {
try {
Field tPotionHashmap = null;

Field[] fields = EntityLiving.class.getDeclaredFields();

for (Field field : fields) {
if (field.getType() == HashMap.class) {
tPotionHashmap = field;
tPotionHashmap.setAccessible(true);
break;
}
}

if (tPotionHashmap != null) return ((HashMap<?, ?>) tPotionHashmap.get(aPlayer)).get(aPotionIndex) != null;
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
public static String capitalizeString(String s) {
if (s != null && !s.isEmpty()) {
return s.substring(0, 1)
.toUpperCase() + s.substring(1);
}
return false;
return "";
}

public static String getClassName(Object aObject) {
Expand All @@ -438,26 +403,6 @@ public static String getClassName(Object aObject) {
.lastIndexOf(".") + 1);
}

public static void removePotion(EntityLivingBase aPlayer, int aPotionIndex) {
try {
Field tPotionHashmap = null;

Field[] fields = EntityLiving.class.getDeclaredFields();

for (Field field : fields) {
if (field.getType() == HashMap.class) {
tPotionHashmap = field;
tPotionHashmap.setAccessible(true);
break;
}
}

if (tPotionHashmap != null) ((HashMap<?, ?>) tPotionHashmap.get(aPlayer)).remove(aPotionIndex);
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
}
}

public static boolean getFullInvisibility(EntityPlayer aPlayer) {
try {
if (aPlayer.isInvisible()) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/gregtech/api/util/ReflectionUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gregtech.api.util;

public class ReflectionUtil {

public static Class<?> getClass(String classname) {
try {
return Class.forName(classname);
} catch (ClassNotFoundException e) {
return null;
}
}

}
14 changes: 14 additions & 0 deletions src/main/java/gregtech/asm/GTCorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class GTCorePlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {

public static File minecraftDir;
private static Boolean islwjgl3Present = null;
private static Boolean isThaumcraftPresent = null;

public GTCorePlugin() {
// Injection Code taken from CodeChickenLib
Expand Down Expand Up @@ -96,4 +97,17 @@ public static boolean islwjgl3Present() {
return islwjgl3Present;
}

public static boolean isThaumcraftPresent() {
if (isThaumcraftPresent == null) {
try {
final String className = "thaumcraft/common/Thaumcraft.class";
isThaumcraftPresent = ClassLoader.getSystemClassLoader()
.getResource(className) != null;
} catch (Exception e) {
isThaumcraftPresent = Boolean.FALSE;
}
}
return isThaumcraftPresent;
}

}
Loading

0 comments on commit f8f53f5

Please sign in to comment.