Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with NeoForge and Mojmapped Forge #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/
plugins {
id("fabric-loom") version "1.6-SNAPSHOT"
id("fabric-loom") version "1.9.2"
`maven-publish`
}

Expand All @@ -24,6 +24,14 @@ repositories {
mavenPom()
}
}

maven(url = "https://maven.neoforged.net/releases") {
name = "NeoForge"
metadataSources {
ignoreGradleMetadataRedirection()
mavenPom()
}
}
}

val archives_base_name: String by project.ext
Expand All @@ -33,6 +41,7 @@ val minecraft_version: String by project.ext
val yarn_mappings: String by project.ext
val loader_version: String by project.ext
val forge_version: String by project.ext
val neofml_version: String by project.ext

base.archivesName.set(archives_base_name)
version = mod_version
Expand Down Expand Up @@ -62,6 +71,9 @@ dependencies {
compileOnly("net.minecraftforge:fmlloader:${forge_version}") {
isTransitive = false
}
compileOnly("net.neoforged.fancymodloader:loader:${neofml_version}") {
isTransitive = false
}
compileOnly("org.apache.maven:maven-artifact:3.8.7") {
isTransitive = false
}
Expand Down Expand Up @@ -119,7 +131,7 @@ tasks.jar {

manifest {
attributes(
"MixinConfigs" to "no-telemetry.mixins.json",
"MixinConfigs" to "no-telemetry-forge.mixins.json",
"Implementation-Version" to project.version,
)
}
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ loader_version=0.15.11
# Forge
forge_version=1.21-51.0.8

# NeoForge
neofml_version=4.0.34

# Mod Properties
mod_version=1.9.0
maven_group=de.kb1000
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 4 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
48 changes: 48 additions & 0 deletions reference/no-telemetry-hashed-refmap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"mappings": {
"de/kb1000/notelemetry/mixin/MinecraftClientMixin": {
"isTelemetryEnabledByApi()Z": "Lnet/minecraft/unmapped/C_ayfeobid;m_oussibsz()Z",
"net.minecraft.client.MinecraftClient": "net/minecraft/unmapped/C_ayfeobid"
},
"de/kb1000/notelemetry/mixin/OptionsScreenMixin": {
"Lnet/minecraft/client/gui/screen/option/OptionsScreen;TELEMETRY_TEXT:Lnet/minecraft/text/Text;": "Lnet/minecraft/unmapped/C_agyxinfj;f_bfgxwwch:Lnet/minecraft/unmapped/C_rdaqiwdt;",
"Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;": "Lnet/minecraft/unmapped/C_qykucwmu$C_iamgoveg;m_xrbojlyf(Lnet/minecraft/unmapped/C_dpukplka;)Lnet/minecraft/unmapped/C_dpukplka;",
"init": "Lnet/minecraft/unmapped/C_agyxinfj;m_xaqeivsh()V",
"net.minecraft.client.gui.screen.option.OptionsScreen": "net/minecraft/unmapped/C_agyxinfj"
},
"de/kb1000/notelemetry/mixin/Post1193TelemetryManagerMixin": {
"Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/unmapped/C_otltijcb;f_kgpztkbc:Z",
"Lnet/minecraft/client/MinecraftClient;isTelemetryEnabledByApi()Z": "Lnet/minecraft/unmapped/C_ayfeobid;m_oussibsz()Z",
"Lnet/minecraft/client/session/telemetry/TelemetryManager;computeSender": "net/minecraft/unmapped/C_cgkxybww;m_qsixfwvb()Lnet/minecraft/unmapped/C_wzhvxvch;",
"net.minecraft.client.session.telemetry.TelemetryManager": "net/minecraft/unmapped/C_cgkxybww"
},
"de/kb1000/notelemetry/mixin/Pre1193TelemetryManagerMixin": {
"Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/unmapped/C_otltijcb;f_kgpztkbc:Z",
"net.minecraft.client.session.telemetry.TelemetryManager": "net/minecraft/unmapped/C_cgkxybww"
}
},
"data": {
"named:intermediary": {
"de/kb1000/notelemetry/mixin/MinecraftClientMixin": {
"isTelemetryEnabledByApi()Z": "Lnet/minecraft/unmapped/C_ayfeobid;m_oussibsz()Z",
"net.minecraft.client.MinecraftClient": "net/minecraft/unmapped/C_ayfeobid"
},
"de/kb1000/notelemetry/mixin/OptionsScreenMixin": {
"Lnet/minecraft/client/gui/screen/option/OptionsScreen;TELEMETRY_TEXT:Lnet/minecraft/text/Text;": "Lnet/minecraft/unmapped/C_agyxinfj;f_bfgxwwch:Lnet/minecraft/unmapped/C_rdaqiwdt;",
"Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;": "Lnet/minecraft/unmapped/C_qykucwmu$C_iamgoveg;m_xrbojlyf(Lnet/minecraft/unmapped/C_dpukplka;)Lnet/minecraft/unmapped/C_dpukplka;",
"init": "Lnet/minecraft/unmapped/C_agyxinfj;m_xaqeivsh()V",
"net.minecraft.client.gui.screen.option.OptionsScreen": "net/minecraft/unmapped/C_agyxinfj"
},
"de/kb1000/notelemetry/mixin/Post1193TelemetryManagerMixin": {
"Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/unmapped/C_otltijcb;f_kgpztkbc:Z",
"Lnet/minecraft/client/MinecraftClient;isTelemetryEnabledByApi()Z": "Lnet/minecraft/unmapped/C_ayfeobid;m_oussibsz()Z",
"Lnet/minecraft/client/session/telemetry/TelemetryManager;computeSender": "net/minecraft/unmapped/C_cgkxybww;m_qsixfwvb()Lnet/minecraft/unmapped/C_wzhvxvch;",
"net.minecraft.client.session.telemetry.TelemetryManager": "net/minecraft/unmapped/C_cgkxybww"
},
"de/kb1000/notelemetry/mixin/Pre1193TelemetryManagerMixin": {
"Lnet/minecraft/SharedConstants;isDevelopment:Z": "Lnet/minecraft/unmapped/C_otltijcb;f_kgpztkbc:Z",
"net.minecraft.client.session.telemetry.TelemetryManager": "net/minecraft/unmapped/C_cgkxybww"
}
}
}
}
35 changes: 0 additions & 35 deletions src/main/java/de/kb1000/notelemetry/CommonUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/
package de.kb1000.notelemetry;

import org.objectweb.asm.tree.ClassNode;
Expand All @@ -15,32 +7,27 @@
import java.util.List;
import java.util.Set;

public class NoTelemetryMixinConfigPlugin implements IMixinConfigPlugin {
public abstract class NoTelemetryAbstractMixinConfigPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}

@Override
public String getRefMapperConfig() {
if (CommonUtil.isMojank() && CommonUtil.minecraftNewerThan("1.21")) {
return "no-telemetry-mojank-refmap.json";
} else if (CommonUtil.isMojank()) {
return "no-telemetry-mojank-1.20-refmap.json";
} else if (CommonUtil.isForge()) {
return "no-telemetry-forge-refmap.json";
}
return "no-telemetry-refmap.json";
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return switch (mixinClassName) {
case "de.kb1000.notelemetry.mixin.YggdrasilUserApiServiceMixin" ->
!this.minecraftNewerThan("1.18-beta.3");
case "de.kb1000.notelemetry.mixin.NewYggdrasilUserApiServiceMixin" ->
CommonUtil.classExists("com.mojang.authlib.yggdrasil.response.UserAttributesResponse$Privileges");
this.minecraftNewerThan("1.18-beta.3");
case "de.kb1000.notelemetry.mixin.Pre1193TelemetryManagerMixin" ->
!CommonUtil.minecraftNewerThan("1.19.3-alpha.22.46.a");
!this.minecraftNewerThan("1.19.3-alpha.22.46.a");
case "de.kb1000.notelemetry.mixin.MinecraftClientMixin", "de.kb1000.notelemetry.mixin.OptionsScreenMixin",
"de.kb1000.notelemetry.mixin.Post1193TelemetryManagerMixin" -> CommonUtil.minecraftNewerThan("1.19.3-alpha.22.46.a");
"de.kb1000.notelemetry.mixin.Post1193TelemetryManagerMixin" -> this.minecraftNewerThan("1.19.3-alpha.22.46.a");
default -> true;
};
}
Expand All @@ -56,11 +43,11 @@ public List<String> getMixins() {

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

protected abstract boolean minecraftNewerThan(String version);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import net.fabricmc.loader.api.SemanticVersion;
import net.fabricmc.loader.api.VersionParsingException;

public class FabricUtil {
public static boolean minecraftNewerThan(String version) {
public class NoTelemetryFabricAbstractMixinConfigPlugin extends NoTelemetryAbstractMixinConfigPlugin {
@Override
protected boolean minecraftNewerThan(String version) {
try {
return FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion().compareTo(SemanticVersion.parse(version)) >= 0;
} catch (VersionParsingException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/
package de.kb1000.notelemetry;

import net.minecraftforge.fml.loading.FMLLoader;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;

public class NoTelemetryForgeMixinConfigPlugin extends NoTelemetryAbstractMixinConfigPlugin {
private boolean isForgeNeo = false;

@Override
public void onLoad(String mixinPackage) {
this.isForgeNeo = isForgeNeo();
}

@Override
public String getRefMapperConfig() {
if (this.isForgeNeo) {
return null;
}

if (this.minecraftNewerThan("1.21")) {
return "no-telemetry-mojank-refmap.json";
} else if (this.minecraftNewerThan("1.20.5")) {
return "no-telemetry-mojank-1.20-refmap.json";
}

return "no-telemetry-forge-refmap.json";
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (this.isForgeNeo) {
return false;
}

return !this.isForgeNeo && super.shouldApplyMixin(targetClassName, mixinClassName);
}

@Override
protected boolean minecraftNewerThan(String version) {
try {
return VersionRange.createFromVersionSpec("[" + version + ",)").containsVersion(new DefaultArtifactVersion(FMLLoader.versionInfo().mcVersion()));
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
}

private static boolean isForgeNeo() {
try {
return NoTelemetryFabricAbstractMixinConfigPlugin.class.getClassLoader().loadClass("net.neoforged.fml.common.Mod") != null;
} catch (Exception | LinkageError e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@
*/
package de.kb1000.notelemetry;

import net.minecraftforge.fml.loading.FMLLoader;
import net.neoforged.fml.loading.FMLLoader;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;

public class ForgeUtil {
public static boolean minecraftNewerThan(String version) {
public class NoTelemetryNeoForgeAbstractMixinConfigPlugin extends NoTelemetryAbstractMixinConfigPlugin {
@Override
public String getRefMapperConfig() {
if (this.minecraftNewerThan("1.21")) {
return "no-telemetry-mojank-refmap.json";
} else {
return "no-telemetry-mojank-1.20-refmap.json";
}
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
// We can just use the mixin.json for this, for now!
return true;
}

protected boolean minecraftNewerThan(String version) {
try {
return VersionRange.createFromVersionSpec("[" + version + ",)").containsVersion(new DefaultArtifactVersion(FMLLoader.versionInfo().mcVersion()));
} catch (InvalidVersionSpecificationException e) {
Expand Down
Loading