Load mod via Forge event (#96)

* fix crash with CustomMainMenu mod

* move loading to a Forge event

* cleanup

* Force load as mod

---------

Co-authored-by: EnZaXD <florian.michael07@gmail.com>
This commit is contained in:
Michael1297 2024-08-01 17:41:50 +03:00 committed by GitHub
parent fee801a9cd
commit 6b6ae4fe32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View File

@ -93,7 +93,8 @@ jar {
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker", "TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder": 0, "TweakOrder": 0,
"FMLCorePlugin": "de.florianmichael.viaforge.mixin.MixinLoader", "FMLCorePlugin": "de.florianmichael.viaforge.mixin.MixinLoader",
"FMLCorePluginContainsFMLMod": "true" "FMLCorePluginContainsFMLMod": "true",
"ForceLoadAsMod": "true"
) )
enabled = false enabled = false

View File

@ -18,12 +18,14 @@
package de.florianmichael.viaforge; package de.florianmichael.viaforge;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.VFPlatform; import de.florianmichael.viaforge.common.platform.VFPlatform;
import de.florianmichael.viaforge.provider.ViaForgeGameProfileFetcher; import de.florianmichael.viaforge.provider.ViaForgeGameProfileFetcher;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.realms.RealmsSharedConstants; import net.minecraft.realms.RealmsSharedConstants;
import net.minecraft.util.Session; import net.minecraft.util.Session;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.provider.GameProfileFetcher; import net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.provider.GameProfileFetcher;
import java.io.File; import java.io.File;
@ -32,7 +34,10 @@ import java.util.function.Supplier;
@Mod(modid = "viaforge", name = "ViaForge", acceptableRemoteVersions = "*", clientSideOnly=true, useMetadata=true) @Mod(modid = "viaforge", name = "ViaForge", acceptableRemoteVersions = "*", clientSideOnly=true, useMetadata=true)
public class ViaForge189 implements VFPlatform { public class ViaForge189 implements VFPlatform {
public static final ViaForge189 PLATFORM = new ViaForge189(); @Mod.EventHandler
public void onInit(FMLInitializationEvent event) {
ViaForgeCommon.init(this);
}
@Override @Override
public int getGameVersion() { public int getGameVersion() {

View File

@ -19,7 +19,6 @@
package de.florianmichael.viaforge.mixin.impl; package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.ViaForge189;
import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig; import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector; import de.florianmichael.viaforge.gui.GuiProtocolSelector;
@ -34,8 +33,6 @@ public class MixinGuiMainMenu extends GuiScreen {
@Inject(method = "initGui", at = @At("RETURN")) @Inject(method = "initGui", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) { public void hookViaForgeButton(CallbackInfo ci) {
ViaForgeCommon.init(ViaForge189.PLATFORM);
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig(); final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowMainMenuButton()) { if (config.isShowMainMenuButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height); final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);