mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-28 15:56:14 +00:00
Clean up some reflection
This commit is contained in:
1 parent
ea4ecf92af
commit
144f023041
3 files changed
+21
-16
No files matched your search
@@ -10,10 +10,12 @@
|
||||
*/
|
||||
package vazkii.botania.common.lib;
|
||||
|
||||
import cpw.mods.modlauncher.api.INameMappingService;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class LibObfuscation {
|
||||
// EntityLiving
|
||||
@@ -28,6 +30,17 @@ public final class LibObfuscation {
|
||||
// HoeItem
|
||||
public static final String HOE_LOOKUP = "field_195973_b";
|
||||
|
||||
public static MethodHandle getGetter(Class<?> clazz, String srg) {
|
||||
try {
|
||||
// From ObfuscationReflectionHelper.findField, because it has weird generics that fail when called alone
|
||||
Field f = clazz.getDeclaredField(ObfuscationReflectionHelper.remapName(INameMappingService.Domain.FIELD, srg));
|
||||
f.setAccessible(true);
|
||||
return MethodHandles.publicLookup().unreflectGetter(f);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
throw new IllegalStateException("Can't find " + srg, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static MethodHandle getMethod(Class<?> clazz, String srg, Class<?>... paramTypes) {
|
||||
try {
|
||||
return MethodHandles.publicLookup().unreflect(ObfuscationReflectionHelper.findMethod(clazz, srg, paramTypes));
|
||||
|
||||
Reference in new issue
Block a user