From c0a2e21ee103897edf258d5b00c2edbc3f27092e Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 17 Apr 2024 19:26:03 +0200 Subject: [PATCH 1/2] Update to MRAPI 1.19 and dependencies, Fix crash on Loader 0.15+ --- build.gradle | 12 +-- gradle.properties | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../codechickencore/ClassMappingMixin.java | 2 +- .../codechickencore/FieldMappingMixin.java | 10 +- .../codechickencore/MethodMappingMixin.java | 10 +- .../asm/transformers/AccessTransformer.java | 25 +++-- .../mods/fml/relauncher/ReflectionHelper.java | 7 +- .../fr/catcore/fabricatedforge/Constants.java | 93 +++---------------- 9 files changed, 48 insertions(+), 121 deletions(-) diff --git a/build.gradle b/build.gradle index 29b3b43e..965f21e7 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ import com.diffplug.gradle.spotless.JavaExtension plugins { id 'java-library' id 'com.diffplug.spotless' version "6.12.0" - id 'fabric-loom' version "1.3-SNAPSHOT" apply false // To use chocoloom, change the version to a commit hash - id 'legacy-looming' version "1.3-SNAPSHOT" apply false // Version must be the same as fabric-loom's + id 'fabric-loom' version "1.6-SNAPSHOT" apply false // To use chocoloom, change the version to a commit hash + id 'legacy-looming' version "1.6-SNAPSHOT" apply false // Version must be the same as fabric-loom's id 'maven-publish' id "com.modrinth.minotaur" version "2.+" } @@ -27,6 +27,7 @@ allprojects { group = project.maven_group repositories { + mavenLocal() maven { name = "Modrinth" url = "https://api.modrinth.com/maven" @@ -52,7 +53,7 @@ allprojects { modApi("maven.modrinth:mod-remapping-api:${project.mod_remapping_api}") modApi("maven.modrinth:spasm:${project.spasm_version}") - implementation(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}")) + implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}")) implementation(group: "local", name: "argo", version: "2.25") implementation(group: "local", name: "guava", version: "12.0.1") @@ -167,9 +168,8 @@ modrinth { projectId = "JpHZ1Cyv" // This can be the project ID or the slug. Either will work! versionName = displayVersion changelog = """ -Update MRAPI to 1.15.0.\\ -ClassTransformers now run after mixins are applied on a class instead of before, improving compatibility with ClassTransformers by a lot.\\ -Some more improvements on NEI Compatibility. +Update MRAPI to 1.19.0.\\ +Fix crash on Fabric Loader 0.15+.\\ """ uploadFile = remapJar gameVersions = [project.minecraft_version] // Must be an array, even with only one version diff --git a/gradle.properties b/gradle.properties index 52f404d2..45d55f70 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,15 +6,15 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties minecraft_version = 1.3.2 yarn_mappings = 451 - loader_version = 0.14.22 + loader_version = 0.15.10 # Legacy Fabric API - mod_remapping_api = 1.15.0 + mod_remapping_api = 1.19.0 forge_version = 4.3.5.318 - mixin_extras_version=0.2.0-beta.10 + mixin_extras_version=0.2.1 spasm_version=0.2 # Mod Properties - mod_version = 2.6.1 + mod_version = 2.6.2 maven_group = fr.catcore archives_base_name = fabricated-forge diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9f4197d5..b82aa23a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java index c7edac02..dd4732d5 100644 --- a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java +++ b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java @@ -15,7 +15,7 @@ public class ClassMappingMixin { @Inject(method = "", remap = false, at = @At("RETURN")) private void remapClassName(String classname, CallbackInfo ci) { if (!this.classname.contains(".")) { - this.classname = Constants.getRemappedClassName(this.classname); + this.classname = Constants.mapClass(this.classname); } } } diff --git a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java index 02aa27b3..b277c3c2 100644 --- a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java +++ b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java @@ -2,7 +2,7 @@ import codechicken.core.asm.ObfuscationManager; import fr.catcore.fabricatedforge.Constants; -import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -20,10 +20,10 @@ public class FieldMappingMixin { @Inject(method = "", at = @At("RETURN"), remap = false) private void remap(String declaringclass, String fieldname, String type, CallbackInfo ci) { if (!this.owner.contains(".")) { - this.owner = Constants.getRemappedClassName(this.owner); + this.owner = Constants.mapClass(this.owner); } - Pair pair = Constants.getRemappedFieldName(this.owner, this.name, this.type); - this.name = pair.first(); - this.type = pair.second(); + MappingUtils.ClassMember pair = Constants.mapFieldFromRemappedClass(this.owner, this.name, this.type); + this.name = pair.name; + this.type = pair.desc; } } diff --git a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java index 4cccb5e5..9a4800e5 100644 --- a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java +++ b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java @@ -2,7 +2,7 @@ import codechicken.core.asm.ObfuscationManager; import fr.catcore.fabricatedforge.Constants; -import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -31,10 +31,10 @@ private void remap(String declaringclass, ObfuscationManager.MethodMapping metho @Unique private void remap() { if (!this.owner.contains(".")) { - this.owner = Constants.getRemappedClassName(this.owner); + this.owner = Constants.mapClass(this.owner); } - Pair pair = Constants.getRemappedMethodName(this.owner, this.name, this.desc); - this.name = pair.first(); - this.desc = pair.second(); + MappingUtils.ClassMember pair = Constants.mapMethodFromRemappedClass(this.owner, this.name, this.desc); + this.name = pair.name; + this.desc = pair.desc; } } diff --git a/src/main/java/cpw/mods/fml/common/asm/transformers/AccessTransformer.java b/src/main/java/cpw/mods/fml/common/asm/transformers/AccessTransformer.java index b1e5912d..a187c40d 100644 --- a/src/main/java/cpw/mods/fml/common/asm/transformers/AccessTransformer.java +++ b/src/main/java/cpw/mods/fml/common/asm/transformers/AccessTransformer.java @@ -23,9 +23,7 @@ import com.google.common.io.Resources; import cpw.mods.fml.relauncher.IClassTransformer; import fr.catcore.fabricatedforge.Constants; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.impl.launch.FabricLauncherBase; -import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; @@ -36,7 +34,6 @@ import java.net.URL; import java.util.Collection; import java.util.List; -import java.util.NoSuchElementException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -81,13 +78,13 @@ public boolean processLine(String input) throws IOException { m.setTargetAccess((String)parts.get(0)); List descriptor = Lists.newArrayList(Splitter.on(".").trimResults().split((CharSequence)parts.get(1))); - String className = ((String)descriptor.get(0)).replace('/', '.'); + String className = descriptor.get(0); String finalClassName = className; try { - className = FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings().getClasses().stream() - .filter(classDef -> classDef.getName("official").equals(finalClassName)).findFirst().get() - .getName(FabricLoader.getInstance().getMappingResolver().getCurrentRuntimeNamespace()); - } catch (NullPointerException | NoSuchElementException ignored) {} + className = Constants.mapClass(finalClassName); + } catch (NullPointerException ignored) { + ignored.printStackTrace(); + } if (className.equals("net")) { className = "net.minecraft.client.Minecraft"; @@ -99,16 +96,16 @@ public boolean processLine(String input) throws IOException { String nameReference = descriptor.get(1); int parenIdx = nameReference.indexOf(40); if (parenIdx > 0) { - Pair o = Constants.getRemappedMethodNameNative(className, + MappingUtils.ClassMember o = Constants.mapMethod(className, nameReference.substring(0, parenIdx), nameReference.substring(parenIdx)); - m.desc = o.second(); - m.name = o.first(); + m.desc = o.desc; + m.name = o.name; } else { - m.name = Constants.getRemappedFieldNameNative(className, nameReference); + m.name = Constants.mapField(className, nameReference).name; } } - AccessTransformer.this.modifiers.put(className, m); + AccessTransformer.this.modifiers.put(className.replace("/", "."), m); return true; } } diff --git a/src/main/java/cpw/mods/fml/relauncher/ReflectionHelper.java b/src/main/java/cpw/mods/fml/relauncher/ReflectionHelper.java index c92f7de3..e828aea4 100644 --- a/src/main/java/cpw/mods/fml/relauncher/ReflectionHelper.java +++ b/src/main/java/cpw/mods/fml/relauncher/ReflectionHelper.java @@ -13,7 +13,7 @@ */ package cpw.mods.fml.relauncher; -import fr.catcore.modremapperapi.remapping.RemapUtil; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -28,7 +28,7 @@ public static Field findField(Class clazz, String... fieldNames) { { try { - fieldName = RemapUtil.getRemappedFieldName(clazz, fieldName); + fieldName = MappingUtils.mapField(clazz, fieldName).name; Field f = clazz.getDeclaredField(fieldName); f.setAccessible(true); return f; @@ -83,6 +83,7 @@ public static Class getClass(ClassLoader loader, String... class { try { + className = MappingUtils.mapClass(className); return (Class) Class.forName(className, false, ReflectionHelper.class.getClassLoader()); } catch (Exception e) @@ -100,7 +101,7 @@ public static Method findMethod(Class clazz, E instance, String[] { try { - methodName = RemapUtil.getRemappedMethodName(clazz, methodName, methodTypes); + methodName = MappingUtils.mapMethod(clazz, methodName, methodTypes).name; Method m = clazz.getDeclaredMethod(methodName, methodTypes); m.setAccessible(true); return m; diff --git a/src/main/java/fr/catcore/fabricatedforge/Constants.java b/src/main/java/fr/catcore/fabricatedforge/Constants.java index 793721b3..eaf66925 100644 --- a/src/main/java/fr/catcore/fabricatedforge/Constants.java +++ b/src/main/java/fr/catcore/fabricatedforge/Constants.java @@ -1,17 +1,8 @@ package fr.catcore.fabricatedforge; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.MappingResolver; -import net.fabricmc.loader.impl.launch.FabricLauncherBase; -import net.fabricmc.mapping.tree.ClassDef; -import net.fabricmc.mapping.tree.FieldDef; -import net.fabricmc.mapping.tree.MethodDef; -import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import java.io.File; -import java.util.Objects; - -import static fr.catcore.modremapperapi.remapping.RemapUtil.getNativeNamespace; public class Constants { public static final String FORGE_URL = "https://maven.minecraftforge.net/net/minecraftforge/forge/1.3.2-4.3.5.318/forge-1.3.2-4.3.5.318-universal.zip"; @@ -24,85 +15,23 @@ public class Constants { COREMODS_FOLDER.mkdirs(); } - public static Pair getRemappedMethodNameNative(String owner, String methodName, String argDesc) { - MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); - - for(ClassDef def : FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings().getClasses()) { - if (def.getName(getNativeNamespace()).replace(".", "/").equals(owner.replace(".", "/"))) { - for(MethodDef methodDef : def.getMethods()) { - if (Objects.equals(methodDef.getName(getNativeNamespace()), methodName)) { - String methodDescriptor = methodDef.getDescriptor(getNativeNamespace()); - if (methodDescriptor.startsWith(argDesc)) { - return Pair.of(methodDef.getName(resolver.getCurrentRuntimeNamespace()), methodDef.getDescriptor(resolver.getCurrentRuntimeNamespace())); - } - } - } - } - } - - return Pair.of(methodName, argDesc); + public static MappingUtils.ClassMember mapMethod(String owner, String methodName, String argDesc) { + return MappingUtils.mapMethod(owner.replace(".", "/"), methodName, argDesc); } - public static Pair getRemappedMethodName(String owner, String methodName, String argDesc) { - MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); - - for(ClassDef def : FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings().getClasses()) { - if (def.getName(resolver.getCurrentRuntimeNamespace()).replace(".", "/").equals(owner.replace(".", "/"))) { - for(MethodDef methodDef : def.getMethods()) { - if (Objects.equals(methodDef.getName(getNativeNamespace()), methodName)) { - String methodDescriptor = methodDef.getDescriptor(getNativeNamespace()); - if (methodDescriptor.startsWith(argDesc)) { - return Pair.of(methodDef.getName(resolver.getCurrentRuntimeNamespace()), methodDef.getDescriptor(resolver.getCurrentRuntimeNamespace())); - } - } - } - } - } - - return Pair.of(methodName, argDesc); + public static MappingUtils.ClassMember mapMethodFromRemappedClass(String owner, String methodName, String argDesc) { + return MappingUtils.mapMethodFromRemappedClass(owner.replace(".", "/"), methodName, argDesc); } - public static String getRemappedClassName(String name) { - MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); - - for(ClassDef def : FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings().getClasses()) { - if (def.getName(getNativeNamespace()).replace(".", "/").equals(name.replace(".", "/"))) { - return def.getName(resolver.getCurrentRuntimeNamespace()).replace("/", "."); - } - } - - return name.replace("/", "."); + public static String mapClass(String className) { + return MappingUtils.mapClass(className.replace(".", "/")).replace("/", "."); } - public static String getRemappedFieldNameNative(String owner, String fieldName) { - MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); - - for(ClassDef def : FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings().getClasses()) { - if (def.getName(getNativeNamespace()).replace(".", "/").equals(owner.replace(".", "/"))) { - for(FieldDef fieldDef : def.getFields()) { - if (Objects.equals(fieldDef.getName(getNativeNamespace()), fieldName)) { - return fieldDef.getName(resolver.getCurrentRuntimeNamespace()); - } - } - } - } - - return fieldName; + public static MappingUtils.ClassMember mapField(String owner, String fieldName) { + return MappingUtils.mapField(owner.replace(".", "/"), fieldName, null); } - public static Pair getRemappedFieldName(String owner, String fieldName, String fieldDesc) { - MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); - - for(ClassDef def : FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings().getClasses()) { - if (def.getName(resolver.getCurrentRuntimeNamespace()).replace(".", "/").equals(owner.replace(".", "/"))) { - for(FieldDef fieldDef : def.getFields()) { - if (Objects.equals(fieldDef.getName(getNativeNamespace()), fieldName)) { - return Pair.of(fieldDef.getName(resolver.getCurrentRuntimeNamespace()), fieldDef.getDescriptor(resolver.getCurrentRuntimeNamespace())); - } - } - } - } - - return Pair.of(fieldName, fieldDesc); + public static MappingUtils.ClassMember mapFieldFromRemappedClass(String owner, String fieldName, String fieldDesc) { + return MappingUtils.mapFieldFromRemappedClass(owner.replace(".", "/"), fieldName, fieldDesc); } } From ea43102fd8f642ae94972412f25625532387ff8a Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 17 Apr 2024 20:06:11 +0200 Subject: [PATCH 2/2] Update CodeChickenCore compat --- .../mixin/codechickencore/ClassMappingMixin.java | 2 +- .../mixin/codechickencore/FieldMappingMixin.java | 10 +++++----- .../mixin/codechickencore/MethodMappingMixin.java | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java index 99d0ca35..8dcdcd6f 100644 --- a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java +++ b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java @@ -18,7 +18,7 @@ private void remapClassName(String classname, CallbackInfo ci) { if (NEIFixer.FIX_CLASSES.containsKey(classname)) { this.classname = NEIFixer.FIX_CLASSES.get(classname); } else if (!this.classname.contains(".")) { - this.classname = Constants.getRemappedClassName(this.classname); + this.classname = Constants.mapClass(this.classname); } } } diff --git a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java index 02aa27b3..b277c3c2 100644 --- a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java +++ b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java @@ -2,7 +2,7 @@ import codechicken.core.asm.ObfuscationManager; import fr.catcore.fabricatedforge.Constants; -import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -20,10 +20,10 @@ public class FieldMappingMixin { @Inject(method = "", at = @At("RETURN"), remap = false) private void remap(String declaringclass, String fieldname, String type, CallbackInfo ci) { if (!this.owner.contains(".")) { - this.owner = Constants.getRemappedClassName(this.owner); + this.owner = Constants.mapClass(this.owner); } - Pair pair = Constants.getRemappedFieldName(this.owner, this.name, this.type); - this.name = pair.first(); - this.type = pair.second(); + MappingUtils.ClassMember pair = Constants.mapFieldFromRemappedClass(this.owner, this.name, this.type); + this.name = pair.name; + this.type = pair.desc; } } diff --git a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java index a63f46d2..43d24a88 100644 --- a/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java +++ b/mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java @@ -3,7 +3,7 @@ import codechicken.core.asm.ObfuscationManager; import fr.catcore.fabricatedforge.Constants; import fr.catcore.fabricatedforge.compat.nei.NEIFixer; -import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair; +import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -34,21 +34,21 @@ private void remap() { if (NEIFixer.FIX_CLASSES.containsKey(this.owner)) { this.owner = NEIFixer.FIX_CLASSES.get(this.owner); } else if (!this.owner.contains(".")) { - this.owner = Constants.getRemappedClassName(this.owner); + this.owner = Constants.mapClass(this.owner); } - Pair pair = Constants.getRemappedMethodName(this.owner, this.name, this.desc); + MappingUtils.ClassMember pair = Constants.mapMethodFromRemappedClass(this.owner, this.name, this.desc); if (NEIFixer.FIX_METHOD_NAMES.containsKey(this.name)) { this.name = NEIFixer.FIX_METHOD_NAMES.get(this.name); } else { - this.name = pair.first(); + this.name = pair.name; } if (NEIFixer.FIX_METHOD_ARGS.containsKey(this.desc)) { this.desc = NEIFixer.FIX_METHOD_ARGS.get(this.desc); } else { - this.desc = pair.second(); + this.desc = pair.desc; } } }