diff options
author | SciWhiz12 <arnoldnunag12@gmail.com> | 2021-05-15 11:24:36 +0800 |
---|---|---|
committer | SciWhiz12 <arnoldnunag12@gmail.com> | 2021-05-15 11:24:36 +0800 |
commit | bf76791ab0cfef81b5ae16736938913903fe676f (patch) | |
tree | dbb643384c7669163734af8b44e384d6c296a3a5 /src/gradlecomp/java/net/minecraftforge | |
parent | 6218dc6442d90e7fa0e385b39ef1dbd8c36b9a1d (diff) | |
download | Artifactural-bf76791ab0cfef81b5ae16736938913903fe676f.tar.gz Artifactural-bf76791ab0cfef81b5ae16736938913903fe676f.tar.bz2 Artifactural-bf76791ab0cfef81b5ae16736938913903fe676f.zip |
Use UnsafeHacks to set final fields
Removes always definalizing fields
Diffstat (limited to 'src/gradlecomp/java/net/minecraftforge')
-rw-r--r-- | src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java index 4e18885..1c8cdac 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java @@ -19,8 +19,11 @@ package net.minecraftforge.artifactural.gradle; +import net.minecraftforge.fml.unsafe.UnsafeHacks; + import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.function.UnaryOperator; public class ReflectionUtils { @@ -39,7 +42,11 @@ public class ReflectionUtils { T oldV = (T)f.get(target); T newV = operator.apply(oldV); - f.set(target, newV); + if (Modifier.isFinal(f.getModifiers())) { + UnsafeHacks.setField(f, target, newV); + } else { + f.set(target, newV); + } if (f.get(target) != newV) { throw new IllegalStateException("Failed to set new value on " + f.getDeclaringClass().getName() + "." + f.getName()); @@ -68,9 +75,6 @@ public class ReflectionUtils { for (Field f : clazz.getDeclaredFields()) { if (f.getName().equals(name)) { f.setAccessible(true); - if (!ModifierAccess.definalize(f)) { - System.out.println("Could not definalize field " + f.getDeclaringClass().getName() + "." + f.getName() + " Exception ate, lets see if it works"); - } return f; } } |