From ecf33f7e9d359e766e6d982ef10552db31ed297b Mon Sep 17 00:00:00 2001 From: tildejustin Date: Mon, 11 Dec 2023 16:53:49 -0500 Subject: [PATCH] suppress launchwrapper classloading failure --- .../optifabric/mixin/ReflectorClassMixin.java | 27 +++++++++++++++++++ .../optifabric/mod/OptifabricSetup.java | 2 ++ .../resources/optifabric.optifine.mixins.json | 8 ++++++ 3 files changed, 37 insertions(+) create mode 100644 src/main/java/me/modmuss50/optifabric/mixin/ReflectorClassMixin.java create mode 100644 src/main/resources/optifabric.optifine.mixins.json diff --git a/src/main/java/me/modmuss50/optifabric/mixin/ReflectorClassMixin.java b/src/main/java/me/modmuss50/optifabric/mixin/ReflectorClassMixin.java new file mode 100644 index 00000000..c8273e80 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/mixin/ReflectorClassMixin.java @@ -0,0 +1,27 @@ +package me.modmuss50.optifabric.mixin; + +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +// suppresses some warnings in the log +@Pseudo +@Mixin(targets = "ReflectorClass") +public class ReflectorClassMixin { + @Shadow + private String targetClassName; + + @Shadow + private boolean checked; + + @SuppressWarnings("UnresolvedMixinReference") + @Inject(method = "getTargetClass", at = @At("HEAD"), remap = false) + private void getTargetClass(CallbackInfoReturnable> infoReturnable) { + if (!checked) { // only check the target if it hasn't been done yet + String name = targetClassName.replaceAll("/", "."); + if (name.startsWith("net.minecraft.launchwrapper") || name.startsWith("net.minecraftforge") || "optifine.OptiFineClassTransformer".equals(name)) { + checked = true; + } + } + } +} diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 07335171..3257f095 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -5,6 +5,7 @@ import me.modmuss50.optifabric.patcher.ClassCache; import net.fabricmc.loader.api.*; import net.fabricmc.loader.api.metadata.ModMetadata; +import org.spongepowered.asm.mixin.Mixins; import java.io.File; import java.util.*; @@ -36,6 +37,7 @@ public void run() { } throw new RuntimeException("Failed to setup optifine", e); } + Mixins.addConfiguration("optifabric.optifine.mixins.json"); } private boolean validateMods() { diff --git a/src/main/resources/optifabric.optifine.mixins.json b/src/main/resources/optifabric.optifine.mixins.json new file mode 100644 index 00000000..d7cc178e --- /dev/null +++ b/src/main/resources/optifabric.optifine.mixins.json @@ -0,0 +1,8 @@ +{ + "required": true, + "package": "me.modmuss50.optifabric.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "ReflectorClassMixin" + ] +}