Skip to content

Commit

Permalink
add init load stage
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Jul 10, 2023
1 parent 524f561 commit 5a63996
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,19 @@ public static void initializeGroovyPreInit() {
Loader.instance().setActiveModContainer(Loader.instance().getIndexedModList().get(ID));
}

long time = System.currentTimeMillis();
getSandbox().run(LoadStage.PRE_INIT);
LOGGER.info("Running early Groovy scripts took " + (System.currentTimeMillis() - time) + " ms");
runGroovyScriptsInLoader(LoadStage.PRE_INIT);

if (wasNull) {
Loader.instance().setActiveModContainer(null);
}
}

@ApiStatus.Internal
public static void initializeGroovyPostInit() {
public static void runGroovyScriptsInLoader(LoadStage loadStage) {
// called via mixin between fml post init and load complete
long time = System.currentTimeMillis();
getSandbox().run(LoadStage.POST_INIT);
LOGGER.info("Running Groovy scripts took " + (System.currentTimeMillis() - time) + " ms");
getSandbox().run(loadStage);
LOGGER.info("Running Groovy scripts during {} took {} ms", loadStage.getName(), System.currentTimeMillis() - time);
}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cleanroommc.groovyscript.core.mixin;

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.sandbox.LoadStage;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.LoaderState;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -16,8 +17,11 @@ public void preInit(LoaderState state, Object[] eventData, CallbackInfo ci) {
if (state == LoaderState.PREINITIALIZATION) {
GroovyScript.initializeGroovyPreInit();
}
if (state == LoaderState.POSTINITIALIZATION) {
GroovyScript.runGroovyScriptsInLoader(LoadStage.INIT);
}
if (state == LoaderState.AVAILABLE) {
GroovyScript.initializeGroovyPostInit();
GroovyScript.runGroovyScriptsInLoader(LoadStage.POST_INIT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static List<LoadStage> getLoadStages() {
}

public static final LoadStage PRE_INIT = new LoadStage("preInit", false, -1000000);
public static final LoadStage INIT = new LoadStage("init", false, -1000);
public static final LoadStage POST_INIT = new LoadStage("postInit", true, 0);

private final String name;
Expand Down

0 comments on commit 5a63996

Please sign in to comment.