Skip to content

Commit

Permalink
Revive unified mods for the development environment (#182)
Browse files Browse the repository at this point in the history
* Add Union Relauncher for Forge 49+

* Don't apply this on Neo
  • Loading branch information
Juuxel authored Dec 13, 2023
1 parent 9f070d2 commit 94eac81
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gradle/runtime.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ access-transformers = "3.0.1"
access-transformers-new = "8.0.5"
unprotect = "1.2.0"
asm = "9.3"
union-relauncher = "1.0.0"

[libraries]
# Decompilers
Expand All @@ -41,3 +42,4 @@ access-transformers = { module = "net.minecraftforge:accesstransformers", versio
access-transformers-new = { module = "net.minecraftforge:accesstransformers", version.ref = "access-transformers-new" }
unprotect = { module = "io.github.juuxel:unprotect", version.ref = "unprotect" }
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
union-relauncher = { module = "io.github.juuxel:union-relauncher", version.ref = "union-relauncher" }
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.DependencyInfo;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.LoomVersions;
import net.fabricmc.loom.util.ModPlatform;

public class ForgeProvider extends DependencyProvider {
Expand All @@ -49,6 +50,10 @@ public void provide(DependencyInfo dependency) throws Exception {
version = new ForgeVersion(dependency.getResolvedVersion());
addDependency(dependency.getDepString() + ":userdev", Constants.Configurations.FORGE_USERDEV);
addDependency(dependency.getDepString() + ":installer", Constants.Configurations.FORGE_INSTALLER);

if (getExtension().isForge() && version.getMajorVersion() >= Constants.Forge.MIN_UNION_RELAUNCHER_VERSION) {
addDependency(LoomVersions.UNION_RELAUNCHER.mavenNotation(), Constants.Configurations.FORGE_EXTRA);
}
}

public ForgeVersion getVersion() {
Expand Down Expand Up @@ -86,13 +91,15 @@ public static final class ForgeVersion {
private final String combined;
private final String minecraftVersion;
private final String forgeVersion;
private final int majorVersion;

public ForgeVersion(String combined) {
this.combined = combined;

if (combined == null) {
this.minecraftVersion = "NO_VERSION";
this.forgeVersion = "NO_VERSION";
this.majorVersion = -1;
return;
}

Expand All @@ -105,6 +112,21 @@ public ForgeVersion(String combined) {
this.minecraftVersion = "NO_VERSION";
this.forgeVersion = combined;
}

int dotIndex = forgeVersion.indexOf('.');
int major;

try {
if (dotIndex >= 0) {
major = Integer.parseInt(forgeVersion.substring(0, dotIndex));
} else {
major = Integer.parseInt(forgeVersion);
}
} catch (NumberFormatException e) {
major = -1;
}

this.majorVersion = major;
}

public String getCombined() {
Expand All @@ -118,5 +140,9 @@ public String getMinecraftVersion() {
public String getForgeVersion() {
return forgeVersion;
}

public int getMajorVersion() {
return majorVersion;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,12 @@ public void applyTo(RunConfigSettings settings, ConfigValue.Resolver configValue

// Add MOD_CLASSES, this is something that ForgeGradle does
settings.getEnvironmentVariables().computeIfAbsent("MOD_CLASSES", $ -> ConfigValue.of("{source_roots}").resolve(configValueResolver));

final ForgeProvider forgeProvider = settings.getExtension().getForgeProvider();

if (settings.getExtension().isForge() && forgeProvider.getVersion().getMajorVersion() >= Constants.Forge.MIN_UNION_RELAUNCHER_VERSION) {
settings.defaultMainClass(Constants.Forge.UNION_RELAUNCHER_MAIN_CLASS);
settings.property(Constants.Forge.UNION_RELAUNCHER_MAIN_CLASS_PROPERTY, main);
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/net/fabricmc/loom/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ public static final class Forge {
public static final String ACCESS_TRANSFORMER_PATH = "META-INF/accesstransformer.cfg";
public static final String MIXIN_CONFIGS_MANIFEST_KEY = "MixinConfigs";

/**
* The minimum Forge version that needs Union Relauncher to use {@code MOD_CLASSES}.
*/
public static final int MIN_UNION_RELAUNCHER_VERSION = 49;
public static final String UNION_RELAUNCHER_MAIN_CLASS = "juuxel.unionrelauncher.UnionRelauncher";
public static final String UNION_RELAUNCHER_MAIN_CLASS_PROPERTY = "unionRelauncher.mainClass";

private Forge() {
}
}
Expand Down

0 comments on commit 94eac81

Please sign in to comment.