Skip to content

Commit

Permalink
Move GTNH LateMixins to pre-init and fix compat with some mods that a…
Browse files Browse the repository at this point in the history
…re triggering FMLConstructionEvent to load too early
  • Loading branch information
mitchej123 committed Oct 29, 2024
1 parent 5fbb67e commit 02a9a1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import com.gtnewhorizon.gtnhmixins.LateMixin;
import com.gtnewhorizon.gtnhmixins.Reflection;

import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.ModClassLoader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.discovery.ASMDataTable;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import net.minecraft.launchwrapper.Launch;

import org.apache.commons.lang3.reflect.FieldUtils;
Expand All @@ -32,18 +33,14 @@
import java.util.Set;


@Mixin(value = FMLConstructionEvent.class, remap = false)
@Mixin(value = LoadController.class, remap = false)
public class LateMixinOrchestrationMixin {
private static boolean finished=false;

@Inject(method = "<init>", at = @At(value = "RETURN"))
private void beforeConstructing(Object[] eventData, CallbackInfo ci) throws Throwable {
// We would normally target something in LoadController, but FastCraft causes that class to be loaded too early to mixin,
// so we instead hijack the very first FMLConstructionEvent that's constructed and run the logic there.
if (finished)
@Inject(method = "distributeStateMessage(Lcpw/mods/fml/common/LoaderState;[Ljava/lang/Object;)V", at = @At(value = "HEAD"))
private void beforeConstructing(LoaderState state, Object[] eventData, CallbackInfo ci) throws Throwable {
// This state is where Forge adds mod files to ModClassLoader
if (state != LoaderState.CONSTRUCTING) {
return;

finished = true;
}

GTNHMixins.LOGGER.info("Instantiating all @LateMixin annotated and ILateMixinLoader implemented classes...");

Expand Down
4 changes: 2 additions & 2 deletions module-gtnhmixins/src/main/resources/mixins.gtnhmixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8.3-GTNH",
"compatibilityLevel": "JAVA_8",
"target": "@env(DEFAULT)",
"target": "@env(PREINIT)",
"package": "com.gtnewhorizon.gtnhmixins.mixins",
"refmap": "mixins.gtnhmixins.refmap.json",
"injectors": {
Expand All @@ -11,4 +11,4 @@
"mixins": [
"LateMixinOrchestrationMixin"
]
}
}

0 comments on commit 02a9a1a

Please sign in to comment.