Merge branch 'master' into bot-system
This commit is contained in:
@@ -450,11 +450,6 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public Setting<Boolean> prefix = new Setting<>(false);
|
public Setting<Boolean> prefix = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
|
||||||
* {@code true}: can mine blocks when in inventory, chat, or tabbed away in ESC menu
|
|
||||||
*/
|
|
||||||
public Setting<Boolean> leftClickWorkaround = new Setting<>(true);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't stop walking forward when you need to break blocks in your way
|
* Don't stop walking forward when you need to break blocks in your way
|
||||||
*/
|
*/
|
||||||
@@ -534,7 +529,7 @@ public class Settings {
|
|||||||
public Setting<Double> followOffsetDistance = new Setting<>(0D);
|
public Setting<Double> 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<Float> followOffsetDirection = new Setting<>(0F);
|
public Setting<Float> followOffsetDirection = new Setting<>(0F);
|
||||||
|
|
||||||
|
|||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,6 +57,9 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
@Override
|
@Override
|
||||||
default void onPlayerRotationMove(RotationMoveEvent event) {}
|
default void onPlayerRotationMove(RotationMoveEvent event) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onPlayerSprintState(SprintStateEvent event) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onBlockInteract(BlockInteractEvent event) {}
|
default void onBlockInteract(BlockInteractEvent event) {}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,14 @@ public interface IGameEventListener {
|
|||||||
*/
|
*/
|
||||||
void onPlayerRotationMove(RotationMoveEvent event);
|
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.
|
* Called when the local player interacts with a block, whether it is breaking or opening/placing.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -22,10 +22,26 @@ import baritone.api.process.PathingCommand;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author leijurv
|
||||||
|
*/
|
||||||
public interface IPathingControlManager {
|
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);
|
void registerProcess(IBaritoneProcess process);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The most recent {@link IBaritoneProcess} that had control
|
||||||
|
*/
|
||||||
Optional<IBaritoneProcess> mostRecentInControl();
|
Optional<IBaritoneProcess> mostRecentInControl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The most recent pathing command executed
|
||||||
|
*/
|
||||||
Optional<PathingCommand> mostRecentCommand();
|
Optional<PathingCommand> mostRecentCommand();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package baritone.api.process;
|
package baritone.api.process;
|
||||||
|
|
||||||
import baritone.api.IBaritone;
|
|
||||||
import baritone.api.behavior.IPathingBehavior;
|
import baritone.api.behavior.IPathingBehavior;
|
||||||
import baritone.api.event.events.PathEvent;
|
import baritone.api.event.events.PathEvent;
|
||||||
|
|
||||||
@@ -25,8 +24,10 @@ import baritone.api.event.events.PathEvent;
|
|||||||
* A process that can control the PathingBehavior.
|
* A process that can control the PathingBehavior.
|
||||||
* <p>
|
* <p>
|
||||||
* Differences between a baritone process and a behavior:
|
* Differences between a baritone process and a behavior:
|
||||||
* Only one baritone process can be active at a time
|
* <ul>
|
||||||
* PathingBehavior can only be controlled by a process
|
* <li>Only one baritone process can be active at a time</li>
|
||||||
|
* <li>PathingBehavior can only be controlled by a process</li>
|
||||||
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* That's it actually
|
* That's it actually
|
||||||
*
|
*
|
||||||
@@ -83,13 +84,6 @@ public interface IBaritoneProcess {
|
|||||||
*/
|
*/
|
||||||
double priority();
|
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.
|
* Returns a user-friendly name for this process. Suitable for a HUD.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ import baritone.api.IBaritone;
|
|||||||
import baritone.api.behavior.IPathingBehavior;
|
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.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import net.minecraft.entity.player.PlayerCapabilities;
|
import net.minecraft.entity.player.PlayerCapabilities;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -92,4 +94,18 @@ public class MixinEntityPlayerSP {
|
|||||||
IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior();
|
IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior();
|
||||||
return !pathingBehavior.isPathing() && capabilities.allowFlying;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ package baritone.behavior;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.behavior.IPathingBehavior;
|
import baritone.api.behavior.IPathingBehavior;
|
||||||
import baritone.api.event.events.PathEvent;
|
import baritone.api.event.events.*;
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
|
||||||
import baritone.api.event.events.RenderEvent;
|
|
||||||
import baritone.api.event.events.TickEvent;
|
|
||||||
import baritone.api.pathing.calc.IPath;
|
import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.goals.GoalXZ;
|
import baritone.api.pathing.goals.GoalXZ;
|
||||||
@@ -98,6 +95,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
dispatchEvents();
|
dispatchEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerSprintState(SprintStateEvent event) {
|
||||||
|
if (current != null) {
|
||||||
|
event.setState(current.isSprinting());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void tickPath() {
|
private void tickPath() {
|
||||||
if (pauseRequestedLastTick && safeToCancel) {
|
if (pauseRequestedLastTick && safeToCancel) {
|
||||||
pauseRequestedLastTick = false;
|
pauseRequestedLastTick = false;
|
||||||
|
|||||||
@@ -134,6 +134,11 @@ public final class GameEventHandler implements IEventBus, Helper {
|
|||||||
listeners.forEach(l -> l.onPlayerRotationMove(event));
|
listeners.forEach(l -> l.onPlayerRotationMove(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerSprintState(SprintStateEvent event) {
|
||||||
|
listeners.forEach(l -> l.onPlayerSprintState(event));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
listeners.forEach(l -> l.onBlockInteract(event));
|
listeners.forEach(l -> l.onBlockInteract(event));
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
private PathingBehavior behavior;
|
private PathingBehavior behavior;
|
||||||
private IPlayerContext ctx;
|
private IPlayerContext ctx;
|
||||||
|
|
||||||
|
private boolean sprintNextTick;
|
||||||
|
|
||||||
public PathExecutor(PathingBehavior behavior, IPath path) {
|
public PathExecutor(PathingBehavior behavior, IPath path) {
|
||||||
this.behavior = behavior;
|
this.behavior = behavior;
|
||||||
this.ctx = behavior.ctx;
|
this.ctx = behavior.ctx;
|
||||||
@@ -269,7 +271,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
onTick();
|
onTick();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sprintIfRequested();
|
sprintNextTick = shouldSprintNextTick();
|
||||||
ticksOnCurrent++;
|
ticksOnCurrent++;
|
||||||
if (ticksOnCurrent > currentMovementOriginalCostEstimate + Baritone.settings().movementTimeoutTicks.get()) {
|
if (ticksOnCurrent > currentMovementOriginalCostEstimate + Baritone.settings().movementTimeoutTicks.get()) {
|
||||||
// only cancel if the total time has exceeded the initial estimate
|
// only cancel if the total time has exceeded the initial estimate
|
||||||
@@ -371,21 +373,17 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
return true;
|
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
|
// 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) {
|
if (!new CalculationContext(behavior.baritone).canSprint) {
|
||||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
||||||
ctx.player().setSprinting(false);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the movement requested sprinting, then we're done
|
// if the movement requested sprinting, then we're done
|
||||||
if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT)) {
|
if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT)) {
|
||||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
||||||
if (!ctx.player().isSprinting()) {
|
return true;
|
||||||
ctx.player().setSprinting(true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we'll take it from here, no need for minecraft to see we're holding down control and sprint for us
|
// 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()) {
|
if (((MovementDescend) current).safeMode()) {
|
||||||
logDebug("Sprinting would be unsafe");
|
logDebug("Sprinting would be unsafe");
|
||||||
ctx.player().setSprinting(false);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IMovement next = path.movements().get(pathPosition + 1);
|
IMovement next = path.movements().get(pathPosition + 1);
|
||||||
if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) {
|
if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) {
|
||||||
// a descend then an ascend in the same direction
|
// a descend then an ascend in the same direction
|
||||||
if (!ctx.player().isSprinting()) {
|
|
||||||
ctx.player().setSprinting(true);
|
|
||||||
}
|
|
||||||
pathPosition++;
|
pathPosition++;
|
||||||
// okay to skip clearKeys and / or onChangeInPathPosition here since this isn't possible to repeat, since it's asymmetric
|
// 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");
|
logDebug("Skipping descend to straight ascend");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
if (canSprintInto(ctx, current, next)) {
|
if (canSprintInto(ctx, current, next)) {
|
||||||
if (ctx.playerFeet().equals(current.getDest())) {
|
if (ctx.playerFeet().equals(current.getDest())) {
|
||||||
pathPosition++;
|
pathPosition++;
|
||||||
onChangeInPathPosition();
|
onChangeInPathPosition();
|
||||||
}
|
}
|
||||||
if (!ctx.player().isSprinting()) {
|
return true;
|
||||||
ctx.player().setSprinting(true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
//logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection()));
|
//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();
|
BlockPos center = current.getSrc().up();
|
||||||
if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand
|
if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand
|
||||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
|
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
|
||||||
if (!ctx.player().isSprinting()) {
|
return true;
|
||||||
ctx.player().setSprinting(true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.player().setSprinting(false);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean canSprintInto(IPlayerContext ctx, IMovement current, IMovement next) {
|
private static boolean canSprintInto(IPlayerContext ctx, IMovement current, IMovement next) {
|
||||||
@@ -532,4 +520,8 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
public Set<BlockPos> toWalkInto() {
|
public Set<BlockPos> toWalkInto() {
|
||||||
return Collections.unmodifiableSet(toWalkInto);
|
return Collections.unmodifiableSet(toWalkInto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSprinting() {
|
||||||
|
return sprintNextTick;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,10 @@ import baritone.api.utils.IPlayerContext;
|
|||||||
|
|
||||||
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
||||||
|
|
||||||
public static final double DEFAULT_PRIORITY = 0;
|
|
||||||
|
|
||||||
protected final Baritone baritone;
|
protected final Baritone baritone;
|
||||||
protected final IPlayerContext ctx;
|
protected final IPlayerContext ctx;
|
||||||
private final double priority;
|
private final double priority;
|
||||||
|
|
||||||
public BaritoneProcessHelper(Baritone baritone) {
|
|
||||||
this(baritone, DEFAULT_PRIORITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaritoneProcessHelper(Baritone baritone, double priority) {
|
public BaritoneProcessHelper(Baritone baritone, double priority) {
|
||||||
this.baritone = baritone;
|
this.baritone = baritone;
|
||||||
this.ctx = baritone.getPlayerContext();
|
this.ctx = baritone.getPlayerContext();
|
||||||
@@ -40,11 +34,6 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper
|
|||||||
baritone.getPathingControlManager().registerProcess(this);
|
baritone.getPathingControlManager().registerProcess(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Baritone associatedWith() {
|
|
||||||
return baritone;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTemporary() {
|
public boolean isTemporary() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import net.minecraft.util.math.RayTraceResult;
|
|||||||
import net.minecraft.world.World;
|
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
|
* @author Brady
|
||||||
* @since 11/12/2018
|
* @since 11/12/2018
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import net.minecraft.util.math.RayTraceResult;
|
|||||||
import net.minecraft.world.GameType;
|
import net.minecraft.world.GameType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Implementation of {@link IPlayerController} that chains to the primary player controller's methods
|
||||||
|
*
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 12/14/2018
|
* @since 12/14/2018
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user