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

Commit

Permalink
Version bump + loader version check
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Nov 10, 2019
1 parent 9914418 commit 8fceb2f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 41 additions & 9 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
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 {

//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<File, ClassCache> runtime = optifineSetup.getRuntime();
Expand Down Expand Up @@ -48,27 +51,56 @@ 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<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 (!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;
OptifabricError.setError("Failed to load optifine, check the log for more info \n\n " + e.getMessage());
}
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<SemanticVersionImpl> predicate = SemanticVersionPredicateParser.create(validVersion);
SemanticVersionImpl version = new SemanticVersionImpl(modMetadata.getVersion().getFriendlyString(), false);
return predicate.test(version);
}

private ModMetadata getModMetaData(String modId) {
Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer(modId);
return modContainer.map(ModContainer::getMetadata).orElse(null);
}

}

0 comments on commit 8fceb2f

Please sign in to comment.