From ae3fc14b52a1972febed67ac424e6040ef05e6f6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 14 Jan 2019 19:52:31 -0800 Subject: [PATCH 01/14] refactor name --- src/main/java/baritone/behavior/InventoryBehavior.java | 2 +- src/main/java/baritone/utils/ToolSet.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index a49cbb7de..8a1ea943c 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -78,7 +78,7 @@ public class InventoryBehavior extends Behavior { continue; } if (klass.isInstance(stack.getItem())) { - double speed = ToolSet.calculateStrVsBlock(stack, against.getDefaultState()); // takes into account enchants + double speed = ToolSet.calculateSpeedVsBlock(stack, against.getDefaultState()); // takes into account enchants if (speed > bestSpeed) { bestSpeed = speed; bestInd = i; diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 0aa02afd0..ab8d2e403 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -103,7 +103,7 @@ public class ToolSet { IBlockState blockState = b.getDefaultState(); for (byte i = 0; i < 9; i++) { ItemStack itemStack = player.inventory.getStackInSlot(i); - double v = calculateStrVsBlock(itemStack, blockState); + double v = calculateSpeedVsBlock(itemStack, blockState); if (v > value) { value = v; best = i; @@ -128,7 +128,7 @@ public class ToolSet { */ private double getBestDestructionTime(Block b) { ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b)); - return calculateStrVsBlock(stack, b.getDefaultState()); + return calculateSpeedVsBlock(stack, b.getDefaultState()); } /** @@ -138,7 +138,7 @@ public class ToolSet { * @param state the blockstate to be mined * @return how long it would take in ticks */ - public static double calculateStrVsBlock(ItemStack item, IBlockState state) { + public static double calculateSpeedVsBlock(ItemStack item, IBlockState state) { float hardness = state.getBlockHardness(null, null); if (hardness < 0) { return -1; From 9dfcef6356e421c510463989f35d7fad30757584 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 15 Jan 2019 17:21:50 -0800 Subject: [PATCH 02/14] crucial performance optimization --- src/main/java/baritone/utils/ToolSet.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index ab8d2e403..fa71a6b0f 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -154,11 +154,10 @@ public class ToolSet { speed /= hardness; if (state.getMaterial().isToolNotRequired() || (!item.isEmpty() && item.canHarvestBlock(state))) { - speed /= 30; + return speed / 30; } else { - speed /= 100; + return speed / 100; } - return speed; } /** From 59320d9b85672f079d3b14ea8a1ed00e67d90fcd Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 16 Jan 2019 13:37:39 -0600 Subject: [PATCH 03/14] Auto test class javadoc --- src/main/java/baritone/utils/BaritoneAutoTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index 2e4a5706a..b7ae5fbb3 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -32,6 +32,15 @@ import net.minecraft.world.GameType; import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldType; +/** + * Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific + * seed, setting a specified goal, and only allowing a certain amount of ticks to pass before the pathing test is + * considered a failure. In order to test locally, docker may be used, or through an IDE: Create a run config which runs + * in a separate directory from the primary one (./run), and set the enrivonmental variable {@code BARITONE_AUTO_TEST} + * to {@code true}. + * + * @author leijurv, Brady + */ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { public static final BaritoneAutoTest INSTANCE = new BaritoneAutoTest(); From db24822d2f908f839a4e1fc2a1808451d19f1045 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 16 Jan 2019 13:50:15 -0600 Subject: [PATCH 04/14] Fix cursed exception --- src/api/java/baritone/api/utils/PathCalculationResult.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/java/baritone/api/utils/PathCalculationResult.java b/src/api/java/baritone/api/utils/PathCalculationResult.java index 20aef9de7..a71c31a6b 100644 --- a/src/api/java/baritone/api/utils/PathCalculationResult.java +++ b/src/api/java/baritone/api/utils/PathCalculationResult.java @@ -19,6 +19,7 @@ package baritone.api.utils; import baritone.api.pathing.calc.IPath; +import java.util.Objects; import java.util.Optional; public class PathCalculationResult { @@ -31,11 +32,9 @@ public class PathCalculationResult { } public PathCalculationResult(Type type, IPath path) { + Objects.requireNonNull(type); this.path = path; this.type = type; - if (type == null) { - throw new IllegalArgumentException("come on"); - } } public final Optional getPath() { From 2daedecf9233c07d3dcf415b9ecbe2a8559ac3c4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 16 Jan 2019 17:42:43 -0800 Subject: [PATCH 05/14] maybe fix --- src/main/java/baritone/behavior/MemoryBehavior.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 499860185..696e107d5 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; import baritone.cache.ContainerMemory; import baritone.cache.Waypoint; @@ -60,6 +61,14 @@ public final class MemoryBehavior extends Behavior { super(baritone); } + @Override + public synchronized void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + enderChestWindowId = null; + futureInventories.clear(); + } + } + @Override public synchronized void onPlayerUpdate(PlayerUpdateEvent event) { if (event.getState() == EventState.PRE) { From a5b98857673a2753a396ae80e2a55511c1e8bc30 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 17 Jan 2019 12:22:36 -0800 Subject: [PATCH 06/14] not even used --- src/main/java/baritone/utils/BaritoneProcessHelper.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/baritone/utils/BaritoneProcessHelper.java b/src/main/java/baritone/utils/BaritoneProcessHelper.java index 4f3870c5a..c5e13619f 100644 --- a/src/main/java/baritone/utils/BaritoneProcessHelper.java +++ b/src/main/java/baritone/utils/BaritoneProcessHelper.java @@ -23,16 +23,10 @@ import baritone.api.utils.IPlayerContext; public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper { - public static final double DEFAULT_PRIORITY = 0; - protected final Baritone baritone; protected final IPlayerContext ctx; private final double priority; - public BaritoneProcessHelper(Baritone baritone) { - this(baritone, DEFAULT_PRIORITY); - } - public BaritoneProcessHelper(Baritone baritone, double priority) { this.baritone = baritone; this.ctx = baritone.getPlayerContext(); From d32c92cbde0b28f6bfaf142053a1e82be13a01ff Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 17 Jan 2019 18:01:05 -0600 Subject: [PATCH 07/14] Specificity time --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1b4f62e01..536905625 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -534,7 +534,7 @@ public class Settings { public Setting followOffsetDistance = new Setting<>(0D); /** - * The actual GoalNear is set in this direction from the entity you're following + * The actual GoalNear is set in this direction from the entity you're following. This value is in degrees. */ public Setting followOffsetDirection = new Setting<>(0F); From 69b1decbba34dcb3e5d0d8f0ef4ef5f5697edea8 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 17 Jan 2019 18:04:12 -0600 Subject: [PATCH 08/14] leftClickWorkaround is no longer applicable --- src/api/java/baritone/api/Settings.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 536905625..89716a383 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -450,11 +450,6 @@ public class Settings { */ public Setting prefix = new Setting<>(false); - /** - * {@code true}: can mine blocks when in inventory, chat, or tabbed away in ESC menu - */ - public Setting leftClickWorkaround = new Setting<>(true); - /** * Don't stop walking forward when you need to break blocks in your way */ From 979b8b2663d08466ab9eea0835d9cdbeb017d04a Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 17 Jan 2019 18:20:27 -0600 Subject: [PATCH 09/14] Remove associatedWith in process and some more javadoc changes --- .../api/pathing/calc/IPathingControlManager.java | 16 ++++++++++++++++ .../baritone/api/process/IBaritoneProcess.java | 14 ++++---------- .../baritone/utils/BaritoneProcessHelper.java | 5 ----- .../utils/player/PrimaryPlayerContext.java | 2 +- .../utils/player/PrimaryPlayerController.java | 2 ++ 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java b/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java index ffaa18b84..dc729748e 100644 --- a/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java +++ b/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java @@ -22,10 +22,26 @@ import baritone.api.process.PathingCommand; import java.util.Optional; +/** + * @author leijurv + */ public interface IPathingControlManager { + + /** + * Registers a process with this pathing control manager. See {@link IBaritoneProcess} for more details. + * + * @param process The process + * @see IBaritoneProcess + */ void registerProcess(IBaritoneProcess process); + /** + * @return The most recent {@link IBaritoneProcess} that had control + */ Optional mostRecentInControl(); + /** + * @return The most recent pathing command executed + */ Optional mostRecentCommand(); } diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java index db7588abb..c2eb2f49e 100644 --- a/src/api/java/baritone/api/process/IBaritoneProcess.java +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -17,7 +17,6 @@ package baritone.api.process; -import baritone.api.IBaritone; import baritone.api.behavior.IPathingBehavior; import baritone.api.event.events.PathEvent; @@ -25,8 +24,10 @@ import baritone.api.event.events.PathEvent; * A process that can control the PathingBehavior. *

* Differences between a baritone process and a behavior: - * Only one baritone process can be active at a time - * PathingBehavior can only be controlled by a process + *

    + *
  • Only one baritone process can be active at a time
  • + *
  • PathingBehavior can only be controlled by a process
  • + *
*

* That's it actually * @@ -83,13 +84,6 @@ public interface IBaritoneProcess { */ double priority(); - /** - * Returns which bot this process is associated with. (5000000iq forward thinking) - * - * @return The Bot associated with this process - */ - IBaritone associatedWith(); - /** * Returns a user-friendly name for this process. Suitable for a HUD. * diff --git a/src/main/java/baritone/utils/BaritoneProcessHelper.java b/src/main/java/baritone/utils/BaritoneProcessHelper.java index c5e13619f..1a66eaa5d 100644 --- a/src/main/java/baritone/utils/BaritoneProcessHelper.java +++ b/src/main/java/baritone/utils/BaritoneProcessHelper.java @@ -34,11 +34,6 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper baritone.getPathingControlManager().registerProcess(this); } - @Override - public Baritone associatedWith() { - return baritone; - } - @Override public boolean isTemporary() { return false; diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index f0d7ee016..1eefc91f3 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -27,7 +27,7 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; /** - * Implementation of {@link IPlayerContext} that provides information about the local player. + * Implementation of {@link IPlayerContext} that provides information about the primary player. * * @author Brady * @since 11/12/2018 diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java index 7b998bb59..c0dc8798b 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -27,6 +27,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.GameType; /** + * Implementation of {@link IPlayerController} that chains to the primary player controller's methods + * * @author Brady * @since 12/14/2018 */ From 20b03d00049dc3f4a75c8d8e9aa83eca1bd7ac55 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 18 Jan 2019 13:43:19 -0600 Subject: [PATCH 10/14] No more setSprinting --- .../api/event/events/SprintStateEvent.java | 42 +++++++++++++++++++ .../listener/AbstractGameEventListener.java | 3 ++ .../event/listener/IGameEventListener.java | 8 ++++ .../launch/mixins/MixinEntityPlayerSP.java | 16 +++++++ .../baritone/behavior/PathingBehavior.java | 12 ++++-- .../java/baritone/event/GameEventHandler.java | 5 +++ .../baritone/pathing/path/PathExecutor.java | 38 +++++++---------- 7 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 src/api/java/baritone/api/event/events/SprintStateEvent.java diff --git a/src/api/java/baritone/api/event/events/SprintStateEvent.java b/src/api/java/baritone/api/event/events/SprintStateEvent.java new file mode 100644 index 000000000..e7b8d1938 --- /dev/null +++ b/src/api/java/baritone/api/event/events/SprintStateEvent.java @@ -0,0 +1,42 @@ +/* + * 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.api.event.events; + +import baritone.api.event.events.type.ManagedPlayerEvent; +import net.minecraft.client.entity.EntityPlayerSP; + +/** + * @author Brady + * @since 1/18/2019 + */ +public class SprintStateEvent extends ManagedPlayerEvent { + + private Boolean state; + + public SprintStateEvent(EntityPlayerSP player) { + super(player); + } + + public final void setState(boolean state) { + this.state = state; + } + + public final Boolean getState() { + return this.state; + } +} diff --git a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java index 135c29a75..71045768a 100644 --- a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -57,6 +57,9 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onPlayerRotationMove(RotationMoveEvent event) {} + @Override + default void onPlayerSprintState(SprintStateEvent event) {} + @Override default void onBlockInteract(BlockInteractEvent event) {} diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index 0572cbe9e..dc471e5fb 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -109,6 +109,14 @@ public interface IGameEventListener { */ void onPlayerRotationMove(RotationMoveEvent event); + /** + * Called whenever the sprint keybind state is checked in {@link EntityPlayerSP#onLivingUpdate} + * + * @param event The event + * @see EntityPlayerSP#onLivingUpdate() + */ + void onPlayerSprintState(SprintStateEvent event); + /** * Called when the local player interacts with a block, whether it is breaking or opening/placing. * diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 9c9509f0a..2f87b72d7 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -21,8 +21,10 @@ import baritone.api.BaritoneAPI; import baritone.api.behavior.IPathingBehavior; import baritone.api.event.events.ChatEvent; import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.SprintStateEvent; import baritone.api.event.events.type.EventState; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.PlayerCapabilities; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -87,4 +89,18 @@ public class MixinEntityPlayerSP { IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior(); return !pathingBehavior.isPathing() && capabilities.allowFlying; } + + @Redirect( + method = "onLivingUpdate", + at = @At( + value = "INVOKE", + target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z" + ) + ) + private boolean isKeyDown(KeyBinding keyBinding) { + EntityPlayerSP self = (EntityPlayerSP) (Object) this; + SprintStateEvent event = new SprintStateEvent(self); + BaritoneAPI.getProvider().getBaritoneForPlayer(self).getGameEventHandler().onPlayerSprintState(event); + return event.getState() == null ? keyBinding.isKeyDown() : event.getState(); + } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 8c5fb8a4e..92eb242ed 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -19,10 +19,7 @@ package baritone.behavior; import baritone.Baritone; import baritone.api.behavior.IPathingBehavior; -import baritone.api.event.events.PathEvent; -import baritone.api.event.events.PlayerUpdateEvent; -import baritone.api.event.events.RenderEvent; -import baritone.api.event.events.TickEvent; +import baritone.api.event.events.*; import baritone.api.pathing.calc.IPath; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalXZ; @@ -98,6 +95,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, dispatchEvents(); } + @Override + public void onPlayerSprintState(SprintStateEvent event) { + if (current != null) { + event.setState(current.isSprinting()); + } + } + private void tickPath() { if (pauseRequestedLastTick && safeToCancel) { pauseRequestedLastTick = false; diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index e85c46de1..3b3270029 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -121,6 +121,11 @@ public final class GameEventHandler implements IEventBus, Helper { listeners.forEach(l -> l.onPlayerRotationMove(event)); } + @Override + public void onPlayerSprintState(SprintStateEvent event) { + listeners.forEach(l -> l.onPlayerSprintState(event)); + } + @Override public void onBlockInteract(BlockInteractEvent event) { listeners.forEach(l -> l.onBlockInteract(event)); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index cad144aa0..ef856f426 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -79,6 +79,8 @@ public class PathExecutor implements IPathExecutor, Helper { private PathingBehavior behavior; private IPlayerContext ctx; + private boolean sprintNextTick; + public PathExecutor(PathingBehavior behavior, IPath path) { this.behavior = behavior; this.ctx = behavior.ctx; @@ -269,7 +271,7 @@ public class PathExecutor implements IPathExecutor, Helper { onTick(); return true; } else { - sprintIfRequested(); + sprintNextTick = shouldSprintNextTick(); ticksOnCurrent++; if (ticksOnCurrent > currentMovementOriginalCostEstimate + Baritone.settings().movementTimeoutTicks.get()) { // only cancel if the total time has exceeded the initial estimate @@ -371,21 +373,17 @@ public class PathExecutor implements IPathExecutor, Helper { return true; } - private void sprintIfRequested() { + private boolean shouldSprintNextTick() { // first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint if (!new CalculationContext(behavior.baritone).canSprint) { behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); - ctx.player().setSprinting(false); - return; + return false; } // if the movement requested sprinting, then we're done if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT)) { behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); - if (!ctx.player().isSprinting()) { - ctx.player().setSprinting(true); - } - return; + return true; } // we'll take it from here, no need for minecraft to see we're holding down control and sprint for us @@ -397,30 +395,23 @@ public class PathExecutor implements IPathExecutor, Helper { if (((MovementDescend) current).safeMode()) { logDebug("Sprinting would be unsafe"); - ctx.player().setSprinting(false); - return; + return false; } IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) { // a descend then an ascend in the same direction - if (!ctx.player().isSprinting()) { - ctx.player().setSprinting(true); - } pathPosition++; // okay to skip clearKeys and / or onChangeInPathPosition here since this isn't possible to repeat, since it's asymmetric logDebug("Skipping descend to straight ascend"); - return; + return true; } if (canSprintInto(ctx, current, next)) { if (ctx.playerFeet().equals(current.getDest())) { pathPosition++; onChangeInPathPosition(); } - if (!ctx.player().isSprinting()) { - ctx.player().setSprinting(true); - } - return; + return true; } //logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); } @@ -430,14 +421,11 @@ public class PathExecutor implements IPathExecutor, Helper { BlockPos center = current.getSrc().up(); if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false); - if (!ctx.player().isSprinting()) { - ctx.player().setSprinting(true); - } - return; + return true; } } } - ctx.player().setSprinting(false); + return false; } private static boolean canSprintInto(IPlayerContext ctx, IMovement current, IMovement next) { @@ -532,4 +520,8 @@ public class PathExecutor implements IPathExecutor, Helper { public Set toWalkInto() { return Collections.unmodifiableSet(toWalkInto); } + + public boolean isSprinting() { + return sprintNextTick; + } } From bc651cb774e20e7b398805348d786f0f5a6099b0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 18 Jan 2019 20:12:40 -0800 Subject: [PATCH 11/14] add todo --- src/main/java/baritone/behavior/MemoryBehavior.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 696e107d5..661c5712c 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -48,6 +48,8 @@ import java.nio.file.Path; import java.util.*; /** + * doesn't work for horse inventories :^) + * * @author Brady * @since 8/6/2018 */ From aa2e6805682ae25597132d074ff444edff7e844a Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 19 Jan 2019 12:10:21 -0600 Subject: [PATCH 12/14] Remove ManagedPlayerEvent --- .../baritone/api/event/events/ChatEvent.java | 8 +-- .../api/event/events/PlayerUpdateEvent.java | 7 +-- .../api/event/events/RotationMoveEvent.java | 7 +-- .../event/events/type/ManagedPlayerEvent.java | 61 ------------------- .../baritone/launch/mixins/MixinEntity.java | 2 +- .../launch/mixins/MixinEntityLivingBase.java | 2 +- .../launch/mixins/MixinEntityPlayerSP.java | 6 +- 7 files changed, 12 insertions(+), 81 deletions(-) delete mode 100644 src/api/java/baritone/api/event/events/type/ManagedPlayerEvent.java diff --git a/src/api/java/baritone/api/event/events/ChatEvent.java b/src/api/java/baritone/api/event/events/ChatEvent.java index 5ab9f5bb2..d91e87b07 100644 --- a/src/api/java/baritone/api/event/events/ChatEvent.java +++ b/src/api/java/baritone/api/event/events/ChatEvent.java @@ -17,22 +17,20 @@ package baritone.api.event.events; -import baritone.api.event.events.type.ManagedPlayerEvent; -import net.minecraft.client.entity.EntityPlayerSP; +import baritone.api.event.events.type.Cancellable; /** * @author Brady * @since 8/1/2018 */ -public final class ChatEvent extends ManagedPlayerEvent.Cancellable { +public final class ChatEvent extends Cancellable { /** * The message being sent */ private final String message; - public ChatEvent(EntityPlayerSP player, String message) { - super(player); + public ChatEvent(String message) { this.message = message; } diff --git a/src/api/java/baritone/api/event/events/PlayerUpdateEvent.java b/src/api/java/baritone/api/event/events/PlayerUpdateEvent.java index 99370552c..6ac08bdd6 100644 --- a/src/api/java/baritone/api/event/events/PlayerUpdateEvent.java +++ b/src/api/java/baritone/api/event/events/PlayerUpdateEvent.java @@ -18,22 +18,19 @@ package baritone.api.event.events; import baritone.api.event.events.type.EventState; -import baritone.api.event.events.type.ManagedPlayerEvent; -import net.minecraft.client.entity.EntityPlayerSP; /** * @author Brady * @since 8/21/2018 */ -public final class PlayerUpdateEvent extends ManagedPlayerEvent { +public final class PlayerUpdateEvent { /** * The state of the event */ private final EventState state; - public PlayerUpdateEvent(EntityPlayerSP player, EventState state) { - super(player); + public PlayerUpdateEvent(EventState state) { this.state = state; } diff --git a/src/api/java/baritone/api/event/events/RotationMoveEvent.java b/src/api/java/baritone/api/event/events/RotationMoveEvent.java index 790318e04..109061c7e 100644 --- a/src/api/java/baritone/api/event/events/RotationMoveEvent.java +++ b/src/api/java/baritone/api/event/events/RotationMoveEvent.java @@ -17,8 +17,6 @@ package baritone.api.event.events; -import baritone.api.event.events.type.ManagedPlayerEvent; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -26,7 +24,7 @@ import net.minecraft.entity.EntityLivingBase; * @author Brady * @since 8/21/2018 */ -public final class RotationMoveEvent extends ManagedPlayerEvent { +public final class RotationMoveEvent { /** * The type of event @@ -38,8 +36,7 @@ public final class RotationMoveEvent extends ManagedPlayerEvent { */ private float yaw; - public RotationMoveEvent(EntityPlayerSP player, Type type, float yaw) { - super(player); + public RotationMoveEvent(Type type, float yaw) { this.type = type; this.yaw = yaw; } diff --git a/src/api/java/baritone/api/event/events/type/ManagedPlayerEvent.java b/src/api/java/baritone/api/event/events/type/ManagedPlayerEvent.java deleted file mode 100644 index a3487a673..000000000 --- a/src/api/java/baritone/api/event/events/type/ManagedPlayerEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.event.events.type; - -import net.minecraft.client.entity.EntityPlayerSP; - -/** - * An event that has a reference to a locally managed player. - * - * @author Brady - * @since 10/11/2018 - */ -public class ManagedPlayerEvent { - - protected final EntityPlayerSP player; - - public ManagedPlayerEvent(EntityPlayerSP player) { - this.player = player; - } - - public final EntityPlayerSP getPlayer() { - return this.player; - } - - public static class Cancellable extends ManagedPlayerEvent implements ICancellable { - - /** - * Whether or not this event has been cancelled - */ - private boolean cancelled; - - public Cancellable(EntityPlayerSP player) { - super(player); - } - - @Override - public final void cancel() { - this.cancelled = true; - } - - @Override - public final boolean isCancelled() { - return this.cancelled; - } - } -} diff --git a/src/launch/java/baritone/launch/mixins/MixinEntity.java b/src/launch/java/baritone/launch/mixins/MixinEntity.java index fe4982029..836557834 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntity.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntity.java @@ -52,7 +52,7 @@ public class MixinEntity { private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) { // noinspection ConstantConditions if (EntityPlayerSP.class.isInstance(this)) { - this.motionUpdateRotationEvent = new RotationMoveEvent((EntityPlayerSP) (Object) this, RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw); + this.motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw); BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.motionUpdateRotationEvent); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java index 1a7d298f7..c6d76634f 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java @@ -55,7 +55,7 @@ public abstract class MixinEntityLivingBase extends Entity { private void preMoveRelative(CallbackInfo ci) { // noinspection ConstantConditions if (EntityPlayerSP.class.isInstance(this)) { - this.jumpRotationEvent = new RotationMoveEvent((EntityPlayerSP) (Object) this, RotationMoveEvent.Type.JUMP, this.rotationYaw); + this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw); BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 2f87b72d7..5ca3c839f 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -45,7 +45,7 @@ public class MixinEntityPlayerSP { cancellable = true ) private void sendChatMessage(String msg, CallbackInfo ci) { - ChatEvent event = new ChatEvent((EntityPlayerSP) (Object) this, msg); + ChatEvent event = new ChatEvent(msg); BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event); if (event.isCancelled()) { ci.cancel(); @@ -62,7 +62,7 @@ public class MixinEntityPlayerSP { ) ) private void onPreUpdate(CallbackInfo ci) { - BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.PRE)); + BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE)); } @Inject( @@ -75,7 +75,7 @@ public class MixinEntityPlayerSP { ) ) private void onPostUpdate(CallbackInfo ci) { - BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.POST)); + BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST)); } @Redirect( From f5446cc415789cde2d77a5992c1d62f9635d73e0 Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 19 Jan 2019 12:12:26 -0600 Subject: [PATCH 13/14] Fix SprintStateEvent --- .../java/baritone/api/event/events/SprintStateEvent.java | 9 +-------- .../java/baritone/launch/mixins/MixinEntityPlayerSP.java | 5 ++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/api/java/baritone/api/event/events/SprintStateEvent.java b/src/api/java/baritone/api/event/events/SprintStateEvent.java index e7b8d1938..6027c79e2 100644 --- a/src/api/java/baritone/api/event/events/SprintStateEvent.java +++ b/src/api/java/baritone/api/event/events/SprintStateEvent.java @@ -17,21 +17,14 @@ package baritone.api.event.events; -import baritone.api.event.events.type.ManagedPlayerEvent; -import net.minecraft.client.entity.EntityPlayerSP; - /** * @author Brady * @since 1/18/2019 */ -public class SprintStateEvent extends ManagedPlayerEvent { +public class SprintStateEvent { private Boolean state; - public SprintStateEvent(EntityPlayerSP player) { - super(player); - } - public final void setState(boolean state) { this.state = state; } diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 5ca3c839f..48ac8c949 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -98,9 +98,8 @@ public class MixinEntityPlayerSP { ) ) private boolean isKeyDown(KeyBinding keyBinding) { - EntityPlayerSP self = (EntityPlayerSP) (Object) this; - SprintStateEvent event = new SprintStateEvent(self); - BaritoneAPI.getProvider().getBaritoneForPlayer(self).getGameEventHandler().onPlayerSprintState(event); + SprintStateEvent event = new SprintStateEvent(); + BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerSprintState(event); return event.getState() == null ? keyBinding.isKeyDown() : event.getState(); } } From 38c7f226cb4f6ffabfc90aceed289a4ddd4fd208 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 19 Jan 2019 16:36:24 -0800 Subject: [PATCH 14/14] brady is rart --- src/main/java/baritone/behavior/MemoryBehavior.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 661c5712c..d371116c3 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -109,7 +109,6 @@ public final class MemoryBehavior extends Behavior { } if (p instanceof CPacketCloseWindow) { - updateInventory(); getCurrent().save(); } } @@ -144,7 +143,6 @@ public final class MemoryBehavior extends Behavior { } if (p instanceof SPacketCloseWindow) { - updateInventory(); getCurrent().save(); } }