From 4babfbbca15f676d6b2575dc062eb6038150cbf0 Mon Sep 17 00:00:00 2001 From: Deftu Date: Wed, 11 Dec 2024 08:10:10 +0200 Subject: [PATCH] yeah no nevermind "finished" was a lie --- build.gradle.kts | 2 + settings.gradle.kts | 2 +- .../crashpatch/mixin/MixinCrashReport.java | 1 - .../crashpatch/mixin/MixinGuiConnecting.java | 6 +- .../crashpatch/mixin/MixinGuiDupesFound.java | 2 + .../crashpatch/mixin/MixinMinecraft.java | 11 +++- .../org/polyfrost/crashpatch/CrashPatch.kt | 2 +- .../polyfrost/crashpatch/CrashPatchCommand.kt | 2 +- .../crashpatch/mixins/MixinPlugin.kt | 60 +++++++++++++++++++ src/main/resources/fabric.mod.json | 31 ++++++++++ src/main/resources/mixins.crashpatch.json | 3 +- 11 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/org/polyfrost/crashpatch/mixins/MixinPlugin.kt create mode 100644 src/main/resources/fabric.mod.json diff --git a/build.gradle.kts b/build.gradle.kts index 2f29b56..6ecde0a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,5 +52,7 @@ dependencies { // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. if (mcData.isLegacyForge) { compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") + } else if (mcData.isFabric) { + modImplementation("net.fabricmc:fabric-language-kotlin:${mcData.dependencies.fabric.fabricLanguageKotlinVersion}") } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index da4280a..6adc8a5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,7 +22,7 @@ pluginManagement { plugins { kotlin("jvm") version("2.0.0") - id("dev.deftu.gradle.multiversion-root") version("2.12.0") + id("dev.deftu.gradle.multiversion-root") version("2.12.2") } } diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinCrashReport.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinCrashReport.java index 3b88a91..ac37b08 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinCrashReport.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinCrashReport.java @@ -10,7 +10,6 @@ import org.polyfrost.crashpatch.hooks.CrashReportHook; import org.polyfrost.crashpatch.hooks.StacktraceDeobfuscator; import net.minecraft.crash.CrashReport; -import net.minecraftforge.fml.common.ModContainer; import org.polyfrost.crashpatch.identifier.ModMetadata; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java index 2102bca..cf633c3 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java @@ -34,7 +34,11 @@ private void drawWarningText(int mouseX, int mouseY, float partialTicks, Callbac } @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) + //#if FORGE + throws IOException + //#endif + { super.mouseClicked(mouseX, mouseY, mouseButton); if (((MinecraftHook) Minecraft.getMinecraft()).hasRecoveredFromCrash()) { if (mouseButton == 0) { diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java index 0b09055..11b7588 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java @@ -1,5 +1,6 @@ package org.polyfrost.crashpatch.mixin; +//#if FORGE import org.polyfrost.crashpatch.CrashPatch; import org.polyfrost.universal.UDesktop; import net.minecraft.client.Minecraft; @@ -93,3 +94,4 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn } } +//#endif diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java index 84427e4..1a4d493 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java @@ -1,5 +1,10 @@ package org.polyfrost.crashpatch.mixin; +//#if FORGE +import net.minecraftforge.fml.client.SplashProgress; +import net.minecraftforge.fml.common.FMLCommonHandler; +//#endif + import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; @@ -23,8 +28,6 @@ import net.minecraft.util.MinecraftError; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.client.SplashProgress; -import net.minecraftforge.fml.common.FMLCommonHandler; import org.apache.logging.log4j.Logger; import org.lwjgl.LWJGLException; import org.lwjgl.input.Mouse; @@ -328,8 +331,10 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { this.running = true; try { + //#if FORGE //noinspection deprecation SplashProgress.pause();// Disable the forge splash progress screen + //#endif GlStateManager.disableTexture2D(); GlStateManager.enableTexture2D(); } catch (Throwable ignored) { @@ -403,12 +408,14 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { } } + //#if FORGE @Redirect(method = "displayCrashReport", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;handleExit(I)V")) public void redirect(FMLCommonHandler instance, int code) { if (crashpatch$letDie) { instance.handleExit(code); } } + //#endif @Unique private void crashpatch$resetState() { diff --git a/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt b/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt index 3801e49..27c14e4 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt @@ -64,7 +64,7 @@ object CrashPatch } fun initialize() { - CommandManager.registerCommand(CrashPatchCommand) + CommandManager.registerCommand(CrashPatchCommand()) CrashPatchConfig // Initialize the config } diff --git a/src/main/kotlin/org/polyfrost/crashpatch/CrashPatchCommand.kt b/src/main/kotlin/org/polyfrost/crashpatch/CrashPatchCommand.kt index db6b9a1..8ba2631 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/CrashPatchCommand.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/CrashPatchCommand.kt @@ -8,7 +8,7 @@ import org.polyfrost.universal.ChatColor import org.polyfrost.universal.UMinecraft @Command(CrashPatch.ID) -object CrashPatchCommand { +class CrashPatchCommand { @Command fun main() { diff --git a/src/main/kotlin/org/polyfrost/crashpatch/mixins/MixinPlugin.kt b/src/main/kotlin/org/polyfrost/crashpatch/mixins/MixinPlugin.kt new file mode 100644 index 0000000..41c60be --- /dev/null +++ b/src/main/kotlin/org/polyfrost/crashpatch/mixins/MixinPlugin.kt @@ -0,0 +1,60 @@ +package org.polyfrost.crashpatch.mixins + +//#if MC >= 1.16.5 || FABRIC +//$$ import org.objectweb.asm.tree.ClassNode +//#endif + +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin +import org.spongepowered.asm.mixin.extensibility.IMixinInfo + +class MixinPlugin : IMixinConfigPlugin { + + override fun getMixins(): MutableList { + val result = mutableListOf() + + //#if FORGE + result.add("MixinGuiDupesFound") + result.add("MixinTileEntityRendererDispatcher") + //#endif + + return result + } + + override fun getRefMapperConfig(): String? = null + override fun shouldApplyMixin(targetClassName: String, mixinClassName: String): Boolean = true + + override fun onLoad(mixinPackage: String) { + // no-op + } + + override fun acceptTargets(myTargets: MutableSet, otherTargets: MutableSet) { + // no-op + } + + override fun preApply( + targetClassName: String, + //#if MC >= 1.16.5 || FABRIC + //$$ targetClass: ClassNode, + //#else + targetClass: org.spongepowered.asm.lib.tree.ClassNode, + //#endif + mixinClassName: String, + mixinInfo: IMixinInfo + ) { + // no-op + } + + override fun postApply( + targetClassName: String, + //#if MC >= 1.16.5 || FABRIC + //$$ targetClass: ClassNode, + //#else + targetClass: org.spongepowered.asm.lib.tree.ClassNode, + //#endif + mixinClassName: String, + mixinInfo: IMixinInfo + ) { + // no-op + } + +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..355dee0 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,31 @@ +{ + "schemaVersion": 1, + "id": "${mod_id}", + "version": "${mod_version}", + "name": "${mod_name}", + "authors": [ + "Polyfrost", + "SkyClient" + ], + "contact": { + "issues": "https://github.com/Polyfrost/${mod_name}/issues", + "sources": "https://github.com/Polyfrost/${mod_name}" + }, + "license": "GPL-3.0-or-later", + "environment": "*", + "entrypoints": { + "client": [ + { + "adapter": "kotlin", + "value": "org.polyfrost.crashpatch.CrashPatch" + } + ] + }, + "mixins": [ + "mixins.${mod_id}.json" + ], + "depends": { + "fabricloader": ">=0.15.11", + "fabric-language-kotlin": "*" + } +} \ No newline at end of file diff --git a/src/main/resources/mixins.crashpatch.json b/src/main/resources/mixins.crashpatch.json index eb1957a..02aa539 100644 --- a/src/main/resources/mixins.crashpatch.json +++ b/src/main/resources/mixins.crashpatch.json @@ -2,6 +2,7 @@ "compatibilityLevel": "JAVA_8", "minVersion": "0.7", "package": "org.polyfrost.crashpatch.mixin", + "plugin": "org.polyfrost.crashpatch.mixins.MixinPlugin", "refmap": "mixin.crashpatch.refmap.json", "injectors": { "maxShiftBy": 5 @@ -11,9 +12,7 @@ "MixinCrashReport", "MixinCrashReportCategory", "MixinGuiConnecting", - "MixinGuiDupesFound", "MixinMinecraft", - "MixinTileEntityRendererDispatcher", "MixinWorldRenderer" ], "verbose": true