Skip to content

Commit

Permalink
Future-proof Forge/Fabric compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-1000 committed Feb 4, 2022
1 parent 86dbf9c commit b311cee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 41 deletions.
19 changes: 1 addition & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}

Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -71,10 +58,6 @@ tasks.withType<JavaCompile> {
options.release.set(16)
}

tasks.javadoc {
classpath += sourceSets["headers"].output
}

java {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
Expand Down
14 changes: 0 additions & 14 deletions src/headers/java/net/minecraft/client/ClientTelemetryManager.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/no-telemetry-forge-refmap.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Expand Down

0 comments on commit b311cee

Please sign in to comment.