From b311cee2fe9722885017fe38eb3a85a20758216c Mon Sep 17 00:00:00 2001 From: kb1000 Date: Fri, 4 Feb 2022 20:48:32 +0100 Subject: [PATCH] Future-proof Forge/Fabric compatibility code --- build.gradle.kts | 19 +------------------ .../client/ClientTelemetryManager.java | 14 -------------- .../NoTelemetryMixinConfigPlugin.java | 10 ++++++---- .../mixin/TelemetrySenderMixin.java | 4 +--- .../resources/no-telemetry-forge-refmap.json | 6 ++++-- 5 files changed, 12 insertions(+), 41 deletions(-) delete mode 100644 src/headers/java/net/minecraft/client/ClientTelemetryManager.java diff --git a/build.gradle.kts b/build.gradle.kts index 61621f5..d048207 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("fabric-loom") version "0.10-SNAPSHOT" - id("io.github.juuxel.loom-quiltflower-mini") version "1.1.0" + id("io.github.juuxel.loom-quiltflower-mini") version "1.2.1" id("maven-publish") } @@ -31,19 +31,6 @@ base.archivesName.set(archives_base_name) version = mod_version group = maven_group -sourceSets { - val headers by creating { - java { - compileClasspath += main.get().compileClasspath - } - } - main { - java { - compileClasspath += headers.output - } - } -} - dependencies { // To change the versions see the gradle.properties file minecraft("com.mojang:minecraft:${minecraft_version}") @@ -71,10 +58,6 @@ tasks.withType { options.release.set(16) } -tasks.javadoc { - classpath += sourceSets["headers"].output -} - java { sourceCompatibility = JavaVersion.VERSION_16 targetCompatibility = JavaVersion.VERSION_16 diff --git a/src/headers/java/net/minecraft/client/ClientTelemetryManager.java b/src/headers/java/net/minecraft/client/ClientTelemetryManager.java deleted file mode 100644 index 6fd9aad..0000000 --- a/src/headers/java/net/minecraft/client/ClientTelemetryManager.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.minecraft.client; - -import net.minecraft.SharedConstants; - -/** - * This is a stub used by the mixin only. - */ -public class ClientTelemetryManager { - public ClientTelemetryManager() { - if (SharedConstants.isDevelopment) { - System.out.println("Is development"); - } - } -} diff --git a/src/main/java/de/kb1000/notelemetry/NoTelemetryMixinConfigPlugin.java b/src/main/java/de/kb1000/notelemetry/NoTelemetryMixinConfigPlugin.java index 9a471cb..51a1c19 100644 --- a/src/main/java/de/kb1000/notelemetry/NoTelemetryMixinConfigPlugin.java +++ b/src/main/java/de/kb1000/notelemetry/NoTelemetryMixinConfigPlugin.java @@ -1,5 +1,6 @@ package de.kb1000.notelemetry; +import net.fabricmc.loader.api.FabricLoader; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -14,12 +15,16 @@ public void onLoad(String mixinPackage) { @Override public String getRefMapperConfig() { - if (classExists("net.minecraftforge.fml.common.Mod")) { + if (isForge()) { return "no-telemetry-forge-refmap.json"; } return "no-telemetry-refmap.json"; } + private boolean isForge() { + return classExists("net.minecraftforge.fml.common.Mod") && !classExists("net.fabricmc.loader.api.FabricLoader"); + } + private static boolean classExists(String name) { try { return NoTelemetryMixinConfigPlugin.class.getClassLoader().loadClass(name) != null; @@ -33,9 +38,6 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { if (mixinClassName.equals("de.kb1000.notelemetry.mixin.NewYggdrasilUserApiServiceMixin")) { return classExists("com.mojang.authlib.yggdrasil.response.UserAttributesResponse$Privileges"); } - if (mixinClassName.equals("de.kb1000.notelemetry.mixin.TelemetrySenderMixin")) { - return classExists("net.minecraftforge.fml.common.Mod") == targetClassName.equals("net.minecraft.client.ClientTelemetryManager"); - } return true; } diff --git a/src/main/java/de/kb1000/notelemetry/mixin/TelemetrySenderMixin.java b/src/main/java/de/kb1000/notelemetry/mixin/TelemetrySenderMixin.java index 9a62e62..90e6491 100644 --- a/src/main/java/de/kb1000/notelemetry/mixin/TelemetrySenderMixin.java +++ b/src/main/java/de/kb1000/notelemetry/mixin/TelemetrySenderMixin.java @@ -2,15 +2,13 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.ClientTelemetryManager; -import net.minecraft.client.util.telemetry.TelemetrySender; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @Pseudo -@Mixin(value = {TelemetrySender.class, ClientTelemetryManager.class}) +@Mixin(targets = "net.minecraft.client.util.telemetry.TelemetrySender") @Environment(EnvType.CLIENT) public class TelemetrySenderMixin { @Redirect(method = "", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) diff --git a/src/main/resources/no-telemetry-forge-refmap.json b/src/main/resources/no-telemetry-forge-refmap.json index 8aba5f5..deeaabd 100644 --- a/src/main/resources/no-telemetry-forge-refmap.json +++ b/src/main/resources/no-telemetry-forge-refmap.json @@ -1,13 +1,15 @@ { "mappings": { "de/kb1000/notelemetry/mixin/TelemetrySenderMixin": { - "Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/SharedConstants;f_136183_:Z" + "Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/SharedConstants;f_136183_:Z", + "net.minecraft.client.util.telemetry.TelemetrySender": "net/minecraft/client/ClientTelemetryManager" } }, "data": { "searge": { "de/kb1000/notelemetry/mixin/TelemetrySenderMixin": { - "Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/SharedConstants;f_136183_:Z" + "Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/SharedConstants;f_136183_:Z", + "net.minecraft.client.util.telemetry.TelemetrySender": "net/minecraft/client/ClientTelemetryManager" } } }