Skip to content

Commit 2341ccc

Browse files
committed
auto init classes
1 parent 2e10dbb commit 2341ccc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ dependencies {
132132
}
133133

134134
api "codechicken:codechickenlib:3.2.3.358"
135+
// api "gregtech:gregtech:2.8.10-beta", { transitive false }
135136

136137
// compiles all mods, and selectively enables mods being debugged
137138
mod_dependencies.entrySet().forEach {

src/main/java/com/cleanroommc/groovyscript/sandbox/GroovySandbox.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.lang.reflect.InvocationTargetException;
23+
import java.lang.reflect.Method;
2224
import java.net.MalformedURLException;
2325
import java.net.URISyntaxException;
2426
import java.net.URL;
@@ -148,6 +150,14 @@ protected void loadClassScripts(GroovyScriptEngine engine, Binding binding, Set<
148150
}
149151
// the superclass of class files is Object
150152
if (clazz.getSuperclass() != Script.class && shouldRunFile(classFile)) {
153+
try {
154+
// $getLookup is present on all groovy created classes
155+
// call it cause the class to be initialised
156+
Method m = clazz.getMethod("$getLookup");
157+
m.invoke(null);
158+
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
159+
GroovyLog.get().errorMC("Error initialising class '{}'", clazz.getName());
160+
}
151161
executedClasses.add(classFile);
152162
}
153163
}

0 commit comments

Comments
 (0)