generated from Legacy-Fabric/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make mixins apply to forge mods classes correctly
Fixes for CodeChickenCore and NEI NEI Plugins are not working currently
- Loading branch information
1 parent
5c753cc
commit 5f8b556
Showing
27 changed files
with
516 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies { | ||
modCompileOnly(group: "local", name: "CodeChickenCore", version: "0.6.5") | ||
modCompileOnly(group: "local", name: "NotEnoughItems", version: "1.4.0.5") | ||
} |
9 changes: 9 additions & 0 deletions
9
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/Dummy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fr.catcore.fabricatedforge.compat; | ||
|
||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; | ||
|
||
public class Dummy implements PreLaunchEntrypoint { | ||
@Override | ||
public void onPreLaunch() { | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/ExtraRemapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fr.catcore.fabricatedforge.compat; | ||
|
||
import fr.catcore.modremapperapi.api.ModRemapper; | ||
import fr.catcore.modremapperapi.remapping.RemapUtil; | ||
import fr.catcore.modremapperapi.remapping.VisitorInfos; | ||
import org.spongepowered.asm.mixin.MixinEnvironment; | ||
import org.spongepowered.asm.mixin.Mixins; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ExtraRemapper implements ModRemapper { | ||
@Override | ||
public String[] getJarFolders() { | ||
return new String[0]; | ||
} | ||
|
||
@Override | ||
public Map<String, List<String>> getExclusions() { | ||
return new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void getMappingList(RemapUtil.MappingList mappingList) { | ||
|
||
} | ||
|
||
@Override | ||
public void registerVisitors(VisitorInfos visitorInfos) { | ||
|
||
} | ||
|
||
@Override | ||
public void afterRemap() { | ||
Mixins.addConfiguration("fabricated-forge.mods.mixins.json"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...in/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassDiscovererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package fr.catcore.fabricatedforge.compat.mixin.codechickencore; | ||
|
||
import codechicken.core.ClassDiscoverer; | ||
import fr.catcore.fabricatedforge.Constants; | ||
import net.minecraft.ModLoader; | ||
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; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
|
||
@Mixin(ClassDiscoverer.class) | ||
public abstract class ClassDiscovererMixin { | ||
@Shadow(remap = false) protected abstract void readFromDirectory(File directory, File basedirectory); | ||
|
||
@Shadow(remap = false) protected abstract void readFromZipFile(File file) throws IOException; | ||
|
||
@Shadow(remap = false) protected abstract void findModDirMods() throws IOException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException; | ||
|
||
@Inject(method = "findModDirMods", cancellable = true, at = @At("HEAD"), remap = false) | ||
private void fixFindModDirMods(CallbackInfo ci) throws IOException { | ||
for(File child : new File[]{Constants.COREMODS_FOLDER, Constants.MODS_FOLDER}) { | ||
if (!child.isFile() || !child.getName().endsWith(".jar") && !child.getName().endsWith(".zip")) { | ||
if (child.isDirectory()) { | ||
this.readFromDirectory(child, child); | ||
} | ||
} else { | ||
this.readFromZipFile(child); | ||
} | ||
} | ||
|
||
ci.cancel(); | ||
} | ||
|
||
@Inject(method = "findClasses", at = @At("RETURN"), remap = false) | ||
private void lookForModsToo(CallbackInfoReturnable<ArrayList> cir) { | ||
try { | ||
this.findModDirMods(); | ||
} catch (Exception var2) { | ||
ModLoader.throwException("Code Chicken Core", var2); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...va/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassHeirachyManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../main/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/ClassMappingMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package fr.catcore.fabricatedforge.compat.mixin.codechickencore; | ||
|
||
import codechicken.core.asm.ObfuscationManager; | ||
import fr.catcore.fabricatedforge.Constants; | ||
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 (!this.classname.contains(".")) { | ||
this.classname = Constants.getRemappedClassName(this.classname); | ||
} | ||
} | ||
} |
Oops, something went wrong.