Skip to content

Commit

Permalink
Add compatibility with NeoForge and Mojmap Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Jan 1, 2025
1 parent 1f4690a commit 94df1fe
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 49 deletions.
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-SNAPSHOT"
`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.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 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,8 @@ 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
' "$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"
}
}
}
}
18 changes: 3 additions & 15 deletions src/main/java/de/kb1000/notelemetry/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@
package de.kb1000.notelemetry;

class CommonUtil {
static boolean isNeoForge() {
return false; // TODO
}

static boolean isForge() {
return classExists("net.minecraftforge.fml.common.Mod") && !classExists("net.fabricmc.loader.api.FabricLoader");
}

static boolean isMojank() {
return isNeoForge() || (isForge() && minecraftNewerThan("1.20.5"));
static boolean isForgeNeo() {
return classExists("net.neoforged.fml.common.Mod");
}

static boolean classExists(String name) {
try {
return NoTelemetryMixinConfigPlugin.class.getClassLoader().loadClass(name) != null;
return NoTelemetryFabricMixinConfigPlugin.class.getClassLoader().loadClass(name) != null;
} catch (Exception | LinkageError e) {
return false;
}
}

static boolean minecraftNewerThan(String version) {
return isForge() ? ForgeUtil.minecraftNewerThan(version) : FabricUtil.minecraftNewerThan(version);
}
}
24 changes: 24 additions & 0 deletions src/main/java/de/kb1000/notelemetry/NeoForgeUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.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 NeoForgeUtil {
public static boolean minecraftNewerThan(String version) {
try {
return VersionRange.createFromVersionSpec("[" + version + ",)").containsVersion(new DefaultArtifactVersion(FMLLoader.versionInfo().mcVersion()));
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,27 @@
import java.util.List;
import java.util.Set;

public class NoTelemetryMixinConfigPlugin implements IMixinConfigPlugin {
public class NoTelemetryFabricMixinConfigPlugin 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" ->
!FabricUtil.minecraftNewerThan("1.18-beta.3");
case "de.kb1000.notelemetry.mixin.NewYggdrasilUserApiServiceMixin" ->
CommonUtil.classExists("com.mojang.authlib.yggdrasil.response.UserAttributesResponse$Privileges");
FabricUtil.minecraftNewerThan("1.18-beta.3");
case "de.kb1000.notelemetry.mixin.Pre1193TelemetryManagerMixin" ->
!CommonUtil.minecraftNewerThan("1.19.3-alpha.22.46.a");
!FabricUtil.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" -> FabricUtil.minecraftNewerThan("1.19.3-alpha.22.46.a");
default -> true;
};
}
Expand All @@ -56,11 +51,9 @@ 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) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class NoTelemetryForgeMixinConfigPlugin implements IMixinConfigPlugin {
private boolean isForgeNeo = false;

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

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

if (ForgeUtil.minecraftNewerThan("1.21")) {
return "no-telemetry-mojank-refmap.json";
} else if (ForgeUtil.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 (isForgeNeo) {
return false;
}

return switch (mixinClassName) {
// You can't use snapshots on Forge!
case "de.kb1000.notelemetry.mixin.YggdrasilUserApiServiceMixin" -> false;
case "de.kb1000.notelemetry.mixin.Pre1193TelemetryManagerMixin" ->
!ForgeUtil.minecraftNewerThan("1.19.3-alpha.22.46.a");
case "de.kb1000.notelemetry.mixin.MinecraftClientMixin", "de.kb1000.notelemetry.mixin.OptionsScreenMixin",
"de.kb1000.notelemetry.mixin.Post1193TelemetryManagerMixin" -> ForgeUtil.minecraftNewerThan("1.19.3-alpha.22.46.a");
default -> true;
};
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return null;
}

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

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

0 comments on commit 94df1fe

Please sign in to comment.