Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Better error handling + remove forge and launchwrapper warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed May 23, 2019
1 parent 6666f8b commit 26fec3e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ minecraft_version=1.14
yarn_mappings=1.14+build.21
loader_version=0.4.7+build.147

mod_version = 0.1.2
mod_version = 0.1.3
maven_group = me.modmuss50
archives_base_name = optifabric
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.modmuss50.optifabric.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
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.CallbackInfoReturnable;

//Suppresses some warnings in the log
@Pseudo
@Mixin(targets = "net.optifine.reflect.ReflectorClass")
public class MixinReflectorClass {

@Shadow
private String targetClassName;

@Shadow
private boolean checked;

@Inject(method = "getTargetClass", at = @At("HEAD"), cancellable = true, remap = false)
public void getTargetClass(CallbackInfoReturnable<Class> infoReturnable) {
String name = targetClassName.replaceAll("/", ".");
if(name.startsWith("net.minecraft.launchwrapper") || name.startsWith("net.minecraftforge")){
checked = true;
}
}

}
28 changes: 21 additions & 7 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,28 @@ public void run() {
throw new RuntimeException("Failed to setup optifine", e);
}

if(FabricLoader.getInstance().isModLoaded("fabric-renderer-indigo")){
try {
Method method = FabricMixinBootstrap.class.getDeclaredMethod("addConfiguration", String.class);
method.setAccessible(true);
method.invoke(null, "optifabric.indigofix.mixins.json");
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to inject indigo render fixes", e);
try {
if(FabricLoader.getInstance().isModLoaded("fabric-renderer-indigo")){
addMixinConfig("optifabric.indigofix.mixins.json");
}

addMixinConfig("optifabric.optifine.mixins.json");
} catch (Exception e){
if(OptifineVersion.error == null || OptifineVersion.error.isEmpty()){
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
OptifineVersion.error = "Failed to load optifine, check the log for more info \n\n " + e.getMessage();
}
throw new RuntimeException("Failed to setup optifine", e);
}
}

private static void addMixinConfig(String mixinConfig){
try {
Method method = FabricMixinBootstrap.class.getDeclaredMethod("addConfiguration", String.class);

This comment has been minimized.

Copy link
@Chocohead

Chocohead May 23, 2019

Contributor

Mixins#addConfiguration is public if you wanted to avoid any more reflecting

This comment has been minimized.

Copy link
@modmuss50

modmuss50 May 23, 2019

Author Owner

So it is!, thanks for having my back on this ;)

method.setAccessible(true);
method.invoke(null, mixinConfig);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to inject indigo render fixes", e);
}
}
}
15 changes: 13 additions & 2 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class OptifineVersion {
public static File findOptifineJar() throws IOException {
File modsDir = new File(FabricLoader.getInstance().getGameDirectory(), "mods");
File[] mods = modsDir.listFiles();

File optifineJar = null;

if (mods != null) {
for (File file : mods) {
if (file.isDirectory()) {
Expand All @@ -34,13 +37,21 @@ public static File findOptifineJar() throws IOException {
throw new RuntimeException("An error occurred when trying to find the optifine jar: " + error);
}
if (type == JarType.OPIFINE_MOD || type == JarType.OPTFINE_INSTALLER) {
if(optifineJar != null){
error = "Found 2 or more optifine jars, please ensure you only have 1 copy of optifine in the mods folder!";
throw new FileNotFoundException("Multiple optifine jars");
}
jarType = type;
return file;
optifineJar = file;
}
}
}
}

if(optifineJar != null){
return optifineJar;
}

error = "OptiFabric could not find the Optifine jar in the mods folder.";
throw new FileNotFoundException("Could not find optifine jar");
}
Expand Down Expand Up @@ -68,7 +79,7 @@ private static JarType getJarType(File file) throws IOException {
//I hope this isnt too early
MinecraftVersion mcVersion = (MinecraftVersion) MinecraftVersion.create();
if (!mcVersion.getName().equals(minecraftVersion)) {
error = "This version of optifine is not compatible with the current minecraft version";
error = String.format("This version of optifine is not compatible with the current minecraft version\n\n Optifine requires %s you have %s", minecraftVersion, mcVersion.getName());
return JarType.INCOMPATIBE;
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/optifabric.optifine.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "me.modmuss50.optifabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinReflectorClass"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 26fec3e

Please sign in to comment.