From bf76791ab0cfef81b5ae16736938913903fe676f Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 11:24:36 +0800 Subject: Use UnsafeHacks to set final fields Removes always definalizing fields --- .../minecraftforge/artifactural/gradle/ReflectionUtils.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java') 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; } } -- cgit