Skip to content

Commit

Permalink
CodeChickenCore and NEI compat for 1.4.2
Browse files Browse the repository at this point in the history
Please use CCC 0.6.6.2 and NEI 1.4.1.2 as more recent versions are broken.
  • Loading branch information
thecatcore committed Aug 17, 2023
1 parent 7b3d29b commit 576ad27
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 77 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ allprojects {
// modRuntimeOnly(files("./forge-${project.minecraft_version}-${project.forge_version}-universal-intermediary.jar"))
}

base {
archivesName = project.archives_base_name + "-" + project.minecraft_version
}

processResources {
inputs.property "version", project.version

Expand Down Expand Up @@ -100,6 +96,10 @@ allprojects {
}
}

base {
archivesName = project.archives_base_name + "-" + project.minecraft_version
}

loom {
accessWidenerPath = file("src/main/resources/fabricated-forge.accesswidener")
}
Expand Down
Binary file added lib/CodeChickenCore-0.6.12.jar
Binary file not shown.
Binary file modified lib/NotEnoughItems-1.4.2.1.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions mod-compat/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
//project.name = "fabricated-forge-mod-compat"

dependencies {
// How to add a mod
// add the intermediary jar of the mod in rootfolder/lib with a dummy fabric.mod.json file in it
// if the file is named like "filename-fileversion.jar" then import it this way:
// modCompileOnly(group: "local", name: "filename", version: "fileversion")
modCompileOnly(group: "local", name: "CodeChickenCore", version: "0.6.12")
modCompileOnly(group: "local", name: "NotEnoughItems", version: "1.4.2.1")
}

base {
archivesName = "fabricated-forge-mod-compat"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.catcore.fabricatedforge.compat;

import fr.catcore.fabricatedforge.util.Utils;
import fr.catcore.modremapperapi.api.ModRemapper;
import fr.catcore.modremapperapi.remapping.RemapUtil;
import fr.catcore.modremapperapi.remapping.VisitorInfos;
Expand Down Expand Up @@ -34,5 +35,6 @@ public void registerVisitors(VisitorInfos visitorInfos) {
@Override
public void afterRemap() {
Mixins.addConfiguration("fabricated-forge.mods.mixins.json");
Utils.TRANSFORMER_EXCLUSIONS.add("fr.catcore.fabricatedforge.compat.nei.NEIFixer");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.catcore.fabricatedforge.compat.mixin.codechickencore;

import codechicken.core.asm.ClassHeirachyManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ClassHeirachyManager.class)
public class ClassHeirachyManagerMixin {
@Redirect(method = "classExtends(Ljava/lang/String;Ljava/lang/String;)Z", at = @At(value = "INVOKE", target = "Ljava/lang/Class;forName(Ljava/lang/String;)Ljava/lang/Class;", remap = false), remap = false)
private static Class<?> fixClassExtends(String className) throws ClassNotFoundException {
return Class.forName(className, false, ClassHeirachyManager.class.getClassLoader());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.catcore.fabricatedforge.compat.mixin.codechickencore;

import codechicken.core.asm.ObfuscationManager;
import fr.catcore.fabricatedforge.Constants;
import fr.catcore.fabricatedforge.compat.nei.NEIFixer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ObfuscationManager.ClassMapping.class)
public class ClassMappingMixin {
@Shadow(remap = false) public String classname;

@Inject(method = "<init>", remap = false, at = @At("RETURN"))
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.catcore.fabricatedforge.compat.mixin.codechickencore;

import codechicken.core.asm.ClassOverrider;
import codechicken.core.asm.ObfuscationManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.io.File;

@Mixin(ClassOverrider.class)
public class ClassOverriderMixin {
@Inject(method = "overrideBytes", remap = false, at = @At("HEAD"), cancellable = true)
private static void disableClassOverwriting(String name, byte[] bytes, ObfuscationManager.ClassMapping classMapping, File location, CallbackInfoReturnable<byte[]> cir) {
if (classMapping.classname.equals(name)) {
System.out.println("[ClassOverrider] Canceled class overwrite of " + name);
}

cir.setReturnValue(bytes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fr.catcore.fabricatedforge.compat.mixin.codechickencore;

import codechicken.core.asm.ObfuscationManager;
import fr.catcore.fabricatedforge.Constants;
import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ObfuscationManager.FieldMapping.class)
public class FieldMappingMixin {
@Shadow(remap = false) public String owner;

@Shadow(remap = false) public String name;

@Shadow(remap = false) public String type;

@Inject(method = "<init>", 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);
}
Pair<String, String> pair = Constants.getRemappedFieldName(this.owner, this.name, this.type);
this.name = pair.first();
this.type = pair.second();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fr.catcore.fabricatedforge.compat.mixin.codechickencore;

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 org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ObfuscationManager.MethodMapping.class)
public class MethodMappingMixin {
@Shadow(remap = false) public String owner;

@Shadow(remap = false) public String name;

@Shadow(remap = false) public String desc;

@Inject(method = "<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", remap = false, at = @At("RETURN"))
private void remap(String declaringclass, String methodname, String descriptor, CallbackInfo ci) {
this.remap();
}

@Inject(method = "<init>(Ljava/lang/String;Lcodechicken/core/asm/ObfuscationManager$MethodMapping;)V", remap = false, at = @At("RETURN"))
private void remap(String declaringclass, ObfuscationManager.MethodMapping methodmap, CallbackInfo ci) {
this.remap();
}

@Unique
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);
}

Pair<String, String> pair = Constants.getRemappedMethodName(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();
}

if (NEIFixer.FIX_METHOD_ARGS.containsKey(this.desc)) {
this.desc = NEIFixer.FIX_METHOD_ARGS.get(this.desc);
} else {
this.desc = pair.second();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.catcore.fabricatedforge.compat.mixin.nei;

import codechicken.nei.recipe.FurnaceRecipeHandler;
import fr.catcore.modremapperapi.remapping.RemapUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.lang.reflect.Method;

@Mixin(FurnaceRecipeHandler.class)
public class FurnaceRecipeHandlerMixin {
@Redirect(method = "findFuels", remap = false, at = @At(value = "INVOKE", target = "Ljava/lang/Class;getDeclaredMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"))
private static Method fixFindFuels(Class<?> instance, String name, Class<?>[] parameterTypes) throws NoSuchMethodException {
name = RemapUtil.getRemappedMethodName(instance, name, parameterTypes);

return instance.getDeclaredMethod(name, parameterTypes);
}
}
Loading

0 comments on commit 576ad27

Please sign in to comment.