diff --git a/gradle.properties b/gradle.properties index bce87186..7a090485 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,6 @@ zt_zip_version=1.13 slf4j_version=1.7.29 stitch_version=0.3.0.66 -mod_version = 0.5.3 +mod_version = 0.6.0 maven_group = me.modmuss50 archives_base_name = optifabric diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 5f7a6198..5c9c978e 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -4,15 +4,16 @@ 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.api.metadata.ModMetadata; import net.fabricmc.loader.util.version.SemanticVersionImpl; import net.fabricmc.loader.util.version.SemanticVersionPredicateParser; +import net.fabricmc.loader.util.version.VersionParsingException; import org.apache.commons.lang3.tuple.Pair; import org.spongepowered.asm.mixin.Mixins; import java.io.File; +import java.util.Optional; import java.util.function.Predicate; -import java.util.function.Supplier; @SuppressWarnings("unused") public class OptifabricSetup implements Runnable { @@ -20,6 +21,8 @@ public class OptifabricSetup implements Runnable { //This is called early on to allow us to get the transformers in beofore minecraft starts @Override public void run() { + if(!validateLoaderVersion()) return; + try { OptifineSetup optifineSetup = new OptifineSetup(); Pair runtime = optifineSetup.getRuntime(); @@ -48,20 +51,32 @@ public void run() { //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) () -> new RuntimeException("Failed to get indigo's mod container, something has broke badly.")); - Version indigoVersion = indigoContainer.getMetadata().getVersion(); - - Predicate predicate = SemanticVersionPredicateParser.create(">=0.1.8"); - SemanticVersionImpl version = new SemanticVersionImpl(indigoVersion.getFriendlyString(), false); - - if (!predicate.test(version)) { + if (!isVersionValid("fabric-renderer-indigo", ">=0.1.8")) { 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); + } + } + private boolean validateLoaderVersion() { + try { + if (!isVersionValid("fabricloader", ">=0.6.4")) { + if(!OptifabricError.hasError()){ + OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE; + OptifabricError.setError("You are using an outdated version of Fabric Loader, please update!\n\nRe-run the installer, or update via your launcher. See the link for help!", "https://fabricmc.net/wiki/install"); + OptifabricError.setHelpButtonText("Installation Instructions"); + return false; + } + } } catch (Throwable e){ if(!OptifabricError.hasError()){ OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE; @@ -69,6 +84,23 @@ private void validateIndigoVersion() { } throw new RuntimeException("Failed to setup optifine", e); } + return true; + } + + private boolean isVersionValid(String modID, String validVersion) throws VersionParsingException { + ModMetadata modMetadata = getModMetaData(modID); + if(modMetadata == null) { + throw new RuntimeException(String.format("Failed to get mod container for %s, something has broke badly.", modID)); + } + + Predicate predicate = SemanticVersionPredicateParser.create(validVersion); + SemanticVersionImpl version = new SemanticVersionImpl(modMetadata.getVersion().getFriendlyString(), false); + return predicate.test(version); + } + + private ModMetadata getModMetaData(String modId) { + Optional modContainer = FabricLoader.getInstance().getModContainer(modId); + return modContainer.map(ModContainer::getMetadata).orElse(null); } }