From 85ea21e83b24ac4d290728a5097114bf97e59878 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 18:22:34 -0800 Subject: [PATCH] epic movement input --- .../baritone/pathing/path/PathExecutor.java | 3 +- .../baritone/utils/InputOverrideHandler.java | 16 +++++- .../baritone/utils/PlayerMovementInput.java | 57 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/main/java/baritone/utils/PlayerMovementInput.java diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 8d841e46..cad144aa 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -380,7 +380,8 @@ public class PathExecutor implements IPathExecutor, Helper { } // if the movement requested sprinting, then we're done - if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(mc.gameSettings.keyBindSprint)) { + if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT)) { + behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); if (!ctx.player().isSprinting()) { ctx.player().setSprinting(true); } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index c6e19c15..654ab10e 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -18,11 +18,14 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.BaritoneAPI; import baritone.api.event.events.TickEvent; import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.input.Input; import baritone.behavior.Behavior; +import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; +import net.minecraft.util.MovementInputFromOptions; import org.lwjgl.input.Keyboard; import java.util.HashMap; @@ -58,7 +61,13 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri */ @Override public final boolean isInputForcedDown(KeyBinding key) { - return isInputForcedDown(Input.getInputForBind(key)); + Input input = Input.getInputForBind(key); + if (input == null || (input != Input.CLICK_LEFT && input != Input.CLICK_RIGHT)) { + // TODO handle left and right better + // ideally we wouldn't force any keybinds and would do everything directly for real + return false; + } + return isInputForcedDown(input); } /** @@ -114,6 +123,11 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri } boolean stillClick = blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); setInputForceState(Input.CLICK_LEFT, stillClick); + if (baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone()) { + ctx.player().movementInput = new PlayerMovementInput(this); + } else { + ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); + } } public BlockBreakHelper getBlockBreakHelper() { diff --git a/src/main/java/baritone/utils/PlayerMovementInput.java b/src/main/java/baritone/utils/PlayerMovementInput.java new file mode 100644 index 00000000..4ffbef2b --- /dev/null +++ b/src/main/java/baritone/utils/PlayerMovementInput.java @@ -0,0 +1,57 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import baritone.api.utils.input.Input; +import net.minecraft.util.MovementInput; + +public class PlayerMovementInput extends MovementInput { + private final InputOverrideHandler handler; + + public PlayerMovementInput(InputOverrideHandler handler) { + this.handler = handler; + } + + public void updatePlayerMoveState() { + this.moveStrafe = 0.0F; + this.moveForward = 0.0F; + + jump = handler.isInputForcedDown(Input.JUMP); // oppa + + if (this.forwardKeyDown = handler.isInputForcedDown(Input.MOVE_FORWARD)) { + this.moveForward++; + } + + if (this.backKeyDown = handler.isInputForcedDown(Input.MOVE_BACK)) { + this.moveForward--; + } + + if (this.leftKeyDown = handler.isInputForcedDown(Input.MOVE_LEFT)) { + this.moveStrafe++; + } + + if (this.rightKeyDown = handler.isInputForcedDown(Input.MOVE_RIGHT)) { + this.moveStrafe--; + } + + if (this.sneak = handler.isInputForcedDown(Input.SNEAK)) { + this.moveStrafe *= 0.3D; + this.moveForward *= 0.3D; + } + } +}