Skip to content

Commit

Permalink
Better mixin error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Dec 7, 2024
1 parent f46676f commit 1b3517e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private FMLContextQuery() {
modApiManager$dataTable.setAccessible(true);
asmDataTable = (ASMDataTable) modApiManager$dataTable.get(ModAPIManager.INSTANCE);
} catch (ReflectiveOperationException e) {
MixinBooterPlugin.LOGGER.fatal("Not able to reflect ModAPIManager#dataTable", e);
FMLLog.log.fatal("Not able to reflect ModAPIManager#dataTable", e);
}
this.asmDataTable = asmDataTable;
}
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/net/minecraftforge/fml/common/LoadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,31 @@ public void distributeStateMessage(LoaderState state, Object... eventData)

FMLContextQuery.init(); // Initialize FMLContextQuery and add it to the global list

MixinBooterPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes...");
FMLLog.log.info("Instantiating all ILateMixinLoader implemented classes...");
for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class.getName().replace('.', '/'))) {
modClassLoader.addFile(asmData.getCandidate().getModContainer()); // Add to path before `newInstance`
Class<?> clazz = Class.forName(asmData.getClassName().replace('/', '.'));
MixinBooterPlugin.LOGGER.info("Instantiating {} for its mixins.", clazz);
ILateMixinLoader loader = (ILateMixinLoader) clazz.newInstance();
FMLLog.log.info("Instantiating {} for its mixins.", clazz);
ILateMixinLoader loader = (ILateMixinLoader) clazz.getConstructor().newInstance();
for (String mixinConfig : loader.getMixinConfigs()) {
if (loader.shouldMixinConfigQueue(mixinConfig)) {
MixinBooterPlugin.LOGGER.info("Adding {} mixin configuration.", mixinConfig);
Mixins.addConfiguration(mixinConfig);
loader.onMixinConfigQueued(mixinConfig);
FMLLog.log.info("Adding {} mixin configuration.", mixinConfig);
try {
Mixins.addConfiguration(mixinConfig);
loader.onMixinConfigQueued(mixinConfig);
} catch (Throwable t) {
FMLLog.log.error("Error adding mixin configuration for {}", mixinConfig, t);
}
}
}
}

for (ModContainer container : this.loader.getActiveModList()) {
modClassLoader.addFile(container.getSource());
}
} catch (Throwable ignored) {}
} catch (Throwable t) {
FMLLog.log.error("Error loading Mods", t);
}
if (MixinService.getService() instanceof MixinServiceLaunchWrapper) {
((MixinServiceLaunchWrapper) MixinService.getService()).setDelegatedTransformers(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixins;
Expand All @@ -17,8 +18,6 @@
@IFMLLoadingPlugin.SortingIndex(1)
public final class MixinBooterPlugin implements IFMLLoadingPlugin {

public static final Logger LOGGER = LogManager.getLogger("MixinBooter");

public MixinBooterPlugin() {
}

Expand Down Expand Up @@ -50,17 +49,17 @@ public void injectData(Map<String, Object> data) {
}
Object theMod = fmlPluginWrapper$coreModInstance.get(coremod);
if (theMod instanceof IEarlyMixinLoader loader) {
LOGGER.info("Grabbing {} for its mixins.", loader.getClass());
FMLLog.log.info("Grabbing {} for its mixins.", loader.getClass());
for (String mixinConfig : loader.getMixinConfigs()) {
if (loader.shouldMixinConfigQueue(mixinConfig)) {
LOGGER.info("Adding {} mixin configuration.", mixinConfig);
FMLLog.log.info("Adding {} mixin configuration.", mixinConfig);
Mixins.addConfiguration(mixinConfig);
loader.onMixinConfigQueued(mixinConfig);;
}
}
}
} catch (Throwable t) {
LOGGER.error("Unexpected error", t);
FMLLog.log.error("Unexpected error handling early mixins", t);
}
}
}
Expand Down

0 comments on commit 1b3517e

Please sign in to comment.