mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-14 11:46:06 +00:00
Corrected issues with worldGenContext not correctly being set (Ref: https://stackoverflow.com/questions/56039341/get-declared-fields-of-java-lang-reflect-fields-in-jdk12/56043252#56043252)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
package com.dfsek.terra.api.util.reflection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
@@ -26,6 +27,18 @@ import java.util.stream.Stream;
|
||||
|
||||
|
||||
public final class ReflectionUtil {
|
||||
private static final Unsafe UNSAFE;
|
||||
|
||||
static {
|
||||
try{
|
||||
final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
unsafeField.setAccessible(true);
|
||||
UNSAFE = (Unsafe) unsafeField.get(null);
|
||||
} catch(NoSuchFieldException | IllegalAccessException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Field[] getFields(@NotNull Class<?> type) {
|
||||
Field[] result = type.getDeclaredFields();
|
||||
Class<?> parentClass = type.getSuperclass();
|
||||
@@ -35,6 +48,14 @@ public final class ReflectionUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setFinalField(Object obj, String fieldName, Object value) throws NoSuchFieldException {
|
||||
Field field = obj.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
long fieldOffset = UNSAFE.objectFieldOffset(field);
|
||||
|
||||
UNSAFE.putObject(obj, fieldOffset, value);
|
||||
}
|
||||
|
||||
public static Method[] getMethods(@NotNull Class<?> type) {
|
||||
Method[] result = type.getDeclaredMethods();
|
||||
Class<?> parentClass = type.getSuperclass();
|
||||
|
||||
Reference in New Issue
Block a user