mirror of https://github.com/cabaletta/baritone
parent
cc4335e48e
commit
e8e00e8dfb
|
@ -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
|
||||||
|
|
|
@ -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,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,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,140 +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) {
|
if (input == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (input == Input.CLICK_LEFT && inControl()) {
|
if (input == Input.CLICK_LEFT && inControl()) {
|
||||||
// only override left click off when pathing
|
// only override left click off when pathing
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (input == Input.CLICK_RIGHT) {
|
if (input == Input.CLICK_RIGHT) {
|
||||||
if (isInputForcedDown(Input.CLICK_RIGHT)) {
|
if (isInputForcedDown(Input.CLICK_RIGHT)) {
|
||||||
// gettoblock and builder can right click even when not pathing; allow them to do so
|
// gettoblock and builder can right click even when not pathing; allow them to do so
|
||||||
return true;
|
return true;
|
||||||
} else if (inControl()) {
|
} else if (inControl()) {
|
||||||
// but when we are pathing for real, force right click off
|
// but when we are pathing for real, force right click off
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null; // dont force any inputs other than left and right click
|
return null; // dont force any inputs other than left and right click
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not we are forcing down the specified {@link Input}.
|
* Returns whether or not we are forcing down the specified {@link Input}.
|
||||||
*
|
*
|
||||||
* @param input The input
|
* @param input The input
|
||||||
* @return Whether or not it is being forced down
|
* @return Whether or not it is being forced down
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final boolean isInputForcedDown(Input input) {
|
public final boolean isInputForcedDown(Input input) {
|
||||||
return input == null ? false : this.inputForceStateMap.getOrDefault(input, false);
|
return input == null ? false : this.inputForceStateMap.getOrDefault(input, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not the specified {@link Input} is being forced down.
|
* Sets whether or not the specified {@link Input} is being forced down.
|
||||||
*
|
*
|
||||||
* @param input The {@link Input}
|
* @param input The {@link Input}
|
||||||
* @param forced Whether or not the state is being forced
|
* @param forced Whether or not the state is being forced
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void setInputForceState(Input input, boolean forced) {
|
public final void setInputForceState(Input input, boolean forced) {
|
||||||
this.inputForceStateMap.put(input, forced);
|
this.inputForceStateMap.put(input, forced);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the override state for all keys
|
* Clears the override state for all keys
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void clearAllKeys() {
|
public final void clearAllKeys() {
|
||||||
this.inputForceStateMap.clear();
|
this.inputForceStateMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onTick(TickEvent event) {
|
public final void onTick(TickEvent event) {
|
||||||
if (event.getType() == TickEvent.Type.OUT) {
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT));
|
blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT));
|
||||||
|
|
||||||
if (inControl()) {
|
if (inControl()) {
|
||||||
if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) {
|
if (ctx.player().movementInput.getClass() != PlayerMovementInput.class) {
|
||||||
ctx.player().movementInput = new PlayerMovementInput(this);
|
ctx.player().movementInput = new PlayerMovementInput(this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam
|
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);
|
ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// only set it if it was previously incorrect
|
// 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
|
// gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inControl() {
|
private boolean inControl() {
|
||||||
return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone();
|
return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockBreakHelper getBlockBreakHelper() {
|
public BlockBreakHelper getBlockBreakHelper() {
|
||||||
return blockBreakHelper;
|
return blockBreakHelper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue