diff --git a/src/main/java/com/replaymod/core/ReplayModMMLauncher.java b/src/main/java/com/replaymod/core/ReplayModMMLauncher.java new file mode 100644 index 00000000..f22e690d --- /dev/null +++ b/src/main/java/com/replaymod/core/ReplayModMMLauncher.java @@ -0,0 +1,21 @@ +//#if FABRIC>=1 +package com.replaymod.core; + +import org.spongepowered.asm.mixin.Mixins; + +// We need to wait for MM to call us, otherwise we might initialize our mixins before it calls optifabric which would +// result in OF classes not existing while our mixins get resolved. +public class ReplayModMMLauncher implements Runnable { + @Override + public void run() { + Mixins.addConfiguration("mixins.compat.mapwriter.replaymod.json"); + Mixins.addConfiguration("mixins.compat.shaders.replaymod.json"); + Mixins.addConfiguration("mixins.core.replaymod.json"); + Mixins.addConfiguration("mixins.extras.playeroverview.replaymod.json"); + Mixins.addConfiguration("mixins.recording.replaymod.json"); + Mixins.addConfiguration("mixins.render.blend.replaymod.json"); + Mixins.addConfiguration("mixins.render.replaymod.json"); + Mixins.addConfiguration("mixins.replay.replaymod.json"); + } +} +//#endif diff --git a/src/main/java/com/replaymod/core/ReplayModNonMMLauncher.java b/src/main/java/com/replaymod/core/ReplayModNonMMLauncher.java new file mode 100644 index 00000000..2fdf1ae8 --- /dev/null +++ b/src/main/java/com/replaymod/core/ReplayModNonMMLauncher.java @@ -0,0 +1,62 @@ +//#if FABRIC>=1 +package com.replaymod.core; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.io.IOException; +import java.util.List; +import java.util.Set; + +// See ReplayModMMLauncher. This is the fallback if MM is not installed. +public class ReplayModNonMMLauncher implements IMixinConfigPlugin { + private final Logger logger = LogManager.getLogger("replaymod/nonmm"); + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return false; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + + } + + @Override + public List getMixins() { + try { + if (ReplayModMixinConfigPlugin.hasClass("com.chocohead.mm.Plugin")) { + logger.info("Detected MM, they should call us..."); + } else { + logger.info("Did not detect MM, initializing ourselves..."); + new ReplayModMMLauncher().run(); + } + return null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } +} +//#endif diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ed46a25a..68b48f8f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,17 +24,14 @@ ], "modmenu": [ "com.replaymod.core.gui.ModMenuApiImpl" + ], + "mm:early_risers": [ + "com.replaymod.core.ReplayModMMLauncher" ] }, "mixins": [ "mixins.jgui.json", - "mixins.core.replaymod.json", - "mixins.compat.shaders.replaymod.json", - "mixins.extras.playeroverview.replaymod.json", - "mixins.recording.replaymod.json", - "mixins.render.blend.replaymod.json", - "mixins.render.replaymod.json", - "mixins.replay.replaymod.json" + "mixins.nonmmlauncher.replaymod.json" ], "requires": { diff --git a/src/main/resources/mixins.nonmmlauncher.replaymod.json b/src/main/resources/mixins.nonmmlauncher.replaymod.json new file mode 100644 index 00000000..3a06b39c --- /dev/null +++ b/src/main/resources/mixins.nonmmlauncher.replaymod.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "com.replaymod.mmdummy", + "plugin": "com.replaymod.core.ReplayModNonMMLauncher", + "mixins": [], + "server": [], + "client": [], + "compatibilityLevel": "JAVA_8", + "minVersion": "0.6.11", + "refmap": "mixins.nonmmlauncher.replaymod.refmap.json" +} \ No newline at end of file