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

Commit

Permalink
Added a custom fabric.mod.json field (optifabric:incompatible) to a…
Browse files Browse the repository at this point in the history
…llow mod devs to specify that their mod is not compatible with optifabric
  • Loading branch information
modmuss50 committed Feb 16, 2020
1 parent c425d55 commit 3f377a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __Note:__ This project does not contain Optifine, you must download it separatel

## Installing

After installing fabric for 1.14.3, you will need to place the OptiFabric mod jar as well as the optifine installer in the mods folder.
After installing fabric for 1.15.2, you will need to place the OptiFabric mod jar as well as the optifine installer in the mods folder.

Fabric Loader should be the latest version from the [Fabric Website](https://fabricmc.net/use/)

Expand Down Expand Up @@ -36,13 +36,10 @@ repositories {
}
dependencies {
modCompile 'com.github.modmuss50:OptiFabric:e1834b016f'
modCompile 'com.github.modmuss50:OptiFabric:1.0.0-beta3'
//Deps required for optifabric
compile 'org.zeroturnaround:zt-zip:1.13'
compile ('net.fabricmc:stitch:0.2.1.61') {
transitive = false
}
compile 'org.zeroturnaround:zt-zip:1.14'
}
```

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
import org.spongepowered.asm.mixin.Mixins;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

@SuppressWarnings("unused")
public class OptifabricSetup implements Runnable {

public static final String OPTIFABRIC_INCOMPATIBLE = "optifabric:incompatible";

//This is called early on to allow us to get the transformers in beofore minecraft starts
@Override
public void run() {
if(!validateLoaderVersion()) return;
if(!validateMods()) return;

try {
OptifineSetup optifineSetup = new OptifineSetup();
Expand Down Expand Up @@ -67,6 +72,28 @@ private void validateIndigoVersion() {
}
}

private boolean validateMods() {
List<ModMetadata> incompatibleMods = new ArrayList<>();
for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
ModMetadata metadata = container.getMetadata();
if(metadata.containsCustomValue(OPTIFABRIC_INCOMPATIBLE)) {
incompatibleMods.add(metadata);
}
}
if (!incompatibleMods.isEmpty()) {
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
StringBuilder errorMessage = new StringBuilder("One or more mods have stated they are incompatible with OptiFabric\nPlease remove OptiFabric or the following mods:\n");
for (ModMetadata metadata : incompatibleMods) {
errorMessage.append(metadata.getName())
.append(" (")
.append(metadata.getId())
.append(")\n");
}
OptifabricError.setError(errorMessage.toString());
}
return incompatibleMods.isEmpty();
}

private boolean validateLoaderVersion() {
try {
if (!isVersionValid("fabricloader", ">=0.7.0")) {
Expand Down

0 comments on commit 3f377a8

Please sign in to comment.