Compare commits

...

30 Commits

Author SHA1 Message Date
Leijurv 6e7320b954 v1.2.1 2019-02-25 18:07:55 -08:00
Leijurv fbb2d37634 allow placing against replacable blocks 2019-02-25 18:01:11 -08:00
Leijurv 7afe16fc10 dont reset every tick 2019-02-25 16:26:17 -08:00
Leijurv b19f241d81 override for the first tick 2019-02-25 15:06:55 -08:00
Leijurv 583ce80003 not reliable enough with jesus to jump from water over a gap 2019-02-24 13:57:33 -08:00
Leijurv 195c33407e cant walk through heads 2019-02-24 13:43:53 -08:00
Leijurv 600c5b77ad v1.2.0 2019-02-23 20:43:29 -08:00
Leijurv f1084fab76 come 2019-02-23 20:33:00 -08:00
Brady bd65e32407 Fix the failing build 2019-02-23 17:04:14 -06:00
Leijurv e4416f424a interesting 2019-02-23 14:13:27 -08:00
Leijurv 73ec110b22 not every player is a baritone 2019-02-23 14:03:47 -08:00
Brady 0bce801a3f Minor javadoc changes 2019-02-23 14:32:10 -06:00
Brady e8e00e8dfb CRLF -> LF
It was inconsistent across the board
2019-02-23 12:27:24 -06:00
Leijurv cc4335e48e better links 2019-02-22 23:32:23 -08:00
Leijurv 5427911da3 only api in javadoc i guess 2019-02-22 23:29:08 -08:00
Brady c808d5a42d Small build.gradle cleanup and README update 2019-02-22 18:12:04 -06:00
Leijurv 3b46dbd6a1 appease codacy 2019-02-22 14:05:29 -08:00
Leijurv e63b2f1bf1 unused arg 2019-02-22 13:58:03 -08:00
Leijurv d32e822057 settings overhaul 2019-02-22 12:13:19 -08:00
Leijurv 16dcd2f44d blocks on top of chests, fixes #299 2019-02-21 11:25:03 -08:00
Leijurv eb9f755b54 disable rendercachedchunks in singleplayer, fixes #331 2019-02-21 10:03:03 -08:00
Leijurv 29a9e6e1d1 fine, forward alias to thisway 2019-02-21 09:45:01 -08:00
Leijurv 1f52f706ed should fix anticheatcompat off on forge 2019-02-20 23:41:29 -08:00
Leijurv a72040f83d imagine breaking the build 2019-02-19 19:52:11 -08:00
Leijurv 84d8f826ff fine lol, fixes #340 2019-02-19 19:41:26 -08:00
Brady 70d216b29f Fix renderGoalXZBeacon path rendering incorrect color 2019-02-19 21:00:14 -06:00
Leijurv 66356d5334 hmm 2019-02-19 18:27:05 -08:00
Leijurv d9625dfe78 no longer needed crab rave 2019-02-19 18:24:12 -08:00
Leijurv 6d847577d8 somehow missed those 2019-02-19 18:22:59 -08:00
Leijurv 8fd687f9d7 more usage help 2019-02-19 15:04:18 -08:00
35 changed files with 951 additions and 819 deletions
+10 -4
View File
@@ -34,6 +34,8 @@ Have committed at least once a day for the last 6 months =D 🦀
1Leijurv3DWTrGAfmmiTphjhXLvQiHg7K2 1Leijurv3DWTrGAfmmiTphjhXLvQiHg7K2
# Getting Started
Here are some links to help to get started: Here are some links to help to get started:
- [Features](FEATURES.md) - [Features](FEATURES.md)
@@ -44,13 +46,17 @@ Here are some links to help to get started:
- [Javadocs](https://baritone.leijurv.com/) - [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)
# Chat control
- [Baritone chat control usage](USAGE.md) - [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; BaritoneAPI.getSettings().allowSprint.value = true;
+2 -2
View File
@@ -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). `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`.
@@ -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). 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 <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#allowBreak">here</a>. All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#field.detail">here</a>.
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. 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` - `allowBreak`
+132 -134
View File
@@ -1,134 +1,132 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
group 'baritone' group 'baritone'
version '1.1.6' version '1.2.1'
buildscript { buildscript {
repositories { repositories {
maven { maven {
name = 'forge' name = 'forge'
url = 'http://files.minecraftforge.net/maven' url = 'http://files.minecraftforge.net/maven'
} }
maven { maven {
name = 'SpongePowered' name = 'SpongePowered'
url = 'http://repo.spongepowered.org/maven' url = 'http://repo.spongepowered.org/maven'
} }
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
} }
} }
import baritone.gradle.task.CreateDistTask import baritone.gradle.task.CreateDistTask
import baritone.gradle.task.ProguardTask import baritone.gradle.task.ProguardTask
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'net.minecraftforge.gradle.tweaker-client' apply plugin: 'net.minecraftforge.gradle.tweaker-client'
apply plugin: 'org.spongepowered.mixin' apply plugin: 'org.spongepowered.mixin'
sourceCompatibility = targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = '1.8'
compileJava { compileJava {
sourceCompatibility = targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = '1.8'
options.encoding = "UTF-8" // allow emoji in comments :^) options.encoding = "UTF-8" // allow emoji in comments :^)
} }
sourceSets { sourceSets {
launch { launch {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
} }
} }
minecraft { minecraft {
version = '1.12.2' version = '1.12.2'
mappings = 'stable_39' mappings = 'stable_39'
tweakClass = 'baritone.launch.BaritoneTweaker' tweakClass = 'baritone.launch.BaritoneTweaker'
runDir = 'run' runDir = 'run'
// The sources jar should use SRG names not MCP to ensure compatibility with all mappings // The sources jar should use SRG names not MCP to ensure compatibility with all mappings
makeObfSourceJar = true makeObfSourceJar = true
} }
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
name = 'spongepowered-repo' name = 'spongepowered-repo'
url = 'http://repo.spongepowered.org/maven/' url = 'http://repo.spongepowered.org/maven/'
} }
maven { maven {
name = 'impactdevelopment-repo' name = 'impactdevelopment-repo'
url = 'https://impactdevelopment.github.io/maven/' url = 'https://impactdevelopment.github.io/maven/'
} }
} }
dependencies { dependencies {
runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2')
runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
// Mixin includes a lot of dependencies that are too up-to-date // Mixin includes a lot of dependencies that are too up-to-date
exclude module: 'launchwrapper' exclude module: 'launchwrapper'
exclude module: 'guava' exclude module: 'guava'
exclude module: 'gson' exclude module: 'gson'
exclude module: 'commons-io' exclude module: 'commons-io'
exclude module: 'log4j-core' exclude module: 'log4j-core'
} }
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
} }
mixin { mixin {
defaultObfuscationEnv searge defaultObfuscationEnv searge
add sourceSets.launch, 'mixins.baritone.refmap.json' add sourceSets.launch, 'mixins.baritone.refmap.json'
} }
javadoc { javadoc {
options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error
options.linkSource true options.linkSource true
options.encoding "UTF-8" // allow emoji in comments :^) options.encoding "UTF-8" // allow emoji in comments :^)
source += sourceSets.api.allJava source = sourceSets.api.allJava
classpath += sourceSets.api.compileClasspath classpath += sourceSets.api.compileClasspath
} }
jar { jar {
from sourceSets.launch.output, sourceSets.api.output from sourceSets.launch.output, sourceSets.api.output
preserveFileTimestamps = false preserveFileTimestamps = false
reproducibleFileOrder = true reproducibleFileOrder = true
}
manifest {
jar { attributes(
manifest { 'MixinConfigs': 'mixins.baritone.json',
attributes(
'MixinConfigs': 'mixins.baritone.json', 'Implementation-Title': 'Baritone',
'Implementation-Version': version
'Implementation-Title': 'Baritone', )
'Implementation-Version': version }
) }
}
} task proguard(type: ProguardTask) {
url 'https://downloads.sourceforge.net/project/proguard/proguard/6.0/proguard6.0.3.zip'
task proguard(type: ProguardTask) { extract 'proguard6.0.3/lib/proguard.jar'
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)
task createDist(type: CreateDistTask, dependsOn: proguard) build.finalizedBy(createDist)
build.finalizedBy(createDist)
+6 -6
View File
@@ -1,6 +1,6 @@
#Tue Jul 31 21:56:56 PDT 2018 #Tue Jul 31 21:56:56 PDT 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
Vendored
+84 -84
View File
@@ -1,84 +1,84 @@
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% 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. @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= set DEFAULT_JVM_OPTS=
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto init
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto init
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:init :init
@rem Get command-line arguments, handling Windows variants @rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args :win9xME_args
@rem Slurp the command line arguments. @rem Slurp the command line arguments.
set CMD_LINE_ARGS= set CMD_LINE_ARGS=
set _SKIP=2 set _SKIP=2
:win9xME_args_slurp :win9xME_args_slurp
if "x%~1" == "x" goto execute if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%* set CMD_LINE_ARGS=%*
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @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% "%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 :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1 exit /b 1
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal
:omega :omega
+1 -3
View File
@@ -14,6 +14,7 @@
# lwjgl is weird # lwjgl is weird
-dontwarn org.lwjgl.opengl.GL14 -dontwarn org.lwjgl.opengl.GL14
-dontwarn org.lwjgl.opengl.GL11
-keep class baritone.api.** { *; } # this is the keep api -keep class baritone.api.** { *; } # this is the keep api
@@ -21,9 +22,6 @@
-keep class baritone.BaritoneProvider -keep class baritone.BaritoneProvider
-keep class baritone.api.IBaritoneProvider -keep class baritone.api.IBaritoneProvider
# hack
-keep class baritone.utils.ExampleBaritoneControl { *; } # have to include this string to remove this keep in the standalone build: # this is the keep api
# setting names are reflected from field names, so keep field names # setting names are reflected from field names, so keep field names
-keepclassmembers class baritone.api.Settings { -keepclassmembers class baritone.api.Settings {
public <fields>; public <fields>;
+19 -19
View File
@@ -1,19 +1,19 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
rootProject.name = 'baritone' rootProject.name = 'baritone'
+1 -3
View File
@@ -23,9 +23,7 @@ import java.util.Iterator;
import java.util.ServiceLoader; import java.util.ServiceLoader;
/** /**
* API exposure for various things implemented in Baritone. * Exposes the {@link IBaritoneProvider} instance and the {@link Settings} instance for API usage.
* <p>
* W.I.P
* *
* @author Brady * @author Brady
* @since 9/23/2018 * @since 9/23/2018
+55 -29
View File
@@ -22,10 +22,7 @@ import baritone.api.behavior.IPathingBehavior;
import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldProvider;
import baritone.api.event.listener.IEventBus; import baritone.api.event.listener.IEventBus;
import baritone.api.pathing.calc.IPathingControlManager; import baritone.api.pathing.calc.IPathingControlManager;
import baritone.api.process.ICustomGoalProcess; import baritone.api.process.*;
import baritone.api.process.IFollowProcess;
import baritone.api.process.IGetToBlockProcess;
import baritone.api.process.IMineProcess;
import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.IInputOverrideHandler;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
@@ -36,22 +33,13 @@ import baritone.api.utils.IPlayerContext;
public interface IBaritone { public interface IBaritone {
/** /**
* @return The {@link IFollowProcess} instance * Call as soon as Minecraft is ready, initializes all of the processes, behaviors, etc. This will
* @see IFollowProcess * only effectively be ran once, any additional calls are redundant because the initialization state
* is saved.
* <p>
* Or whenever your overeager utility client wants.
*/ */
IFollowProcess getFollowProcess(); void init();
/**
* @return The {@link ILookBehavior} instance
* @see ILookBehavior
*/
ILookBehavior getLookBehavior();
/**
* @return The {@link IMineProcess} instance
* @see IMineProcess
*/
IMineProcess getMineProcess();
/** /**
* @return The {@link IPathingBehavior} instance * @return The {@link IPathingBehavior} instance
@@ -59,28 +47,66 @@ public interface IBaritone {
*/ */
IPathingBehavior getPathingBehavior(); 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 * @return The {@link IWorldProvider} instance
* @see IWorldProvider * @see IWorldProvider
*/ */
IWorldProvider getWorldProvider(); 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(); IPathingControlManager getPathingControlManager();
/**
* @return The {@link IInputOverrideHandler} instance
* @see IInputOverrideHandler
*/
IInputOverrideHandler getInputOverrideHandler(); IInputOverrideHandler getInputOverrideHandler();
ICustomGoalProcess getCustomGoalProcess(); /**
* @return The {@link IPlayerContext} instance
IGetToBlockProcess getGetToBlockProcess(); * @see IPlayerContext
*/
IPlayerContext getPlayerContext(); IPlayerContext getPlayerContext();
IEventBus getGameEventHandler();
/** /**
* Call as soon as Minecraft is ready. * @return The {@link IEventBus} instance
* <p> * @see IEventBus
* Or whenever your overeager utility client wants.
*/ */
void init(); IEventBus getGameEventHandler();
} }
@@ -23,7 +23,9 @@ import net.minecraft.client.entity.EntityPlayerSP;
import java.util.List; import java.util.List;
/** /**
* @author Leijurv * Provides the present {@link IBaritone} instances
*
* @author leijurv
*/ */
public interface IBaritoneProvider { public interface IBaritoneProvider {
@@ -47,7 +49,8 @@ public interface IBaritoneProvider {
/** /**
* Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be * 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 * @param player The player
* @return The {@link IBaritone} instance. * @return The {@link IBaritone} instance.
@@ -58,7 +61,7 @@ public interface IBaritoneProvider {
return baritone; return baritone;
} }
} }
throw new IllegalStateException("No baritone for player " + player); return null;
} }
/** /**
+11 -11
View File
@@ -17,6 +17,7 @@
package baritone.api; package baritone.api;
import baritone.api.utils.SettingsUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@@ -29,7 +30,7 @@ import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
* Baritone's settings * Baritone's settings. Settings apply to all Baritone instances.
* *
* @author leijurv * @author leijurv
*/ */
@@ -500,18 +501,18 @@ public final class Settings {
* <p> * <p>
* SOLID is rendered as stone in the overworld, netherrack in the nether, and end stone in the end * SOLID is rendered as stone in the overworld, netherrack in the nether, and end stone in the end
*/ */
public Setting<Boolean> renderCachedChunks = new Setting<>(false); public final Setting<Boolean> renderCachedChunks = new Setting<>(false);
/** /**
* 0.0f = not visible, fully transparent * 0.0f = not visible, fully transparent
* 1.0f = fully opaque * 1.0f = fully opaque
*/ */
public Setting<Float> cachedChunksOpacity = new Setting<>(0.5f); public final Setting<Float> cachedChunksOpacity = new Setting<>(0.5f);
/** /**
* If true, Baritone will not allow you to left or right click while pathing * If true, Baritone will not allow you to left or right click while pathing
*/ */
public Setting<Boolean> suppressClicks = new Setting<>(false); public final Setting<Boolean> suppressClicks = new Setting<>(false);
/** /**
* Whether or not to use the "#" command prefix * Whether or not to use the "#" command prefix
@@ -704,12 +705,6 @@ public final class Settings {
*/ */
public final List<Setting<?>> allSettings; public final List<Setting<?>> allSettings;
public void reset() {
for (Setting setting : allSettings) {
setting.value = setting.defaultValue;
}
}
public final class Setting<T> { public final class Setting<T> {
public T value; public T value;
public final T defaultValue; public final T defaultValue;
@@ -739,8 +734,13 @@ public final class Settings {
return klass; return klass;
} }
@Override
public String toString() { public String toString() {
return name + ": " + value; return SettingsUtil.settingToString(this);
}
public void reset() {
value = defaultValue;
} }
} }
@@ -18,8 +18,13 @@
package baritone.api.behavior; package baritone.api.behavior;
import baritone.api.event.listener.AbstractGameEventListener; 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 * @author Brady
* @since 9/23/2018 * @since 9/23/2018
*/ */
@@ -27,10 +27,8 @@ import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.*;
import java.util.Collections; import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -89,22 +87,8 @@ public class SettingsUtil {
public static synchronized void save(Settings settings) { public static synchronized void save(Settings settings) {
try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) { try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) {
for (Settings.Setting setting : settings.allSettings) { for (Settings.Setting setting : modifiedSettings(settings)) {
if (setting.get() == null) { out.write(settingToString(setting) + "\n");
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");
} }
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Exception thrown while saving Baritone settings!"); 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<Settings.Setting> modifiedSettings(Settings settings) {
List<Settings.Setting> 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); Settings.Setting setting = settings.byLowerName.get(settingName);
if (setting == null) { if (setting == null) {
throw new IllegalStateException("No setting by that name"); throw new IllegalStateException("No setting by that name");
@@ -41,7 +41,7 @@ public class MixinChunkRenderContainer {
) )
) )
private BlockPos getPosition(RenderChunk renderChunkIn) { private BlockPos getPosition(RenderChunk renderChunkIn) {
if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) {
GlStateManager.enableAlpha(); GlStateManager.enableAlpha();
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get()); GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get());
@@ -20,6 +20,7 @@ package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.chunk.ChunkRenderWorker; import net.minecraft.client.renderer.chunk.ChunkRenderWorker;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@@ -42,7 +43,7 @@ public abstract class MixinChunkRenderWorker {
) )
) )
private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) { private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) {
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) {
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext(); IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
@@ -18,6 +18,7 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.RotationMoveEvent; import baritone.api.event.events.RotationMoveEvent;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -55,8 +56,11 @@ public abstract class MixinEntityLivingBase extends Entity {
private void preMoveRelative(CallbackInfo ci) { private void preMoveRelative(CallbackInfo ci) {
// noinspection ConstantConditions // noinspection ConstantConditions
if (EntityPlayerSP.class.isInstance(this)) { if (EntityPlayerSP.class.isInstance(this)) {
this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw); IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent); 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) { 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 this.jumpRotationEvent.getYaw();
} }
return self.rotationYaw; 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) { private void travel(EntityLivingBase self, float strafe, float up, float forward, float friction) {
// noinspection ConstantConditions // noinspection ConstantConditions
if (!EntityPlayerSP.class.isInstance(this)) { if (!EntityPlayerSP.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) == null) {
moveRelative(strafe, up, forward, friction); moveRelative(strafe, up, forward, friction);
return; return;
} }
@@ -19,7 +19,6 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.behavior.IPathingBehavior;
import baritone.api.event.events.ChatEvent; import baritone.api.event.events.ChatEvent;
import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.SprintStateEvent; import baritone.api.event.events.SprintStateEvent;
@@ -48,7 +47,11 @@ public class MixinEntityPlayerSP {
) )
private void sendChatMessage(String msg, CallbackInfo ci) { private void sendChatMessage(String msg, CallbackInfo ci) {
ChatEvent event = new ChatEvent(msg); 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()) { if (event.isCancelled()) {
ci.cancel(); ci.cancel();
} }
@@ -64,7 +67,10 @@ public class MixinEntityPlayerSP {
) )
) )
private void onPreUpdate(CallbackInfo ci) { 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( @Inject(
@@ -77,7 +83,10 @@ public class MixinEntityPlayerSP {
) )
) )
private void onPostUpdate(CallbackInfo ci) { 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( @Redirect(
@@ -88,8 +97,11 @@ public class MixinEntityPlayerSP {
) )
) )
private boolean isAllowFlying(PlayerCapabilities capabilities) { private boolean isAllowFlying(PlayerCapabilities capabilities) {
IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior(); IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
return !pathingBehavior.isPathing() && capabilities.allowFlying; if (baritone == null) {
return capabilities.allowFlying;
}
return !baritone.getPathingBehavior().isPathing() && capabilities.allowFlying;
} }
@Redirect( @Redirect(
@@ -100,8 +112,11 @@ public class MixinEntityPlayerSP {
) )
) )
private boolean isKeyDown(KeyBinding keyBinding) { private boolean isKeyDown(KeyBinding keyBinding) {
SprintStateEvent event = new SprintStateEvent();
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this); IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
if (baritone == null) {
return keyBinding.isKeyDown();
}
SprintStateEvent event = new SprintStateEvent();
baritone.getGameEventHandler().onPlayerSprintState(event); baritone.getGameEventHandler().onPlayerSprintState(event);
if (event.getState() != null) { if (event.getState() != null) {
return event.getState(); return event.getState();
@@ -120,6 +135,9 @@ public class MixinEntityPlayerSP {
) )
) )
private void updateRidden(CallbackInfo cb) { 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();
}
} }
} }
@@ -21,6 +21,7 @@ import baritone.Baritone;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.chunk.RenderChunk; import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkCache; import net.minecraft.world.ChunkCache;
@@ -46,7 +47,7 @@ public class MixinRenderChunk {
if (!chunkCache.isEmpty()) { if (!chunkCache.isEmpty()) {
return false; return false;
} }
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) {
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext(); IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
@@ -75,7 +76,7 @@ public class MixinRenderChunk {
) )
) )
private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) { private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) {
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) {
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext(); IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
@@ -18,6 +18,7 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderList; import net.minecraft.client.renderer.RenderList;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -37,7 +38,7 @@ public class MixinRenderList {
) )
) )
private void popMatrix() { private void popMatrix() {
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) {
// reset the blend func to normal (not dependent on constant alpha) // reset the blend func to normal (not dependent on constant alpha)
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
} }
@@ -18,6 +18,7 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.VboRenderList; import net.minecraft.client.renderer.VboRenderList;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -37,7 +38,7 @@ public class MixinVboRenderList {
) )
) )
private void popMatrix() { private void popMatrix() {
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) {
// reset the blend func to normal (not dependent on constant alpha) // reset the blend func to normal (not dependent on constant alpha)
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
} }
+211 -211
View File
@@ -1,211 +1,211 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone; package baritone;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.Settings; import baritone.api.Settings;
import baritone.api.event.listener.IEventBus; import baritone.api.event.listener.IEventBus;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
import baritone.behavior.*; import baritone.behavior.*;
import baritone.cache.WorldProvider; import baritone.cache.WorldProvider;
import baritone.event.GameEventHandler; import baritone.event.GameEventHandler;
import baritone.process.CustomGoalProcess; import baritone.process.CustomGoalProcess;
import baritone.process.FollowProcess; import baritone.process.FollowProcess;
import baritone.process.GetToBlockProcess; import baritone.process.GetToBlockProcess;
import baritone.process.MineProcess; import baritone.process.MineProcess;
import baritone.utils.*; import baritone.utils.*;
import baritone.utils.player.PrimaryPlayerContext; import baritone.utils.player.PrimaryPlayerContext;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 * @since 7/31/2018
*/ */
public class Baritone implements IBaritone { public class Baritone implements IBaritone {
private static ThreadPoolExecutor threadPool; private static ThreadPoolExecutor threadPool;
private static File dir; private static File dir;
static { static {
threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());
dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
if (!Files.exists(dir.toPath())) { if (!Files.exists(dir.toPath())) {
try { try {
Files.createDirectories(dir.toPath()); Files.createDirectories(dir.toPath());
} catch (IOException ignored) {} } catch (IOException ignored) {}
} }
} }
/** /**
* Whether or not {@link Baritone#init()} has been called yet * Whether or not {@link Baritone#init()} has been called yet
*/ */
private boolean initialized; private boolean initialized;
private GameEventHandler gameEventHandler; private GameEventHandler gameEventHandler;
private List<Behavior> behaviors; private List<Behavior> behaviors;
private PathingBehavior pathingBehavior; private PathingBehavior pathingBehavior;
private LookBehavior lookBehavior; private LookBehavior lookBehavior;
private MemoryBehavior memoryBehavior; private MemoryBehavior memoryBehavior;
private InputOverrideHandler inputOverrideHandler; private InputOverrideHandler inputOverrideHandler;
private FollowProcess followProcess; private FollowProcess followProcess;
private MineProcess mineProcess; private MineProcess mineProcess;
private GetToBlockProcess getToBlockProcess; private GetToBlockProcess getToBlockProcess;
private CustomGoalProcess customGoalProcess; private CustomGoalProcess customGoalProcess;
private PathingControlManager pathingControlManager; private PathingControlManager pathingControlManager;
private IPlayerContext playerContext; private IPlayerContext playerContext;
private WorldProvider worldProvider; private WorldProvider worldProvider;
public BlockStateInterface bsi; public BlockStateInterface bsi;
Baritone() { Baritone() {
this.gameEventHandler = new GameEventHandler(this); this.gameEventHandler = new GameEventHandler(this);
} }
@Override @Override
public synchronized void init() { public synchronized void init() {
if (initialized) { if (initialized) {
return; return;
} }
// Define this before behaviors try and get it, or else it will be null and the builds will fail! // Define this before behaviors try and get it, or else it will be null and the builds will fail!
this.playerContext = PrimaryPlayerContext.INSTANCE; this.playerContext = PrimaryPlayerContext.INSTANCE;
this.behaviors = new ArrayList<>(); this.behaviors = new ArrayList<>();
{ {
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
pathingBehavior = new PathingBehavior(this); pathingBehavior = new PathingBehavior(this);
lookBehavior = new LookBehavior(this); lookBehavior = new LookBehavior(this);
memoryBehavior = new MemoryBehavior(this); memoryBehavior = new MemoryBehavior(this);
new InventoryBehavior(this); new InventoryBehavior(this);
inputOverrideHandler = new InputOverrideHandler(this); inputOverrideHandler = new InputOverrideHandler(this);
new ExampleBaritoneControl(this); new ExampleBaritoneControl(this);
} }
this.pathingControlManager = new PathingControlManager(this); this.pathingControlManager = new PathingControlManager(this);
{ {
followProcess = new FollowProcess(this); followProcess = new FollowProcess(this);
mineProcess = new MineProcess(this); mineProcess = new MineProcess(this);
customGoalProcess = new CustomGoalProcess(this); // very high iq customGoalProcess = new CustomGoalProcess(this); // very high iq
getToBlockProcess = new GetToBlockProcess(this); getToBlockProcess = new GetToBlockProcess(this);
} }
this.worldProvider = new WorldProvider(); this.worldProvider = new WorldProvider();
if (BaritoneAutoTest.ENABLE_AUTO_TEST) { if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE); this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE);
} }
this.initialized = true; this.initialized = true;
} }
@Override @Override
public PathingControlManager getPathingControlManager() { public PathingControlManager getPathingControlManager() {
return this.pathingControlManager; return this.pathingControlManager;
} }
public List<Behavior> getBehaviors() { public List<Behavior> getBehaviors() {
return this.behaviors; return this.behaviors;
} }
public void registerBehavior(Behavior behavior) { public void registerBehavior(Behavior behavior) {
this.behaviors.add(behavior); this.behaviors.add(behavior);
this.gameEventHandler.registerEventListener(behavior); this.gameEventHandler.registerEventListener(behavior);
} }
@Override @Override
public InputOverrideHandler getInputOverrideHandler() { public InputOverrideHandler getInputOverrideHandler() {
return this.inputOverrideHandler; return this.inputOverrideHandler;
} }
@Override @Override
public CustomGoalProcess getCustomGoalProcess() { // Iffy public CustomGoalProcess getCustomGoalProcess() { // Iffy
return this.customGoalProcess; return this.customGoalProcess;
} }
@Override @Override
public GetToBlockProcess getGetToBlockProcess() { // Iffy public GetToBlockProcess getGetToBlockProcess() { // Iffy
return this.getToBlockProcess; return this.getToBlockProcess;
} }
@Override @Override
public IPlayerContext getPlayerContext() { public IPlayerContext getPlayerContext() {
return this.playerContext; return this.playerContext;
} }
public MemoryBehavior getMemoryBehavior() { public MemoryBehavior getMemoryBehavior() {
return this.memoryBehavior; return this.memoryBehavior;
} }
@Override @Override
public FollowProcess getFollowProcess() { public FollowProcess getFollowProcess() {
return this.followProcess; return this.followProcess;
} }
@Override @Override
public LookBehavior getLookBehavior() { public LookBehavior getLookBehavior() {
return this.lookBehavior; return this.lookBehavior;
} }
@Override @Override
public MineProcess getMineProcess() { public MineProcess getMineProcess() {
return this.mineProcess; return this.mineProcess;
} }
@Override @Override
public PathingBehavior getPathingBehavior() { public PathingBehavior getPathingBehavior() {
return this.pathingBehavior; return this.pathingBehavior;
} }
@Override @Override
public WorldProvider getWorldProvider() { public WorldProvider getWorldProvider() {
return this.worldProvider; return this.worldProvider;
} }
@Override @Override
public IEventBus getGameEventHandler() { public IEventBus getGameEventHandler() {
return this.gameEventHandler; return this.gameEventHandler;
} }
public static Settings settings() { public static Settings settings() {
return BaritoneAPI.getSettings(); return BaritoneAPI.getSettings();
} }
public static File getDir() { public static File getDir() {
return dir; return dir;
} }
public static Executor getExecutor() { public static Executor getExecutor() {
return threadPool; return threadPool;
} }
} }
@@ -109,7 +109,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
// Also the type has to be MOTION_UPDATE because that is called after JUMP // Also the type has to be MOTION_UPDATE because that is called after JUMP
if (!Baritone.settings().antiCheatCompatibility.get() && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE) { if (!Baritone.settings().antiCheatCompatibility.get() && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE && !this.force) {
this.target = null; this.target = null;
} }
} }
+1
View File
@@ -85,6 +85,7 @@ public final class CachedChunk {
temp.add(Blocks.END_GATEWAY); temp.add(Blocks.END_GATEWAY);
temp.add(Blocks.WEB); temp.add(Blocks.WEB);
temp.add(Blocks.NETHER_WART); temp.add(Blocks.NETHER_WART);
temp.add(Blocks.LADDER);
BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp); BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp);
} }
@@ -40,6 +40,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; 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; import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP;
/** /**
@@ -74,7 +76,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.AIR) { // early return for most common case if (block == Blocks.AIR) { // early return for most common case
return true; 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; return false;
} }
if (block instanceof BlockDoor || block instanceof BlockFenceGate) { if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@@ -157,7 +159,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|| block instanceof BlockSnow || block instanceof BlockSnow
|| block instanceof BlockLiquid || block instanceof BlockLiquid
|| block instanceof BlockTrapDoor || block instanceof BlockTrapDoor
|| block instanceof BlockEndPortal) { || block instanceof BlockEndPortal
|| block instanceof BlockSkull) {
return false; return false;
} }
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
@@ -493,7 +496,12 @@ public interface MovementHelper extends ActionCosts, Helper {
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) { static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) {
IPlayerContext ctx = baritone.getPlayerContext(); IPlayerContext ctx = baritone.getPlayerContext();
Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable
boolean found = false; boolean found = false;
if (direct.isPresent()) {
state.setTarget(new MovementState.MovementTarget(direct.get(), true));
found = true;
}
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]); BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
if (MovementHelper.canPlaceAgainst(ctx, against1)) { if (MovementHelper.canPlaceAgainst(ctx, against1)) {
@@ -28,6 +28,7 @@ import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult; import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.BlockStairs; import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@@ -85,7 +86,7 @@ public class MovementParkour extends Movement {
return; return;
} }
IBlockState standingOn = context.get(x, y - 1, z); 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; return;
} }
int maxJump; int maxJump;
@@ -178,7 +178,7 @@ public class MovementTraverse extends Movement {
float pitchToBreak = state.getTarget().getRotation().get().getPitch(); float pitchToBreak = state.getTarget().getRotation().get().getPitch();
state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true)); state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true));
return state.setInput(Input.MOVE_FORWARD, true); return state.setInput(Input.MOVE_FORWARD, true).setInput(Input.SPRINT, true);
} }
//sneak may have been set to true in the PREPPING state while mining an adjacent block //sneak may have been set to true in the PREPPING state while mining an adjacent block
@@ -106,33 +106,31 @@ public class PathExecutor implements IPathExecutor, Helper {
} }
BetterBlockPos whereShouldIBe = path.positions().get(pathPosition); BetterBlockPos whereShouldIBe = path.positions().get(pathPosition);
BetterBlockPos whereAmI = ctx.playerFeet(); BetterBlockPos whereAmI = ctx.playerFeet();
if (!whereShouldIBe.equals(whereAmI)) { 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
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
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))) {
if (whereAmI.equals(path.positions().get(i))) { logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i);
logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); int previousPos = pathPosition;
int previousPos = pathPosition; pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done for (int j = pathPosition; j <= previousPos; j++) {
for (int j = pathPosition; j <= previousPos; j++) { path.movements().get(j).reset();
path.movements().get(j).reset();
}
onChangeInPathPosition();
onTick();
return false;
} }
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 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)
if (whereAmI.equals(path.positions().get(i))) { // also don't check pathPosition+2 because reasons
if (i - pathPosition > 2) { if (whereAmI.equals(path.positions().get(i))) {
logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + 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;
} }
//System.out.println("Double skip sundae");
pathPosition = i - 1;
onChangeInPathPosition();
onTick();
return false;
} }
} }
} }
@@ -391,7 +389,7 @@ public class PathExecutor implements IPathExecutor, Helper {
if (current instanceof MovementTraverse && pathPosition < path.length() - 3) { if (current instanceof MovementTraverse && pathPosition < path.length() - 3) {
IMovement next = path.movements().get(pathPosition + 1); IMovement next = path.movements().get(pathPosition + 1);
if (next instanceof MovementAscend && sprintableAscend(ctx, (MovementTraverse) current, (MovementAscend) next, path.movements().get(pathPosition + 2))) { 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"); logDebug("Skipping traverse to straight ascend");
pathPosition++; pathPosition++;
onChangeInPathPosition(); onChangeInPathPosition();
@@ -513,7 +511,7 @@ public class PathExecutor implements IPathExecutor, Helper {
movement.getDest().add(flatDir.getX() * (i - pathPosition), 0, flatDir.getZ() * (i - pathPosition))); 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)); 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) { if (offTarget > 0.1) {
return false; return false;
@@ -561,10 +559,7 @@ public class PathExecutor implements IPathExecutor, Helper {
if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(current.getSrc().up(3)).getBlock())) { if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(current.getSrc().up(3)).getBlock())) {
return false; return false;
} }
if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(next.getDest().up(2)).getBlock())) { return !MovementHelper.avoidWalkingInto(ctx.world().getBlockState(next.getDest().up(2)).getBlock()); // codacy smh my head
return false;
}
return true;
} }
private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) {
@@ -81,7 +81,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
} }
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL); return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
case PATH_REQUESTED: 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; this.state = State.EXECUTING;
return ret; return ret;
case EXECUTING: case EXECUTING:
@@ -131,8 +131,11 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
} }
} }
} }
if (true) { // i can't do break; (codacy gets mad), and i can't do if(true){break}; (codacy gets mad)
break; // codacy gets mad if i just end on a break LOL // so i will do this
switch (newBlacklist.size()) {
default:
break outer;
} }
} }
logDebug("Blacklisting unreachable locations " + newBlacklist); logDebug("Blacklisting unreachable locations " + newBlacklist);
@@ -168,7 +171,13 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
} }
private Goal createGoal(BlockPos pos) { private Goal createGoal(BlockPos pos) {
return walkIntoInsteadOfAdjacent(gettingTo) ? new GoalTwoBlocks(pos) : new GoalGetToBlock(pos); if (walkIntoInsteadOfAdjacent(gettingTo)) {
return new GoalTwoBlocks(pos);
}
if (blockOnTopMustBeRemoved(gettingTo) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
return new GoalBlock(pos.up());
}
return new GoalGetToBlock(pos);
} }
private boolean rightClick() { private boolean rightClick() {
@@ -203,4 +212,12 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
} }
return block == Blocks.CRAFTING_TABLE || block == Blocks.FURNACE || block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST; return block == Blocks.CRAFTING_TABLE || block == Blocks.FURNACE || block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST;
} }
private boolean blockOnTopMustBeRemoved(Block block) {
if (!rightClickOnArrival(block)) { // only if we plan to actually open it on arrival
return false;
}
// only these chests; you can open a crafting table or furnace even with a block on top
return block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST;
}
} }
@@ -115,7 +115,9 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
} }
// Setup Baritone's pathing goal and (if needed) begin pathing // 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 we have reached our goal, print a message and safely close the game
if (GOAL.isInGoal(ctx.playerFeet())) { if (GOAL.isInGoal(ctx.playerFeet())) {
@@ -77,7 +77,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
"sethome - Sets \"home\"\n" + "sethome - Sets \"home\"\n" +
"home - Paths towards \"home\" \n" + "home - Paths towards \"home\" \n" +
"costs - (debug) all movement costs from current location\n" + "costs - (debug) all movement costs from current location\n" +
"damn - Daniel "; "damn - Daniel\n" +
"Go to https://github.com/cabaletta/baritone/blob/master/USAGE.md for more information";
private static final String COMMAND_PREFIX = "#"; private static final String COMMAND_PREFIX = "#";
@@ -116,12 +117,33 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true; return true;
} }
} }
if (msg.equals("baritone") || msg.equals("settings")) { if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) {
for (Settings.Setting<?> setting : Baritone.settings().allSettings) { logDirect("All settings that have been modified from their default values:");
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(Baritone.settings())) {
logDirect(setting.toString()); logDirect(setting.toString());
} }
return true; 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 <num>");
}
return true;
}
if (msg.equals("") || msg.equals("help") || msg.equals("?")) { if (msg.equals("") || msg.equals("help") || msg.equals("?")) {
for (String line : HELP_MSG.split("\n")) { for (String line : HELP_MSG.split("\n")) {
logDirect(line); logDirect(line);
@@ -129,31 +151,24 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true; return true;
} }
if (msg.contains(" ")) { if (msg.contains(" ")) {
String[] data = msg.split(" "); String settingName = msg.substring(0, msg.indexOf(' '));
if (data.length == 2) { String settingValue = msg.substring(msg.indexOf(' ') + 1);
Settings.Setting setting = Baritone.settings().byLowerName.get(data[0]); Settings.Setting setting = Baritone.settings().byLowerName.get(settingName);
if (setting != null) { if (setting != null) {
if (settingValue.equals("reset")) {
logDirect("Resetting setting " + settingName + " to default value.");
setting.reset();
} else {
try { try {
if (setting.value.getClass() == Long.class) { SettingsUtil.parseAndApply(Baritone.settings(), settingName, settingValue);
setting.value = Long.parseLong(data[1]); } catch (Exception ex) {
} logDirect("Unable to parse setting");
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]);
return true; 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)) { if (Baritone.settings().byLowerName.containsKey(msg)) {
@@ -236,6 +251,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("Queued " + count + " chunks for repacking"); logDirect("Queued " + count + " chunks for repacking");
return true; 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")) { if (msg.equals("axis") || msg.equals("highway")) {
customGoalProcess.setGoalAndPath(new GoalAxis()); customGoalProcess.setGoalAndPath(new GoalAxis());
return true; return true;
@@ -277,7 +297,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true; return true;
} }
if (msg.equals("reset")) { if (msg.equals("reset")) {
Baritone.settings().reset(); for (Settings.Setting setting : Baritone.settings().allSettings) {
setting.reset();
}
SettingsUtil.save(Baritone.settings());
logDirect("Baritone settings reset"); logDirect("Baritone settings reset");
return true; return true;
} }
@@ -384,7 +407,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes)); logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
return true; return true;
} }
if (msg.startsWith("thisway")) { if (msg.startsWith("thisway") || msg.startsWith("forward")) {
try { try {
Goal goal = GoalXZ.fromDirection(ctx.playerFeetAsVec(), ctx.player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); Goal goal = GoalXZ.fromDirection(ctx.playerFeetAsVec(), ctx.player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
customGoalProcess.setGoal(goal); customGoalProcess.setGoal(goal);
+72 -72
View File
@@ -1,72 +1,72 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.utils; package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
/** /**
* @author Brady * @author Brady
* @since 8/1/2018 * @since 8/1/2018
*/ */
public interface Helper { public interface Helper {
/** /**
* Instance of {@link Helper}. Used for static-context reference. * Instance of {@link Helper}. Used for static-context reference.
*/ */
Helper HELPER = new Helper() {}; Helper HELPER = new Helper() {};
ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format( ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format(
"%s[%sBaritone%s]%s", "%s[%sBaritone%s]%s",
TextFormatting.DARK_PURPLE, TextFormatting.DARK_PURPLE,
TextFormatting.LIGHT_PURPLE, TextFormatting.LIGHT_PURPLE,
TextFormatting.DARK_PURPLE, TextFormatting.DARK_PURPLE,
TextFormatting.GRAY TextFormatting.GRAY
)); ));
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();
/** /**
* Send a message to chat only if chatDebug is on * Send a message to chat only if chatDebug is on
* *
* @param message The message to display in chat * @param message The message to display in chat
*/ */
default void logDebug(String message) { default void logDebug(String message) {
if (!Baritone.settings().chatDebug.get()) { if (!Baritone.settings().chatDebug.get()) {
//System.out.println("Suppressed debug message:"); //System.out.println("Suppressed debug message:");
//System.out.println(message); //System.out.println(message);
return; return;
} }
logDirect(message); 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) * 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 * @param message The message to display in chat
*/ */
default void logDirect(String message) { default void logDirect(String message) {
ITextComponent component = MESSAGE_PREFIX.createCopy(); ITextComponent component = MESSAGE_PREFIX.createCopy();
component.getStyle().setColor(TextFormatting.GRAY); component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(new TextComponentString(" " + message)); component.appendSibling(new TextComponentString(" " + message));
Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component)); Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component));
} }
} }
@@ -1,133 +1,140 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.utils; package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.IInputOverrideHandler;
import baritone.api.utils.input.Input; import baritone.api.utils.input.Input;
import baritone.behavior.Behavior; import baritone.behavior.Behavior;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.MovementInputFromOptions; import net.minecraft.util.MovementInputFromOptions;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* An interface with the game's control system allowing the ability to * 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 * force down certain controls, having the same effect as if we were actually
* physically forcing down the assigned key. * physically forcing down the assigned key.
* *
* @author Brady * @author Brady
* @since 7/31/2018 * @since 7/31/2018
*/ */
public final class InputOverrideHandler extends Behavior implements IInputOverrideHandler { public final class InputOverrideHandler extends Behavior implements IInputOverrideHandler {
/** /**
* Maps inputs to whether or not we are forcing their state down. * Maps inputs to whether or not we are forcing their state down.
*/ */
private final Map<Input, Boolean> inputForceStateMap = new HashMap<>(); private final Map<Input, Boolean> inputForceStateMap = new HashMap<>();
private final BlockBreakHelper blockBreakHelper; private final BlockBreakHelper blockBreakHelper;
public InputOverrideHandler(Baritone baritone) { public InputOverrideHandler(Baritone baritone) {
super(baritone); super(baritone);
this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext()); this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext());
} }
/** /**
* Returns whether or not we are forcing down the specified {@link KeyBinding}. * Returns whether or not we are forcing down the specified {@link KeyBinding}.
* *
* @param key The KeyBinding object * @param key The KeyBinding object
* @return Whether or not it is being forced down * @return Whether or not it is being forced down
*/ */
@Override @Override
public final Boolean isInputForcedDown(KeyBinding key) { public final Boolean isInputForcedDown(KeyBinding key) {
Input input = Input.getInputForBind(key); Input input = Input.getInputForBind(key);
if (input == null || !inControl()) { if (input == null) {
return null; return null;
} }
if (input == Input.CLICK_LEFT) { if (input == Input.CLICK_LEFT && inControl()) {
return false; // only override left click off when pathing
} return false;
if (input == Input.CLICK_RIGHT) { }
return isInputForcedDown(Input.CLICK_RIGHT); if (input == Input.CLICK_RIGHT) {
} if (isInputForcedDown(Input.CLICK_RIGHT)) {
return null; // 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
* Returns whether or not we are forcing down the specified {@link Input}. return false;
* }
* @param input The input }
* @return Whether or not it is being forced down return null; // dont force any inputs other than left and right click
*/ }
@Override
public final boolean isInputForcedDown(Input input) { /**
return input == null ? false : this.inputForceStateMap.getOrDefault(input, false); * 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
* Sets whether or not the specified {@link Input} is being forced down. */
* @Override
* @param input The {@link Input} public final boolean isInputForcedDown(Input input) {
* @param forced Whether or not the state is being forced return input == null ? false : this.inputForceStateMap.getOrDefault(input, false);
*/ }
@Override
public final void setInputForceState(Input input, boolean forced) { /**
this.inputForceStateMap.put(input, forced); * 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
* Clears the override state for all keys */
*/ @Override
@Override public final void setInputForceState(Input input, boolean forced) {
public final void clearAllKeys() { this.inputForceStateMap.put(input, forced);
this.inputForceStateMap.clear(); }
}
/**
@Override * Clears the override state for all keys
public final void onTick(TickEvent event) { */
if (event.getType() == TickEvent.Type.OUT) { @Override
return; public final void clearAllKeys() {
} this.inputForceStateMap.clear();
blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); }
if (inControl()) { @Override
if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) { public final void onTick(TickEvent event) {
ctx.player().movementInput = new PlayerMovementInput(this); if (event.getType() == TickEvent.Type.OUT) {
} return;
} else { }
if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT));
ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings);
} if (inControl()) {
} if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) {
// only set it if it was previously incorrect ctx.player().movementInput = new PlayerMovementInput(this);
// gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol }
} } else {
if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam
private boolean inControl() { ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings);
return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); }
} }
// only set it if it was previously incorrect
public BlockBreakHelper getBlockBreakHelper() { // gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol
return blockBreakHelper; }
}
} private boolean inControl() {
return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone();
}
public BlockBreakHelper getBlockBreakHelper() {
return blockBreakHelper;
}
}
@@ -295,6 +295,8 @@ public final class PathRenderer implements Helper {
GoalXZ goalPos = (GoalXZ) goal; GoalXZ goalPos = (GoalXZ) goal;
if (Baritone.settings().renderGoalXZBeacon.get()) { if (Baritone.settings().renderGoalXZBeacon.get()) {
glPushAttrib(GL_LIGHTING_BIT);
mc.getTextureManager().bindTexture(TileEntityBeaconRenderer.TEXTURE_BEACON_BEAM); mc.getTextureManager().bindTexture(TileEntityBeaconRenderer.TEXTURE_BEACON_BEAM);
if (Baritone.settings().renderGoalIgnoreDepth.get()) { if (Baritone.settings().renderGoalIgnoreDepth.get()) {
@@ -316,6 +318,8 @@ public final class PathRenderer implements Helper {
if (Baritone.settings().renderGoalIgnoreDepth.get()) { if (Baritone.settings().renderGoalIgnoreDepth.get()) {
GlStateManager.enableDepth(); GlStateManager.enableDepth();
} }
glPopAttrib();
return; return;
} }
@@ -82,6 +82,7 @@ public class PathingControlManager implements IPathingControlManager {
public void preTick() { public void preTick() {
inControlLastTick = inControlThisTick; inControlLastTick = inControlThisTick;
inControlThisTick = null;
PathingBehavior p = baritone.getPathingBehavior(); PathingBehavior p = baritone.getPathingBehavior();
command = executeProcesses(); command = executeProcesses();
if (command == null) { if (command == null) {