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

Commit

Permalink
Full Support for indigo's Shader compatibility.
Browse files Browse the repository at this point in the history
Refactor Error handling
  • Loading branch information
modmuss50 committed Jul 7, 2019
1 parent 44c1e79 commit 82e01db
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 46 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.3
yarn_mappings=1.14.3+build.9
loader_version=0.4.8+build.155

mod_version = 0.3.2
mod_version = 0.4.0
maven_group = me.modmuss50
archives_base_name = optifabric
31 changes: 0 additions & 31 deletions src/main/java/me/modmuss50/optifabric/mixin/MixinIndigo.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.modmuss50.optifabric.mixin;

import me.modmuss50.optifabric.mod.Optifabric;
import me.modmuss50.optifabric.mod.OptifabricError;
import me.modmuss50.optifabric.mod.OptifineVersion;

import net.minecraft.client.gui.screen.Screen;
Expand Down Expand Up @@ -36,7 +37,7 @@ private void init(CallbackInfo info) {

@Inject(method = "render", at = @At("RETURN"))
private void render(int int_1, int int_2, float float_1, CallbackInfo info) {
if (OptifineVersion.error == null) {
if (!OptifabricError.hasError()) {
float fadeTime = this.doBackgroundFade ? (float) (SystemUtil.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
float fadeColor = this.doBackgroundFade ? MathHelper.clamp(fadeTime - 1.0F, 0.0F, 1.0F) : 1.0F;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/modmuss50/optifabric/mod/Optifabric.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
public class Optifabric implements ModInitializer {

public static void checkForErrors() {
if (OptifineVersion.error != null) {
if (OptifabricError.hasError()) {
ConfirmScreen confirmScreen = new ConfirmScreen(t -> {
if (t) {
SystemUtil.getOperatingSystem().open("https://github.com/modmuss50/OptiFabric/blob/master/README.md");
SystemUtil.getOperatingSystem().open(OptifabricError.getErrorURL());
} else {
MinecraftClient.getInstance().scheduleStop();
}
}, new LiteralText(Formatting.RED + "There was an error finding Optifine in the mods folder!"), new LiteralText(OptifineVersion.error), Formatting.GREEN + "Open Help", Formatting.RED + "Close Game");
}, new LiteralText(Formatting.RED + "There was an error loading OptiFabric!"), new LiteralText(OptifabricError.getError()), Formatting.GREEN + OptifabricError.getHelpButtonText(), Formatting.RED + "Close Game");

MinecraftClient.getInstance().openScreen(confirmScreen);
}
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.modmuss50.optifabric.mod;

public class OptifabricError {

private static String error = null;
private static String errorURL = "https://github.com/modmuss50/OptiFabric/blob/master/README.md";
private static String helpButtonText = "Open Help";

public static boolean hasError(){
return getError() != null;
}

public static String getError() {
return error;
}

public static String getErrorURL() {
return errorURL;
}

public static void setError(String error){
OptifabricError.error = error;
}

public static void setError(String error, String url){
setError(error);
OptifabricError.errorURL = url;
}

public static String getHelpButtonText() {
return helpButtonText;
}

public static void setHelpButtonText(String helpButtonText) {
OptifabricError.helpButtonText = helpButtonText;
}
}
37 changes: 35 additions & 2 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import com.chocohead.mm.api.ClassTinkerers;
import me.modmuss50.optifabric.patcher.ClassCache;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.util.version.SemanticVersionImpl;
import net.fabricmc.loader.util.version.SemanticVersionPredicateParser;
import org.apache.commons.lang3.tuple.Pair;
import org.spongepowered.asm.mixin.Mixins;

import java.io.File;
import java.util.function.Predicate;
import java.util.function.Supplier;

@SuppressWarnings("unused")
public class OptifabricSetup implements Runnable {
Expand All @@ -24,18 +30,45 @@ public void run() {
OptifineInjector injector = new OptifineInjector(runtime.getRight());
injector.setup();
} catch (Throwable e) {
if(OptifineVersion.error == null || OptifineVersion.error.isEmpty()){
if(!OptifabricError.hasError()){
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
OptifineVersion.error = "Failed to load optifine, check the log for more info \n\n " + e.getMessage();
OptifabricError.setError("Failed to load optifine, check the log for more info \n\n " + e.getMessage());
}
throw new RuntimeException("Failed to setup optifine", e);
}

if(FabricLoader.getInstance().isModLoaded("fabric-renderer-indigo")){
validateIndigoVersion();
Mixins.addConfiguration("optifabric.indigofix.mixins.json");
}

Mixins.addConfiguration("optifabric.optifine.mixins.json");
}

//I check the version like this as I want to show issues on our error screen
private void validateIndigoVersion() {
try {
ModContainer indigoContainer = FabricLoader.getInstance().getModContainer("fabric-renderer-indigo").orElseThrow((Supplier<Throwable>) () -> new RuntimeException("Failed to get indigo's mod container, something has broke badly."));
Version indigoVersion = indigoContainer.getMetadata().getVersion();

Predicate<SemanticVersionImpl> predicate = SemanticVersionPredicateParser.create(">=0.1.8");
SemanticVersionImpl version = new SemanticVersionImpl(indigoVersion.getFriendlyString(), false);

if (!predicate.test(version)) {
if(!OptifabricError.hasError()){
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
OptifabricError.setError("You are using an outdated version of Fabric (API), please update!\n\nDownload the jar from the link bellow and replace the existing Fabric (API) jar in your mods folder.", "https://www.curseforge.com/minecraft/mc-mods/fabric-api/files");
OptifabricError.setHelpButtonText("Download Fabric (API)");
}
}

} catch (Throwable e){
if(!OptifabricError.hasError()){
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
OptifabricError.setError("Failed to load optifine, check the log for more info \n\n " + e.getMessage());
}
throw new RuntimeException("Failed to setup optifine", e);
}
}

}
12 changes: 6 additions & 6 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class OptifineVersion {

public static String error = null;

public static String version;
public static String minecraftVersion;
public static JarType jarType;
Expand All @@ -34,11 +34,11 @@ public static File findOptifineJar() throws IOException {
if (file.getName().endsWith(".jar")) {
JarType type = getJarType(file);
if (type.error) {
throw new RuntimeException("An error occurred when trying to find the optifine jar: " + error);
throw new RuntimeException("An error occurred when trying to find the optifine jar: " + type.name());
}
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!";
OptifabricError.setError("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;
Expand All @@ -52,7 +52,7 @@ public static File findOptifineJar() throws IOException {
return optifineJar;
}

error = "OptiFabric could not find the Optifine jar in the mods folder.";
OptifabricError.setError("OptiFabric could not find the Optifine jar in the mods folder.");
throw new FileNotFoundException("Could not find optifine jar");
}

Expand Down Expand Up @@ -88,13 +88,13 @@ private static JarType getJarType(File file) throws IOException {
}
}
} catch (Exception e){
error = "Failed to find minecraft version";
OptifabricError.setError("Failed to find minecraft version");
e.printStackTrace();
return JarType.INCOMPATIBE;
}

if (!currentMcVersion.equals(minecraftVersion)) {
error = String.format("This version of optifine is not compatible with the current minecraft version\n\n Optifine requires %s you have %s", minecraftVersion, currentMcVersion);
OptifabricError.setError(String.format("This version of optifine is not compatible with the current minecraft version\n\n Optifine requires %s you have %s", minecraftVersion, currentMcVersion));
return JarType.INCOMPATIBE;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
]
},
"custom": {
"fabric-renderer-indigo:force_compatibility" : true,
"mm:early_risers": [
"me.modmuss50.optifabric.mod.OptifabricSetup"
]
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/optifabric.indigofix.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"package": "me.modmuss50.optifabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinChunkCacheOF",
"MixinIndigo"
"MixinChunkCacheOF"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 82e01db

Please sign in to comment.