diff --git a/README.md b/README.md index 75ce55135..83305b618 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,12 @@ [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) +[![KAMI Blue integration](https://img.shields.io/badge/KAMI%20Blue%20integration-v1.2.14--master-green)](https://github.com/kami-blue/client) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) -[![Future integration](https://img.shields.io/badge/Future%20integration-Soon™%3F%3F%3F-red.svg)](https://futureclient.net/) +[![Future integration](https://img.shields.io/badge/Future%20integration-v1.2.12%20%2F%20v1.3.6%20%2F%20v1.4.4-red)](https://futureclient.net/) [![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/) [![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com/) @@ -34,9 +35,9 @@ A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. -The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.14/baritone-api-forge-1.2.14.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. -For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. +For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. If you need Forge 1.15.2, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.5.3), follow the instructions, and get the `api-forge` jar. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 through 1.15.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). @@ -88,6 +89,16 @@ That's what it's for, sure! (As long as usage is in compliance with the LGPL 3.0 Magic. (Hours of [leijurv](https://github.com/leijurv/) enduring excruciating pain) +### Additional Special Thanks To: + +![YourKit-Logo](https://www.yourkit.com/images/yklogo.png) + +YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. + +YourKit is the creator of the [YourKit Java Profiler](https://www.yourkit.com/java/profiler/), [YourKit .NET Profiler](https://www.yourkit.com/.net/profiler/), and [YourKit YouMonitor](https://www.yourkit.com/youmonitor/). + +We thank them for granting Baritone an OSS license so that we can make our software the best it can be. + ## Why is it called Baritone? -It's named for FitMC's deep sultry voice. +It's named for FitMC's deep sultry voice. diff --git a/USAGE.md b/USAGE.md index b22537406..d817c24cb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -52,7 +52,7 @@ Some common examples: - `version` to get the version of Baritone you're running - `damn` daniel -For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java). +For the rest of the commands, you can take a look at the code [here](https://baritone.leijurv.com/baritone/api/Settings.html). All the settings and documentation are here. If you find HTML easier to read than Javadoc, you can look here. diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index b19efdedd..6ad9e5a4e 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -20,8 +20,21 @@ package baritone.gradle.task; import baritone.gradle.util.Determinizer; import org.apache.commons.io.IOUtils; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.JavaVersion; +import org.gradle.api.NamedDomainObjectContainer; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.internal.file.IdentityFileResolver; +import org.gradle.api.internal.plugins.DefaultConvention; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; +import org.gradle.api.tasks.TaskCollection; +import org.gradle.api.tasks.compile.ForkOptions; +import org.gradle.api.tasks.compile.JavaCompile; +import org.gradle.internal.Pair; +import org.gradle.internal.jvm.Jvm; +import org.gradle.internal.jvm.inspection.DefaultJvmVersionDetector; +import org.gradle.process.internal.DefaultExecActionFactory; import java.io.*; import java.net.URL; @@ -86,6 +99,101 @@ public class ProguardTask extends BaritoneGradleTask { } } + private String getJavaBinPathForProguard() { + String path; + try { + path = findJavaPathByGradleConfig(); + if (path != null) return path; + } + catch (Exception ex) { + System.err.println("Unable to find java by javaCompile options"); + ex.printStackTrace(); + } + + try { + path = findJavaByJavaHome(); + if (path != null) return path; + } + catch(Exception ex) { + System.err.println("Unable to find java by JAVA_HOME"); + ex.printStackTrace(); + } + + + path = findJavaByGradleCurrentRuntime(); + if (path != null) return path; + + throw new Exception("Unable to find java to determine ProGuard libraryjars. Please specify forkOptions.executable in javaCompile," + + " JAVA_HOME environment variable, or make sure to run Gradle with the correct JDK (a v1.8 only)"); + } + + private String findJavaByGradleCurrentRuntime() { + String path = Jvm.current().getJavaExecutable().getAbsolutePath(); + + if (this.validateJavaVersion(path)) { + System.out.println("Using Gradle's runtime Java for ProGuard"); + return path; + } + return null; + } + + private String findJavaByJavaHome() { + final String javaHomeEnv = System.getenv("JAVA_HOME"); + if (javaHomeEnv != null) { + + String path = Jvm.forHome(new File(javaHomeEnv)).getJavaExecutable().getAbsolutePath(); + if (this.validateJavaVersion(path)) { + System.out.println("Detected Java path by JAVA_HOME"); + return path; + } + } + return null; + } + + private String findJavaPathByGradleConfig() { + final TaskCollection javaCompiles = super.getProject().getTasks().withType(JavaCompile.class); + + final JavaCompile compileTask = javaCompiles.iterator().next(); + final ForkOptions forkOptions = compileTask.getOptions().getForkOptions(); + + if (forkOptions != null) { + String javacPath = forkOptions.getExecutable(); + if (javacPath != null) { + File javacFile = new File(javacPath); + if (javacFile.exists()) { + File[] maybeJava = javacFile.getParentFile().listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.equals("java"); + } + }); + + if (maybeJava != null && maybeJava.length > 0) { + String path = maybeJava[0].getAbsolutePath(); + if (this.validateJavaVersion(path)) { + System.out.println("Detected Java path by forkOptions"); + return path; + } + } + } + } + } + return null; + } + + private boolean validateJavaVersion(String java) { + final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java); + + if (!javaVersion.getMajorVersion().equals("8")) { + System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars"); + // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java); + return false; + } + + System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars"); + return true; + } + private void generateConfigs() throws Exception { Files.copy(getRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING); @@ -95,7 +203,7 @@ public class ProguardTask extends BaritoneGradleTask { template.add(1, "-outjars " + this.getTemporaryFile(PROGUARD_EXPORT_PATH)); // Acquire the RT jar using "java -verbose". This doesn't work on Java 9+ - Process p = new ProcessBuilder("java", "-verbose").start(); + Process p = new ProcessBuilder(this.getJavaBinPathForProguard(), "-verbose").start(); String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", ""); template.add(2, "-libraryjars '" + out + "'"); diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 84034ef33..6f64a8350 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -22,7 +22,7 @@ import baritone.api.IBaritoneProvider; import baritone.api.cache.IWorldScanner; import baritone.api.command.ICommandSystem; import baritone.api.schematic.ISchematicSystem; -import baritone.command.BaritoneChatControl; +import baritone.command.ExampleBaritoneControl; import baritone.cache.WorldScanner; import baritone.command.CommandSystem; import baritone.utils.schematic.SchematicSystem; @@ -44,7 +44,7 @@ public final class BaritoneProvider implements IBaritoneProvider { this.all = Collections.singletonList(this.primary); // Setup chat control, just for the primary instance - new BaritoneChatControl(this.primary); + new ExampleBaritoneControl(this.primary); } @Override diff --git a/src/main/java/baritone/command/BaritoneChatControl.java b/src/main/java/baritone/command/ExampleBaritoneControl.java similarity index 98% rename from src/main/java/baritone/command/BaritoneChatControl.java rename to src/main/java/baritone/command/ExampleBaritoneControl.java index 7071cedd8..9c6313dd2 100644 --- a/src/main/java/baritone/command/BaritoneChatControl.java +++ b/src/main/java/baritone/command/ExampleBaritoneControl.java @@ -49,12 +49,12 @@ import java.util.stream.Stream; import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; -public class BaritoneChatControl implements Helper, AbstractGameEventListener { +public class ExampleBaritoneControl implements Helper, AbstractGameEventListener { private static final Settings settings = BaritoneAPI.getSettings(); private final ICommandManager manager; - public BaritoneChatControl(IBaritone baritone) { + public ExampleBaritoneControl(IBaritone baritone) { this.manager = baritone.getCommandManager(); baritone.getGameEventHandler().registerEventListener(this); } diff --git a/src/main/java/baritone/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java index 9bfa8732a..aa6723c27 100644 --- a/src/main/java/baritone/command/defaults/BuildCommand.java +++ b/src/main/java/baritone/command/defaults/BuildCommand.java @@ -46,7 +46,7 @@ public class BuildCommand extends Command { public void execute(String label, IArgConsumer args) throws CommandException { File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile(); if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) { - file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension); + file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension.value); } BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos buildOrigin;