mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Add Forge dependencies using the userdev jar
This commit is contained in:
@@ -51,6 +51,7 @@ import org.gradle.plugins.ide.idea.model.IdeaModel;
|
||||
|
||||
import net.fabricmc.loom.providers.ForgeProvider;
|
||||
import net.fabricmc.loom.providers.ForgeUniversalProvider;
|
||||
import net.fabricmc.loom.providers.ForgeUserdevProvider;
|
||||
import net.fabricmc.loom.providers.LaunchProvider;
|
||||
import net.fabricmc.loom.providers.MappingsCache;
|
||||
import net.fabricmc.loom.providers.MappingsProvider;
|
||||
@@ -128,12 +129,18 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||
if (project.getExtensions().getByType(LoomGradleExtension.class).isForge()) {
|
||||
Configuration forgeConfig = project.getConfigurations().maybeCreate(Constants.FORGE);
|
||||
forgeConfig.setTransitive(false);
|
||||
Configuration forgeUserdevConfig = project.getConfigurations().maybeCreate(Constants.FORGE_USERDEV);
|
||||
forgeUserdevConfig.setTransitive(false);
|
||||
Configuration forgeInstallerConfig = project.getConfigurations().maybeCreate(Constants.FORGE_INSTALLER);
|
||||
forgeInstallerConfig.setTransitive(false);
|
||||
Configuration forgeUniversalConfig = project.getConfigurations().maybeCreate(Constants.FORGE_UNIVERSAL);
|
||||
forgeUniversalConfig.setTransitive(false);
|
||||
Configuration forgeDependencies = project.getConfigurations().maybeCreate(Constants.FORGE_DEPENDENCIES);
|
||||
forgeDependencies.setTransitive(false);
|
||||
Configuration mcpConfig = project.getConfigurations().maybeCreate(Constants.MCP_CONFIG);
|
||||
mcpConfig.setTransitive(false);
|
||||
|
||||
extendsFrom(Constants.MINECRAFT_DEPENDENCIES, Constants.FORGE_DEPENDENCIES);
|
||||
}
|
||||
|
||||
Configuration includeConfig = project.getConfigurations().maybeCreate(Constants.INCLUDE);
|
||||
@@ -248,8 +255,9 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||
extension.setDependencyManager(dependencyManager);
|
||||
|
||||
if (extension.isForge()) {
|
||||
dependencyManager.addProvider(new McpConfigProvider(getProject()));
|
||||
dependencyManager.addProvider(new ForgeProvider(getProject()));
|
||||
dependencyManager.addProvider(new ForgeUserdevProvider(getProject()));
|
||||
dependencyManager.addProvider(new McpConfigProvider(getProject()));
|
||||
dependencyManager.addProvider(new PatchProvider(getProject()));
|
||||
dependencyManager.addProvider(new ForgeUniversalProvider(getProject()));
|
||||
}
|
||||
|
||||
@@ -38,12 +38,8 @@ public class ForgeProvider extends DependencyProvider {
|
||||
|
||||
@Override
|
||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||
addDependency(dependency.getDepString() + ":universal", Constants.FORGE_UNIVERSAL);
|
||||
addDependency(dependency.getDepString() + ":launcher", Constants.MINECRAFT_DEPENDENCIES);
|
||||
addDependency(dependency.getDepString() + ":userdev", Constants.FORGE_USERDEV);
|
||||
addDependency(dependency.getDepString() + ":installer", Constants.FORGE_INSTALLER);
|
||||
|
||||
addDependency("net.minecraftforge:eventbus:3.0.2", Constants.MINECRAFT_DEPENDENCIES);
|
||||
addDependency("net.minecraftforge:forgespi:3.0.0", Constants.MINECRAFT_DEPENDENCIES);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ForgeUniversalProvider extends DependencyProvider {
|
||||
forge = new File(getExtension().getProjectPersistentCache(), "forge-" + dependency.getDependency().getVersion() + ".jar");
|
||||
|
||||
if (!forge.exists() || isRefreshDeps()) {
|
||||
File dep = dependency.resolveFile().orElseThrow(() -> new IllegalStateException("Could not resolve Forge"));
|
||||
File dep = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge"));
|
||||
Files.copy(dep, forge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.providers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
|
||||
public class ForgeUserdevProvider extends DependencyProvider {
|
||||
public ForgeUserdevProvider(Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||
Path configJson = getExtension()
|
||||
.getProjectPersistentCache()
|
||||
.toPath()
|
||||
.resolve("forge-config-" + dependency.getDependency().getVersion() + ".json");
|
||||
|
||||
if (Files.notExists(configJson) || isRefreshDeps()) {
|
||||
File resolved = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge userdev"));
|
||||
Files.copy(resolved.toPath(), configJson);
|
||||
}
|
||||
|
||||
JsonObject json;
|
||||
|
||||
try (Reader reader = Files.newBufferedReader(configJson)) {
|
||||
json = new Gson().fromJson(reader, JsonObject.class);
|
||||
}
|
||||
|
||||
addDependency(json.get("mcp").getAsString(), Constants.MCP_CONFIG);
|
||||
addDependency(json.get("universal").getAsString(), Constants.FORGE_UNIVERSAL);
|
||||
|
||||
for (JsonElement lib : json.get("libraries").getAsJsonArray()) {
|
||||
addDependency(lib.getAsString(), Constants.FORGE_DEPENDENCIES);
|
||||
}
|
||||
|
||||
// TODO: Read launch configs from the JSON too
|
||||
// TODO: Should I copy the patches from here as well?
|
||||
// That'd require me to run the "MCP environment" fully up to merging.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.FORGE_USERDEV;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class McpConfigProvider extends DependencyProvider {
|
||||
return; // No work for us to do here
|
||||
}
|
||||
|
||||
Path mcpZip = dependency.resolveFile().orElseThrow(() -> new IllegalStateException("Could not resolve MCPConfig")).toPath();
|
||||
Path mcpZip = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve MCPConfig")).toPath();
|
||||
|
||||
if (!mcp.exists() || isRefreshDeps()) {
|
||||
Files.copy(mcpZip, mcp.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PatchProvider extends DependencyProvider {
|
||||
if (Files.notExists(clientPatches) || Files.notExists(serverPatches) || isRefreshDeps()) {
|
||||
getProject().getLogger().info(":extracting forge patches");
|
||||
|
||||
Path installerJar = dependency.resolveFile().orElseThrow(() -> new IllegalStateException("Could not resolve Forge installer")).toPath();
|
||||
Path installerJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge installer")).toPath();
|
||||
|
||||
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + installerJar.toUri()), ImmutableMap.of("create", false))) {
|
||||
Files.copy(fs.getPath("data", "client.lzma"), clientPatches, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
@@ -55,8 +55,10 @@ public class Constants {
|
||||
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
||||
public static final String MCP_CONFIG = "mcp";
|
||||
public static final String FORGE = "forge";
|
||||
public static final String FORGE_USERDEV = "forgeUserdev";
|
||||
public static final String FORGE_INSTALLER = "forgeInstaller";
|
||||
public static final String FORGE_UNIVERSAL = "forgeUniversal";
|
||||
public static final String FORGE_DEPENDENCIES = "forgeDependencies";
|
||||
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.3.1.5";
|
||||
public static final String DEV_LAUNCH_INJECTOR_VERSION = "0.2.1+build.8";
|
||||
|
||||
Reference in New Issue
Block a user