Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/1.4.2-forge' into 1…
Browse files Browse the repository at this point in the history
….4.3-forge

# Conflicts:
#	gradle.properties
#	mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java
#	mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/FieldMappingMixin.java
#	mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/MethodMappingMixin.java
  • Loading branch information
thecatcore committed Apr 17, 2024
2 parents bb61298 + ea43102 commit 409add7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 110 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.+"
}
Expand All @@ -27,6 +27,7 @@ allprojects {
group = project.maven_group

repositories {
mavenLocal()
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ org.gradle.jvmargs=-Xmx2G
# Fabric Properties
minecraft_version = 1.4.3
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 = 6.2.1.358
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
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.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -80,13 +77,13 @@ public boolean processLine(String input) throws IOException {
m.setTargetAccess((String)parts.get(0));
List<String> 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";
Expand All @@ -98,16 +95,16 @@ public boolean processLine(String input) throws IOException {
String nameReference = descriptor.get(1);
int parenIdx = nameReference.indexOf(40);
if (parenIdx > 0) {
Pair<String, String> 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;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/cpw/mods/fml/relauncher/ReflectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -82,6 +82,7 @@ public static Class<? super Object> getClass(ClassLoader loader, String... class
{
try
{
className = MappingUtils.mapClass(className);
return (Class<? super Object>) Class.forName(className, false, ReflectionHelper.class.getClassLoader());
}
catch (Exception e)
Expand All @@ -99,7 +100,7 @@ public static <E> Method findMethod(Class<? super E> 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;
Expand Down
93 changes: 11 additions & 82 deletions src/main/java/fr/catcore/fabricatedforge/Constants.java
Original file line number Diff line number Diff line change
@@ -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.4.3-6.2.1.358/forge-1.4.3-6.2.1.358-universal.zip";
Expand All @@ -24,85 +15,23 @@ public class Constants {
COREMODS_FOLDER.mkdirs();
}

public static Pair<String, String> 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<String, String> 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<String, String> 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);
}
}

0 comments on commit 409add7

Please sign in to comment.