diff --git a/.gitignore b/.gitignore index 6aeefb22e..4aaeac45e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ run/ autotest/ dist/ +volderyarn/ # Gradle build/ diff --git a/.travis.yml b/.travis.yml index 514a408cd..75d14ffc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ install: script: - docker run --name baritone cabaletta/baritone ./gradlew javadoc -#- docker run --name baritone cabaletta/baritone /bin/sh -c "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 128x128x24 -ac +extension GLX +render; DISPLAY=:99 BARITONE_AUTO_TEST=true ./gradlew runAutoTest; cat /code/autotest/success" - docker cp baritone:/code/dist dist - ls dist - cat dist/checksums.txt diff --git a/Dockerfile b/Dockerfile index d861c16ed..81ae402ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM debian:stretch -RUN echo 'deb http://deb.debian.org/debian stretch-backports main' > /etc/apt/sources.list.d/stretch-backports.list - ENV DEBIAN_FRONTEND noninteractive RUN apt update -y @@ -10,15 +8,10 @@ RUN apt install \ openjdk-8-jdk \ --assume-yes -RUN apt install -qq --assume-yes mesa-utils libgl1-mesa-glx libxcursor1 libxrandr2 libxxf86vm1 x11-xserver-utils xfonts-base xserver-common - COPY . /code WORKDIR /code -# this .deb is specially patched to support lwjgl -# source: https://github.com/tectonicus/tectonicus/issues/60#issuecomment-154239173 -RUN dpkg -i scripts/xvfb_1.16.4-1_amd64.deb - RUN ./gradlew build RUN ./gradlew build -Pbaritone.forge_build +RUN ./gradlew build -Pbaritone.fabric_build diff --git a/build.gradle b/build.gradle index 5bf7d85a5..bb39188e3 100755 --- a/build.gradle +++ b/build.gradle @@ -31,25 +31,42 @@ buildscript { maven { url = 'https://www.dogforce-games.com/maven/' } + maven { + url = 'https://maven.fabricmc.net/' + } + maven { + url = 'https://libraries.minecraft.net/' + } + mavenCentral() jcenter() } dependencies { classpath group: 'com.github.ImpactDevelopment', name: 'ForgeGradle', version: '3.0.115' classpath group: 'com.github.ImpactDevelopment', name: 'MixinGradle', version: '0.6.2' + classpath group: 'net.fabricmc', name: 'fabric-loom', version: '0.5-SNAPSHOT' } } + +import baritone.gradle.fabric.CreateVolderYarn 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' -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'org.spongepowered.mixin' + +def mcpVersion = [channel: 'snapshot', version: '20201028-1.16.3'] + +if (getProject().hasProperty("baritone.fabric_build")) { + CreateVolderYarn.genMappings("1.16.4", mcpVersion) + apply plugin: 'fabric-loom' +} else { + apply plugin: 'net.minecraftforge.gradle' + apply plugin: 'org.spongepowered.mixin' +} + sourceCompatibility = targetCompatibility = '1.8' compileJava { @@ -57,6 +74,7 @@ compileJava { options.encoding = "UTF-8" // allow emoji in comments :^) } + sourceSets { api { compileClasspath += main.compileClasspath @@ -86,51 +104,59 @@ task sourceJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.api.allSource } +if (getProject().hasProperty("baritone.fabric_build")) { + minecraft.refmapName = "mixins.baritone.refmap.json" +} else { + minecraft { + mappings mcpVersion -minecraft { - mappings channel: 'snapshot', version: '20201028-1.16.3' + if (getProject().hasProperty("baritone.forge_build")) { + reobfMappings 'searge' + } else { + reobfMappings 'notch' + } - if (getProject().hasProperty("baritone.forge_build")) { - reobfMappings 'searge' - } else { - reobfMappings 'notch' + runs { + client { + workingDirectory project.file('run') + source sourceSets.launch + + main 'baritone.launch.LaunchTesting' + + environment 'assetIndex', '{asset_index}' + environment 'assetDirectory', downloadAssets.output + environment 'nativesDirectory', extractNatives.output + + environment 'tweakClass', 'baritone.launch.BaritoneTweaker' + + if (Os.isFamily(Os.FAMILY_MAC)) { + jvmArgs "-XstartOnFirstThread" + } + } + + autoTest { + workingDirectory project.file('autotest') + source sourceSets.launch + + main 'baritone.launch.LaunchTesting' + + environment 'assetIndex', '{asset_index}' + environment 'assetDirectory', downloadAssets.output + environment 'nativesDirectory', extractNatives.output + + environment 'tweakClass', 'baritone.launch.BaritoneTweaker' + environment 'BARITONE_AUTO_TEST', 'true' + + if (Os.isFamily(Os.FAMILY_MAC)) { + jvmArgs "-XstartOnFirstThread" + } + } + } } - runs { - client { - workingDirectory project.file('run') - source sourceSets.launch - - main 'baritone.launch.LaunchTesting' - - environment 'assetIndex', '{asset_index}' - environment 'assetDirectory', downloadAssets.output - environment 'nativesDirectory', extractNatives.output - - environment 'tweakClass', 'baritone.launch.BaritoneTweaker' - - if (Os.isFamily(Os.FAMILY_MAC)) { - jvmArgs "-XstartOnFirstThread" - } - } - - autoTest { - workingDirectory project.file('autotest') - source sourceSets.launch - - main 'baritone.launch.LaunchTesting' - - environment 'assetIndex', '{asset_index}' - environment 'assetDirectory', downloadAssets.output - environment 'nativesDirectory', extractNatives.output - - environment 'tweakClass', 'baritone.launch.BaritoneTweaker' - environment 'BARITONE_AUTO_TEST', 'true' - - if (Os.isFamily(Os.FAMILY_MAC)) { - jvmArgs "-XstartOnFirstThread" - } - } + mixin { + defaultObfuscationEnv searge + add sourceSets.launch, 'mixins.baritone.refmap.json' } } @@ -151,30 +177,39 @@ repositories { } dependencies { - minecraft 'com.github.ImpactDevelopment:Vanilla:1.16.4' + if (getProject().hasProperty("baritone.fabric_build")) { + minecraft "com.mojang:minecraft:1.16.4" + mappings fileTree(dir: "./build/volderyarn", include: "**.jar") + modImplementation "net.fabricmc:fabric-loader:0.9.1+build.205" - runtime launchCompile('net.minecraft:launchwrapper:1.12') { - exclude module: 'lwjgl' - } - runtime launchCompile('org.ow2.asm:asm-debug-all:5.2') - runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') - 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' - exclude module: 'gson' - exclude module: 'commons-io' - exclude module: 'log4j-core' + // this makes it compile with the forge tweak stuff + implementation 'com.github.ImpactDevelopment:SimpleTweaker:1.2' + implementation('net.minecraft:launchwrapper:1.12') { + exclude module: 'lwjgl' + } + + implementation 'com.google.code.findbugs:jsr305:3.0.2' + } else { + minecraft 'com.github.ImpactDevelopment:Vanilla:1.16.4' + + runtime launchCompile('net.minecraft:launchwrapper:1.12') { + exclude module: 'lwjgl' + } + runtime launchCompile('org.ow2.asm:asm-debug-all:5.2') + runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') + 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' + exclude module: 'gson' + exclude module: 'commons-io' + exclude module: 'log4j-core' + } } testImplementation 'junit:junit:4.12' } -mixin { - defaultObfuscationEnv searge - add sourceSets.launch, 'mixins.baritone.refmap.json' -} - javadoc { options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error options.linkSource true @@ -183,6 +218,25 @@ javadoc { classpath += sourceSets.api.compileClasspath } +if (getProject().hasProperty("baritone.fabric_build")) { + // skidded from fabric-example-mod (comments and all) + tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + + // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too + // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. + // We'll use that if it's available, but otherwise we'll use the older option. + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release = targetVersion + } + } +} + jar { from sourceSets.launch.output, sourceSets.api.output @@ -194,6 +248,15 @@ jar { preserveFileTimestamps = false reproducibleFileOrder = true + if (getProject().hasProperty("baritone.fabric_build")) { + filesMatching("fabric.mod.json") { + expand "version": version + } + } else { + exclude("fabric.mod.json") + } + + manifest { attributes( 'MixinConfigs': 'mixins.baritone.json', @@ -209,39 +272,67 @@ jar { 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")}) + .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'} +File getClientJarFabric() { + return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles() + .stream() + .filter({ f -> f.getName().endsWith("-v2.jar") && f.getName().startsWith("minecraft-") }) + .map({ f -> new File(f.getParentFile().getParentFile(), f.getName().toString().replace("mapped", "intermediary")) }) + .findFirst() + .get() } -task createSrgMc(type: RenameJarInPlace) { - setInput(new File(copyMcJar.getOutputs().getFiles().getSingleFile(), "client-srg.jar")) - setClasspath(files({getClientJar()})) +if (getProject().hasProperty("baritone.fabric_build")) { + task copyMcJar(type: Copy) { + def mcJar = { getClientJarFabric() } + + from mcJar + into 'build/createMcIntermediaryJar/' + rename { 'client.jar' } + } + + task proguard(type: ProguardTask, dependsOn: copyMcJar) { + url 'https://downloads.sourceforge.net/project/proguard/proguard/6.0/proguard6.0.3.zip' + extract 'proguard6.0.3/lib/proguard.jar' + } + + task createDist(type: CreateDistTask, dependsOn: proguard) + +} else { + 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' + } + + task createDist(type: CreateDistTask, dependsOn: proguard) - // 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' -} - -task createDist(type: CreateDistTask, dependsOn: proguard) - build.finalizedBy(createDist) diff --git a/buildSrc/src/main/java/baritone/gradle/fabric/CreateVolderYarn.java b/buildSrc/src/main/java/baritone/gradle/fabric/CreateVolderYarn.java new file mode 100644 index 000000000..9d19d8202 --- /dev/null +++ b/buildSrc/src/main/java/baritone/gradle/fabric/CreateVolderYarn.java @@ -0,0 +1,259 @@ +/* + * 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 . + */ + +package baritone.gradle.fabric; + +import java.io.*; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +/** + * @Author Wagyourtail + */ +public class CreateVolderYarn { + public static String VOLDERYARNFOLDER = "./build/volderyarn/"; + public static String VOLDERYARN = "volderyarn-%s-%s-%s.jar"; + + public static void genMappings(String mcVersion, Map mcpVersion) throws IOException { + //download yarn intermediary + URL intURL = new URL(String.format("https://maven.fabricmc.net/net/fabricmc/intermediary/%s/intermediary-%s-v2.jar", mcVersion, mcVersion)); + String intermediary = readZipContentFromURL(intURL, "mappings/mappings.tiny").get("mappings/mappings.tiny"); + Map mappings = parseTinyMap(intermediary); + + //download srg + URL srgURL = new URL(String.format("https://files.minecraftforge.net/maven/de/oceanlabs/mcp/mcp_config/%s/mcp_config-%s.zip", mcVersion, mcVersion)); + String tsrg = readZipContentFromURL(srgURL, "config/joined.tsrg").get("config/joined.tsrg"); + MCPData mcpData = addTSRGData(mappings, tsrg); + + //download mcp + URL mcpURL = new URL(String.format("https://files.minecraftforge.net/maven/de/oceanlabs/mcp/mcp_%s/%s/mcp_%s-%s.zip", mcpVersion.get("channel"), mcpVersion.get("version"), mcpVersion.get("channel"), mcpVersion.get("version"))); + Map mcpfiles = readZipContentFromURL(mcpURL, "fields.csv", "methods.csv"); + addMCPData(mcpData, mcpfiles.get("fields.csv"), mcpfiles.get("methods.csv")); + + StringBuilder builder = new StringBuilder("tiny\t2\t0\tintermediary\tnamed"); + for (ClassData clazz : mappings.values()) { + builder.append("\n").append(clazz.getIntToMCP()); + } + + File outputFolder = new File(VOLDERYARNFOLDER); + if (!outputFolder.exists() && !outputFolder.mkdirs()) + throw new RuntimeException("Failed to create dir for volderyarn mappings."); + + for (File f : outputFolder.listFiles()) { + if (!f.isDirectory()) f.delete(); + } + + File outputFile = new File(outputFolder, String.format(VOLDERYARN, mcVersion, mcpVersion.get("channel"), mcpVersion.get("version"))); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdir()) + throw new FileNotFoundException("Failed to create folder for volderyarn!"); + } + + try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(outputFile))) { + output.putNextEntry(new ZipEntry("mappings/mappings.tiny")); + byte[] outData = builder.toString().getBytes(StandardCharsets.UTF_8); + output.write(outData, 0, outData.length); + } + } + + private static Map parseTinyMap(String map) { + Map mappings = new LinkedHashMap<>(); + ClassData clazzdata = null; + for (String line : map.split("\n")) { + String[] parts = line.trim().split("\t"); + switch (parts[0]) { + case "c": + mappings.put(parts[1], clazzdata = new ClassData(mappings, parts[1], parts[2])); + break; + case "m": + assert clazzdata != null; + clazzdata.addMethod(parts[2], parts[1], parts[3]); + break; + case "f": + assert clazzdata != null; + clazzdata.addField(parts[2], parts[1], parts[3]); + break; + default: + } + } + return mappings; + } + + private static MCPData addTSRGData(Map mappings, String tsrg) { + MCPData mcpData = new MCPData(); + String[] classes = String.join("\t", tsrg.split("\n\t")).split("\n"); + for (String c : classes) { + String[] lines = c.split("\t"); + String[] classData = lines[0].split("\\s+"); + ClassData clazz = mappings.get(classData[0]); + if (clazz == null) continue; + clazz.mcpName = classData[1]; + for (int i = 1; i < lines.length; ++i) { + String[] lineData = lines[i].split("\\s+"); + //method + if (lineData.length == 3) { + if (!mcpData.methods.containsKey(lineData[2])) mcpData.methods.put(lineData[2], new LinkedList<>()); + MethodData d = clazz.methods.get(lineData[0] + lineData[1]); + if (d == null) continue; + d.mcpName = lineData[2]; + mcpData.methods.get(lineData[2]).add(d); + //field + } else { + if (!mcpData.fields.containsKey(lineData[1])) mcpData.fields.put(lineData[1], new LinkedList<>()); + FieldData d = clazz.fields.get(lineData[0]); + if (d == null) continue; + d.mcpName = lineData[1]; + mcpData.fields.get(lineData[1]).add(d); + } + } + } + return mcpData; + } + + private static void addMCPData(MCPData mcpData, String fields, String methods) { + for (String field : fields.split("\n")) { + String[] fieldData = field.split(","); + mcpData.fields.getOrDefault(fieldData[0].trim(), new LinkedList<>()).forEach(f -> f.mcpName = fieldData[1].trim()); + } + + for (String method : methods.split("\n")) { + String[] methodData = method.split(","); + mcpData.methods.getOrDefault(methodData[0].trim(), new LinkedList<>()).forEach(m -> m.mcpName = methodData[1].trim()); + } + } + + private static Map readZipContentFromURL(URL remote, String... files) throws IOException { + try (ZipInputStream is = new ZipInputStream(new BufferedInputStream(remote.openStream(), 1024))) { + byte[] buff = new byte[1024]; + ZipEntry entry; + Set fileList = new HashSet<>(Arrays.asList(files)); + Map fileContents = new HashMap<>(); + while ((entry = is.getNextEntry()) != null) { + if (fileList.contains(entry.getName())) { + StringBuilder builder = new StringBuilder(); + int read; + while ((read = is.read(buff, 0, 1024)) > 0) { + builder.append(new String(buff, 0, read)); + } + fileContents.put(entry.getName(), builder.toString()); + } + } + return fileContents; + } + } + + private static class ClassData { + final Map classMap; + final String obf; + final String intermediary; + String mcpName; + + final Map methods = new LinkedHashMap<>(); + final Map fields = new LinkedHashMap<>(); + + public ClassData(Map classMap, String obf, String intermediary) { + this.classMap = classMap; + this.obf = obf; + this.intermediary = intermediary; + } + + public void addMethod(String obf, String obfSig, String intermediary) { + methods.put(obf + obfSig, new MethodData(classMap, obf, obfSig, intermediary)); + } + + public void addField(String obf, String obfSig, String intermediary) { + fields.put(obf, new FieldData(classMap, obf, obfSig, intermediary)); + } + + public String getIntToMCP() { + StringBuilder builder = new StringBuilder("c\t").append(intermediary).append("\t").append(mcpName); + for (MethodData method : methods.values()) { + builder.append("\n\tm\t").append(method.getIntermediarySig()).append("\t").append(method.intermediary).append("\t").append(method.mcpName); + } + for (FieldData field : fields.values()) { + builder.append("\n\tf\t").append(field.getIntermediarySig()).append("\t").append(field.intermediary).append("\t").append(field.mcpName); + } + return builder.toString(); + } + } + + private static class MethodData { + final Map classMap; + final String obf; + final String intermediary; + String mcpName; + + final String obfSig; + + public MethodData(Map classMap, String obf, String obfSig, String intermediary) { + this.classMap = classMap; + this.obf = obf; + this.obfSig = obfSig; + this.intermediary = intermediary; + } + + public String getIntermediarySig() { + int offset = 0; + Matcher m = Pattern.compile("L(.+?);").matcher(obfSig); + String intSig = obfSig; + while (m.find()) { + if (!classMap.containsKey(m.group(1))) continue; + String intName = classMap.get(m.group(1)).intermediary; + intSig = intSig.substring(0, m.start(1) + offset) + intName + intSig.substring(m.end(1) + offset); + offset += intName.length() - m.group(1).length(); + } + return intSig; + } + } + + private static class FieldData { + final Map classMap; + final String obf; + final String intermediary; + String mcpName; + + final String obfSig; + + public FieldData(Map classMap, String obf, String obfSig, String intermediary) { + this.classMap = classMap; + this.obf = obf; + this.obfSig = obfSig; + this.intermediary = intermediary; + } + + public String getIntermediarySig() { + Matcher m = Pattern.compile("(\\[*)L(.+?);").matcher(obfSig); + if (m.find()) { + if (!classMap.containsKey(m.group(2))) return obfSig; + return m.group(1) + "L" + classMap.get(m.group(2)).intermediary + ";"; + } else { + return obfSig; + } + } + } + + private static class MCPData { + final Map> methods = new HashMap<>(); + final Map> fields = new HashMap<>(); + } +} diff --git a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java index b77889d79..c86a51e79 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java @@ -41,13 +41,16 @@ 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_FORGE_UNOPTIMIZED = "%s-unoptimized-forge-%s.jar", - ARTIFACT_FORGE_API = "%s-api-forge-%s.jar", - ARTIFACT_FORGE_STANDALONE = "%s-standalone-forge-%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", + ARTIFACT_FABRIC_UNOPTIMIZED = "%s-unoptimized-fabric-%s.jar", + ARTIFACT_FABRIC_API = "%s-api-fabric-%s.jar", + ARTIFACT_FABRIC_STANDALONE = "%s-standalone-fabric-%s.jar"; protected String artifactName, artifactVersion; protected final Path @@ -65,6 +68,10 @@ class BaritoneGradleTask extends DefaultTask { 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 if (getProject().hasProperty("baritone.fabric_build")) { + this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_FABRIC_UNOPTIMIZED)); + this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_FABRIC_API)); + this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_FABRIC_STANDALONE)); } else { this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED)); this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API)); diff --git a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java index 28be55127..ed01841a9 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java @@ -81,7 +81,10 @@ public class CreateDistTask extends BaritoneGradleTask { getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)), getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE)), getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)), - getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED)) + getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED)), + getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_API)), + getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_STANDALONE)), + getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_UNOPTIMIZED)) ); } diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 2485f1056..0773eb5bf 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -222,6 +222,9 @@ public class ProguardTask extends BaritoneGradleTask { if (getProject().hasProperty("baritone.forge_build")) { libraries = dependencies .map(f -> f.toString().endsWith("client.jar") ? getSrgMcJar() : f); + } else if (getProject().hasProperty("baritone.fabric_build")) { + libraries = dependencies + .map(f -> f.getName().endsWith("-v2.jar") && f.getName().startsWith("minecraft-") ? getSrgMcJar() : f); } else { libraries = dependencies; } diff --git a/scripts/xvfb_1.16.4-1_amd64.deb b/scripts/xvfb_1.16.4-1_amd64.deb deleted file mode 100644 index c3ef3de48..000000000 Binary files a/scripts/xvfb_1.16.4-1_amd64.deb and /dev/null differ diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 01aebacad..9acdb614e 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -22,7 +22,6 @@ import baritone.api.IBaritone; import baritone.api.event.events.TickEvent; import baritone.api.event.events.WorldEvent; import baritone.api.event.events.type.EventState; -import baritone.utils.BaritoneAutoTest; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.gui.screen.Screen; @@ -58,14 +57,6 @@ public class MixinMinecraft { } - @Inject( - method = "", - at = @At("RETURN") - ) - private void preInit(CallbackInfo ci) { - BaritoneAutoTest.INSTANCE.onPreInit(); - } - @Inject( method = "runTick", at = @At( diff --git a/src/launch/resources/fabric.mod.json b/src/launch/resources/fabric.mod.json new file mode 100644 index 000000000..e9faec869 --- /dev/null +++ b/src/launch/resources/fabric.mod.json @@ -0,0 +1,31 @@ + +{ + "schemaVersion": 1, + "id": "baritone", + "version": "${version}", + + "name": "Baritone", + "description": "Google Maps for Blockgame", + "authors": [ + "leijurv", "Brady" + ], + "contact": { + "homepage": "https://github.com/cabaletta/baritone", + "sources": "https://github.com/cabaletta/baritone" + }, + + "license": "LGPL-3.0", + "icon": "assets/baritone/icon.png", + + "environment": "*", + "entrypoints": { + }, + "mixins": [ + "mixins.baritone.json" + ], + + "depends": { + "fabricloader": ">=0.7.4", + "minecraft": "1.16.x" + } +} \ No newline at end of file diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 44bccf2bb..f7b44556c 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -29,7 +29,10 @@ import baritone.command.manager.CommandManager; import baritone.event.GameEventHandler; import baritone.process.*; import baritone.selection.SelectionManager; -import baritone.utils.*; +import baritone.utils.BlockStateInterface; +import baritone.utils.GuiClick; +import baritone.utils.InputOverrideHandler; +import baritone.utils.PathingControlManager; import baritone.utils.player.PrimaryPlayerContext; import net.minecraft.client.Minecraft; @@ -117,10 +120,6 @@ public class Baritone implements IBaritone { this.worldProvider = new WorldProvider(); this.selectionManager = new SelectionManager(this); this.commandManager = new CommandManager(this); - - if (BaritoneAutoTest.ENABLE_AUTO_TEST) { - this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE); - } } @Override diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java deleted file mode 100644 index 4037a6fff..000000000 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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 . - */ - -package baritone.utils; - -import baritone.api.BaritoneAPI; -import baritone.api.event.events.TickEvent; -import baritone.api.event.listener.AbstractGameEventListener; -import baritone.api.pathing.goals.Goal; -import baritone.api.pathing.goals.GoalBlock; -import baritone.api.utils.Helper; -import baritone.api.utils.IPlayerContext; -import net.minecraft.client.GameSettings; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screen.MainMenuScreen; -import net.minecraft.client.settings.AmbientOcclusionStatus; -import net.minecraft.client.settings.CloudOption; -import net.minecraft.client.settings.GraphicsFanciness; -import net.minecraft.client.settings.ParticleStatus; -import net.minecraft.client.tutorial.TutorialSteps; -import net.minecraft.server.integrated.IntegratedServer; -import net.minecraft.util.HTTPUtil; -import net.minecraft.util.datafix.codec.DatapackCodec; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.DynamicRegistries; -import net.minecraft.world.*; -import net.minecraft.world.gen.settings.DimensionGeneratorSettings; -import net.minecraft.world.server.ServerWorld; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.OptionalLong; - -/** - * Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific - * seed, setting a specified goal, and only allowing a certain amount of ticks to pass before the pathing test is - * considered a failure. In order to test locally, docker may be used, or through an IDE: Create a run config which runs - * in a separate directory from the primary one (./run), and set the enrivonmental variable {@code BARITONE_AUTO_TEST} - * to {@code true}. - * - * @author leijurv, Brady - */ -public class BaritoneAutoTest implements AbstractGameEventListener, Helper { - - public static final BaritoneAutoTest INSTANCE = new BaritoneAutoTest(); - - public static final boolean ENABLE_AUTO_TEST = "true".equals(System.getenv("BARITONE_AUTO_TEST")); - private static final long TEST_SEED = -928872506371745L; - private static final BlockPos STARTING_POSITION = new BlockPos(0, 65, 0); - private static final Goal GOAL = new GoalBlock(69, 69, 420); - private static final int MAX_TICKS = 3300; - - /** - * Called right after the {@link GameSettings} object is created in the {@link Minecraft} instance. - */ - public void onPreInit() { - if (!BaritoneAutoTest.ENABLE_AUTO_TEST) { - return; - } - System.out.println("Optimizing Game Settings"); - - GameSettings s = mc.gameSettings; - s.framerateLimit = 20; - s.mipmapLevels = 0; - s.particles = ParticleStatus.MINIMAL; - s.overrideWidth = 128; - s.overrideHeight = 128; - s.heldItemTooltips = false; - s.entityShadows = false; - s.chatScale = 0.0F; - s.ambientOcclusionStatus = AmbientOcclusionStatus.OFF; - s.cloudOption = CloudOption.OFF; - s.graphicFanciness = GraphicsFanciness.FAST; - s.tutorialStep = TutorialSteps.NONE; - s.hideGUI = true; - s.fov = 30.0F; - } - - @Override - public void onTick(TickEvent event) { - IPlayerContext ctx = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext(); - // If we're on the main menu then create the test world and launch the integrated server - if (mc.currentScreen instanceof MainMenuScreen) { - System.out.println("Beginning Baritone automatic test routine"); - mc.displayGuiScreen(null); - WorldSettings worldsettings = new WorldSettings("BaritoneAutoTest", GameType.SURVIVAL, false, Difficulty.NORMAL, true, new GameRules(), DatapackCodec.VANILLA_CODEC); - final DynamicRegistries.Impl impl = DynamicRegistries.func_239770_b_(); - mc.createWorld("BaritoneAutoTest", worldsettings, impl, DimensionGeneratorSettings.func_242752_a(impl).create(false, OptionalLong.of(TEST_SEED))); - } - - IntegratedServer server = mc.getIntegratedServer(); - - // If the integrated server is launched and the world has initialized, set the spawn point - // to our defined starting position - if (server != null && server.getWorld(World.OVERWORLD) != null) { - server.setDifficultyForAllWorlds(Difficulty.PEACEFUL, true); - if (mc.player == null) { - server.execute(() -> { - server.getWorld(World.OVERWORLD).func_241124_a__(STARTING_POSITION, 0.0f); - server.getCommandManager().handleCommand(server.getCommandSource(), "/difficulty peaceful"); - int result = server.getCommandManager().handleCommand(server.getCommandSource(), "/gamerule spawnRadius 0"); - if (result != 0) { - throw new IllegalStateException(result + ""); - } - }); - for (final ServerWorld world : mc.getIntegratedServer().getWorlds()) { - // If the world has initialized, set the spawn point to our defined starting position - if (world != null) { - world.getGameRules().get(GameRules.SPAWN_RADIUS).parseIntValue("0"); - world.func_241124_a__(STARTING_POSITION, 0.0f); - } - } - } - } - - if (event.getType() == TickEvent.Type.IN) { // If we're in-game - - // Force the integrated server to share the world to LAN so that - // the ingame pause menu gui doesn't actually pause our game - if (mc.isSingleplayer() && !mc.getIntegratedServer().getPublic()) { - mc.getIntegratedServer().shareToLAN(GameType.SURVIVAL, false, HTTPUtil.getSuitableLanPort()); - } - - // For the first 200 ticks, wait for the world to generate - if (event.getCount() < 200) { - System.out.println("Waiting for world to generate... " + event.getCount()); - return; - } - - // Print out an update of our position every 5 seconds - if (event.getCount() % 100 == 0) { - System.out.println(ctx.playerFeet() + " " + event.getCount()); - } - - // Setup Baritone's pathing goal and (if needed) begin pathing - if (!BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().isActive()) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(GOAL); - } - - // If we have reached our goal, print a message and safely close the game - if (GOAL.isInGoal(ctx.playerFeet())) { - System.out.println("Successfully pathed to " + ctx.playerFeet() + " in " + event.getCount() + " ticks"); - try { - File file = new File("success"); - System.out.println("Writing success to " + file.getAbsolutePath()); - Files.write(file.getAbsoluteFile().toPath(), "Success!".getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - mc.shutdown(); - mc.shutdownMinecraftApplet(); - System.exit(0); - } - - // If we have exceeded the expected number of ticks to complete the pathing - // task, then throw an IllegalStateException to cause the build to fail - if (event.getCount() > MAX_TICKS) { - throw new IllegalStateException("took too long"); - } - } - } - - private BaritoneAutoTest() { - } -}