Skip to content

Commit

Permalink
Merge pull request #9
Browse files Browse the repository at this point in the history
Improve compatibility with Fabricated Legacy Forge
  • Loading branch information
tildejustin authored Nov 2, 2024
2 parents e686592 + 840344e commit ed762f8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.modmuss50.optifabric.mixin;

import net.fabricmc.loader.api.FabricLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

/* Optifine 1.4.3+ */
@Pseudo
@Mixin(targets = "ReflectorClass")
public abstract class ReflectorClassMixin {
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "getTargetClass", at = @At(value = "INVOKE", target = "Ljava/lang/Class;forName(Ljava/lang/String;)Ljava/lang/Class;", remap = false), remap = false)
private Class fixClassNameForFabricatedForge(String className) throws ClassNotFoundException {
try {
return Class.forName(className);
} catch (ClassNotFoundException exception) {
if (FabricLoader.getInstance().isModLoaded("fabricated-forge")) {
return Class.forName("net.minecraft." + className);
} else {
throw exception;
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.modmuss50.optifabric.mixin;

import net.fabricmc.loader.api.FabricLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.Map;

/* Optifine 1.3-1.4.2 */
@Pseudo
@Mixin(targets = "Reflector")
public class ReflectorMixin {
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "getClassNameMap", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", remap = false), remap = false)
private static Object fixClassNameForFabricatedForge(Map map, Object key, Object value) {
if (FabricLoader.getInstance().isModLoaded("fabricated-forge")) {
if (value instanceof String && !((String) value).contains(".")) {
value = "net.minecraft." + value;
}
}

return map.put(key, value);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.modmuss50.optifabric.mixin;

import me.modmuss50.optifabric.mod.*;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.*;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -18,7 +19,7 @@ private void init(CallbackInfo info) {

@Inject(method = "render", at = @At("RETURN"))
private void render(CallbackInfo ci) {
if (!Optifabric.hasError()) {
if (!Optifabric.hasError() && !FabricLoader.getInstance().isModLoaded("fabricated-forge")) {
this.drawWithShadow(Minecraft.getMinecraft().textRenderer, OptifineVersion.version, 2, this.height - 20, 0xFFFFFFFF);
}
}
Expand Down
9 changes: 9 additions & 0 deletions 1.3-1.5.2/src/main/resources/optifabric.optifine.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"required": true,
"package": "me.modmuss50.optifabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ReflectorClassMixin",
"ReflectorMixin"
]
}
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"depends": {
"fabricloader": ">=0.14",
"minecraft": ">=1.3 <=1.13.2"
},
"breaks": {
"fabricated-forge": "<2.7.5"
}
}

0 comments on commit ed762f8

Please sign in to comment.