Merge pull request #1446 from babbaj/1.15.2

Add support for building forge jars
This commit is contained in:
Leijurv 2020-03-25 21:07:45 -07:00 committed by GitHub
commit be2ee1a07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 201 additions and 44 deletions

View File

@ -39,6 +39,9 @@ buildscript {
import baritone.gradle.task.CreateDistTask
import baritone.gradle.task.ProguardTask
import net.minecraftforge.gradle.userdev.tasks.GenerateSRG
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'java'
@ -83,7 +86,12 @@ task sourceJar(type: Jar, dependsOn: classes) {
minecraft {
mappings channel: 'snapshot', version: '20200213-1.15.1'
reobfMappings 'notch'
if (getProject().hasProperty("baritone.forge_build")) {
reobfMappings 'searge'
} else {
reobfMappings 'notch'
}
runs {
client {
@ -145,7 +153,7 @@ dependencies {
}
runtime launchCompile('org.ow2.asm:asm-debug-all:5.2')
runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2')
runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
runtime launchCompile('org.spongepowered:mixin:0.8.+') {
// Mixin includes a lot of dependencies that are too up-to-date
exclude module: 'launchwrapper'
exclude module: 'guava'
@ -178,14 +186,47 @@ jar {
manifest {
attributes(
'MixinConfigs': 'mixins.baritone.json',
"MixinConnector": "baritone.launch.BaritoneMixinConnector",
'Implementation-Title': 'Baritone',
'Implementation-Version': version
'Implementation-Version': version,
)
}
}
task proguard(type: ProguardTask) {
// skidded from ProguardTask
File getClientJar() {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
.stream()
.filter({f -> f.toString().endsWith("client-extra.jar")})
.map({f -> new File(f.getParentFile(), "client.jar")})
.findFirst()
.get()
}
task copyMcJar(type: Copy) {
def mcJar = {getClientJar()}
from mcJar
into 'build/createMcSrgJar/'
rename {'client-srg.jar'}
}
task createSrgMc(type: RenameJarInPlace) {
setInput(new File(copyMcJar.getOutputs().getFiles().getSingleFile(), "client-srg.jar"))
setClasspath(files({getClientJar()}))
// fork
setMappingType(net.minecraftforge.gradle.common.util.MappingFile.Mapping.SEARGE)
setJarTask('trans alaska pipeline')
}
project.afterEvaluate {
createSrgMc.dependsOn(extractSrg, copyMcJar)
createSrgMc.setMappings(extractSrg.getOutput())
}
task proguard(type: ProguardTask, dependsOn: createSrgMc) { // TODO: dont need to create srg mc if doing notch build
url 'https://downloads.sourceforge.net/project/proguard/proguard/6.0/proguard6.0.3.zip'
extract 'proguard6.0.3/lib/proguard.jar'
}

View File

@ -20,6 +20,7 @@ package baritone.gradle.task;
import org.gradle.api.DefaultTask;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
@ -40,31 +41,46 @@ class BaritoneGradleTask extends DefaultTask {
PROGUARD_STANDALONE_CONFIG = "standalone.pro",
PROGUARD_EXPORT_PATH = "proguard_out.jar",
ARTIFACT_STANDARD = "%s-%s.jar",
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
ARTIFACT_API = "%s-api-%s.jar",
ARTIFACT_STANDALONE = "%s-standalone-%s.jar";
ARTIFACT_STANDARD = "%s-%s.jar",
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
ARTIFACT_API = "%s-api-%s.jar",
ARTIFACT_STANDALONE = "%s-standalone-%s.jar",
ARTIFACT_FORGE_UNOPTIMIZED = "%s-unoptimized-forge-%s.jar",
ARTIFACT_FORGE_API = "%s-api-forge-%s.jar",
ARTIFACT_FORGE_STANDALONE = "%s-standalone-forge-%s.jar";
protected String artifactName, artifactVersion;
protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, proguardOut;
protected final Path
artifactPath,
artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, // these are different for forge builds
proguardOut;
protected void verifyArtifacts() throws IllegalStateException {
public BaritoneGradleTask() {
this.artifactName = getProject().getName();
this.artifactVersion = getProject().getVersion().toString();
this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
if (getProject().hasProperty("baritone.forge_build")) {
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_UNOPTIMIZED));
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_STANDALONE));
} else {
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
}
this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH);
}
protected void verifyArtifacts() throws IllegalStateException {
if (!Files.exists(this.artifactPath)) {
throw new IllegalStateException("Artifact not found! Run build first!");
}
}
protected void write(InputStream stream, Path file) throws Exception {
protected void write(InputStream stream, Path file) throws IOException {
if (Files.exists(file)) {
Files.delete(file);
}

View File

@ -23,9 +23,9 @@ import javax.xml.bind.DatatypeConverter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
@ -42,9 +42,9 @@ public class CreateDistTask extends BaritoneGradleTask {
super.verifyArtifacts();
// Define the distribution file paths
Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API));
Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE));
Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED));
Path api = getRelativeFile("dist/" + getFileName(artifactApiPath));
Path standalone = getRelativeFile("dist/" + getFileName(artifactStandalonePath));
Path unoptimized = getRelativeFile("dist/" + getFileName(artifactUnoptimizedPath));
// NIO will not automatically create directories
Path dir = getRelativeFile("dist/");
@ -53,12 +53,14 @@ public class CreateDistTask extends BaritoneGradleTask {
}
// Copy build jars to dist/
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
// TODO: dont copy files that dont exist
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
// Calculate all checksums and format them like "shasum"
List<String> shasum = Stream.of(api, standalone, unoptimized)
List<String> shasum = getAllDistJars().stream()
.filter(Files::exists)
.map(path -> sha1(path) + " " + path.getFileName().toString())
.collect(Collectors.toList());
@ -68,6 +70,21 @@ public class CreateDistTask extends BaritoneGradleTask {
Files.write(getRelativeFile("dist/checksums.txt"), shasum);
}
private static String getFileName(Path p) {
return p.getFileName().toString();
}
private List<Path> getAllDistJars() {
return Arrays.asList(
getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE))
);
}
private static synchronized String sha1(Path path) {
try {
if (SHA1_DIGEST == null) {

View File

@ -99,18 +99,27 @@ public class ProguardTask extends BaritoneGradleTask {
String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", "");
template.add(2, "-libraryjars '" + out + "'");
// Discover all of the libraries that we will need to acquire from gradle
acquireDependencies().forEach(f -> {
if (f.toString().endsWith("-recomp.jar")) {
// remove MCP mapped jar
return;
{
final Stream<File> libraries;
{
// Discover all of the libraries that we will need to acquire from gradle
final Stream<File> dependencies = acquireDependencies()
// remove MCP mapped jar
.filter(f -> !f.toString().endsWith("-recomp.jar"))
// go from the extra to the original downloaded client
.map(f -> f.toString().endsWith("client-extra.jar") ? new File(f.getParentFile(), "client.jar") : f);
if (getProject().hasProperty("baritone.forge_build")) {
libraries = dependencies
.map(f -> f.toString().endsWith("client.jar") ? getSrgMcJar() : f);
} else {
libraries = dependencies;
}
}
if (f.toString().endsWith("client-extra.jar")) {
// go from the extra to the original downloaded client
f = new File(f.getParentFile(), "client.jar");
}
template.add(2, "-libraryjars '" + f + "'");
});
libraries.forEach(f -> {
template.add(2, "-libraryjars '" + f + "'");
});
}
// API config doesn't require any changes from the changes that we made to the template
Files.write(getTemporaryFile(PROGUARD_API_CONFIG), template);
@ -121,8 +130,14 @@ public class ProguardTask extends BaritoneGradleTask {
Files.write(getTemporaryFile(PROGUARD_STANDALONE_CONFIG), standalone);
}
private File getSrgMcJar() {
return getProject().getTasks().findByName("copyMcJar").getOutputs().getFiles().getSingleFile();
}
private Stream<File> acquireDependencies() {
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles().stream().filter(File::isFile);
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
.stream()
.filter(File::isFile);
}
private void proguardApi() throws Exception {

View File

@ -16,7 +16,10 @@
-dontwarn org.lwjgl.**
# also lwjgl lol
-dontwarn module-info
# we dont have forge
-dontwarn baritone.launch.BaritoneForgeModXD
# please do not change the comment below
-keep class baritone.api.** { *; } # this is the keep api
# service provider needs these class names

View File

@ -19,9 +19,6 @@ package baritone.api;
import baritone.api.utils.SettingsUtil;
import java.util.Iterator;
import java.util.ServiceLoader;
/**
* Exposes the {@link IBaritoneProvider} instance and the {@link Settings} instance for API usage.
*
@ -37,9 +34,11 @@ public final class BaritoneAPI {
settings = new Settings();
SettingsUtil.readAndApply(settings);
ServiceLoader<IBaritoneProvider> baritoneLoader = ServiceLoader.load(IBaritoneProvider.class);
Iterator<IBaritoneProvider> instances = baritoneLoader.iterator();
provider = instances.next();
try {
provider = (IBaritoneProvider) Class.forName("baritone.BaritoneProvider").newInstance();
} catch (ReflectiveOperationException ex) {
throw new RuntimeException(ex);
}
}
public static IBaritoneProvider getProvider() {

View File

@ -0,0 +1,29 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.launch;
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.connect.IMixinConnector;
public class BaritoneMixinConnector implements IMixinConnector {
@Override
public void connect() {
Mixins.addConfiguration("mixins.baritone.json");
}
}

View File

@ -32,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.spongepowered.asm.lib.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.GETFIELD;
/**
* @author Brady

View File

@ -27,7 +27,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.lib.Opcodes;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

View File

@ -0,0 +1,32 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[31,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# A URL to refer people to when problems occur with this mod
issueTrackerURL="https://github.com/cabaletta/baritone/issues" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="baritoe" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Baritone" #mandatory
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="https://github.com/cabaletta/baritone" #optional
# A file name (in the root of the mod JAR) containing a logo for display
#logoFile="examplemod.png" #optional
# A text field displayed in the mod UI
credits="Hat Gamers" #optional
# A text field displayed in the mod UI
authors="leijurv, Brady" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
A Minecraft pathfinder bot.
'''

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "baritoe",
"pack_format": 5
}
}

View File

@ -1 +0,0 @@
baritone.BaritoneProvider