Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Legacy Forge versions for loom 1.2 #138

Draft
wants to merge 15 commits into
base: dev/1.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ dependencies {
implementation ('org.ow2.asm:asm-tree:9.5')
implementation ('org.ow2.asm:asm-util:9.5')
implementation ('me.tongfei:progressbar:0.9.0')
implementation 'com.github.jponge:lzma-java:1.3'
runtimeOnly 'dev.architectury.architectury-pack200:dev.architectury.architectury-pack200.gradle.plugin:0.1.3'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not want this to be applied by default, pack200 is GPL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPL with the classpath exception (same as OpenJDK), no? So it shouldn't be a problem to my knowledge.


// game handling utils
implementation ('net.fabricmc:stitch:0.6.2') {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/fabricmc/loom/LoomGradleExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,12 @@ default ForgeProvider getForgeProvider() {

ForgeRunsProvider getForgeRunsProvider();
void setForgeRunsProvider(ForgeRunsProvider forgeRunsProvider);

default boolean isLegacyForge() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would want to have old forge as a different platform all together, can’t believe there are much code to share anyways

return isForge() && getForgeUserdevProvider().isLegacyForge();
}

default boolean isModernForge() {
return isForge() && !isLegacyForge();
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import java.util.List;

import net.fabricmc.loom.configuration.providers.forge.fg2.Pack200Provider;

import org.gradle.api.Action;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.Property;
Expand Down Expand Up @@ -134,6 +136,8 @@ default void mixinConfig(String... mixinConfigs) {
@Deprecated(forRemoval = true)
void dataGen(Action<DataGenConsumer> action);

Property<Pack200Provider> getPack200Provider();

/**
* Data generation config.
* @deprecated Removed in favor of configuring the data generator directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ private synchronized void setupMinecraft(ConfigContext configContext) throws Exc

if (extension.isForge()) {
ForgeLibrariesProvider.provide(mappingConfiguration, project);
if (extension.isLegacyForge()) ((ForgeMinecraftProvider) minecraftProvider).getPatchedProvider().setMappingConfiguration(mappingConfiguration);
((ForgeMinecraftProvider) minecraftProvider).getPatchedProvider().provide();
}

mappingConfiguration.setupPost(project);
if (!extension.isLegacyForge())
mappingConfiguration.setupPost(project);
mappingConfiguration.applyToProject(getProject(), mappingsDep);

if (extension.isForge()) {
Expand Down Expand Up @@ -363,9 +365,9 @@ public static void setupDependencyProviders(Project project, LoomGradleExtension
}

if (extension.isForge()) {
dependencyProviders.addProvider(new ForgeUniversalProvider(project));
dependencyProviders.addProvider(new McpConfigProvider(project));
dependencyProviders.addProvider(new PatchProvider(project));
dependencyProviders.addProvider(new ForgeUniversalProvider(project));
}

dependencyProviders.handleDependencies(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static void executeAt(Project project, Path input, Path output, AccessTra
args.add(output.toAbsolutePath().toString());

configuration.apply(args);
project.getLogger().info(args.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


ForgeToolExecutor.exec(project, spec -> {
spec.getMainClass().set("net.minecraftforge.accesstransformer.TransformerProcessor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected void manipulateMappings(Project project, Path mappingsJar) throws IOEx
if (extension.shouldGenerateSrgTiny()) {
if (Files.notExists(rawTinyMappingsWithSrg) || extension.refreshDeps()) {
// Merge tiny mappings with srg
SrgMerger.ExtraMappings extraMappings = SrgMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));
SrgMerger.ExtraMappings extraMappings = extension.isLegacyForge() ? null : SrgMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));
SrgMerger.mergeSrg(getRawSrgFile(project), rawTinyMappings, rawTinyMappingsWithSrg, extraMappings, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@
public class ForgeLibrariesProvider {
private static final String FML_LOADER_GROUP = "net.minecraftforge";
private static final String FML_LOADER_NAME = "fmlloader";
private static final boolean isLegacyForge = true;

public static void provide(MappingConfiguration mappingConfiguration, Project project) throws Exception {
LoomGradleExtension extension = LoomGradleExtension.get(project);
final List<Dependency> dependencies = new ArrayList<>();

// Collect all dependencies with possible relocations, such as Mixin.
for (JsonElement lib : extension.getForgeUserdevProvider().getJson().get("libraries").getAsJsonArray()) {
if (isLegacyForge) {
lib = lib.getAsJsonObject().get("name");
}
String dep = null;

if (lib.getAsString().startsWith("org.spongepowered:mixin:")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,28 @@ public ForgeRunsProvider(Project project, JsonObject json) {
}

private void readTemplates() {
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject("runs").entrySet()) {
if (!extension.isLegacyForge()) {
configureRuns(json.getAsJsonObject("runs"));
} else {
configureRunsForLegacyForge();
}
}

private void configureRuns(JsonObject runs) {
for (Map.Entry<String, JsonElement> entry : runs.entrySet()) {
ForgeRunTemplate template = ForgeRunTemplate.fromJson(entry.getValue().getAsJsonObject());
templates.add(template);
}
}

private void configureRunsForLegacyForge() {
extension.getRunConfigs().configureEach(config -> {
// if (Constants.Forge.LAUNCH_TESTING.equals(config.getDefaultMainClass())) {
config.setDefaultMainClass(Constants.LegacyForge.LAUNCH_WRAPPER);
// }
});
}

public NamedDomainObjectSet<ForgeRunTemplate> getTemplates() {
return templates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
package net.fabricmc.loom.configuration.providers.forge;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
Expand All @@ -40,11 +42,14 @@
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ZipUtils;

import org.gradle.api.artifacts.repositories.IvyArtifactRepository;

public class ForgeUserdevProvider extends DependencyProvider {
private File userdevJar;
private JsonObject json;
Path joinedPatches;
BinaryPatcherConfig binaryPatcherConfig;
private boolean isLegacyForge;

public ForgeUserdevProvider(Project project) {
super(project);
Expand All @@ -59,22 +64,80 @@ public void provide(DependencyInfo dependency) throws Exception {
if (!userdevJar.exists() || Files.notExists(configJson) || refreshDeps()) {
File resolved = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge userdev"));
Files.copy(resolved.toPath(), userdevJar.toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.write(configJson, ZipUtils.unpack(resolved.toPath(), "config.json"));
try {
Files.write(configJson, ZipUtils.unpack(resolved.toPath(), "config.json"));
} catch (IOException e) {
Files.write(configJson, ZipUtils.unpack(resolved.toPath(), "dev.json"));
}
}

try (Reader reader = Files.newBufferedReader(configJson)) {
json = new Gson().fromJson(reader, JsonObject.class);
}

addDependency(json.get("mcp").getAsString(), Constants.Configurations.MCP_CONFIG);
addDependency(json.get("mcp").getAsString(), Constants.Configurations.SRG);
addDependency(json.get("universal").getAsString(), Constants.Configurations.FORGE_UNIVERSAL);

if (Files.notExists(joinedPatches)) {
Files.write(joinedPatches, ZipUtils.unpack(userdevJar.toPath(), json.get("binpatches").getAsString()));
isLegacyForge = !json.has("mcp");

if (!isLegacyForge) {
addDependency(json.get("mcp").getAsString(), Constants.Configurations.MCP_CONFIG);
addDependency(json.get("mcp").getAsString(), Constants.Configurations.SRG);
addDependency(json.get("universal").getAsString(), Constants.Configurations.FORGE_UNIVERSAL);

binaryPatcherConfig = BinaryPatcherConfig.fromJson(json.getAsJsonObject("binpatcher"));

if (Files.notExists(joinedPatches)) {
Files.write(joinedPatches, ZipUtils.unpack(userdevJar.toPath(), json.get("binpatches").getAsString()));
}
} else {
Map<String, String> mcpDep = Map.of(
"group", "de.oceanlabs.mcp",
"name", "mcp",
"version", json.get("inheritsFrom").getAsString(),
"classifier", "srg",
"ext", "zip"
);
addDependency(mcpDep, Constants.Configurations.MCP_CONFIG);
addDependency(mcpDep, Constants.Configurations.SRG);
addDependency(dependency.getDepString() + ":universal", Constants.Configurations.FORGE_UNIVERSAL);
addLegacyMCPRepo();

binaryPatcherConfig = BinaryPatcherConfig.fromJson(new Gson().fromJson("""
{
"version": "net.minecraftforge:binarypatcher:1.0.12:fatjar",
"args": [
"--clean",
"{clean}",
"--output",
"{output}",
"--apply",
"{patch}"
]
}""", JsonObject.class));

if (Files.notExists(joinedPatches)) {
Files.write(joinedPatches, ZipUtils.unpack(userdevJar.toPath(), "devbinpatches.pack.lzma"));
}
}
}

private void addLegacyMCPRepo() {
getProject().getRepositories().ivy(repo -> {
// Old MCP data does not have POMs
repo.setName("LegacyMCP");
repo.setUrl("https://maven.minecraftforge.net/");
repo.patternLayout(layout -> {
layout.artifact("[orgPath]/[artifact]/[revision]/[artifact]-[revision](-[classifier])(.[ext])");
// also check the zip so people do not have to explicitly specify the extension for older versions
layout.artifact("[orgPath]/[artifact]/[revision]/[artifact]-[revision](-[classifier]).zip");
});
repo.content(descriptor -> {
descriptor.includeGroup("de.oceanlabs.mcp");
});
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
});
}

binaryPatcherConfig = BinaryPatcherConfig.fromJson(json.getAsJsonObject("binpatcher"));
public boolean isLegacyForge() {
return isLegacyForge;
}

public File getUserdevJar() {
Expand Down
Loading