aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/miscutil/core')
-rw-r--r--src/Java/miscutil/core/util/ClassUtils.java75
-rw-r--r--src/Java/miscutil/core/util/Utils.java20
2 files changed, 85 insertions, 10 deletions
diff --git a/src/Java/miscutil/core/util/ClassUtils.java b/src/Java/miscutil/core/util/ClassUtils.java
index 6ea9336006..ecf83f8b8f 100644
--- a/src/Java/miscutil/core/util/ClassUtils.java
+++ b/src/Java/miscutil/core/util/ClassUtils.java
@@ -1,23 +1,78 @@
package miscutil.core.util;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
public class ClassUtils {
-
+
/*@ if (isPresent("com.optionaldependency.DependencyClass")) {
// This block will never execute when the dependency is not present
// There is therefore no more risk of code throwing NoClassDefFoundException.
executeCodeLinkingToDependency();
}*/
public static boolean isPresent(String className) {
- try {
- Class.forName(className);
- return true;
- } catch (Throwable ex) {
- // Class or one of its dependencies is not present...
- return false;
- }
+ try {
+ Class.forName(className);
+ return true;
+ } catch (Throwable ex) {
+ // Class or one of its dependencies is not present...
+ return false;
+ }
+ }
+
+ public static Method getMethodViaReflection(Class<?> lookupClass, String methodName, boolean invoke) throws Exception{
+ Class<? extends Class> lookup = lookupClass.getClass();
+ Method m = lookup.getDeclaredMethod(methodName);
+ m.setAccessible(true);// Abracadabra
+ if (invoke){
+ m.invoke(lookup);// now its OK
+ }
+ return m;
}
-
-
+ public static Class getNonPublicClass(String className){
+ Class<?> c = null;
+ try {
+ c = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ //full package name --------^^^^^^^^^^
+ //or simpler without Class.forName:
+ //Class<package1.A> c = package1.A.class;
+
+ if (null != c){
+ //In our case we need to use
+ Constructor<?> constructor = null;
+ try {
+ constructor = c.getDeclaredConstructor();
+ } catch (NoSuchMethodException | SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ //note: getConstructor() can return only public constructors
+ //so we needed to search for any Declared constructor
+
+ //now we need to make this constructor accessible
+ if (null != constructor){
+ constructor.setAccessible(true);//ABRACADABRA!
+
+ try {
+ Object o = constructor.newInstance();
+ return (Class) o;
+ } catch (InstantiationException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
+
+
+
}
diff --git a/src/Java/miscutil/core/util/Utils.java b/src/Java/miscutil/core/util/Utils.java
index 476ca77e98..64e7b46496 100644
--- a/src/Java/miscutil/core/util/Utils.java
+++ b/src/Java/miscutil/core/util/Utils.java
@@ -3,10 +3,14 @@ package miscutil.core.util;
import gregtech.api.enums.TC_Aspects;
import gregtech.api.enums.TC_Aspects.TC_AspectStack;
import ic2.core.IC2Potion;
+import ic2.core.Ic2Items;
+import ic2.core.init.InternalName;
import ic2.core.item.armor.ItemArmorHazmat;
+import ic2.core.item.resources.ItemCell;
import java.awt.Color;
import java.awt.Graphics;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -31,6 +35,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
+import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -461,6 +466,21 @@ public class Utils {
return false;
}
+ public static ItemStack createInternalNameAndFluidCell(String s){
+ InternalName yourName = EnumHelper.addEnum(InternalName.class, s, new Class[0], new Object[0]);
+ ItemCell item = (ItemCell)Ic2Items.cell.getItem();
+ try
+ {
+ Class<? extends ItemCell> clz = item.getClass();
+ Method methode = clz.getMethod("addCell", int.class, InternalName.class, Block[].class);
+ methode.setAccessible(true);
+ return (ItemStack) methode.invoke(item, 1000, yourName, new Block[0]);
+ }
+ catch(Exception e){
+ }
+ return null;
+ }
+
}