Some Forge stuff

This commit is contained in:
Juuxel
2020-07-27 15:58:31 +03:00
parent 9d142efb01
commit ffa70d6637
7 changed files with 126 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ if (ENV.BUILD_NUMBER) {
build = 'jenkins #${ENV.BUILD_NUMBER}'
version = baseVersion + '.' + ENV.BUILD_NUMBER
} else {
version = baseVersion + '.local'
version = baseVersion + '-forge.2'
}
repositories {
@@ -29,6 +29,10 @@ repositories {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
name = 'Forge'
url = 'https://files.minecraftforge.net/maven/'
}
mavenCentral()
}
@@ -65,6 +69,9 @@ dependencies {
// Kapt integration
compileOnly('org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72')
// Forge patches
implementation ('net.minecraftforge:binarypatcher:1.1.1')
// Testing
testImplementation(gradleTestKit())
testImplementation('org.spockframework:spock-core:1.3-groovy-2.4') {

View File

@@ -3,6 +3,8 @@
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="fileExtensions" value="java"/>
<property name="localeLanguage" value="en"/>
<property name="localeCountry" value="US"/>
<module name="NewlineAtEndOfFile"/>

View File

@@ -53,6 +53,7 @@ import net.fabricmc.loom.providers.LaunchProvider;
import net.fabricmc.loom.providers.MappingsCache;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PatchProvider;
import net.fabricmc.loom.task.AbstractLoomTask;
import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask;
@@ -119,6 +120,8 @@ public class AbstractPlugin implements Plugin<Project> {
minecraftDependenciesConfig.setTransitive(false);
Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT);
minecraftConfig.setTransitive(false);
Configuration forgeConfig = project.getConfigurations().maybeCreate(Constants.FORGE);
forgeConfig.setTransitive(false);
Configuration includeConfig = project.getConfigurations().maybeCreate(Constants.INCLUDE);
includeConfig.setTransitive(false); // Dont get transitive deps
@@ -226,6 +229,7 @@ public class AbstractPlugin implements Plugin<Project> {
LoomDependencyManager dependencyManager = new LoomDependencyManager();
extension.setDependencyManager(dependencyManager);
dependencyManager.addProvider(new PatchProvider(getProject()));
dependencyManager.addProvider(new MinecraftProvider(getProject()));
dependencyManager.addProvider(new MappingsProvider(getProject()));
dependencyManager.addProvider(new LaunchProvider(getProject()));

View File

@@ -51,6 +51,7 @@ import net.fabricmc.loom.processors.JarProcessorManager;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PatchProvider;
import net.fabricmc.loom.util.LoomDependencyManager;
public class LoomGradleExtension {
@@ -314,6 +315,10 @@ public class LoomGradleExtension {
return dependencyManager;
}
public PatchProvider getPatchProvider() {
return getDependencyManager().getProvider(PatchProvider.class);
}
public MinecraftProvider getMinecraftProvider() {
return getDependencyManager().getProvider(MinecraftProvider.class);
}

View File

@@ -29,6 +29,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.zip.ZipError;
@@ -36,6 +37,7 @@ import java.util.zip.ZipError;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraftforge.binarypatcher.ConsoleTool;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
@@ -57,6 +59,8 @@ public class MinecraftProvider extends DependencyProvider {
private File minecraftJson;
private File minecraftClientJar;
private File minecraftServerJar;
private File minecraftClientPatchedJar;
private File minecraftServerPatchedJar;
private File minecraftMergedJar;
Gson gson = new Gson();
@@ -98,12 +102,18 @@ public class MinecraftProvider extends DependencyProvider {
libraryProvider = new MinecraftLibraryProvider();
libraryProvider.provide(this, getProject());
if (!minecraftClientPatchedJar.exists() || !minecraftServerPatchedJar.exists()) {
patchJars(getProject().getLogger());
}
if (!minecraftMergedJar.exists() || isRefreshDeps()) {
try {
mergeJars(getProject().getLogger());
} catch (ZipError e) {
DownloadUtil.delete(minecraftClientJar);
DownloadUtil.delete(minecraftServerJar);
DownloadUtil.delete(minecraftClientPatchedJar);
DownloadUtil.delete(minecraftServerPatchedJar);
getProject().getLogger().error("Could not merge JARs! Deleting source JARs - please re-run the command and move on.", e);
throw new RuntimeException();
@@ -115,6 +125,9 @@ public class MinecraftProvider extends DependencyProvider {
minecraftJson = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-info.json");
minecraftClientJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-client.jar");
minecraftServerJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-server.jar");
PatchProvider patchProvider = getExtension().getPatchProvider();
minecraftClientPatchedJar = new File(getExtension().getProjectPersistentCache(), "minecraft-" + minecraftVersion + "-client-patched-" + patchProvider.forgeVersion + ".jar");
minecraftServerPatchedJar = new File(getExtension().getProjectPersistentCache(), "minecraft-" + minecraftVersion + "-server-patched-" + patchProvider.forgeVersion + ".jar");
minecraftMergedJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar");
}
@@ -184,10 +197,26 @@ public class MinecraftProvider extends DependencyProvider {
DownloadUtil.downloadIfChanged(new URL(versionInfo.downloads.get("server").url), minecraftServerJar, logger);
}
private void patchJars(Logger logger) throws IOException {
logger.info(":patching jars");
PatchProvider patchProvider = getExtension().getPatchProvider();
patchJars(minecraftClientJar, minecraftClientPatchedJar, patchProvider.clientPatches);
patchJars(minecraftServerJar, minecraftServerPatchedJar, patchProvider.serverPatches);
}
private void patchJars(File clean, File output, Path patches) throws IOException {
ConsoleTool.main(new String[] {
"--clean", clean.getAbsolutePath(),
"--output", output.getAbsolutePath(),
"--apply", patches.toAbsolutePath().toString()
});
}
private void mergeJars(Logger logger) throws IOException {
logger.lifecycle(":merging jars");
try (JarMerger jarMerger = new JarMerger(minecraftClientJar, minecraftServerJar, minecraftMergedJar)) {
try (JarMerger jarMerger = new JarMerger(minecraftClientPatchedJar, minecraftServerPatchedJar, minecraftMergedJar)) {
jarMerger.enableSyntheticParamsOffset();
jarMerger.merge();
}

View File

@@ -0,0 +1,75 @@
/*
* 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.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DependencyProvider;
public class PatchProvider extends DependencyProvider {
public Path clientPatches;
public Path serverPatches;
public String forgeVersion;
public PatchProvider(Project project) {
super(project);
}
@Override
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
init(dependency.getDependency().getVersion());
if (Files.notExists(clientPatches) || Files.notExists(serverPatches)) {
getProject().getLogger().info(":extracting forge patches");
Path installerJar = dependency.resolveFile().orElseThrow(() -> new IllegalStateException("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);
Files.copy(fs.getPath("data", "server.lzma"), serverPatches);
}
}
}
private void init(String forgeVersion) {
this.forgeVersion = forgeVersion;
clientPatches = getExtension().getProjectPersistentCache().toPath().resolve("patches-" + forgeVersion + "-client.lzma");
serverPatches = getExtension().getProjectPersistentCache().toPath().resolve("patches-" + forgeVersion + "-server.lzma");
}
@Override
public String getTargetConfig() {
return Constants.FORGE;
}
}

View File

@@ -53,6 +53,8 @@ public class Constants {
public static final String MINECRAFT_NAMED = "minecraftNamed";
public static final String MAPPINGS = "mappings";
public static final String MAPPINGS_FINAL = "mappingsFinal";
public static final String MCP_CONFIG = "mcp";
public static final String FORGE = "forge";
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";