Skip to content
This repository was archived by the owner on Dec 22, 2019. It is now read-only.

Commit 683510b

Browse files
committed
removeFinalModifier
1 parent a8f0bce commit 683510b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/com/therandomlabs/randomlib/TRLUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.Field;
44
import java.lang.reflect.Method;
5+
import java.lang.reflect.Modifier;
56
import java.util.Arrays;
67
import net.minecraft.crash.CrashReport;
78
import net.minecraft.launchwrapper.Launch;
@@ -17,6 +18,8 @@ public final class TRLUtils {
1718
public static final String MC_VERSION = (String) FMLInjectionData.data()[4];
1819
public static final int MC_VERSION_NUMBER = Integer.parseInt(MC_VERSION.split("\\.")[1]);
1920

21+
private static Field modifiers;
22+
2023
private TRLUtils() {}
2124

2225
@SuppressWarnings("deprecation")
@@ -134,6 +137,21 @@ public static Method findMethod(Class<?> clazz, String name, String obfName,
134137
return null;
135138
}
136139

140+
public static Field removeFinalModifier(Field field) {
141+
try {
142+
if(modifiers == null) {
143+
modifiers = Field.class.getDeclaredField("modifiers");
144+
modifiers.setAccessible(true);
145+
}
146+
147+
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
148+
} catch(Exception ex) {
149+
crashReport("Failed to make " + field.getName() + " non-final", ex);
150+
}
151+
152+
return field;
153+
}
154+
137155
public static Class<?> getClass(String name) {
138156
try {
139157
return Class.forName(name);

0 commit comments

Comments
 (0)