From d32e822057913cdaf68ebb760230a1bdc32406ed Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 22 Feb 2019 12:13:19 -0800 Subject: [PATCH 01/37] settings overhaul --- USAGE.md | 2 +- src/api/java/baritone/api/Settings.java | 14 ++-- .../java/baritone/api/utils/SettingsUtil.java | 55 ++++++++++------ .../utils/ExampleBaritoneControl.java | 65 ++++++++++++------- 4 files changed, 83 insertions(+), 53 deletions(-) diff --git a/USAGE.md b/USAGE.md index 391e5e456..b73f4afbb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -21,7 +21,7 @@ Other clients like Kami and Asuna have their own custom things (like `-path`), a `help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java#L53). -To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. +To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`. diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 2878e4d69..2879ba782 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -17,6 +17,7 @@ package baritone.api; +import baritone.api.utils.SettingsUtil; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -704,12 +705,6 @@ public final class Settings { */ public final List> allSettings; - public void reset() { - for (Setting setting : allSettings) { - setting.value = setting.defaultValue; - } - } - public final class Setting { public T value; public final T defaultValue; @@ -739,8 +734,13 @@ public final class Settings { return klass; } + @Override public String toString() { - return name + ": " + value; + return SettingsUtil.settingToString(this); + } + + public void reset() { + value = defaultValue; } } diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 07b4cd98d..84e9af689 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -27,10 +27,8 @@ import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; +import java.util.List; import java.util.function.Consumer; import java.util.function.Function; import java.util.regex.Matcher; @@ -89,22 +87,8 @@ public class SettingsUtil { public static synchronized void save(Settings settings) { try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) { - for (Settings.Setting setting : settings.allSettings) { - if (setting.get() == null) { - System.out.println("NULL SETTING?" + setting.getName()); - continue; - } - if (setting.getName().equals("logger")) { - continue; // NO - } - if (setting.value == setting.defaultValue) { - continue; - } - SettingsIO io = map.get(setting.getValueClass()); - if (io == null) { - throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting + " " + setting.getName()); - } - out.write(setting.getName() + " " + io.toString.apply(setting.get()) + "\n"); + for (Settings.Setting setting : modifiedSettings(settings)) { + out.write(settingToString(setting) + "\n"); } } catch (Exception ex) { System.out.println("Exception thrown while saving Baritone settings!"); @@ -112,7 +96,36 @@ public class SettingsUtil { } } - private static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException { + public static List modifiedSettings(Settings settings) { + List modified = new ArrayList<>(); + for (Settings.Setting setting : settings.allSettings) { + if (setting.get() == null) { + System.out.println("NULL SETTING?" + setting.getName()); + continue; + } + if (setting.getName().equals("logger")) { + continue; // NO + } + if (setting.value == setting.defaultValue) { + continue; + } + modified.add(setting); + } + return modified; + } + + public static String settingToString(Settings.Setting setting) throws IllegalStateException { + if (setting.getName().equals("logger")) { + return "logger"; + } + SettingsIO io = map.get(setting.getValueClass()); + if (io == null) { + throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName()); + } + return setting.getName() + " " + io.toString.apply(setting.get()); + } + + public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException { Settings.Setting setting = settings.byLowerName.get(settingName); if (setting == null) { throw new IllegalStateException("No setting by that name"); diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 83a8df6c2..d86504712 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -117,12 +117,33 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } } - if (msg.equals("baritone") || msg.equals("settings")) { - for (Settings.Setting setting : Baritone.settings().allSettings) { + if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) { + logDirect("All settings that have been modified from their default values:"); + for (Settings.Setting setting : SettingsUtil.modifiedSettings(Baritone.settings())) { logDirect(setting.toString()); } return true; } + if (msg.startsWith("settings")) { + String rest = msg.substring("settings".length()); + try { + int page = Integer.parseInt(rest.trim()); + int min = page * 10; + int max = Math.min(Baritone.settings().allSettings.size(), (page + 1) * 10); + logDirect("Settings " + min + " to " + (max - 1) + ":"); + for (int i = min; i < max; i++) { + logDirect(Baritone.settings().allSettings.get(i).toString()); + } + } catch (Exception ex) { // NumberFormatException | ArrayIndexOutOfBoundsException and probably some others I'm forgetting lol + ex.printStackTrace(); + logDirect("All settings:"); + for (Settings.Setting setting : Baritone.settings().allSettings) { + logDirect(setting.toString()); + } + logDirect("To get one page of ten settings at a time, do settings "); + } + return true; + } if (msg.equals("") || msg.equals("help") || msg.equals("?")) { for (String line : HELP_MSG.split("\n")) { logDirect(line); @@ -130,31 +151,24 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.contains(" ")) { - String[] data = msg.split(" "); - if (data.length == 2) { - Settings.Setting setting = Baritone.settings().byLowerName.get(data[0]); - if (setting != null) { + String settingName = msg.substring(0, msg.indexOf(' ')); + String settingValue = msg.substring(msg.indexOf(' ') + 1); + Settings.Setting setting = Baritone.settings().byLowerName.get(settingName); + if (setting != null) { + if (settingValue.equals("reset")) { + logDirect("Resetting setting " + settingName + " to default value."); + setting.reset(); + } else { try { - if (setting.value.getClass() == Long.class) { - setting.value = Long.parseLong(data[1]); - } - if (setting.value.getClass() == Integer.class) { - setting.value = Integer.parseInt(data[1]); - } - if (setting.value.getClass() == Double.class) { - setting.value = Double.parseDouble(data[1]); - } - if (setting.value.getClass() == Float.class) { - setting.value = Float.parseFloat(data[1]); - } - } catch (NumberFormatException e) { - logDirect("Unable to parse " + data[1]); + SettingsUtil.parseAndApply(Baritone.settings(), settingName, settingValue); + } catch (Exception ex) { + logDirect("Unable to parse setting"); return true; } - SettingsUtil.save(Baritone.settings()); - logDirect(setting.toString()); - return true; } + SettingsUtil.save(Baritone.settings()); + logDirect(setting.toString()); + return true; } } if (Baritone.settings().byLowerName.containsKey(msg)) { @@ -278,7 +292,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("reset")) { - Baritone.settings().reset(); + for (Settings.Setting setting : Baritone.settings().allSettings) { + setting.reset(); + } + SettingsUtil.save(Baritone.settings()); logDirect("Baritone settings reset"); return true; } From e63b2f1bf1347d4639f53d0fef1bc6751802c23f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 22 Feb 2019 13:58:03 -0800 Subject: [PATCH 02/37] unused arg --- src/main/java/baritone/pathing/path/PathExecutor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index d4897eecb..4bc86cd46 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -391,7 +391,7 @@ public class PathExecutor implements IPathExecutor, Helper { if (current instanceof MovementTraverse && pathPosition < path.length() - 3) { IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && sprintableAscend(ctx, (MovementTraverse) current, (MovementAscend) next, path.movements().get(pathPosition + 2))) { - if (skipNow(ctx, current, next)) { + if (skipNow(ctx, current)) { logDebug("Skipping traverse to straight ascend"); pathPosition++; onChangeInPathPosition(); @@ -513,7 +513,7 @@ public class PathExecutor implements IPathExecutor, Helper { movement.getDest().add(flatDir.getX() * (i - pathPosition), 0, flatDir.getZ() * (i - pathPosition))); } - private static boolean skipNow(IPlayerContext ctx, IMovement current, IMovement next) { + private static boolean skipNow(IPlayerContext ctx, IMovement current) { double offTarget = Math.abs(current.getDirection().getX() * (current.getSrc().z + 0.5D - ctx.player().posZ)) + Math.abs(current.getDirection().getZ() * (current.getSrc().x + 0.5D - ctx.player().posX)); if (offTarget > 0.1) { return false; From 3b46dbd6a1be8d584c706afabe704f0a1f431a5b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 22 Feb 2019 14:05:29 -0800 Subject: [PATCH 03/37] appease codacy --- .../baritone/pathing/path/PathExecutor.java | 51 +++++++++---------- .../baritone/process/GetToBlockProcess.java | 7 ++- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 4bc86cd46..b025f6899 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -106,33 +106,31 @@ public class PathExecutor implements IPathExecutor, Helper { } BetterBlockPos whereShouldIBe = path.positions().get(pathPosition); BetterBlockPos whereAmI = ctx.playerFeet(); - if (!whereShouldIBe.equals(whereAmI)) { - if (!Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip - for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks - if (whereAmI.equals(path.positions().get(i))) { - logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); - int previousPos = pathPosition; - pathPosition = Math.max(i - 1, 0); // previous step might not actually be done - for (int j = pathPosition; j <= previousPos; j++) { - path.movements().get(j).reset(); - } - onChangeInPathPosition(); - onTick(); - return false; + if (!whereShouldIBe.equals(whereAmI) && !Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip + for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks + if (whereAmI.equals(path.positions().get(i))) { + logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); + int previousPos = pathPosition; + pathPosition = Math.max(i - 1, 0); // previous step might not actually be done + for (int j = pathPosition; j <= previousPos; j++) { + path.movements().get(j).reset(); } + onChangeInPathPosition(); + onTick(); + return false; } - for (int i = pathPosition + 3; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing) - // also don't check pathPosition+2 because reasons - if (whereAmI.equals(path.positions().get(i))) { - if (i - pathPosition > 2) { - logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i); - } - //System.out.println("Double skip sundae"); - pathPosition = i - 1; - onChangeInPathPosition(); - onTick(); - return false; + } + for (int i = pathPosition + 3; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing) + // also don't check pathPosition+2 because reasons + if (whereAmI.equals(path.positions().get(i))) { + if (i - pathPosition > 2) { + logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i); } + //System.out.println("Double skip sundae"); + pathPosition = i - 1; + onChangeInPathPosition(); + onTick(); + return false; } } } @@ -561,10 +559,7 @@ public class PathExecutor implements IPathExecutor, Helper { if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(current.getSrc().up(3)).getBlock())) { return false; } - if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(next.getDest().up(2)).getBlock())) { - return false; - } - return true; + return !MovementHelper.avoidWalkingInto(ctx.world().getBlockState(next.getDest().up(2)).getBlock()); // codacy smh my head } private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 0eb9f339b..cb80926b1 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -131,8 +131,11 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } } } - if (true) { - break; // codacy gets mad if i just end on a break LOL + // i can't do break; (codacy gets mad), and i can't do if(true){break}; (codacy gets mad) + // so i will do this + switch (newBlacklist.size()) { + default: + break outer; } } logDebug("Blacklisting unreachable locations " + newBlacklist); From c808d5a42dd8b07d569eef82c6b438c783d69b47 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 22 Feb 2019 18:12:04 -0600 Subject: [PATCH 04/37] Small build.gradle cleanup and README update --- README.md | 12 ++- build.gradle | 266 +++++++++++++++++++++++++-------------------------- 2 files changed, 141 insertions(+), 137 deletions(-) diff --git a/README.md b/README.md index eb96e9e4a..1039f0f61 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ Have committed at least once a day for the last 6 months =D 🦀 1Leijurv3DWTrGAfmmiTphjhXLvQiHg7K2 +# Getting Started + Here are some links to help to get started: - [Features](FEATURES.md) @@ -46,11 +48,15 @@ Here are some links to help to get started: - [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#allowBreak) -# Chat control - - [Baritone chat control usage](USAGE.md) -# API example +# API + +The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/). +Please note that usage of anything located outside of the ``baritone.api`` package is not supported by the API release +jar. + +Below is an example of basic usage for changing some settings, and then pathing to a X/Z goal. ``` BaritoneAPI.getSettings().allowSprint.value = true; diff --git a/build.gradle b/build.gradle index 996a8e0f7..dabc0367f 100755 --- a/build.gradle +++ b/build.gradle @@ -1,134 +1,132 @@ -/* - * 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 . - */ - -group 'baritone' -version '1.1.6' - -buildscript { - repositories { - maven { - name = 'forge' - url = 'http://files.minecraftforge.net/maven' - } - maven { - name = 'SpongePowered' - url = 'http://repo.spongepowered.org/maven' - } - jcenter() - } - - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' - } -} - - -import baritone.gradle.task.CreateDistTask -import baritone.gradle.task.ProguardTask - -apply plugin: 'java' -apply plugin: 'net.minecraftforge.gradle.tweaker-client' -apply plugin: 'org.spongepowered.mixin' - -sourceCompatibility = targetCompatibility = '1.8' -compileJava { - sourceCompatibility = targetCompatibility = '1.8' - options.encoding = "UTF-8" // allow emoji in comments :^) -} - -sourceSets { - launch { - compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output - } -} - -minecraft { - version = '1.12.2' - mappings = 'stable_39' - tweakClass = 'baritone.launch.BaritoneTweaker' - runDir = 'run' - - // The sources jar should use SRG names not MCP to ensure compatibility with all mappings - makeObfSourceJar = true -} - -repositories { - mavenCentral() - - maven { - name = 'spongepowered-repo' - url = 'http://repo.spongepowered.org/maven/' - } - - maven { - name = 'impactdevelopment-repo' - url = 'https://impactdevelopment.github.io/maven/' - } -} - -dependencies { - runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') - runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { - // 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 - options.encoding "UTF-8" // allow emoji in comments :^) - source += sourceSets.api.allJava - classpath += sourceSets.api.compileClasspath -} - -jar { - from sourceSets.launch.output, sourceSets.api.output - preserveFileTimestamps = false - reproducibleFileOrder = true -} - -jar { - manifest { - attributes( - 'MixinConfigs': 'mixins.baritone.json', - - 'Implementation-Title': 'Baritone', - 'Implementation-Version': version - ) - } -} - -task proguard(type: ProguardTask) { - 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) +/* + * 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 . + */ + +group 'baritone' +version '1.1.6' + +buildscript { + repositories { + maven { + name = 'forge' + url = 'http://files.minecraftforge.net/maven' + } + maven { + name = 'SpongePowered' + url = 'http://repo.spongepowered.org/maven' + } + jcenter() + } + + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' + } +} + + +import baritone.gradle.task.CreateDistTask +import baritone.gradle.task.ProguardTask + +apply plugin: 'java' +apply plugin: 'net.minecraftforge.gradle.tweaker-client' +apply plugin: 'org.spongepowered.mixin' + +sourceCompatibility = targetCompatibility = '1.8' +compileJava { + sourceCompatibility = targetCompatibility = '1.8' + options.encoding = "UTF-8" // allow emoji in comments :^) +} + +sourceSets { + launch { + compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output + } +} + +minecraft { + version = '1.12.2' + mappings = 'stable_39' + tweakClass = 'baritone.launch.BaritoneTweaker' + runDir = 'run' + + // The sources jar should use SRG names not MCP to ensure compatibility with all mappings + makeObfSourceJar = true +} + +repositories { + mavenCentral() + + maven { + name = 'spongepowered-repo' + url = 'http://repo.spongepowered.org/maven/' + } + + maven { + name = 'impactdevelopment-repo' + url = 'https://impactdevelopment.github.io/maven/' + } +} + +dependencies { + runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') + runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + // 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 + options.encoding "UTF-8" // allow emoji in comments :^) + source += sourceSets.api.allJava + classpath += sourceSets.api.compileClasspath +} + +jar { + from sourceSets.launch.output, sourceSets.api.output + preserveFileTimestamps = false + reproducibleFileOrder = true + + manifest { + attributes( + 'MixinConfigs': 'mixins.baritone.json', + + 'Implementation-Title': 'Baritone', + 'Implementation-Version': version + ) + } +} + +task proguard(type: ProguardTask) { + 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) From 5427911da3f37115826707f2c5212dad47a2df78 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 22 Feb 2019 23:29:08 -0800 Subject: [PATCH 05/37] only api in javadoc i guess --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index dabc0367f..b0173f5de 100755 --- a/build.gradle +++ b/build.gradle @@ -103,7 +103,7 @@ javadoc { options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error options.linkSource true options.encoding "UTF-8" // allow emoji in comments :^) - source += sourceSets.api.allJava + source = sourceSets.api.allJava classpath += sourceSets.api.compileClasspath } From cc4335e48e39893b7d6327363e77619b7830d75a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 22 Feb 2019 23:32:23 -0800 Subject: [PATCH 06/37] better links --- README.md | 2 +- USAGE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1039f0f61..8090c904a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Here are some links to help to get started: - [Javadocs](https://baritone.leijurv.com/) -- [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#allowBreak) +- [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail) - [Baritone chat control usage](USAGE.md) diff --git a/USAGE.md b/USAGE.md index b73f4afbb..de5b836d3 100644 --- a/USAGE.md +++ b/USAGE.md @@ -43,7 +43,7 @@ Some common examples: For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java). -All the settings and documentation are here. If you find HTML easier to read than Javadoc, you can look here. +All the settings and documentation are here. If you find HTML easier to read than Javadoc, you can look here. There are about a hundred settings, but here are some fun / interesting / important ones that you might want to look at changing in normal usage of Baritone. The documentation for each can be found at the above links. - `allowBreak` From e8e00e8dfb514bd4c1e34184ec66ded88f317d90 Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 23 Feb 2019 12:27:24 -0600 Subject: [PATCH 07/37] CRLF -> LF It was inconsistent across the board --- gradle/wrapper/gradle-wrapper.properties | 12 +- gradlew.bat | 168 +++---- settings.gradle | 38 +- src/main/java/baritone/Baritone.java | 422 +++++++++--------- src/main/java/baritone/utils/Helper.java | 144 +++--- .../baritone/utils/InputOverrideHandler.java | 280 ++++++------ 6 files changed, 532 insertions(+), 532 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59006a9e6..599a02b7a 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jul 31 21:56:56 PDT 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip +#Tue Jul 31 21:56:56 PDT 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip diff --git a/gradlew.bat b/gradlew.bat index e95643d6a..f9553162f 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,84 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index baa9dfc9b..567f84110 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1,19 +1,19 @@ -/* - * 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 . - */ - -rootProject.name = 'baritone' - +/* + * 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 . + */ + +rootProject.name = 'baritone' + diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 2eb69cba6..51a6ff699 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -1,211 +1,211 @@ -/* - * 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; - -import baritone.api.BaritoneAPI; -import baritone.api.IBaritone; -import baritone.api.Settings; -import baritone.api.event.listener.IEventBus; -import baritone.api.utils.IPlayerContext; -import baritone.behavior.*; -import baritone.cache.WorldProvider; -import baritone.event.GameEventHandler; -import baritone.process.CustomGoalProcess; -import baritone.process.FollowProcess; -import baritone.process.GetToBlockProcess; -import baritone.process.MineProcess; -import baritone.utils.*; -import baritone.utils.player.PrimaryPlayerContext; -import net.minecraft.client.Minecraft; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Executor; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * @author Brady - * @since 7/31/2018 - */ -public class Baritone implements IBaritone { - - private static ThreadPoolExecutor threadPool; - private static File dir; - - static { - threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); - - dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); - if (!Files.exists(dir.toPath())) { - try { - Files.createDirectories(dir.toPath()); - } catch (IOException ignored) {} - } - } - - /** - * Whether or not {@link Baritone#init()} has been called yet - */ - private boolean initialized; - - private GameEventHandler gameEventHandler; - - private List behaviors; - private PathingBehavior pathingBehavior; - private LookBehavior lookBehavior; - private MemoryBehavior memoryBehavior; - private InputOverrideHandler inputOverrideHandler; - - private FollowProcess followProcess; - private MineProcess mineProcess; - private GetToBlockProcess getToBlockProcess; - private CustomGoalProcess customGoalProcess; - - private PathingControlManager pathingControlManager; - - private IPlayerContext playerContext; - private WorldProvider worldProvider; - - public BlockStateInterface bsi; - - Baritone() { - this.gameEventHandler = new GameEventHandler(this); - } - - @Override - public synchronized void init() { - if (initialized) { - return; - } - - // Define this before behaviors try and get it, or else it will be null and the builds will fail! - this.playerContext = PrimaryPlayerContext.INSTANCE; - - this.behaviors = new ArrayList<>(); - { - // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist - pathingBehavior = new PathingBehavior(this); - lookBehavior = new LookBehavior(this); - memoryBehavior = new MemoryBehavior(this); - new InventoryBehavior(this); - inputOverrideHandler = new InputOverrideHandler(this); - new ExampleBaritoneControl(this); - } - - this.pathingControlManager = new PathingControlManager(this); - { - followProcess = new FollowProcess(this); - mineProcess = new MineProcess(this); - customGoalProcess = new CustomGoalProcess(this); // very high iq - getToBlockProcess = new GetToBlockProcess(this); - } - - this.worldProvider = new WorldProvider(); - - if (BaritoneAutoTest.ENABLE_AUTO_TEST) { - this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE); - } - - this.initialized = true; - } - - @Override - public PathingControlManager getPathingControlManager() { - return this.pathingControlManager; - } - - public List getBehaviors() { - return this.behaviors; - } - - public void registerBehavior(Behavior behavior) { - this.behaviors.add(behavior); - this.gameEventHandler.registerEventListener(behavior); - } - - @Override - public InputOverrideHandler getInputOverrideHandler() { - return this.inputOverrideHandler; - } - - @Override - public CustomGoalProcess getCustomGoalProcess() { // Iffy - return this.customGoalProcess; - } - - @Override - public GetToBlockProcess getGetToBlockProcess() { // Iffy - return this.getToBlockProcess; - } - - @Override - public IPlayerContext getPlayerContext() { - return this.playerContext; - } - - public MemoryBehavior getMemoryBehavior() { - return this.memoryBehavior; - } - - @Override - public FollowProcess getFollowProcess() { - return this.followProcess; - } - - @Override - public LookBehavior getLookBehavior() { - return this.lookBehavior; - } - - @Override - public MineProcess getMineProcess() { - return this.mineProcess; - } - - @Override - public PathingBehavior getPathingBehavior() { - return this.pathingBehavior; - } - - @Override - public WorldProvider getWorldProvider() { - return this.worldProvider; - } - - @Override - public IEventBus getGameEventHandler() { - return this.gameEventHandler; - } - - public static Settings settings() { - return BaritoneAPI.getSettings(); - } - - public static File getDir() { - return dir; - } - - public static Executor getExecutor() { - return threadPool; - } -} +/* + * 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; + +import baritone.api.BaritoneAPI; +import baritone.api.IBaritone; +import baritone.api.Settings; +import baritone.api.event.listener.IEventBus; +import baritone.api.utils.IPlayerContext; +import baritone.behavior.*; +import baritone.cache.WorldProvider; +import baritone.event.GameEventHandler; +import baritone.process.CustomGoalProcess; +import baritone.process.FollowProcess; +import baritone.process.GetToBlockProcess; +import baritone.process.MineProcess; +import baritone.utils.*; +import baritone.utils.player.PrimaryPlayerContext; +import net.minecraft.client.Minecraft; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author Brady + * @since 7/31/2018 + */ +public class Baritone implements IBaritone { + + private static ThreadPoolExecutor threadPool; + private static File dir; + + static { + threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); + + dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); + if (!Files.exists(dir.toPath())) { + try { + Files.createDirectories(dir.toPath()); + } catch (IOException ignored) {} + } + } + + /** + * Whether or not {@link Baritone#init()} has been called yet + */ + private boolean initialized; + + private GameEventHandler gameEventHandler; + + private List behaviors; + private PathingBehavior pathingBehavior; + private LookBehavior lookBehavior; + private MemoryBehavior memoryBehavior; + private InputOverrideHandler inputOverrideHandler; + + private FollowProcess followProcess; + private MineProcess mineProcess; + private GetToBlockProcess getToBlockProcess; + private CustomGoalProcess customGoalProcess; + + private PathingControlManager pathingControlManager; + + private IPlayerContext playerContext; + private WorldProvider worldProvider; + + public BlockStateInterface bsi; + + Baritone() { + this.gameEventHandler = new GameEventHandler(this); + } + + @Override + public synchronized void init() { + if (initialized) { + return; + } + + // Define this before behaviors try and get it, or else it will be null and the builds will fail! + this.playerContext = PrimaryPlayerContext.INSTANCE; + + this.behaviors = new ArrayList<>(); + { + // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist + pathingBehavior = new PathingBehavior(this); + lookBehavior = new LookBehavior(this); + memoryBehavior = new MemoryBehavior(this); + new InventoryBehavior(this); + inputOverrideHandler = new InputOverrideHandler(this); + new ExampleBaritoneControl(this); + } + + this.pathingControlManager = new PathingControlManager(this); + { + followProcess = new FollowProcess(this); + mineProcess = new MineProcess(this); + customGoalProcess = new CustomGoalProcess(this); // very high iq + getToBlockProcess = new GetToBlockProcess(this); + } + + this.worldProvider = new WorldProvider(); + + if (BaritoneAutoTest.ENABLE_AUTO_TEST) { + this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE); + } + + this.initialized = true; + } + + @Override + public PathingControlManager getPathingControlManager() { + return this.pathingControlManager; + } + + public List getBehaviors() { + return this.behaviors; + } + + public void registerBehavior(Behavior behavior) { + this.behaviors.add(behavior); + this.gameEventHandler.registerEventListener(behavior); + } + + @Override + public InputOverrideHandler getInputOverrideHandler() { + return this.inputOverrideHandler; + } + + @Override + public CustomGoalProcess getCustomGoalProcess() { // Iffy + return this.customGoalProcess; + } + + @Override + public GetToBlockProcess getGetToBlockProcess() { // Iffy + return this.getToBlockProcess; + } + + @Override + public IPlayerContext getPlayerContext() { + return this.playerContext; + } + + public MemoryBehavior getMemoryBehavior() { + return this.memoryBehavior; + } + + @Override + public FollowProcess getFollowProcess() { + return this.followProcess; + } + + @Override + public LookBehavior getLookBehavior() { + return this.lookBehavior; + } + + @Override + public MineProcess getMineProcess() { + return this.mineProcess; + } + + @Override + public PathingBehavior getPathingBehavior() { + return this.pathingBehavior; + } + + @Override + public WorldProvider getWorldProvider() { + return this.worldProvider; + } + + @Override + public IEventBus getGameEventHandler() { + return this.gameEventHandler; + } + + public static Settings settings() { + return BaritoneAPI.getSettings(); + } + + public static File getDir() { + return dir; + } + + public static Executor getExecutor() { + return threadPool; + } +} diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 9ee6ed59f..f85f240cc 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -1,72 +1,72 @@ -/* - * 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.Baritone; -import net.minecraft.client.Minecraft; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; - -/** - * @author Brady - * @since 8/1/2018 - */ -public interface Helper { - - /** - * Instance of {@link Helper}. Used for static-context reference. - */ - Helper HELPER = new Helper() {}; - - ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format( - "%s[%sBaritone%s]%s", - TextFormatting.DARK_PURPLE, - TextFormatting.LIGHT_PURPLE, - TextFormatting.DARK_PURPLE, - TextFormatting.GRAY - )); - - Minecraft mc = Minecraft.getMinecraft(); - - /** - * Send a message to chat only if chatDebug is on - * - * @param message The message to display in chat - */ - default void logDebug(String message) { - if (!Baritone.settings().chatDebug.get()) { - //System.out.println("Suppressed debug message:"); - //System.out.println(message); - return; - } - logDirect(message); - } - - /** - * Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command) - * - * @param message The message to display in chat - */ - default void logDirect(String message) { - ITextComponent component = MESSAGE_PREFIX.createCopy(); - component.getStyle().setColor(TextFormatting.GRAY); - component.appendSibling(new TextComponentString(" " + message)); - Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component)); - } -} +/* + * 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.Baritone; +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; + +/** + * @author Brady + * @since 8/1/2018 + */ +public interface Helper { + + /** + * Instance of {@link Helper}. Used for static-context reference. + */ + Helper HELPER = new Helper() {}; + + ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format( + "%s[%sBaritone%s]%s", + TextFormatting.DARK_PURPLE, + TextFormatting.LIGHT_PURPLE, + TextFormatting.DARK_PURPLE, + TextFormatting.GRAY + )); + + Minecraft mc = Minecraft.getMinecraft(); + + /** + * Send a message to chat only if chatDebug is on + * + * @param message The message to display in chat + */ + default void logDebug(String message) { + if (!Baritone.settings().chatDebug.get()) { + //System.out.println("Suppressed debug message:"); + //System.out.println(message); + return; + } + logDirect(message); + } + + /** + * Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command) + * + * @param message The message to display in chat + */ + default void logDirect(String message) { + ITextComponent component = MESSAGE_PREFIX.createCopy(); + component.getStyle().setColor(TextFormatting.GRAY); + component.appendSibling(new TextComponentString(" " + message)); + Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component)); + } +} diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index f5ee0530d..6b0a96e70 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -1,140 +1,140 @@ -/* - * 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.Baritone; -import baritone.api.BaritoneAPI; -import baritone.api.event.events.TickEvent; -import baritone.api.utils.IInputOverrideHandler; -import baritone.api.utils.input.Input; -import baritone.behavior.Behavior; -import net.minecraft.client.Minecraft; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.util.MovementInputFromOptions; - -import java.util.HashMap; -import java.util.Map; - -/** - * An interface with the game's control system allowing the ability to - * force down certain controls, having the same effect as if we were actually - * physically forcing down the assigned key. - * - * @author Brady - * @since 7/31/2018 - */ -public final class InputOverrideHandler extends Behavior implements IInputOverrideHandler { - - /** - * Maps inputs to whether or not we are forcing their state down. - */ - private final Map inputForceStateMap = new HashMap<>(); - - private final BlockBreakHelper blockBreakHelper; - - public InputOverrideHandler(Baritone baritone) { - super(baritone); - this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext()); - } - - /** - * Returns whether or not we are forcing down the specified {@link KeyBinding}. - * - * @param key The KeyBinding object - * @return Whether or not it is being forced down - */ - @Override - public final Boolean isInputForcedDown(KeyBinding key) { - Input input = Input.getInputForBind(key); - if (input == null) { - return null; - } - if (input == Input.CLICK_LEFT && inControl()) { - // only override left click off when pathing - return false; - } - if (input == Input.CLICK_RIGHT) { - if (isInputForcedDown(Input.CLICK_RIGHT)) { - // gettoblock and builder can right click even when not pathing; allow them to do so - return true; - } else if (inControl()) { - // but when we are pathing for real, force right click off - return false; - } - } - return null; // dont force any inputs other than left and right click - } - - /** - * Returns whether or not we are forcing down the specified {@link Input}. - * - * @param input The input - * @return Whether or not it is being forced down - */ - @Override - public final boolean isInputForcedDown(Input input) { - return input == null ? false : this.inputForceStateMap.getOrDefault(input, false); - } - - /** - * Sets whether or not the specified {@link Input} is being forced down. - * - * @param input The {@link Input} - * @param forced Whether or not the state is being forced - */ - @Override - public final void setInputForceState(Input input, boolean forced) { - this.inputForceStateMap.put(input, forced); - } - - /** - * Clears the override state for all keys - */ - @Override - public final void clearAllKeys() { - this.inputForceStateMap.clear(); - } - - @Override - public final void onTick(TickEvent event) { - if (event.getType() == TickEvent.Type.OUT) { - return; - } - blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); - - if (inControl()) { - if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) { - ctx.player().movementInput = new PlayerMovementInput(this); - } - } else { - if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam - ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); - } - } - // only set it if it was previously incorrect - // gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol - } - - private boolean inControl() { - return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); - } - - public BlockBreakHelper getBlockBreakHelper() { - return blockBreakHelper; - } -} +/* + * 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.Baritone; +import baritone.api.BaritoneAPI; +import baritone.api.event.events.TickEvent; +import baritone.api.utils.IInputOverrideHandler; +import baritone.api.utils.input.Input; +import baritone.behavior.Behavior; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.util.MovementInputFromOptions; + +import java.util.HashMap; +import java.util.Map; + +/** + * An interface with the game's control system allowing the ability to + * force down certain controls, having the same effect as if we were actually + * physically forcing down the assigned key. + * + * @author Brady + * @since 7/31/2018 + */ +public final class InputOverrideHandler extends Behavior implements IInputOverrideHandler { + + /** + * Maps inputs to whether or not we are forcing their state down. + */ + private final Map inputForceStateMap = new HashMap<>(); + + private final BlockBreakHelper blockBreakHelper; + + public InputOverrideHandler(Baritone baritone) { + super(baritone); + this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext()); + } + + /** + * Returns whether or not we are forcing down the specified {@link KeyBinding}. + * + * @param key The KeyBinding object + * @return Whether or not it is being forced down + */ + @Override + public final Boolean isInputForcedDown(KeyBinding key) { + Input input = Input.getInputForBind(key); + if (input == null) { + return null; + } + if (input == Input.CLICK_LEFT && inControl()) { + // only override left click off when pathing + return false; + } + if (input == Input.CLICK_RIGHT) { + if (isInputForcedDown(Input.CLICK_RIGHT)) { + // gettoblock and builder can right click even when not pathing; allow them to do so + return true; + } else if (inControl()) { + // but when we are pathing for real, force right click off + return false; + } + } + return null; // dont force any inputs other than left and right click + } + + /** + * Returns whether or not we are forcing down the specified {@link Input}. + * + * @param input The input + * @return Whether or not it is being forced down + */ + @Override + public final boolean isInputForcedDown(Input input) { + return input == null ? false : this.inputForceStateMap.getOrDefault(input, false); + } + + /** + * Sets whether or not the specified {@link Input} is being forced down. + * + * @param input The {@link Input} + * @param forced Whether or not the state is being forced + */ + @Override + public final void setInputForceState(Input input, boolean forced) { + this.inputForceStateMap.put(input, forced); + } + + /** + * Clears the override state for all keys + */ + @Override + public final void clearAllKeys() { + this.inputForceStateMap.clear(); + } + + @Override + public final void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + return; + } + blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); + + if (inControl()) { + if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) { + ctx.player().movementInput = new PlayerMovementInput(this); + } + } else { + if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam + ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); + } + } + // only set it if it was previously incorrect + // gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol + } + + private boolean inControl() { + return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); + } + + public BlockBreakHelper getBlockBreakHelper() { + return blockBreakHelper; + } +} From 0bce801a3f97821d9a40b738823d121173dca649 Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 23 Feb 2019 14:32:10 -0600 Subject: [PATCH 08/37] Minor javadoc changes --- src/api/java/baritone/api/BaritoneAPI.java | 4 +- src/api/java/baritone/api/IBaritone.java | 84 ++++++++++++------- .../java/baritone/api/IBaritoneProvider.java | 7 +- src/api/java/baritone/api/Settings.java | 2 +- .../java/baritone/api/behavior/IBehavior.java | 5 ++ 5 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java index c1227830e..4ea6ef3eb 100644 --- a/src/api/java/baritone/api/BaritoneAPI.java +++ b/src/api/java/baritone/api/BaritoneAPI.java @@ -23,9 +23,7 @@ import java.util.Iterator; import java.util.ServiceLoader; /** - * API exposure for various things implemented in Baritone. - *

- * W.I.P + * Exposes the {@link IBaritoneProvider} instance and the {@link Settings} instance for API usage. * * @author Brady * @since 9/23/2018 diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 21157eb15..e88f600e1 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -22,10 +22,7 @@ import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.event.listener.IEventBus; import baritone.api.pathing.calc.IPathingControlManager; -import baritone.api.process.ICustomGoalProcess; -import baritone.api.process.IFollowProcess; -import baritone.api.process.IGetToBlockProcess; -import baritone.api.process.IMineProcess; +import baritone.api.process.*; import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.IPlayerContext; @@ -36,22 +33,13 @@ import baritone.api.utils.IPlayerContext; public interface IBaritone { /** - * @return The {@link IFollowProcess} instance - * @see IFollowProcess + * Call as soon as Minecraft is ready, initializes all of the processes, behaviors, etc. This will + * only effectively be ran once, any additional calls are redundant because the initialization state + * is saved. + *

+ * Or whenever your overeager utility client wants. */ - IFollowProcess getFollowProcess(); - - /** - * @return The {@link ILookBehavior} instance - * @see ILookBehavior - */ - ILookBehavior getLookBehavior(); - - /** - * @return The {@link IMineProcess} instance - * @see IMineProcess - */ - IMineProcess getMineProcess(); + void init(); /** * @return The {@link IPathingBehavior} instance @@ -59,28 +47,66 @@ public interface IBaritone { */ IPathingBehavior getPathingBehavior(); + /** + * @return The {@link ILookBehavior} instance + * @see ILookBehavior + */ + ILookBehavior getLookBehavior(); + + /** + * @return The {@link IFollowProcess} instance + * @see IFollowProcess + */ + IFollowProcess getFollowProcess(); + + /** + * @return The {@link IMineProcess} instance + * @see IMineProcess + */ + IMineProcess getMineProcess(); + + /** + * @return The {@link ICustomGoalProcess} instance + * @see ICustomGoalProcess + */ + ICustomGoalProcess getCustomGoalProcess(); + + /** + * @return The {@link IGetToBlockProcess} instance + * @see IGetToBlockProcess + */ + IGetToBlockProcess getGetToBlockProcess(); + /** * @return The {@link IWorldProvider} instance * @see IWorldProvider */ IWorldProvider getWorldProvider(); + /** + * Returns the {@link IPathingControlManager} for this {@link IBaritone} instance, which is responsible + * for managing the {@link IBaritoneProcess}es which control the {@link IPathingBehavior} state. + * + * @return The {@link IPathingControlManager} instance + * @see IPathingControlManager + */ IPathingControlManager getPathingControlManager(); + /** + * @return The {@link IInputOverrideHandler} instance + * @see IInputOverrideHandler + */ IInputOverrideHandler getInputOverrideHandler(); - ICustomGoalProcess getCustomGoalProcess(); - - IGetToBlockProcess getGetToBlockProcess(); - + /** + * @return The {@link IPlayerContext} instance + * @see IPlayerContext + */ IPlayerContext getPlayerContext(); - IEventBus getGameEventHandler(); - /** - * Call as soon as Minecraft is ready. - *

- * Or whenever your overeager utility client wants. + * @return The {@link IEventBus} instance + * @see IEventBus */ - void init(); + IEventBus getGameEventHandler(); } diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index d17e8e004..34a3aa211 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -23,7 +23,9 @@ import net.minecraft.client.entity.EntityPlayerSP; import java.util.List; /** - * @author Leijurv + * Provides the present {@link IBaritone} instances + * + * @author leijurv */ public interface IBaritoneProvider { @@ -47,7 +49,8 @@ public interface IBaritoneProvider { /** * Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be - * replaced with {@code #getBaritoneForUser(IBaritoneUser)} when {@code bot-system} is merged. + * replaced with or be overloaded in addition to {@code #getBaritoneForUser(IBaritoneUser)} when + * {@code bot-system} is merged into {@code master}. * * @param player The player * @return The {@link IBaritone} instance. diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 2879ba782..2d67dbe34 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -30,7 +30,7 @@ import java.util.List; import java.util.function.Consumer; /** - * Baritone's settings + * Baritone's settings. Settings apply to all Baritone instances. * * @author leijurv */ diff --git a/src/api/java/baritone/api/behavior/IBehavior.java b/src/api/java/baritone/api/behavior/IBehavior.java index 248148e77..fbef52580 100644 --- a/src/api/java/baritone/api/behavior/IBehavior.java +++ b/src/api/java/baritone/api/behavior/IBehavior.java @@ -18,8 +18,13 @@ package baritone.api.behavior; import baritone.api.event.listener.AbstractGameEventListener; +import baritone.api.event.listener.IGameEventListener; /** + * A behavior is simply a type that is able to listen to events. + * + * @see IGameEventListener + * * @author Brady * @since 9/23/2018 */ From 73ec110b22216c3d877887dd2122c323b547443f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 23 Feb 2019 14:03:47 -0800 Subject: [PATCH 09/37] not every player is a baritone --- .../java/baritone/api/IBaritoneProvider.java | 2 +- .../launch/mixins/MixinEntityLivingBase.java | 12 ++++-- .../launch/mixins/MixinEntityPlayerSP.java | 38 +++++++++++++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index 34a3aa211..bdefb66f1 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -61,7 +61,7 @@ public interface IBaritoneProvider { return baritone; } } - throw new IllegalStateException("No baritone for player " + player); + return null; } /** diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java index 460d8a274..0fd2436c9 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java @@ -18,6 +18,7 @@ package baritone.launch.mixins; import baritone.api.BaritoneAPI; +import baritone.api.IBaritone; import baritone.api.event.events.RotationMoveEvent; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; @@ -55,8 +56,11 @@ public abstract class MixinEntityLivingBase extends Entity { private void preMoveRelative(CallbackInfo ci) { // noinspection ConstantConditions if (EntityPlayerSP.class.isInstance(this)) { - this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw); - BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent); + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone != null) { + this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw); + baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent); + } } } @@ -69,7 +73,7 @@ public abstract class MixinEntityLivingBase extends Entity { ) ) private float overrideYaw(EntityLivingBase self) { - if (self instanceof EntityPlayerSP) { + if (self instanceof EntityPlayerSP && BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) != null) { return this.jumpRotationEvent.getYaw(); } return self.rotationYaw; @@ -84,7 +88,7 @@ public abstract class MixinEntityLivingBase extends Entity { ) private void travel(EntityLivingBase self, float strafe, float up, float forward, float friction) { // noinspection ConstantConditions - if (!EntityPlayerSP.class.isInstance(this)) { + if (!EntityPlayerSP.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) == null) { moveRelative(strafe, up, forward, friction); return; } diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 87cc65624..964641ada 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -19,7 +19,6 @@ package baritone.launch.mixins; import baritone.api.BaritoneAPI; import baritone.api.IBaritone; -import baritone.api.behavior.IPathingBehavior; import baritone.api.event.events.ChatEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.SprintStateEvent; @@ -41,6 +40,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityPlayerSP.class) public class MixinEntityPlayerSP { + private IBaritone baritone() { + return + } + @Inject( method = "sendChatMessage", at = @At("HEAD"), @@ -48,7 +51,11 @@ public class MixinEntityPlayerSP { ) private void sendChatMessage(String msg, CallbackInfo ci) { ChatEvent event = new ChatEvent(msg); - BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event); + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone == null) { + return; + } + baritone.getGameEventHandler().onSendChatMessage(event); if (event.isCancelled()) { ci.cancel(); } @@ -64,7 +71,10 @@ public class MixinEntityPlayerSP { ) ) private void onPreUpdate(CallbackInfo ci) { - BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE)); + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone != null) { + baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE)); + } } @Inject( @@ -77,7 +87,10 @@ public class MixinEntityPlayerSP { ) ) private void onPostUpdate(CallbackInfo ci) { - BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST)); + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone != null) { + baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST)); + } } @Redirect( @@ -88,8 +101,11 @@ public class MixinEntityPlayerSP { ) ) private boolean isAllowFlying(PlayerCapabilities capabilities) { - IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior(); - return !pathingBehavior.isPathing() && capabilities.allowFlying; + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone == null) { + return capabilities.allowFlying; + } + return !baritone.getPathingBehavior().isPathing() && capabilities.allowFlying; } @Redirect( @@ -100,8 +116,11 @@ public class MixinEntityPlayerSP { ) ) private boolean isKeyDown(KeyBinding keyBinding) { - SprintStateEvent event = new SprintStateEvent(); IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone == null) { + return keyBinding.isKeyDown(); + } + SprintStateEvent event = new SprintStateEvent(); baritone.getGameEventHandler().onPlayerSprintState(event); if (event.getState() != null) { return event.getState(); @@ -120,6 +139,9 @@ public class MixinEntityPlayerSP { ) ) private void updateRidden(CallbackInfo cb) { - ((LookBehavior) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getLookBehavior()).pig(); + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); + if (baritone != null) { + ((LookBehavior) baritone.getLookBehavior()).pig(); + } } } From e4416f424a865f7e4c11fc1cd971e959973b43f9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 23 Feb 2019 14:13:27 -0800 Subject: [PATCH 10/37] interesting --- src/main/java/baritone/cache/CachedChunk.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/baritone/cache/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java index ebf0bfc95..d2737190f 100644 --- a/src/main/java/baritone/cache/CachedChunk.java +++ b/src/main/java/baritone/cache/CachedChunk.java @@ -85,6 +85,7 @@ public final class CachedChunk { temp.add(Blocks.END_GATEWAY); temp.add(Blocks.WEB); temp.add(Blocks.NETHER_WART); + temp.add(Blocks.LADDER); BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp); } From bd65e32407651bdcad92a818b3a5e24d7c2e5f7e Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 23 Feb 2019 17:04:14 -0600 Subject: [PATCH 11/37] Fix the failing build --- .../java/baritone/launch/mixins/MixinEntityPlayerSP.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 964641ada..7c1225b9b 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -40,10 +40,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityPlayerSP.class) public class MixinEntityPlayerSP { - private IBaritone baritone() { - return - } - @Inject( method = "sendChatMessage", at = @At("HEAD"), From f1084fab768522604911c71798aaf1f0725fa4e2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 23 Feb 2019 20:33:00 -0800 Subject: [PATCH 12/37] come --- src/main/java/baritone/utils/ExampleBaritoneControl.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index d86504712..31ee8ff1f 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -251,6 +251,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Queued " + count + " chunks for repacking"); return true; } + if (msg.equals("come")) { + customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(mc.getRenderViewEntity()))); + logDirect("Coming"); + return true; + } if (msg.equals("axis") || msg.equals("highway")) { customGoalProcess.setGoalAndPath(new GoalAxis()); return true; From 600c5b77ad02864a1fc8cd2de03925a0b36bf643 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 23 Feb 2019 20:43:29 -0800 Subject: [PATCH 13/37] v1.2.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b0173f5de..7d9e09583 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.1.6' +version '1.2.0' buildscript { repositories { From 195c33407e264c525de516cf9bedf7ffb54052c2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 24 Feb 2019 13:43:53 -0800 Subject: [PATCH 14/37] cant walk through heads --- src/main/java/baritone/pathing/movement/MovementHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 0f6659b93..07a983a3e 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -74,7 +74,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.AIR) { // early return for most common case return true; } - if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA) { + if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull) { return false; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { @@ -157,7 +157,8 @@ public interface MovementHelper extends ActionCosts, Helper { || block instanceof BlockSnow || block instanceof BlockLiquid || block instanceof BlockTrapDoor - || block instanceof BlockEndPortal) { + || block instanceof BlockEndPortal + || block instanceof BlockSkull) { return false; } // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters From 583ce800037c1f06bd28f19238ea72ca06588da9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 24 Feb 2019 13:57:33 -0800 Subject: [PATCH 15/37] not reliable enough with jesus to jump from water over a gap --- .../baritone/pathing/movement/movements/MovementParkour.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 74acac48b..185167c69 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -28,6 +28,7 @@ import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.pathing.MutableMoveResult; import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; import net.minecraft.block.BlockStairs; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -85,7 +86,7 @@ public class MovementParkour extends Movement { return; } IBlockState standingOn = context.get(x, y - 1, z); - if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn)) { + if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn) || standingOn.getBlock() instanceof BlockLiquid) { return; } int maxJump; From b19f241d81caee9b0520af4399a507ee4df8fce6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 25 Feb 2019 15:06:55 -0800 Subject: [PATCH 16/37] override for the first tick --- src/main/java/baritone/process/CustomGoalProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 1c4e03118..00d3c8025 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -81,7 +81,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG } return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL); case PATH_REQUESTED: - PathingCommand ret = new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH); + PathingCommand ret = new PathingCommand(this.goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH); this.state = State.EXECUTING; return ret; case EXECUTING: From 7afe16fc1012f0240b096b4889aaa52546aa230e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 25 Feb 2019 16:26:17 -0800 Subject: [PATCH 17/37] dont reset every tick --- src/main/java/baritone/utils/BaritoneAutoTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index b7ae5fbb3..c798c563f 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -115,7 +115,9 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { } // Setup Baritone's pathing goal and (if needed) begin pathing - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(GOAL); + 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())) { From fbb2d37634714ee99fc13f7ec3bd7e8654cf07b6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 25 Feb 2019 18:01:11 -0800 Subject: [PATCH 18/37] allow placing against replacable blocks --- .../java/baritone/pathing/movement/MovementHelper.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 07a983a3e..a3fbf0419 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -40,6 +40,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; +import java.util.Optional; + import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP; /** @@ -494,7 +496,12 @@ public interface MovementHelper extends ActionCosts, Helper { static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) { IPlayerContext ctx = baritone.getPlayerContext(); + Optional direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable boolean found = false; + if (direct.isPresent()) { + state.setTarget(new MovementState.MovementTarget(direct.get(), true)); + found = true; + } for (int i = 0; i < 5; i++) { BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]); if (MovementHelper.canPlaceAgainst(ctx, against1)) { From 6e7320b954bee323f41b8373bd7746ced87b04cb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 25 Feb 2019 18:07:55 -0800 Subject: [PATCH 19/37] v1.2.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7d9e09583..a03a89631 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.0' +version '1.2.1' buildscript { repositories { From 5412fa6cfd92d6249e2c507d06b8fe3164c31ee4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 25 Feb 2019 20:35:06 -0800 Subject: [PATCH 20/37] cursed flowing --- src/main/java/baritone/cache/ChunkPacker.java | 17 ++++++++------ .../pathing/movement/MovementHelper.java | 22 +++++++++++++++---- .../movement/movements/MovementDescend.java | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index e2903ceaf..892369d5b 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -19,10 +19,7 @@ package baritone.cache; import baritone.pathing.movement.MovementHelper; import baritone.utils.pathing.PathingBlockType; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoublePlant; -import net.minecraft.block.BlockFlower; -import net.minecraft.block.BlockTallGrass; +import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -73,7 +70,7 @@ public final class ChunkPacker { for (int x = 0; x < 16; x++) { int index = CachedChunk.getPositionIndex(x, y, z); IBlockState state = bsc.get(x, y1, z); - boolean[] bits = getPathingBlockType(state).getBits(); + boolean[] bits = getPathingBlockType(state, chunk, x, y, z).getBits(); bitSet.set(index, bits[0]); bitSet.set(index + 1, bits[1]); Block block = state.getBlock(); @@ -122,11 +119,17 @@ public final class ChunkPacker { return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n)); } - private static PathingBlockType getPathingBlockType(IBlockState state) { + private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) { Block block = state.getBlock(); - if ((block == Blocks.WATER || block == Blocks.FLOWING_WATER) && !MovementHelper.isFlowing(state)) { + if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) { // only water source blocks are plausibly usable, flowing water should be avoid // FLOWING_WATER is a waterfall, it doesn't really matter and caching it as AVOID just makes it look wrong + if (!MovementHelper.possiblyFlowing(state)) { + return PathingBlockType.WATER; + } + if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) != -1000.0F) { + return PathingBlockType.AVOID; + } return PathingBlockType.WATER; } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index a3fbf0419..592aecd0e 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -109,7 +109,7 @@ public interface MovementHelper extends ActionCosts, Helper { } throw new IllegalStateException(); } - if (isFlowing(state)) { + if (isFlowing(x, y, z, state, bsi)) { return false; // Don't walk through flowing liquids } if (block instanceof BlockLiquid) { @@ -288,10 +288,10 @@ public interface MovementHelper extends ActionCosts, Helper { // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()" // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability Block up = bsi.get0(x, y + 1, z).getBlock(); - if (up == Blocks.WATERLILY) { + if (up == Blocks.WATERLILY || up == Blocks.CARPET) { return true; } - if (isFlowing(state) || block == Blocks.FLOWING_WATER) { + if (isFlowing(x, y, z, state, bsi) || block == Blocks.FLOWING_WATER) { // the only scenario in which we can walk on flowing water is if it's under still water with jesus off return isWater(up) && !Baritone.settings().assumeWalkOnWater.get(); } @@ -488,12 +488,26 @@ public interface MovementHelper extends ActionCosts, Helper { return BlockStateInterface.getBlock(ctx, p) instanceof BlockLiquid; } - static boolean isFlowing(IBlockState state) { + static boolean possiblyFlowing(IBlockState state) { // Will be IFluidState in 1.13 return state.getBlock() instanceof BlockLiquid && state.getValue(BlockLiquid.LEVEL) != 0; } + static boolean isFlowing(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { + if (!(state.getBlock() instanceof BlockLiquid)) { + return false; + } + if (state.getValue(BlockLiquid.LEVEL) != 0) { + return true; + } + return possiblyFlowing(bsi.get0(x + 1, y, z)) + || possiblyFlowing(bsi.get0(x - 1, y, z)) + || possiblyFlowing(bsi.get0(x, y, z + 1)) + || possiblyFlowing(bsi.get0(x, y, z - 1)); + } + + static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) { IPlayerContext ctx = baritone.getPlayerContext(); Optional direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 914a2993e..3a8ed913e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -143,7 +143,7 @@ public class MovementDescend extends Movement { if (context.assumeWalkOnWater) { return false; // TODO fix } - if (MovementHelper.isFlowing(ontoBlock)) { + if (MovementHelper.isFlowing(destX, newY, destZ, ontoBlock, context.bsi)) { return false; // TODO flowing check required here? } if (!MovementHelper.canWalkOn(context.bsi, destX, newY - 1, destZ)) { From 9be44c0371b172fb119d0ba69b93c44b1a367414 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 26 Feb 2019 14:57:44 -0800 Subject: [PATCH 21/37] placement without unepic right click --- src/api/java/baritone/api/Settings.java | 15 ++-- .../api/utils/IInputOverrideHandler.java | 3 - .../baritone/api/utils/IPlayerController.java | 7 ++ .../launch/mixins/MixinKeyBinding.java | 79 ------------------- src/launch/resources/mixins.baritone.json | 1 - .../movement/movements/MovementPillar.java | 2 +- .../java/baritone/utils/BlockBreakHelper.java | 2 +- .../java/baritone/utils/BlockPlaceHelper.java | 53 +++++++++++++ .../baritone/utils/InputOverrideHandler.java | 36 ++------- .../utils/player/PrimaryPlayerController.java | 12 +++ 10 files changed, 86 insertions(+), 124 deletions(-) delete mode 100644 src/launch/java/baritone/launch/mixins/MixinKeyBinding.java create mode 100644 src/main/java/baritone/utils/BlockPlaceHelper.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 2d67dbe34..7b47a2a6f 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -170,6 +170,11 @@ public final class Settings { */ public final Setting sprintAscends = new Setting<>(true); + /** + * How many ticks between right clicks are allowed. Default in game is 4 + */ + public final Setting rightClickSpeed = new Setting<>(4); + /** * This is the big A* setting. * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path. @@ -386,11 +391,6 @@ public final class Settings { */ public final Setting pruneRegionsFromRAM = new Setting<>(false); - /** - * Cancel baritone on left click, as a form of "panic button" - */ - public final Setting clickCancel = new Setting<>(false); - /** * Remember the contents of containers (chests, echests, furnaces) *

@@ -509,11 +509,6 @@ public final class Settings { */ public final Setting cachedChunksOpacity = new Setting<>(0.5f); - /** - * If true, Baritone will not allow you to left or right click while pathing - */ - public final Setting suppressClicks = new Setting<>(false); - /** * Whether or not to use the "#" command prefix */ diff --git a/src/api/java/baritone/api/utils/IInputOverrideHandler.java b/src/api/java/baritone/api/utils/IInputOverrideHandler.java index 03f6e4ddf..3cfb74385 100644 --- a/src/api/java/baritone/api/utils/IInputOverrideHandler.java +++ b/src/api/java/baritone/api/utils/IInputOverrideHandler.java @@ -19,7 +19,6 @@ package baritone.api.utils; import baritone.api.behavior.IBehavior; import baritone.api.utils.input.Input; -import net.minecraft.client.settings.KeyBinding; /** * @author Brady @@ -27,8 +26,6 @@ import net.minecraft.client.settings.KeyBinding; */ public interface IInputOverrideHandler extends IBehavior { - Boolean isInputForcedDown(KeyBinding key); - boolean isInputForcedDown(Input input); void setInputForceState(Input input, boolean forced); diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java index dd63a41b2..dced52865 100644 --- a/src/api/java/baritone/api/utils/IPlayerController.java +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -17,12 +17,17 @@ package baritone.api.utils; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ClickType; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameType; +import net.minecraft.world.World; /** * @author Brady @@ -43,4 +48,6 @@ public interface IPlayerController { default double getBlockReachDistance() { return this.getGameType().isCreative() ? 5.0F : 4.5F; } + + EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand); } diff --git a/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java deleted file mode 100644 index d61537c9d..000000000 --- a/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java +++ /dev/null @@ -1,79 +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.launch.mixins; - -import baritone.Baritone; -import baritone.api.BaritoneAPI; -import baritone.utils.Helper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.settings.KeyBinding; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/** - * @author Brady - * @since 7/31/2018 - */ -@Mixin(KeyBinding.class) -public class MixinKeyBinding { - - @Shadow - private int pressTime; - - @Inject( - method = "isKeyDown", - at = @At("HEAD"), - cancellable = true - ) - private void isKeyDown(CallbackInfoReturnable cir) { - // only the primary baritone forces keys - Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this); - if (force != null) { - if (!force && !Baritone.settings().suppressClicks.get()) { - return; - } - cir.setReturnValue(force); // :sunglasses: - } - } - - @Inject( - method = "isPressed", - at = @At("HEAD"), - cancellable = true - ) - private void isPressed(CallbackInfoReturnable cir) { - // only the primary baritone forces keys - Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this); - if (pressTime > 0 && (KeyBinding) (Object) this == Minecraft.getMinecraft().gameSettings.keyBindAttack && Baritone.settings().clickCancel.get() && BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing()) { - Helper.HELPER.logDirect("Cancelling path on left click since the clickCancel setting is enabled!"); - BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); - return; - } - if (force != null && !force && Baritone.settings().suppressClicks.get()) { // <-- cursed - if (pressTime > 0) { - Helper.HELPER.logDirect("You're trying to press this mouse button but I won't let you."); - Helper.HELPER.logDirect("Turn off the suppressClicks setting to allow clicking while pathing."); - pressTime--; - } - cir.setReturnValue(force); // :sunglasses: - } - } -} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index fea9cca7d..3b5fa70cc 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -17,7 +17,6 @@ "MixinEntityLivingBase", "MixinEntityPlayerSP", "MixinEntityRenderer", - "MixinKeyBinding", "MixinMinecraft", "MixinNetHandlerPlayClient", "MixinNetworkManager", diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index d430f8c58..1bbfa6f91 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -226,7 +226,7 @@ public class MovementPillar extends Movement { if (!(fr instanceof BlockAir || fr.isReplaceable(ctx.world(), src))) { state.setInput(Input.CLICK_LEFT, true); blockIsThere = false; - } else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos()))) { + } else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos())) && ctx.player().posY > dest.getY() + 0.1) { state.setInput(Input.CLICK_RIGHT, true); } } diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index b410e6b37..db56b91f7 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -31,7 +31,7 @@ public final class BlockBreakHelper implements Helper { private boolean didBreakLastTick; - private IPlayerContext playerContext; + private final IPlayerContext playerContext; public BlockBreakHelper(IPlayerContext playerContext) { this.playerContext = playerContext; diff --git a/src/main/java/baritone/utils/BlockPlaceHelper.java b/src/main/java/baritone/utils/BlockPlaceHelper.java new file mode 100644 index 000000000..e0c782bb4 --- /dev/null +++ b/src/main/java/baritone/utils/BlockPlaceHelper.java @@ -0,0 +1,53 @@ +/* + * 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.Baritone; +import baritone.api.utils.IPlayerContext; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; + +public class BlockPlaceHelper implements Helper { + private final IPlayerContext ctx; + private int rightClickTimer; + + public BlockPlaceHelper(IPlayerContext playerContext) { + this.ctx = playerContext; + } + + public void tick(boolean rightClickRequested) { + if (rightClickTimer > 0) { + rightClickTimer--; + return; + } + RayTraceResult mouseOver = ctx.objectMouseOver(); + BlockPos pos = mouseOver.getBlockPos(); + if (!rightClickRequested || ctx.player().isRowingBoat() || pos == null || mouseOver.typeOfHit != RayTraceResult.Type.BLOCK) { + return; + } + rightClickTimer = Baritone.settings().rightClickSpeed.get(); + for (EnumHand hand : EnumHand.values()) { + if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), pos, mouseOver.sideHit, mouseOver.hitVec, hand) == EnumActionResult.SUCCESS) { + ctx.player().swingArm(hand); + return; + } + } + } +} diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 6b0a96e70..47a068546 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -24,7 +24,6 @@ import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.input.Input; import baritone.behavior.Behavior; import net.minecraft.client.Minecraft; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.util.MovementInputFromOptions; import java.util.HashMap; @@ -46,38 +45,12 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri private final Map inputForceStateMap = new HashMap<>(); private final BlockBreakHelper blockBreakHelper; + private final BlockPlaceHelper blockPlaceHelper; public InputOverrideHandler(Baritone baritone) { super(baritone); this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext()); - } - - /** - * Returns whether or not we are forcing down the specified {@link KeyBinding}. - * - * @param key The KeyBinding object - * @return Whether or not it is being forced down - */ - @Override - public final Boolean isInputForcedDown(KeyBinding key) { - Input input = Input.getInputForBind(key); - if (input == null) { - return null; - } - if (input == Input.CLICK_LEFT && inControl()) { - // only override left click off when pathing - return false; - } - if (input == Input.CLICK_RIGHT) { - if (isInputForcedDown(Input.CLICK_RIGHT)) { - // gettoblock and builder can right click even when not pathing; allow them to do so - return true; - } else if (inControl()) { - // but when we are pathing for real, force right click off - return false; - } - } - return null; // dont force any inputs other than left and right click + this.blockPlaceHelper = new BlockPlaceHelper(baritone.getPlayerContext()); } /** @@ -115,7 +88,11 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri if (event.getType() == TickEvent.Type.OUT) { return; } + if (isInputForcedDown(Input.CLICK_LEFT)) { + setInputForceState(Input.CLICK_RIGHT, false); + } blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); + blockPlaceHelper.tick(isInputForcedDown(Input.CLICK_RIGHT)); if (inControl()) { if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) { @@ -131,6 +108,7 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri } private boolean inControl() { + // if we are not primary (a bot) we should set the movementinput even when idle (not pathing) return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); } diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java index c0dc8798b..76e389e77 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -19,12 +19,18 @@ package baritone.utils.player; import baritone.api.utils.IPlayerController; import baritone.utils.Helper; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ClickType; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameType; +import net.minecraft.world.World; /** * Implementation of {@link IPlayerController} that chains to the primary player controller's methods @@ -60,4 +66,10 @@ public enum PrimaryPlayerController implements IPlayerController, Helper { public GameType getGameType() { return mc.playerController.getCurrentGameType(); } + + @Override + public EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) { + // primaryplayercontroller is always in a WorldClient so this is ok + return mc.playerController.processRightClickBlock(player, (WorldClient) world, pos, direction, vec, hand); + } } From c947c778536e46b4ead96838142e4da41af094ab Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 26 Feb 2019 15:07:01 -0800 Subject: [PATCH 22/37] goodbye mc.objectMouseOver --- src/main/java/baritone/utils/player/PrimaryPlayerContext.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 1eefc91f3..20fe98366 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -21,6 +21,7 @@ import baritone.api.BaritoneAPI; import baritone.api.cache.IWorldData; import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerController; +import baritone.api.utils.RayTraceUtils; import baritone.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.util.math.RayTraceResult; @@ -58,6 +59,6 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper { @Override public RayTraceResult objectMouseOver() { - return mc.objectMouseOver; + return RayTraceUtils.rayTraceTowards(player(), playerRotations(), playerController().getBlockReachDistance()); } } From 4086c9f4b5daa157a14bb7d4d52634a6d0c7a794 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 26 Feb 2019 17:25:12 -0600 Subject: [PATCH 23/37] Implement secondary license conditioning Sorry fellas, no anime in this town. --- LICENSE-Part-2.jpg | Bin 0 -> 6834 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 LICENSE-Part-2.jpg diff --git a/LICENSE-Part-2.jpg b/LICENSE-Part-2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d087ee7e07347d5b116d4407290fa56fba240ea5 GIT binary patch literal 6834 zcmb7IWmr_-*PUTt7|EfA4naDkyIYWMq&uVq1WBn8q@+Q*1?d!&Zlt?IB&54}hhIJa zukSwR!=Am@Id?txp1by*`!Msc0)Q&WzK{g~fk1#fVgMfI0a5@kG71<484N}NqoRT# zXizk?Cr{Auv9K|qg!n{6g!nKR2{|n#2`LR33`WI5MMFo=$izrY$;!^kz)s7+$ndxc z5ET^_4T6S;hK9#L0wZDgf7?Sl00#nC0Q>;~sR2khKoAb_p%Xv`00NLek97Yt6fg)G z6$uDIWQh@RMDo8B!T}}{fdEl@hnb%dpwq|VU z<<1)n_wS#QT1K1{#5`9;=1l&E008Bh`B?&dSHvZ@U$aYZPRj1goO#HE7H=ijYk&Q=ghz;(SV$wEn}bk`SxJG7`8WPXc@4}jVO z_qo~MUvHEtby|}>07RC}YLd3tg)laftIjQ8h~)y-8i4}Oox(E&-nb7% zmTPxxP8YI%qOrzexpzOl`Vsckslh=1omaknLWDh*k^KBpN80>4W)@;4fai+O^h>;o zY74Dk(5bR-XutgAX5K&sv-)Ea0Nm`04I-}lm^(G=RWlX(&fQCX_?6q1nm49?s*ZOH zUTT@f~ND~ZS2S>Lex=Tp75{juC5@(P+GdQ8qT7TU+H&+H@} zUfg}>KCz|{33$B1zeb5TOe|0U5E%&wLKw>5aS-A(A*0~ng7Kc>vx^f@b3my~XgImJ zB@pKef;e_S6r_7>fllY9iQyry-QYN@DvYoR!knOq6D=;y(gNRGzw-EbvM|j~>wJbO zQPy^QO(lKDIn65VVo`ct((3;-REgzQt+uV4e{P$Ai@EUYZXL zajh9wlGJhva2iOG!d`Oh1?fpfx=QpOkTl{-YI?sp$6}C{x=c4W2rhpBI7dMSKYc6= zO5{Fs)kd1_^DYDv#U{$FTL5=#$!KvHTBDJ)+_#Ezuo}9e0<2$=-IezA^ta=xv&y;} z7sC=|3f2j78%#+OxaQwxw6p-Dy#VS*({be^=p4 zh&bP4p%6aXU_bT%F+?j02#vn1Ukeql!HgJ0J7{mT(E`T(c%AZRGIrOTLn5Cre5Iiv z+@&Trp|#ML+RsjDihA>F@xkW`fUAyTd_A3wTtP`iN6UO|?S$_6Gpm5>M2h9SmVMZ- zr9H)$o`y!&A%d|ZOgd+t_ChY!ukLv3>e5H^*XbyJHi#u9F|0UTf1_Adof3IRP=$)Q zQy3ECo_5!Eq*KsUr0rjs?tn0%VnMFUq53nLtGR6&A;a?xSiDCM$u;tKh={{%l6kA0 zXN&t|YHA{#cye79fBnjkf>rCnNt3+)3N5(M9Pra>H!WWLR;%HHwX^xCLnu66!MSg9 zy+N;#xmm1HpUhI$-4@w{aSXq5u@aQ>ER0R{LU6QJ7-hQHC->Lanh?*#GMpPX>m!#7 zNW!H+-geAJmF|fg*L{H`c|Xn@(M`0W>kBTTtzRV*U0UTRnc(%!AM#(t92#G!3~vqp zGQu>8u}hKznK5+p8d1mflXb5zQ~I?gw=v60@3XBT=I=&&os`YjL=94yL0!IrV%R*< zXHc*0o04x$#qi`0g|+WXmVf#<7UhDYGT-jf+8xqy#u8+tV6 z6)f6Qwdy+Bl>5wlLF9>}MDl@%8cht_XQ9NL@I`KNZVkSc{H`RJ0kOv{Vx;^tW}Pj& z5?kIs01z)MEe-$)35bM(@?QY}A^|`+$WL+c*f}Ji_~NQAv46d(h!Ph~N$lK}^zD*zNEFz8>kc`Ru-$hc40IiPqb_%!0GY7+l2MS5g<#kn$S$*J8E zV)n=5H8lBmEoE4ZYZ{*Uy7%a1Q2@QB46_{WXurqP=#l9B%~>COm%)C>lQJyg&`#rc zrI2&YI?bOV!)uX+<97+4qO1+=+XJ&J14J5~(HoqULsl3zhCBu&^yHMs9XJAmRO}H9 z1)%`MeMD4MFftfXHW7yS1$bmg%^{%%#iQXAH+5m>l2i|j#dpmfrQ$X*t8629_UZ5+ z9R!OZ-G{OKLLvENQ-;N^v*{=Tcl(Xi=UbpVPh;-)O1{XT5mt{L0tjoz;f^wE5G4V{#eDuie6p*6X)c;g*Au zKavM*O=zsHjWefe&5mX2J~3QG-Yq3ei|3i;-{4Dj^3t~HoQZ|6fwdy9RIT0)rd(I!rd9A1gjO66EL%>u_c7P0=K7Xv`$(5%vZ?04 zB|8KC_JC95J|#|+M5oB(pLwYTW_37}G&9FaQ)00(I;XUOpsG(tS>LW|GWCKxNNL`vfo9>YMzKakcR#I!Wu!=b-!Bt{of)D!gS zMSh&DYl=9&IgQna7`DHmy*-QKT~0~^!=Tc$uuaVC z%MVjrZ`W0Un?toXQ+cT)uW}C$NxOx94rf0iJx$=c&zW*{l)s146m8L(FHPy*a<88G78k(E4kvX&jZ7 zGFsP6$+HdukKUlY%IH^0yt^xIUyaq5F&H$ML5n4_NaeCthUZX{+Mnhu=uS8v(iwDi`qYu%66j|<$X2h-)pKDn)uH7q`b=t(J&F*KYhU>yVYKi+t)HlpKo?VAJ8k- zm%VH5RQR&e`Ay6G9JGC9%I2)2#dDzlTZ)SL(+5CbDc^>j%7D@9ko!{+xNus5+)CvG zAk%JCp)t08N_L8C!O=ZTPvn<)vG5Lm_j%O>yy-nubb^8PMud$q9jlpvE8Ra_i$;6A zz}C;Betw=?JrbKjb7Y{|QMgNX-4$a(PO#rIlBpwsU1(at;QN{qWBjLra+%Qgq2H!z z;Vf+0=S8$Bk`azqk!;k8EWGbu?SbbF+Q)W^_GEc9Xd|;W@|?WOtygi4g7nU?d-;;R;x+Hbb=k@+-pJw=$2aVC;O-8S;cQx{*ox&?JF$Z(2& zVjp``-2<`1tIg&l58CpKCFn=1|rDCgp&z<^GP85t*a9n=ptvGx9Xo+IC8 z@4J=a{)hBa*fQiiUT=ydoiKy;E0DV2`)}{7kjrBSci!riHI46$oQjDi+HEfE^*AMz z+89?-1FW!CBNo0_PBo2X9wc#~rAZKooC-3e+SL-2_bd*EcAa*8rSxhi=Z*qxSP7Eg zkIvu=-D=h8TeE>!<8((tc0|?6^STn3+43>t6K$FjJ%y77=h(0+#q=A*SacQJuDs<; zv|`2!v56>zq2Zb#AE`uNJ^(1;ZOBA&HpwV@!8}9^O3eFb#{f~)X1=-4!+O;nza75C zRo-=AANhf8?>#Hr7LLq*>X`7KifK~3*doV(RSWrHPDA!ZA+&_&*mIH(fEY;ElE%vB z>XYDE%xL6@BT7&T;4A&Or7AE{NJNj@SEWe8f$s*ZmyvF*DY(xddg2TSTF4In8C|#) z?{SNF2iR2JCK^vxoV`eR0QhA;BcRDqV990kX~D}~_~v?UcK@@N@l^4Karz|x?V5jp z4;F(MymS1c;}h@P(>v8uGz=L>C-e(eU){Yfk>4X5f8Z$WayC^criy9@>^n&L%c+|^ zK5Q_78ipe`mG%b!w~FbFU+rQwNT*7|)0unjMUl81R%Wu@787kPfw%NxoDt$btXcgJ zD$&91lqzw9)-A2>BRQLtkZRZ@D#i=vPjGTCizi*WY-zHB1O)C@NCX(aBkxO|v>nSV zJL83oesma+w%&EIMAu|;z^XDEN4aVJEUQlvlLV;bpDrB;w|g#W-E(UeSN^Sypaeh) zWs+Q%5p2;>E>bLW>7;K%n%!)NTXPkRkjz&JVg*xT6|lVjbe+6Lbf>`el7?88ts*k| zZGbY_WP<2e^9HiMW{Wn8$qnvWdez|-x?*^fq}@-r#H3K+8+wMa=N8C|W~lkz1%Af1 z(PPjoQVN1!nTo_KcU=;dJj9DatCND&C9B|G#wGLPD`$M}rJ*fG8HFe6(+$|jK%)&G z@#!nmW1sZtU;f`7d;(&X_HnA7XPHnG9WxWqwBZnvbBT z%Q~Rf6)&{cnsl|d%TkN`eN}jikqPm!+qx`ngQ)A=;~})?udfh*$HotOGA#VRGfRnk z{+|ecC4}GYAD?g}{a+ZolBxV3UmZjf6#eM02Pwo1l60sbe3s)reDg8DNh7+yN;TF0T50HgI@YJ}IS;qariWhiA!wnp*^g@#<~dH+hsXSqzB{Ft80wOW3bM zulcseautQ0jqeP%cKo|i3VQk?KF5cbi%S{%5%CQnq~Yb$ucZ(ipZ&!V35;k@|FOS0 zQi(q*f8Zgs^5`#`k9{%*jsN~j=ouD z`eg7b6Pfh_+mTA>KBWeL%h3GIme+gvuPdC|7dxagZdrk+rs0D#Qb}x-c_vbOfh=Nk z#uPUD%cle2tUoP7fvwx?+J;J*K^KWKTDJShz={u+;_u(YV`=?cq>vCF6%cg)X8d1~ zLX;?|_+Ldz)nxU*A_aW_bQ|wgSOufo9m>8dx(fIrTt5?;5k=qseBm@$4=rII=(ml@ z?H;`=x;i{2WGrPph!$cplip(J=X8ba*eeoD&e@H}!^~k8DS(bN8_kKA_B04fS2#e& zA&U`XokPBgxzETUwIgGc)=7eqf>dS5{wI;QGiy@gu!pw+shIY9V8dZFWK8&(th|l- z#%mUx7q*@CbcBH+uk)4N?A)06`BO_5%oEpyjn{dq{>DDm%GB2$?wczk=*Esnq3($RB3=b1$Tw- z-gR6ML3LyuV6|;fxgYSI)UdZ(@BCfL_u03tMVMjfUnuMWWHV*xkwfe037 z$Lzg}vg%f=F(3eEjV0vS5!|8yF^SfOU?qtSpU2u#?3);&rAPF_$ftlQE+AT*#{_yd5mqv zbrEP9i-_fS0DAog>6MZ;{y(V912aP>Rmj{^)mjut znHiZy{`2%1fVpO{1RL@YP zR`evA3)X8?f^PI@Y*}^ZWi{)1XhB2de$T!rjQCzIgcqZgn#CI?OY+2E<1m6oPMWgo zFudL~s4H4c($YE|b+Kne!*}&C_nWvtN2y-WsCxS=W@cs`*D7sgdvZFqpKtn%(nJ&z z23UV;5IQQkg0?96ZUbVoD#Bv=NhdLi`gu`aZS_bKD?|L0i&jbTig~f`i}KEH5>oW| zQZZC)&xn{)Uuv{mk!^aIE>u6O`JA?jcVj*OzJfo|vS@`?4EqY#D!K;$L+`+1`E#D- z`M5^r5~!>))*xv6kEm+oL3sVzdhRT&55xWNrO@qL>9ddP3$w|5@uP37vvLpP7?^EE z;MeyW*IX2_t7Op_{c)qY1*gIpgPik1CAGCP_?JISa2G&dshdGq$e4>bGiNOEN;WFvAh7CWt$$)-I+3KYT zfzYa$QjBH&1+m11lZNTWr9z~6i06xY@ee1#O1`qH5}peFDmy|ec!~vsLr?NE3zHJ&Tj9H(29s>i zf~KfBYt0Dup(5@Co;}mY6+88rnxwF(TWGWWr!VE-zc@DBIt55nTKdfH18o3OB<3!0 zk()Jai@-kDjo{`ZJoFKa%RThhja+TXBNny4SE-o@G#3nfsDNlvjyZ-@CIlheiQOl_ z8k_>CJ&?qmwP3u1adIb5?Eyf;`f}G_%1(dLKs42yLCH|%BxNaR5K4v3PR{~?4HUcy z>i?8l!&4^bj?@Hk^3Hr+!j({aG^T07e5yZ_!(SeaCHNxQU-| zJe88gW%#3LlN?g5Bg=(kU8gnmoh|uuv093KV$J;b{}^rR%XC2zze# zeF_P>){0i%sb3B|>@1+ Date: Tue, 26 Feb 2019 17:29:50 -0600 Subject: [PATCH 24/37] Better update the badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8090c904a..928acab80 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Baritone [![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone) [![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases) -[![License](https://img.shields.io/badge/license-LGPL--3.0-green.svg)](LICENSE) +[![License](https://img.shields.io/badge/license-LGPL--3.0%20with%20anime%20exception-green.svg)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a73d037823b64a5faf597a18d71e3400)](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade) [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) [![Known Vulnerabilities](https://snyk.io/test/github/cabaletta/baritone/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle) From 3de02cbf21c98d6c7d34fe6a2e7487ed32fed58a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 26 Feb 2019 18:34:11 -0800 Subject: [PATCH 25/37] brady save me idk how to gl --- .../utils/ExampleBaritoneControl.java | 7 ++ .../java/baritone/utils/GuiClickMeme.java | 97 +++++++++++++++++++ .../java/baritone/utils/PathRenderer.java | 3 + 3 files changed, 107 insertions(+) create mode 100644 src/main/java/baritone/utils/GuiClickMeme.java diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 31ee8ff1f..a5fe93e9f 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -407,6 +407,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Started mining blocks of type " + Arrays.toString(blockTypes)); return true; } + if (msg.equals("click")) { + mc.addScheduledTask(() -> { + mc.displayGuiScreen(new GuiClickMeme()); + }); + logDirect("click owo"); + return true; + } if (msg.startsWith("thisway") || msg.startsWith("forward")) { try { Goal goal = GoalXZ.fromDirection(ctx.playerFeetAsVec(), ctx.player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); diff --git a/src/main/java/baritone/utils/GuiClickMeme.java b/src/main/java/baritone/utils/GuiClickMeme.java new file mode 100644 index 000000000..1e5e096e3 --- /dev/null +++ b/src/main/java/baritone/utils/GuiClickMeme.java @@ -0,0 +1,97 @@ +/* + * 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.Baritone; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.Display; +import org.lwjgl.util.glu.GLU; + +import java.awt.*; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import static org.lwjgl.opengl.GL11.*; + +public class GuiClickMeme extends GuiScreen { + private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16); + private final FloatBuffer PROJECTION = BufferUtils.createFloatBuffer(16); + private final IntBuffer VIEWPORT = BufferUtils.createIntBuffer(16); + private final FloatBuffer TO_SCREEN_BUFFER = BufferUtils.createFloatBuffer(3); + private final FloatBuffer TO_WORLD_BUFFER = BufferUtils.createFloatBuffer(3); + private Vec3d meme; + + @Override + public boolean doesGuiPauseGame() { + return false; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + System.out.println("Screen " + mouseX + " " + mouseY); + System.out.println(toWorld(mouseX, mouseY, 0)); + System.out.println(toWorld(mouseX, mouseY, 0.1)); + System.out.println(toWorld(mouseX, mouseY, 1)); + System.out.println(VIEWPORT.get(3) + " " + Display.getHeight()); + meme = toWorld(mouseX, Display.getHeight() - mouseY, 0); + System.out.println(toScreen(mc.player.posX + 1, mc.player.posY, mc.player.posZ)); + System.out.println(toScreen(1, 0, 0)); + } + + public void onRender(float partialTicks) { + System.out.println("on render"); + GlStateManager.getFloat(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear()); + GlStateManager.getFloat(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear()); + GlStateManager.glGetInteger(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear()); + if (meme != null) { + Entity e = mc.getRenderViewEntity(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + GlStateManager.color(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F); + GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + PathRenderer.drawLine(e, e.posX + 1, e.posY, e.posZ, e.posX + meme.x + 1, e.posY + meme.y, e.posZ + meme.z, partialTicks); + Tessellator.getInstance().draw(); + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + } + + public Vec3d toWorld(double x, double y, double z) { + boolean result = GLU.gluUnProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_WORLD_BUFFER.clear()); + if (result) { + return new Vec3d(TO_WORLD_BUFFER.get(0), TO_WORLD_BUFFER.get(1), TO_WORLD_BUFFER.get(2)); + } + return null; + } + + public Vec3d toScreen(double x, double y, double z) { + boolean result = GLU.gluProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_SCREEN_BUFFER.clear()); + if (result) { + return new Vec3d(TO_SCREEN_BUFFER.get(0), Display.getHeight() - TO_SCREEN_BUFFER.get(1), TO_SCREEN_BUFFER.get(2)); + } + return null; + } +} diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 06e298be3..a51f2e8d7 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -59,6 +59,9 @@ public final class PathRenderer implements Helper { public static void render(RenderEvent event, PathingBehavior behavior) { float partialTicks = event.getPartialTicks(); Goal goal = behavior.getGoal(); + if (mc.currentScreen instanceof GuiClickMeme) { + ((GuiClickMeme) mc.currentScreen).onRender(partialTicks); + } int thisPlayerDimension = behavior.baritone.getPlayerContext().world().provider.getDimensionType().getId(); int currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().provider.getDimensionType().getId(); From c474cdb1f819853f8fb8c430bde713e9d74b7098 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 26 Feb 2019 21:41:08 -0600 Subject: [PATCH 26/37] Working clicking goals --- .../utils/ExampleBaritoneControl.java | 11 +++-- .../java/baritone/utils/GuiClickMeme.java | 48 ++++++++++++++----- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index a5fe93e9f..041a54011 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -408,10 +408,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("click")) { - mc.addScheduledTask(() -> { - mc.displayGuiScreen(new GuiClickMeme()); - }); - logDirect("click owo"); + new Thread(() -> { + try { + Thread.sleep(100); + mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiClickMeme())); + } catch (Exception ignored) {} + }).start(); + logDirect("aight dude"); return true; } if (msg.startsWith("thisway") || msg.startsWith("forward")) { diff --git a/src/main/java/baritone/utils/GuiClickMeme.java b/src/main/java/baritone/utils/GuiClickMeme.java index 1e5e096e3..66a067255 100644 --- a/src/main/java/baritone/utils/GuiClickMeme.java +++ b/src/main/java/baritone/utils/GuiClickMeme.java @@ -18,28 +18,37 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.BaritoneAPI; +import baritone.api.pathing.goals.GoalBlock; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import org.lwjgl.BufferUtils; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.util.glu.GLU; import java.awt.*; +import java.io.IOException; import java.nio.FloatBuffer; import java.nio.IntBuffer; +import java.util.Collections; import static org.lwjgl.opengl.GL11.*; public class GuiClickMeme extends GuiScreen { + + // My name is Brady and I grant Leijurv permission to use this pasted code private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16); private final FloatBuffer PROJECTION = BufferUtils.createFloatBuffer(16); private final IntBuffer VIEWPORT = BufferUtils.createIntBuffer(16); private final FloatBuffer TO_SCREEN_BUFFER = BufferUtils.createFloatBuffer(3); private final FloatBuffer TO_WORLD_BUFFER = BufferUtils.createFloatBuffer(3); - private Vec3d meme; + + private BlockPos meme; @Override public boolean doesGuiPauseGame() { @@ -48,21 +57,32 @@ public class GuiClickMeme extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { - System.out.println("Screen " + mouseX + " " + mouseY); - System.out.println(toWorld(mouseX, mouseY, 0)); - System.out.println(toWorld(mouseX, mouseY, 0.1)); - System.out.println(toWorld(mouseX, mouseY, 1)); - System.out.println(VIEWPORT.get(3) + " " + Display.getHeight()); - meme = toWorld(mouseX, Display.getHeight() - mouseY, 0); - System.out.println(toScreen(mc.player.posX + 1, mc.player.posY, mc.player.posZ)); - System.out.println(toScreen(1, 0, 0)); + int mx = Mouse.getX(); + int my = Mouse.getY(); + Vec3d near = toWorld(mx, my, 0); + Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - Leijurv + if (near != null && far != null) { + Vec3d viewerPos = new Vec3d(mc.getRenderManager().viewerPosX, mc.getRenderManager().viewerPosY, mc.getRenderManager().viewerPosZ); + RayTraceResult result = mc.world.rayTraceBlocks(near.add(viewerPos), far.add(viewerPos), false, false, true); + if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { + meme = result.getBlockPos(); + } + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (mouseButton == 0) { + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoal(new GoalBlock(meme)); + } } public void onRender(float partialTicks) { - System.out.println("on render"); GlStateManager.getFloat(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear()); GlStateManager.getFloat(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear()); GlStateManager.glGetInteger(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear()); + if (meme != null) { Entity e = mc.getRenderViewEntity(); GlStateManager.enableBlend(); @@ -71,8 +91,10 @@ public class GuiClickMeme extends GuiScreen { GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); - PathRenderer.drawLine(e, e.posX + 1, e.posY, e.posZ, e.posX + meme.x + 1, e.posY + meme.y, e.posZ + meme.z, partialTicks); - Tessellator.getInstance().draw(); + + // drawSingleSelectionBox WHEN? + PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(meme), partialTicks, Color.CYAN); + GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); From 3dbbe053d7a9d90ee0b3f246abde32af6967681f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 26 Feb 2019 19:45:20 -0800 Subject: [PATCH 27/37] teensy change --- src/main/java/baritone/utils/GuiClickMeme.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/GuiClickMeme.java b/src/main/java/baritone/utils/GuiClickMeme.java index 66a067255..8f485ffb9 100644 --- a/src/main/java/baritone/utils/GuiClickMeme.java +++ b/src/main/java/baritone/utils/GuiClickMeme.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.pathing.goals.GoalBlock; +import baritone.api.pathing.goals.GoalTwoBlocks; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; @@ -74,7 +75,9 @@ public class GuiClickMeme extends GuiScreen { protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); if (mouseButton == 0) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoal(new GoalBlock(meme)); + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalTwoBlocks(meme)); + } else if (mouseButton == 1) { + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(meme.up())); } } From 76914b78591985e190ee8b00a3405aa6793c72ae Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 26 Feb 2019 19:50:35 -0800 Subject: [PATCH 28/37] awesome --- scripts/proguard.pro | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/proguard.pro b/scripts/proguard.pro index e4189f7f3..1c67e2584 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -13,8 +13,7 @@ -repackageclasses 'baritone' # lwjgl is weird --dontwarn org.lwjgl.opengl.GL14 --dontwarn org.lwjgl.opengl.GL11 +-dontwarn org.lwjgl.* -keep class baritone.api.** { *; } # this is the keep api From 596849c7e68be492c662e6653602fbb23149e310 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 26 Feb 2019 19:51:20 -0800 Subject: [PATCH 29/37] i am rarted --- scripts/proguard.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 1c67e2584..4bed6b5dc 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -13,7 +13,7 @@ -repackageclasses 'baritone' # lwjgl is weird --dontwarn org.lwjgl.* +-dontwarn org.lwjgl.** -keep class baritone.api.** { *; } # this is the keep api From a47b0c0581b59436e9fdf2ef4af9c4bcae53a4a9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Feb 2019 12:00:39 -0800 Subject: [PATCH 30/37] rendering cleanup, fixes #317 --- .../java/baritone/utils/GuiClickMeme.java | 22 +------------ .../java/baritone/utils/PathRenderer.java | 33 ++++++++----------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/src/main/java/baritone/utils/GuiClickMeme.java b/src/main/java/baritone/utils/GuiClickMeme.java index 8f485ffb9..1db794bab 100644 --- a/src/main/java/baritone/utils/GuiClickMeme.java +++ b/src/main/java/baritone/utils/GuiClickMeme.java @@ -17,7 +17,6 @@ package baritone.utils; -import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalTwoBlocks; @@ -88,19 +87,8 @@ public class GuiClickMeme extends GuiScreen { if (meme != null) { Entity e = mc.getRenderViewEntity(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); - GlStateManager.color(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F); - GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - // drawSingleSelectionBox WHEN? - PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(meme), partialTicks, Color.CYAN); - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); + PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(meme), Color.CYAN); } } @@ -111,12 +99,4 @@ public class GuiClickMeme extends GuiScreen { } return null; } - - public Vec3d toScreen(double x, double y, double z) { - boolean result = GLU.gluProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_SCREEN_BUFFER.clear()); - if (result) { - return new Vec3d(TO_SCREEN_BUFFER.get(0), Display.getHeight() - TO_SCREEN_BUFFER.get(1), TO_SCREEN_BUFFER.get(2)); - } - return null; - } } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index a51f2e8d7..c0af870ee 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -105,9 +105,9 @@ public final class PathRenderer implements Helper { //long split = System.nanoTime(); if (current != null) { - drawManySelectionBoxes(renderView, current.toBreak(), partialTicks, Baritone.settings().colorBlocksToBreak.get()); - drawManySelectionBoxes(renderView, current.toPlace(), partialTicks, Baritone.settings().colorBlocksToPlace.get()); - drawManySelectionBoxes(renderView, current.toWalkInto(), partialTicks, Baritone.settings().colorBlocksToWalkInto.get()); + drawManySelectionBoxes(renderView, current.toBreak(), Baritone.settings().colorBlocksToBreak.get()); + drawManySelectionBoxes(renderView, current.toPlace(), Baritone.settings().colorBlocksToPlace.get()); + drawManySelectionBoxes(renderView, current.toWalkInto(), Baritone.settings().colorBlocksToWalkInto.get()); } // If there is a path calculation currently running, render the path calculation process @@ -118,7 +118,7 @@ public final class PathRenderer implements Helper { currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> { drawPath(mr, 0, renderView, partialTicks, Baritone.settings().colorMostRecentConsidered.get(), Baritone.settings().fadePath.get(), 10, 20); - drawManySelectionBoxes(renderView, Collections.singletonList(mr.getDest()), partialTicks, Baritone.settings().colorMostRecentConsidered.get()); + drawManySelectionBoxes(renderView, Collections.singletonList(mr.getDest()), Baritone.settings().colorMostRecentConsidered.get()); }); }); //long end = System.nanoTime(); @@ -175,7 +175,7 @@ public final class PathRenderer implements Helper { } GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], alpha); } - drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks); + drawLine(player, x1, y1, z1, x2, y2, z2); tessellator.draw(); } if (Baritone.settings().renderPathIgnoreDepth.get()) { @@ -187,10 +187,10 @@ public final class PathRenderer implements Helper { GlStateManager.disableBlend(); } - public static void drawLine(Entity player, double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z, float partialTicks) { - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; + public static void drawLine(Entity player, double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z) { + double d0 = mc.getRenderManager().viewerPosX; + double d1 = mc.getRenderManager().viewerPosY; + double d2 = mc.getRenderManager().viewerPosZ; BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex(); BUFFER.pos(bp2x + 0.5D - d0, bp2y + 0.5D - d1, bp2z + 0.5D - d2).endVertex(); @@ -199,7 +199,7 @@ public final class PathRenderer implements Helper { BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex(); } - public static void drawManySelectionBoxes(Entity player, Collection positions, float partialTicks, Color color) { + public static void drawManySelectionBoxes(Entity player, Collection positions, Color color) { GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); @@ -213,10 +213,6 @@ public final class PathRenderer implements Helper { float expand = 0.002F; //BlockPos blockpos = movingObjectPositionIn.getBlockPos(); - - double renderPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; - double renderPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; - double renderPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; BlockStateInterface bsi = new BlockStateInterface(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()); // TODO this assumes same dimension between primary baritone and render view? is this safe? positions.forEach(pos -> { IBlockState state = bsi.get0(pos); @@ -226,7 +222,7 @@ public final class PathRenderer implements Helper { } else { toDraw = state.getSelectedBoundingBox(player.world, pos); } - toDraw = toDraw.expand(expand, expand, expand).offset(-renderPosX, -renderPosY, -renderPosZ); + toDraw = toDraw.expand(expand, expand, expand).offset(-mc.getRenderManager().viewerPosX, -mc.getRenderManager().viewerPosY, -mc.getRenderManager().viewerPosZ); BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); @@ -263,10 +259,9 @@ public final class PathRenderer implements Helper { } public static void drawDankLitGoalBox(Entity player, Goal goal, float partialTicks, Color color) { - double renderPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; - double renderPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; - double renderPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; - + double renderPosX = mc.getRenderManager().viewerPosX; + double renderPosY = mc.getRenderManager().viewerPosY; + double renderPosZ = mc.getRenderManager().viewerPosZ; double minX; double maxX; double minZ; From bf25d7328eaa18e8d5ee9c0289ae917b31b97076 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Feb 2019 12:23:05 -0800 Subject: [PATCH 31/37] revalidate on goal update too --- src/main/java/baritone/process/CustomGoalProcess.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 00d3c8025..a62342273 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -55,6 +55,9 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG if (this.state == State.NONE) { this.state = State.GOAL_SET; } + if (this.state == State.EXECUTING) { + this.state = State.PATH_REQUESTED; + } } @Override From 0ed6ccab716cefe20ce2de08fafe8c6c7e592453 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Feb 2019 15:46:28 -0800 Subject: [PATCH 32/37] update some documentation --- FEATURES.md | 2 +- INSTALL.md | 90 ----------------------------------------------------- README.md | 6 ++-- SETUP.md | 21 +++++++------ USAGE.md | 3 +- 5 files changed, 17 insertions(+), 105 deletions(-) delete mode 100644 INSTALL.md diff --git a/FEATURES.md b/FEATURES.md index 09c932f04..372a77410 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -4,7 +4,7 @@ - **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. - **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. Example - **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. -- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). +- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). Baritone can break its fall by grabbing ladders / vines midair, and understands when that is and isn't possible. - **Opening fence gates and doors** - **Slabs and stairs** - **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore). diff --git a/INSTALL.md b/INSTALL.md deleted file mode 100644 index e66054b64..000000000 --- a/INSTALL.md +++ /dev/null @@ -1,90 +0,0 @@ -# Integration between Baritone and Impact -Impact 4.4 has Baritone included. - -These instructions apply to Impact 4.3. - -For Forge follow the instructions in [Setup](SETUP.md). - -To run Baritone on Vanilla, just follow the instructions in the README (it's `./gradlew runClient`). - -## An Introduction -There are some basic steps to getting Baritone setup with Impact. -- Acquiring a build of Baritone -- Placing Baritone in the libraries directory -- Modifying the Impact Profile JSON to run baritone -- How to use Baritone - -## Acquiring a build of Baritone -There are two methods of acquiring a build of Baritone - -### Official Release (Not always up to date) -https://github.com/cabaletta/baritone/releases - -For Impact 4.3, there is no Baritone integration yet, so you will want `baritone-standalone-X.Y.Z.jar`. **For the rest of this guide, replace `X.Y.Z` with the actual numeric version you are using.** - -Any official release will be GPG signed by leijurv (44A3EA646EADAC6A) and ZeroMemes (73A788379A197567). Please verify that the hash of the file you download is in `checksums.txt` and that `checksums_signed.asc` is a valid signature by those two public keys of `checksums.txt`. - -The build is fully deterministic and reproducible, and you can verify Travis did it properly by running `docker build --no-cache -t cabaletta/baritone .` yourself and comparing the shasum. This works identically on Travis, Mac, and Linux (if you have docker on Windows, I'd be grateful if you could let me know if it works there too). - -### Building Baritone yourself -You can either build Baritone through a command line or through IntelliJ's UI, information on that can be found [here](SETUP.md#building). - -## Placing Baritone in the libraries directory -``/libraries`` is a neat directory in your Minecraft Installation Directory -that contains all of the dependencies that are required from the game and some mods. This is where we will be -putting baritone. -- Locate the ``libraries`` folder, it should be in the Minecraft Installation Directory -- Create 3 new subdirectories starting from ``libraries`` - - ``cabaletta`` - - ``baritone`` - - ``X.Y.Z`` - - Copy the build of Baritone that was acquired earlier, and place it into the ``X.Y.Z`` folder, renamed like so: - - The full path should look like ``/libraries/cabaletta/baritone/X.Y.Z/baritone-X.Y.Z.jar`` - -## Modifying the Impact Profile JSON to run baritone -The final step is "registering" the Baritone library with Impact, so that it loads on launch. -- Ensure your Minecraft launcher is closed -- Navigate back to the Minecraft Installation Directory -- Find the ``versions`` directory, and open in -- In here there should be a ``1.12.2-Impact_4.3`` folder. - - If you don't have any Impact folder or have a version older than 4.3, you can download Impact here. -- Open the folder and inside there should be a file called ``1.12.2-Impact_4.3.json`` -- Open the JSON file with a text editor that supports your system's line endings - - For example, Notepad on Windows likely will NOT work for this. You should instead use a Text Editor like - Notepad++ if you're on Windows. (For other systems, I'm not sure - what would work the best so you may have to do some research.) -- Find the ``libraries`` array in the JSON. It should look something like this. - ``` - "libraries": [ - { - "name": "net.minecraft:launchwrapper:1.12" - }, - { - "name": "com.github.ImpactDevelopment:Impact:4.3-1.12.2", - "url": "https://impactdevelopment.github.io/maven/" - }, - { - "name": "com.github.ImpactDeveloment:ClientAPI:3.0.2", - "url": "https://impactdevelopment.github.io/maven/" - }, - ... - ``` -- Create two new objects in the array, between the ``Impact`` and ``ClientAPI`` dependencies preferably. - ``` - { - "name": "cabaletta:baritone:X.Y.Z" - }, - { - "name": "com.github.ImpactDevelopment:SimpleTweaker:1.2", - "url": "https://impactdevelopment.github.io/maven/" - }, - ``` -- Now find the ``"minecraftArguments": "..."`` text near the top. -- At the very end of the quotes where it says ``--tweakClass clientapi.load.ClientTweaker"``, add on the following so it looks like: - - ``--tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweaker"`` -- If you didn't close your launcher for this step, restart it now. -- You can now launch Impact 4.3 as normal, and Baritone should start up - - ## How to use Baritone - -- [Baritone chat control usage](USAGE.md) diff --git a/README.md b/README.md index 928acab80..5aee57022 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,9 @@ Here are some links to help to get started: - [Features](FEATURES.md) -- [Setup](SETUP.md) +- [Installation & setup](SETUP.md) -- [Installation](INSTALL.md) - -- [Javadocs](https://baritone.leijurv.com/) +- [API Javadocs](https://baritone.leijurv.com/) - [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail) diff --git a/SETUP.md b/SETUP.md index 6d50a85be..33563147d 100644 --- a/SETUP.md +++ b/SETUP.md @@ -1,20 +1,23 @@ -# Setup +# Installation -## Prebuilt -(not always completely up to date with latest features) +## Prebuilt official releases +These releases are not always completely up to date with latest features, and are only released from `master`. (so if you want `builder` branch for example, you'll have to build it yourself) -Download from the [Releases](https://github.com/cabaletta/baritone/releases) +Link to the releases page: [Releases](https://github.com/cabaletta/baritone/releases) -The Forge releases can simply be added as a Forge mod. +Any official release will be GPG signed by leijurv (44A3EA646EADAC6A) and ZeroMemes (73A788379A197567). Please verify that the hash of the file you download is in `checksums.txt` and that `checksums_signed.asc` is a valid signature by those two public keys of `checksums.txt`. -If another one of your Forge mods has a Baritone integration, you want `baritone-api-forge-VERSION.jar`. Otherwise, you want `baritone-standalone-forge-VERSION.jar` +The build is fully deterministic and reproducible, and you can verify Travis did it properly by running `docker build --no-cache -t cabaletta/baritone .` yourself and comparing the shasum. This works identically on Travis, Mac, and Linux (if you have docker on Windows, I'd be grateful if you could let me know if it works there too). -Previously (Baritone v1.1.2 and below), it was not fully compatible with the latest version of Forge. `freeLook` was broken in Forge 14.23.4.2744. Forge 14.23.4.2743 or **older** worked with Baritone v1.1.2 and lower. Newer versions of Forge "worked", sort of, but Baritone's movement became unreliable and `freeLook` must be off. ## Artifacts Building Baritone will result in 5 artifacts created in the ``dist`` directory. These are the same as the artifacts created in the [releases](https://github.com/cabaletta/baritone/releases). +**The Forge release can simply be added as a Forge mod.** + +If another one of your Forge mods has a Baritone integration, you want `baritone-api-forge-VERSION.jar`. Otherwise, you want `baritone-standalone-forge-VERSION.jar` + - **API**: Only the non-api packages are obfuscated. This should be used in environments where other mods would like to use Baritone's features. - **Forge API**: Same as API, but packaged for Forge. This should be used where another mod has a Baritone integration. - **Standalone**: Everything is obfuscated. This should be used in environments where there are no other mods present that would like to use Baritone's features. @@ -22,9 +25,9 @@ Building Baritone will result in 5 artifacts created in the ``dist`` directory. - **Unoptimized**: Nothing is obfuscated. This shouldn't be used ever in production. ## More Info -To replace out Impact 4.4's Baritone build with a customized one, switch to the `impact4.4-compat` branch, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.0.0/baritone-api-1.0.0.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.4/1.12.2-Impact_4.4.json`, find the line `"name": "cabaletta:baritone-api:1.0.0"`, remove the comma from the end, and entirely remove the line that's immediately after (starts with `"url"`). +To replace out Impact 4.5's Baritone build with a customized one, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.2/baritone-api-1.2.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.5/1.12.2-Impact_4.5.json`, find the line `"name": "cabaletta:baritone-api:1.2"`, remove the comma from the end, and **entirely remove the next line** (starts with `"url"`). -Impact 4.4 **only** works with builds from the quite outdated `impact4.4-compat` branch. If you must have the latest Baritone features with Impact, and can't wait for 4.5, consider creating a standalone (non forge) build then adding it to Impact 4.**3** via the instructions in [Install](INSTALL.md). +You can verify whether or not it worked by running `.b version` in chat (only valid in Impact). If it says `v1.2.0` then you didn't do it properly, and it's still running the version that came with 4.5. ## Build it yourself - Clone or download Baritone diff --git a/USAGE.md b/USAGE.md index de5b836d3..6a07518b2 100644 --- a/USAGE.md +++ b/USAGE.md @@ -9,7 +9,7 @@ Therefore you can use a prefix before your messages. On Baritone v1.1.0 and newer: The prefix is `#` by default. Anything beginning with `#` isn't sent, and is only interpreted by Baritone. For older than v1.1.0, `#` must be enabled by toggling on the `prefix` setting. -**Only** in Impact 4.4 is `.b` also a valid prefix. In 4.4, `#` does **not** work, neither does saying the commands directly in chat. +**Only** in Impact is `.b` also a valid prefix. In 4.4, `#` does **not** work, neither does saying the commands directly in chat. `#` works by default in 4.5 (not 4.4). Other clients like Kami and Asuna have their own custom things (like `-path`), and can disable direct chat control entirely. @@ -39,6 +39,7 @@ Some common examples: - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `invert` to invert the current goal and path. This gets as far away from it as possible, instead of as close as possible. For example, do `goal` then `invert` to run as far as possible from where you're standing at the start. - `render` to rerender the world in case `renderCachedChunks` is being glitchy +- `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/main/java/baritone/utils/ExampleBaritoneControl.java). From 8ac82ebe2ae44b94c09e5c403b430d347b5b8ee9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Feb 2019 17:48:57 -0800 Subject: [PATCH 33/37] v1.2.2 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a03a89631..2044d3db3 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.1' +version '1.2.2' buildscript { repositories { From e767e34b92de076dfdc3ecba1256154a581c9a47 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Feb 2019 22:15:54 -0800 Subject: [PATCH 34/37] well that was stupid, thanks thesmarttheorist --- src/main/java/baritone/utils/BlockPlaceHelper.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/utils/BlockPlaceHelper.java b/src/main/java/baritone/utils/BlockPlaceHelper.java index e0c782bb4..e93bf8073 100644 --- a/src/main/java/baritone/utils/BlockPlaceHelper.java +++ b/src/main/java/baritone/utils/BlockPlaceHelper.java @@ -21,7 +21,6 @@ import baritone.Baritone; import baritone.api.utils.IPlayerContext; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; public class BlockPlaceHelper implements Helper { @@ -38,13 +37,12 @@ public class BlockPlaceHelper implements Helper { return; } RayTraceResult mouseOver = ctx.objectMouseOver(); - BlockPos pos = mouseOver.getBlockPos(); - if (!rightClickRequested || ctx.player().isRowingBoat() || pos == null || mouseOver.typeOfHit != RayTraceResult.Type.BLOCK) { + if (!rightClickRequested || ctx.player().isRowingBoat() || mouseOver == null || mouseOver.getBlockPos() == null || mouseOver.typeOfHit != RayTraceResult.Type.BLOCK) { return; } rightClickTimer = Baritone.settings().rightClickSpeed.get(); for (EnumHand hand : EnumHand.values()) { - if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), pos, mouseOver.sideHit, mouseOver.hitVec, hand) == EnumActionResult.SUCCESS) { + if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), mouseOver.getBlockPos(), mouseOver.sideHit, mouseOver.hitVec, hand) == EnumActionResult.SUCCESS) { ctx.player().swingArm(hand); return; } From a4237bf1f943bab7b08cd7a35e295421fafe2530 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Feb 2019 23:04:43 -0800 Subject: [PATCH 35/37] tentative fix to descend, needs testing --- .../pathing/movement/movements/MovementDescend.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 3a8ed913e..2a2679afc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -202,7 +202,8 @@ public class MovementDescend extends Movement { } BlockPos playerFeet = ctx.playerFeet(); - if (playerFeet.equals(dest) && (MovementHelper.isLiquid(ctx, dest) || ctx.player().posY - playerFeet.getY() < 0.094)) { // lilypads + BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ()); + if ((playerFeet.equals(dest) || playerFeet.equals(fakeDest)) && (MovementHelper.isLiquid(ctx, dest) || ctx.player().posY - dest.getY() < 0.5)) { // lilypads // Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately return state.setStatus(MovementStatus.SUCCESS); /* else { @@ -228,12 +229,8 @@ public class MovementDescend extends Movement { double z = ctx.player().posZ - (src.getZ() + 0.5); double fromStart = Math.sqrt(x * x + z * z); if (!playerFeet.equals(dest) || ab > 0.25) { - BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ()); - if (numTicks++ < 20) { + if (numTicks++ < 20 && fromStart < 1.25) { MovementHelper.moveTowards(ctx, state, fakeDest); - if (fromStart > 1.25) { - state.getTarget().rotation = new Rotation(state.getTarget().rotation.getYaw() + 180F, state.getTarget().rotation.getPitch()); - } } else { MovementHelper.moveTowards(ctx, state, dest); } From c72eb3e19531c7548e7b9f5972429504f1888d33 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 28 Feb 2019 09:47:47 -0800 Subject: [PATCH 36/37] v1.2.3 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2044d3db3..e52cc3704 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.2' +version '1.2.3' buildscript { repositories { From 4c6f321cfff945b544e8dddc1d9aed99b794edd1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 28 Feb 2019 12:12:16 -0800 Subject: [PATCH 37/37] clarify --- SETUP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SETUP.md b/SETUP.md index 33563147d..cd19a5740 100644 --- a/SETUP.md +++ b/SETUP.md @@ -27,7 +27,7 @@ If another one of your Forge mods has a Baritone integration, you want `baritone ## More Info To replace out Impact 4.5's Baritone build with a customized one, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.2/baritone-api-1.2.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.5/1.12.2-Impact_4.5.json`, find the line `"name": "cabaletta:baritone-api:1.2"`, remove the comma from the end, and **entirely remove the next line** (starts with `"url"`). -You can verify whether or not it worked by running `.b version` in chat (only valid in Impact). If it says `v1.2.0` then you didn't do it properly, and it's still running the version that came with 4.5. +You can verify whether or not it worked by running `.b version` in chat (only valid in Impact). It should print out the version that you downloaded. Note: The version that comes with 4.5 is `v1.2.3`. ## Build it yourself - Clone or download Baritone