Scuffed support for forge and building a forge jar

This commit is contained in:
Babbaj 2020-03-25 00:28:55 -04:00
parent e926ff2a16
commit 261bf005f6
No known key found for this signature in database
GPG Key ID: 48FD0BEFD63C8E3F
11 changed files with 199 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,13 @@ task sourceJar(type: Jar, dependsOn: classes) {
minecraft {
mappings channel: 'snapshot', version: '20200213-1.15.1'
reobfMappings 'notch'
if (getProject().hasProperty("baritone.forge_build")) {
println 'searge mappings!!'
reobfMappings 'searge'
} else {
reobfMappings 'notch'
}
runs {
client {
@ -145,7 +154,8 @@ 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') {
//"org.spongepowered:mixin:0.8.+"
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 +188,48 @@ 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('nword')
}
project.afterEvaluate {
createSrgMc.dependsOn(extractSrg, copyMcJar)
createSrgMc.setMappings(extractSrg.getOutput())
//println(createSrgMc.getClasspath().getFiles())
}
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;
@ -43,28 +44,44 @@ class BaritoneGradleTask extends DefaultTask {
ARTIFACT_STANDARD = "%s-%s.jar",
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
ARTIFACT_API = "%s-api-%s.jar",
ARTIFACT_STANDALONE = "%s-standalone-%s.jar";
ARTIFACT_STANDALONE = "%s-standalone-%s.jar",
ARTIFACT_FORGE_API = "%s-api-forge-%s.jar";
// TODO: forge standalone
protected String artifactName, artifactVersion;
protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, proguardOut;
protected void verifyArtifacts() throws IllegalStateException {
protected final Path
artifactPath, artifactUnoptimizedPath,
// processed by proguard
artifactApiPath, artifactStandalonePath,
proguardOut;
protected final Path artifactForgeApiPath;
{
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));
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
// just make it null if its not used lol
if (getProject().hasProperty("baritone.forge_build")) {
this.artifactForgeApiPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_API));
this.artifactApiPath = null;
this.artifactStandalonePath = null;
} else {
this.artifactForgeApiPath = null;
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

@ -45,6 +45,7 @@ public class CreateDistTask extends BaritoneGradleTask {
Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API));
Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE));
Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED));
Path forgeApi = getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API));
// NIO will not automatically create directories
Path dir = getRelativeFile("dist/");
@ -53,12 +54,18 @@ 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);
if (getProject().hasProperty("baritone.forge_build")) {
Files.copy(this.artifactForgeApiPath, forgeApi, REPLACE_EXISTING);
} else {
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 = Stream.of(forgeApi, api, standalone, unoptimized)
.filter(f -> false) // TODO: dont sha nonexistant artifacts
.map(path -> sha1(path) + " " + path.getFileName().toString())
.collect(Collectors.toList());

View File

@ -56,8 +56,12 @@ public class ProguardTask extends BaritoneGradleTask {
downloadProguard();
extractProguard();
generateConfigs();
proguardApi();
proguardStandalone();
if (getProject().hasProperty("baritone.forge_build")) {
proguardApi(this.artifactForgeApiPath.toString());
} else {
proguardApi(this.artifactApiPath.toString());
proguardStandalone(this.artifactStandalonePath.toString());
}
cleanup();
}
@ -99,18 +103,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,18 +134,25 @@ 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);
//.peek(f -> System.out.println("xd: " + f));
}
private void proguardApi() throws Exception {
private void proguardApi(String artifact) throws Exception {
runProguard(getTemporaryFile(PROGUARD_API_CONFIG));
Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString());
Determinizer.determinize(this.proguardOut.toString(), artifact);
}
private void proguardStandalone() throws Exception {
private void proguardStandalone(String artifact) throws Exception {
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString());
Determinizer.determinize(this.proguardOut.toString(), artifact);
}
private void cleanup() {

View File

@ -17,6 +17,7 @@
# also lwjgl lol
-dontwarn module-info
# 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,30 @@
/*
* 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,8 @@ 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;
//import static org.spongepowered.asm.lib.Opcodes.GETFIELD;
/**
* @author Brady

View File

@ -27,7 +27,8 @@ 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.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,36 @@
# 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="http://my.issue.tracker/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="baritbone" #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="Example Mod" #mandatory
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="http://example.com/" #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="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
authors="Love, Cheese and small house plants" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
This is a long form description of the mod. You can write whatever you want here
Have some lorem ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
'''

View File

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