From 7dc43720c7ac07b5e7fe59442d7ae36157f6448f Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 31 Jul 2025 18:15:32 -0400 Subject: [PATCH 01/21] Add basic functionality for looking at entities. --- src/api/java/baritone/api/Settings.java | 7 ++++ .../pathing/movement/MovementHelper.java | 36 +++++++++++++++++-- .../movement/movements/MovementTraverse.java | 19 ++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 43ace5e31..7d8795d02 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1247,6 +1247,13 @@ public final class Settings { */ public final Setting followTargetMaxDistance = new Setting<>(0); + /** + * The distance until you start locking on and attacking entities. + *

+ * This doesn't change the direction you go, just the direction you face. + */ + public final Setting entityAttackRadius = new Setting<>(0D); + /** * Turn this on if your exploration filter is enormous, you don't want it to check if it's done, * and you are just fine with it just hanging on completion diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 821027070..df0b15f33 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -32,6 +32,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.piston.MovingPistonBlock; @@ -689,8 +691,8 @@ private static int getSelection(Rotation blockRotation, float ax, float az) { float closestZ = 100000; for (int i = 0; i < options.length; i++) { if (Mth.abs(targetAx - options[i][0]) + Mth.abs(targetAz - options[i][1]) < closestX + closestZ) { - closestX = Math.abs(targetAx - options[i][0]); - closestZ = Math.abs(targetAz - options[i][1]); + closestX = Mth.abs(targetAx - options[i][0]); + closestZ = Mth.abs(targetAz - options[i][1]); selection = i; } } @@ -702,7 +704,7 @@ private static float[][] getOptions(float ax, float az) { return new float[][]{ {canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az}, // W {-ax, -az}, // S - {-az, az}, // A + {-az, ax}, // A {az, -ax}, // D {(canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax}, // W+A {(canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax}, // W+D @@ -871,4 +873,32 @@ static List steppingOnBlocks(IPlayerContext ctx) { } return blocks; } + + static Rotation getRotationForEntityInRange(IPlayerContext ctx) { + double closestDistance = Double.MAX_VALUE; + Entity closestEntity = null; + for (Entity entity : ctx.entities()) { + if (entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable() && !entity.is(ctx.player())) { + double distance = ctx.player().getEyePosition().distanceToSqr(entity.getEyePosition()); // Not most accurate distance calculation, but it doesn't matter for now. + if (distance < closestDistance) { + closestDistance = distance; + closestEntity = entity; + } + } + } + if (closestEntity != null) { + // Finds the closest point to attack the entity. Doesn't account for any blocks in the way. + Vec3 attackPoint = new Vec3( + Mth.clamp(ctx.playerHead().x(), closestEntity.getBoundingBox().minX, closestEntity.getBoundingBox().maxX), + Mth.clamp(ctx.playerHead().y(), closestEntity.getBoundingBox().minY, closestEntity.getBoundingBox().maxY), + Mth.clamp(ctx.playerHead().z(), closestEntity.getBoundingBox().minZ, closestEntity.getBoundingBox().maxZ) + ); + Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), attackPoint, ctx.playerRotations()); + return rotation; +// if (RayTraceUtils.rayTraceTowards(ctx.player(), rotation, Baritone.settings().entityAttackRadius.value).getType().equals(HitResult.Type.ENTITY)) { +// return rotation; +// } + } + return null; + } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 1e2dc8457..53f18aac0 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -286,7 +286,15 @@ public MovementState updateState(MovementState state) { return state.setStatus(MovementStatus.UNREACHABLE); } } - MovementHelper.moveTowards(ctx, state, against); + Rotation faceEntityRotation = MovementHelper.getRotationForEntityInRange(ctx); + System.out.println(faceEntityRotation); + if (faceEntityRotation != null) { + state.setTarget(new MovementState.MovementTarget(faceEntityRotation, false)); + MovementHelper.moveTowardsWithoutRotation(ctx, state, against); + } + else { + MovementHelper.moveTowards(ctx, state, against); + } return state; } else { wasTheBridgeBlockAlwaysThere = false; @@ -294,7 +302,14 @@ public MovementState updateState(MovementState state) { if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().position().x), Math.abs(dest.getZ() + 0.5 - ctx.player().position().z)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon - MovementHelper.moveTowards(ctx, state, dest); + Rotation faceEntityRotation = MovementHelper.getRotationForEntityInRange(ctx); + if (faceEntityRotation != null) { + state.setTarget(new MovementState.MovementTarget(faceEntityRotation, false)); + MovementHelper.moveTowardsWithoutRotation(ctx, state, dest); + } + else { + MovementHelper.moveTowards(ctx, state, dest); + } return state.setInput(Input.MOVE_FORWARD, false) .setInput(Input.MOVE_BACK, true); } From 83b2e1f27cc7d268fcdcb652935ae5bfa4345323 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 31 Jul 2025 22:40:01 -0400 Subject: [PATCH 02/21] Try to add attacking. --- .../pathing/movement/MovementHelper.java | 54 ++++++++++--------- .../movement/movements/MovementTraverse.java | 19 +------ 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index df0b15f33..063d4f32a 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -29,6 +29,8 @@ import baritone.pathing.precompute.Ternary; import baritone.utils.BlockStateInterface; import baritone.utils.ToolSet; +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.client.KeyMapping; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; @@ -655,12 +657,20 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo } static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { - state.setTarget(new MovementTarget( - RotationUtils.calcRotationFromVec3d(ctx.playerHead(), - VecUtils.getBlockPosCenter(pos), - ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), - false - )).setInput(Input.MOVE_FORWARD, true); + Rotation faceEntityRotation = MovementHelper.getRotationForEntityInRange(ctx); + if (faceEntityRotation != null && Baritone.settings().entityAttackRadius.value != 0d) { + state.setTarget(new MovementState.MovementTarget(faceEntityRotation, false)); + MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); + state.setInput(Input.CLICK_LEFT, true); + } + else { + state.setTarget(new MovementTarget( + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), + VecUtils.getBlockPosCenter(pos), + ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), + false + )).setInput(Input.MOVE_FORWARD, true); + } } static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { @@ -876,29 +886,25 @@ static List steppingOnBlocks(IPlayerContext ctx) { static Rotation getRotationForEntityInRange(IPlayerContext ctx) { double closestDistance = Double.MAX_VALUE; - Entity closestEntity = null; + Vec3 closestPosition = null; for (Entity entity : ctx.entities()) { - if (entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable() && !entity.is(ctx.player())) { - double distance = ctx.player().getEyePosition().distanceToSqr(entity.getEyePosition()); // Not most accurate distance calculation, but it doesn't matter for now. + if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { + Vec3 attackPoint = new Vec3( + Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), + Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), + Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) + ); + double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); if (distance < closestDistance) { closestDistance = distance; - closestEntity = entity; + closestPosition = attackPoint; } } } - if (closestEntity != null) { - // Finds the closest point to attack the entity. Doesn't account for any blocks in the way. - Vec3 attackPoint = new Vec3( - Mth.clamp(ctx.playerHead().x(), closestEntity.getBoundingBox().minX, closestEntity.getBoundingBox().maxX), - Mth.clamp(ctx.playerHead().y(), closestEntity.getBoundingBox().minY, closestEntity.getBoundingBox().maxY), - Mth.clamp(ctx.playerHead().z(), closestEntity.getBoundingBox().minZ, closestEntity.getBoundingBox().maxZ) - ); - Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), attackPoint, ctx.playerRotations()); - return rotation; -// if (RayTraceUtils.rayTraceTowards(ctx.player(), rotation, Baritone.settings().entityAttackRadius.value).getType().equals(HitResult.Type.ENTITY)) { -// return rotation; -// } - } - return null; + if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { + return RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()); + } else { + return null; + } } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 53f18aac0..1e2dc8457 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -286,15 +286,7 @@ public MovementState updateState(MovementState state) { return state.setStatus(MovementStatus.UNREACHABLE); } } - Rotation faceEntityRotation = MovementHelper.getRotationForEntityInRange(ctx); - System.out.println(faceEntityRotation); - if (faceEntityRotation != null) { - state.setTarget(new MovementState.MovementTarget(faceEntityRotation, false)); - MovementHelper.moveTowardsWithoutRotation(ctx, state, against); - } - else { - MovementHelper.moveTowards(ctx, state, against); - } + MovementHelper.moveTowards(ctx, state, against); return state; } else { wasTheBridgeBlockAlwaysThere = false; @@ -302,14 +294,7 @@ public MovementState updateState(MovementState state) { if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().position().x), Math.abs(dest.getZ() + 0.5 - ctx.player().position().z)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon - Rotation faceEntityRotation = MovementHelper.getRotationForEntityInRange(ctx); - if (faceEntityRotation != null) { - state.setTarget(new MovementState.MovementTarget(faceEntityRotation, false)); - MovementHelper.moveTowardsWithoutRotation(ctx, state, dest); - } - else { - MovementHelper.moveTowards(ctx, state, dest); - } + MovementHelper.moveTowards(ctx, state, dest); return state.setInput(Input.MOVE_FORWARD, false) .setInput(Input.MOVE_BACK, true); } From 3631d99acdc1956b173454993860d6fb1e018e40 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Sat, 2 Aug 2025 23:29:57 -0400 Subject: [PATCH 03/21] Ummm... attacking kind of works??? --- .../pathing/movement/MovementHelper.java | 54 ++++++++-------- .../java/baritone/utils/BlockBreakHelper.java | 61 ++++++++++--------- .../baritone/utils/InputOverrideHandler.java | 18 +++--- 3 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 063d4f32a..60a417981 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -657,11 +657,33 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo } static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { - Rotation faceEntityRotation = MovementHelper.getRotationForEntityInRange(ctx); - if (faceEntityRotation != null && Baritone.settings().entityAttackRadius.value != 0d) { - state.setTarget(new MovementState.MovementTarget(faceEntityRotation, false)); + double closestDistance = Double.MAX_VALUE; + Vec3 closestPosition = null; + for (Entity entity : ctx.entities()) { + if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { + Vec3 attackPoint = new Vec3( + Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), + Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), + Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) + ); + double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); + if (distance < closestDistance) { + closestDistance = distance; + closestPosition = attackPoint; + } + } + } + if (Baritone.settings().entityAttackRadius.value != 0d && + closestPosition != null && + Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { + state.setTarget(new MovementState.MovementTarget( + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), + false + )); MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); - state.setInput(Input.CLICK_LEFT, true); + if (Math.sqrt(closestDistance) <= 3) { // 4.5 for blocks, 3 for entities while in survival. + state.setInput(Input.CLICK_LEFT, true); + } } else { state.setTarget(new MovementTarget( @@ -883,28 +905,4 @@ static List steppingOnBlocks(IPlayerContext ctx) { } return blocks; } - - static Rotation getRotationForEntityInRange(IPlayerContext ctx) { - double closestDistance = Double.MAX_VALUE; - Vec3 closestPosition = null; - for (Entity entity : ctx.entities()) { - if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { - Vec3 attackPoint = new Vec3( - Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), - Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), - Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) - ); - double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); - if (distance < closestDistance) { - closestDistance = distance; - closestPosition = attackPoint; - } - } - } - if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { - return RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()); - } else { - return null; - } - } } diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index 0c5cf6f00..99c34ab16 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -20,6 +20,7 @@ import baritone.api.BaritoneAPI; import baritone.api.utils.IPlayerContext; import baritone.utils.accessor.IPlayerControllerMP; +import net.minecraft.client.KeyMapping; import net.minecraft.world.InteractionHand; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -54,34 +55,38 @@ public void tick(boolean isLeftClick) { breakDelayTimer--; return; } - HitResult trace = ctx.objectMouseOver(); - boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK; - - if (isLeftClick && isBlockTrace) { - ctx.playerController().setHittingBlock(wasHitting); - if (ctx.playerController().hasBrokenBlock()) { - ctx.playerController().syncHeldItem(); - ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection()); - ctx.player().swing(InteractionHand.MAIN_HAND); - } else { - if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) { - ctx.player().swing(InteractionHand.MAIN_HAND); - } - if (ctx.playerController().hasBrokenBlock()) { // block broken this tick - // break delay timer only applies for multi-tick block breaks like vanilla - breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; - // must reset controller's destroy delay to prevent the client from delaying itself unnecessarily - ((IPlayerControllerMP) ctx.minecraft().gameMode).setDestroyDelay(0); - } - } - // if true, we're breaking a block. if false, we broke the block this tick - wasHitting = !ctx.playerController().hasBrokenBlock(); - // this value will be reset by the MC client handling mouse keys - // since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true - // we store and restore this value on the next tick to determine if we're breaking a block - ctx.playerController().setHittingBlock(false); - } else { - wasHitting = false; + if (isLeftClick && !ctx.minecraft().options.keyAttack.consumeClick()) { + KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); } + +// HitResult trace = ctx.objectMouseOver(); +// boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK; +// +// if (isLeftClick && isBlockTrace) { +// ctx.playerController().setHittingBlock(wasHitting); +// if (ctx.playerController().hasBrokenBlock()) { +// ctx.playerController().syncHeldItem(); +// ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection()); +// ctx.player().swing(InteractionHand.MAIN_HAND); +// } else { +// if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) { +// ctx.player().swing(InteractionHand.MAIN_HAND); +// } +// if (ctx.playerController().hasBrokenBlock()) { // block broken this tick +// // break delay timer only applies for multi-tick block breaks like vanilla +// breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; +// // must reset controller's destroy delay to prevent the client from delaying itself unnecessarily +// ((IPlayerControllerMP) ctx.minecraft().gameMode).setDestroyDelay(0); +// } +// } +// // if true, we're breaking a block. if false, we broke the block this tick +// wasHitting = !ctx.playerController().hasBrokenBlock(); +// // this value will be reset by the MC client handling mouse keys +// // since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true +// // we store and restore this value on the next tick to determine if we're breaking a block +// ctx.playerController().setHittingBlock(false); +// } else { +// wasHitting = false; +// } } } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 38a32f515..c4d75b5bb 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -59,8 +59,8 @@ public InputOverrideHandler(Baritone baritone) { * @return Whether or not it is being forced down */ @Override - public final boolean isInputForcedDown(Input input) { - return input == null ? false : this.inputForceStateMap.getOrDefault(input, false); + public boolean isInputForcedDown(Input input) { + return input != null && this.inputForceStateMap.getOrDefault(input, false); } /** @@ -78,22 +78,22 @@ public final void setInputForceState(Input input, boolean forced) { * Clears the override state for all keys */ @Override - public final void clearAllKeys() { + public void clearAllKeys() { this.inputForceStateMap.clear(); } @Override - public final void onTick(TickEvent event) { + public void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } - if (isInputForcedDown(Input.CLICK_LEFT)) { - setInputForceState(Input.CLICK_RIGHT, false); - } - blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); - blockPlaceHelper.tick(isInputForcedDown(Input.CLICK_RIGHT)); if (inControl()) { + if (isInputForcedDown(Input.CLICK_LEFT)) { + setInputForceState(Input.CLICK_RIGHT, false); + } + blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); + blockPlaceHelper.tick(isInputForcedDown(Input.CLICK_RIGHT)); if (ctx.player().input.getClass() != PlayerMovementInput.class) { ctx.player().input = new PlayerMovementInput(this); } From 811d419da68fbfbba10353f76b3e8bd616f10954 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Sun, 3 Aug 2025 12:12:12 -0400 Subject: [PATCH 04/21] Some renaming. --- .../baritone/pathing/movement/MovementHelper.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 60a417981..0cbf7a5a7 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -29,8 +29,6 @@ import baritone.pathing.precompute.Ternary; import baritone.utils.BlockStateInterface; import baritone.utils.ToolSet; -import com.mojang.blaze3d.platform.InputConstants; -import net.minecraft.client.KeyMapping; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; @@ -681,7 +679,8 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { false )); MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); - if (Math.sqrt(closestDistance) <= 3) { // 4.5 for blocks, 3 for entities while in survival. + if (ctx.minecraft().hitResult.getType().equals(HitResult.Type.ENTITY) && + !ctx.player().getCooldowns().isOnCooldown(ctx.player().getMainHandItem().getItem())) { state.setInput(Input.CLICK_LEFT, true); } } @@ -701,7 +700,7 @@ static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()); - int selection = getSelection(blockRotation, ax, az); + int selection = getDirectionSelection(blockRotation, ax, az); switch (selection) { case 0 -> state.setInput(Input.MOVE_FORWARD, true); case 1 -> state.setInput(Input.MOVE_BACK, true); @@ -714,10 +713,10 @@ static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, } } - private static int getSelection(Rotation blockRotation, float ax, float az) { + private static int getDirectionSelection(Rotation blockRotation, float ax, float az) { float targetAx = Mth.sin(blockRotation.getYaw() * DEG_TO_RAD_F); float targetAz = Mth.cos(blockRotation.getYaw() * DEG_TO_RAD_F); - float[][] options = getOptions(ax, az); + float[][] options = getDirectionOptions(ax, az); int selection = -1; float closestX = 100000; float closestZ = 100000; @@ -731,7 +730,7 @@ private static int getSelection(Rotation blockRotation, float ax, float az) { return selection; } - private static float[][] getOptions(float ax, float az) { + private static float[][] getDirectionOptions(float ax, float az) { boolean canSprint = Baritone.settings().allowSprint.value; return new float[][]{ {canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az}, // W From f55aeb4e4f2501529bb7d99aba13b5ca43aef193 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Tue, 5 Aug 2025 13:18:10 -0400 Subject: [PATCH 05/21] Update that allows for timed clicks. --- .../baritone/behavior/PathingBehavior.java | 5 +- .../baritone/pathing/path/PathExecutor.java | 2 +- .../java/baritone/utils/BlockBreakHelper.java | 92 ------------------- .../baritone/utils/InputOverrideHandler.java | 12 +-- .../java/baritone/utils/LeftClickHelper.java | 81 ++++++++++++++++ 5 files changed, 90 insertions(+), 102 deletions(-) delete mode 100644 src/main/java/baritone/utils/BlockBreakHelper.java create mode 100644 src/main/java/baritone/utils/LeftClickHelper.java diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index d8df46681..6c936975f 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -33,7 +33,6 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.PathExecutor; -import baritone.process.ElytraProcess; import baritone.utils.PathRenderer; import baritone.utils.PathingCommandContext; import baritone.utils.pathing.Favoring; @@ -120,7 +119,7 @@ private void tickPath() { pauseRequestedLastTick = false; if (unpausedLastTick) { baritone.getInputOverrideHandler().clearAllKeys(); - baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock(); + baritone.getInputOverrideHandler().getLeftClickHelper().stopBreakingBlock(); } unpausedLastTick = false; pausedThisTick = true; @@ -363,7 +362,7 @@ public void secretInternalSegmentCancel() { current = null; next = null; baritone.getInputOverrideHandler().clearAllKeys(); - baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock(); + baritone.getInputOverrideHandler().getLeftClickHelper().stopBreakingBlock(); } } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 96d105208..4d986088e 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -589,7 +589,7 @@ private void clearKeys() { private void cancel() { clearKeys(); - behavior.baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock(); + behavior.baritone.getInputOverrideHandler().getLeftClickHelper().stopBreakingBlock(); pathPosition = path.length() + 3; failed = true; } diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java deleted file mode 100644 index 99c34ab16..000000000 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ /dev/null @@ -1,92 +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.utils; - -import baritone.api.BaritoneAPI; -import baritone.api.utils.IPlayerContext; -import baritone.utils.accessor.IPlayerControllerMP; -import net.minecraft.client.KeyMapping; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.HitResult; - -/** - * @author Brady - * @since 8/25/2018 - */ -public final class BlockBreakHelper { - // base ticks between block breaks caused by tick logic - private static final int BASE_BREAK_DELAY = 1; - - private final IPlayerContext ctx; - private boolean wasHitting; - private int breakDelayTimer = 0; - - BlockBreakHelper(IPlayerContext ctx) { - this.ctx = ctx; - } - - public void stopBreakingBlock() { - // The player controller will never be null, but the player can be - if (ctx.player() != null && wasHitting) { - ctx.playerController().setHittingBlock(false); - ctx.playerController().resetBlockRemoving(); - wasHitting = false; - } - } - - public void tick(boolean isLeftClick) { - if (breakDelayTimer > 0) { - breakDelayTimer--; - return; - } - if (isLeftClick && !ctx.minecraft().options.keyAttack.consumeClick()) { - KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); - } - -// HitResult trace = ctx.objectMouseOver(); -// boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK; -// -// if (isLeftClick && isBlockTrace) { -// ctx.playerController().setHittingBlock(wasHitting); -// if (ctx.playerController().hasBrokenBlock()) { -// ctx.playerController().syncHeldItem(); -// ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection()); -// ctx.player().swing(InteractionHand.MAIN_HAND); -// } else { -// if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) { -// ctx.player().swing(InteractionHand.MAIN_HAND); -// } -// if (ctx.playerController().hasBrokenBlock()) { // block broken this tick -// // break delay timer only applies for multi-tick block breaks like vanilla -// breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; -// // must reset controller's destroy delay to prevent the client from delaying itself unnecessarily -// ((IPlayerControllerMP) ctx.minecraft().gameMode).setDestroyDelay(0); -// } -// } -// // if true, we're breaking a block. if false, we broke the block this tick -// wasHitting = !ctx.playerController().hasBrokenBlock(); -// // this value will be reset by the MC client handling mouse keys -// // since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true -// // we store and restore this value on the next tick to determine if we're breaking a block -// ctx.playerController().setHittingBlock(false); -// } else { -// wasHitting = false; -// } - } -} diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index c4d75b5bb..4a5036d79 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -43,12 +43,12 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri */ private final Map inputForceStateMap = new HashMap<>(); - private final BlockBreakHelper blockBreakHelper; + private final LeftClickHelper leftClickHelper; private final BlockPlaceHelper blockPlaceHelper; public InputOverrideHandler(Baritone baritone) { super(baritone); - this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext()); + this.leftClickHelper = new LeftClickHelper(baritone.getPlayerContext()); this.blockPlaceHelper = new BlockPlaceHelper(baritone.getPlayerContext()); } @@ -70,7 +70,7 @@ public boolean isInputForcedDown(Input input) { * @param forced Whether or not the state is being forced */ @Override - public final void setInputForceState(Input input, boolean forced) { + public void setInputForceState(Input input, boolean forced) { this.inputForceStateMap.put(input, forced); } @@ -92,7 +92,7 @@ public void onTick(TickEvent event) { if (isInputForcedDown(Input.CLICK_LEFT)) { setInputForceState(Input.CLICK_RIGHT, false); } - blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); + leftClickHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); blockPlaceHelper.tick(isInputForcedDown(Input.CLICK_RIGHT)); if (ctx.player().input.getClass() != PlayerMovementInput.class) { ctx.player().input = new PlayerMovementInput(this); @@ -116,7 +116,7 @@ private boolean inControl() { return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); } - public BlockBreakHelper getBlockBreakHelper() { - return blockBreakHelper; + public LeftClickHelper getLeftClickHelper() { + return leftClickHelper; } } diff --git a/src/main/java/baritone/utils/LeftClickHelper.java b/src/main/java/baritone/utils/LeftClickHelper.java new file mode 100644 index 000000000..f339c9277 --- /dev/null +++ b/src/main/java/baritone/utils/LeftClickHelper.java @@ -0,0 +1,81 @@ +/* + * 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.BaritoneAPI; +import baritone.api.utils.IPlayerContext; +import net.minecraft.client.KeyMapping; +import net.minecraft.world.phys.HitResult; + +/** + * @author Brady + * @since 8/25/2018 + */ +public final class LeftClickHelper { + // base ticks between block breaks caused by tick logic + private static final int BASE_BREAK_DELAY = 1; + + private final IPlayerContext ctx; + private boolean isBreaking = false; + private int breakDelayTimer = 0; + + LeftClickHelper(IPlayerContext ctx) { + this.ctx = ctx; + } + + public void stopBreakingBlock() { + isBreaking = false; + ctx.minecraft().options.keyAttack.setDown(false); + } + + public void tick(boolean isLeftClick) { + if (breakDelayTimer > 0) { + breakDelayTimer--; + return; + } + if (isLeftClick) { + HitResult trace = ctx.objectMouseOver(); + switch (trace.getType()) { + case ENTITY: + isBreaking = false; + if (ctx.player().getAttackStrengthScale(0f) == 1f) { + KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); + ctx.minecraft().options.keyAttack.setDown(true); + } + break; + case BLOCK: + if (!isBreaking) { + isBreaking = true; + KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); + } + ctx.minecraft().options.keyAttack.setDown(true); + if (ctx.playerController().hasBrokenBlock()) { + breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; + } + break; + default: + isBreaking = false; + ctx.minecraft().options.keyAttack.setDown(false); + break; + } + } else { + isBreaking = false; + ctx.minecraft().options.keyAttack.setDown(false); + } + } +} From f9c2d9da33dde689b95ec7c6834409424142f480 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Tue, 5 Aug 2025 14:27:19 -0400 Subject: [PATCH 06/21] Add settings for spamming + clean. --- src/api/java/baritone/api/Settings.java | 10 +++++ .../baritone/api/utils/RayTraceUtils.java | 2 +- .../java/baritone/utils/LeftClickHelper.java | 43 ++++++++++--------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 7d8795d02..98110acf3 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -411,6 +411,16 @@ public final class Settings { */ public final Setting blockBreakSpeed = new Setting<>(6); + /** + * Determines if Baritone waits for the attack cooldown to recharge completely before attacking + */ + public final Setting timedAttacks = new Setting<>(true); + + /** + * Determines how many ticks between left clicks are allowed. + */ + public final Setting leftClickSpeed = new Setting<>(6); + /** * How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable */ diff --git a/src/api/java/baritone/api/utils/RayTraceUtils.java b/src/api/java/baritone/api/utils/RayTraceUtils.java index ed544302d..1c982957a 100644 --- a/src/api/java/baritone/api/utils/RayTraceUtils.java +++ b/src/api/java/baritone/api/utils/RayTraceUtils.java @@ -50,7 +50,7 @@ public static HitResult rayTraceTowards(Entity entity, Rotation rotation, double if (wouldSneak) { start = inferSneakingEyePosition(entity); } else { - start = entity.getEyePosition(1.0F); // do whatever is correct + start = entity.getEyePosition(); } Vec3 direction = RotationUtils.calcLookDirectionFromRotation(rotation); diff --git a/src/main/java/baritone/utils/LeftClickHelper.java b/src/main/java/baritone/utils/LeftClickHelper.java index f339c9277..f82367ca3 100644 --- a/src/main/java/baritone/utils/LeftClickHelper.java +++ b/src/main/java/baritone/utils/LeftClickHelper.java @@ -17,7 +17,7 @@ package baritone.utils; -import baritone.api.BaritoneAPI; +import baritone.Baritone; import baritone.api.utils.IPlayerContext; import net.minecraft.client.KeyMapping; import net.minecraft.world.phys.HitResult; @@ -33,6 +33,7 @@ public final class LeftClickHelper { private final IPlayerContext ctx; private boolean isBreaking = false; private int breakDelayTimer = 0; + private int leftClickTimer = 0; LeftClickHelper(IPlayerContext ctx) { this.ctx = ctx; @@ -44,38 +45,38 @@ public void stopBreakingBlock() { } public void tick(boolean isLeftClick) { - if (breakDelayTimer > 0) { - breakDelayTimer--; - return; - } - if (isLeftClick) { - HitResult trace = ctx.objectMouseOver(); + HitResult trace = ctx.minecraft().hitResult; + if (isLeftClick && trace != null) { switch (trace.getType()) { case ENTITY: - isBreaking = false; - if (ctx.player().getAttackStrengthScale(0f) == 1f) { + stopBreakingBlock(); + if (leftClickTimer > 0) { + leftClickTimer--; + } else if (!Baritone.settings().timedAttacks.value || ctx.player().getAttackStrengthScale(0f) == 1f) { + leftClickTimer = Baritone.settings().leftClickSpeed.value; KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); - ctx.minecraft().options.keyAttack.setDown(true); } break; case BLOCK: - if (!isBreaking) { - isBreaking = true; - KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); - } - ctx.minecraft().options.keyAttack.setDown(true); - if (ctx.playerController().hasBrokenBlock()) { - breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; + if (breakDelayTimer > 0) { + breakDelayTimer--; + } else { + if (!isBreaking) { + isBreaking = true; + KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); + } + ctx.minecraft().options.keyAttack.setDown(true); + if (ctx.playerController().hasBrokenBlock()) { + breakDelayTimer = Baritone.settings().blockBreakSpeed.value - BASE_BREAK_DELAY; + } } break; default: - isBreaking = false; - ctx.minecraft().options.keyAttack.setDown(false); + stopBreakingBlock(); break; } } else { - isBreaking = false; - ctx.minecraft().options.keyAttack.setDown(false); + stopBreakingBlock(); } } } From fddf47d5a4499d980cf37a77cda24bdcd3ec4f6a Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Tue, 5 Aug 2025 15:28:25 -0400 Subject: [PATCH 07/21] Clean up. --- .../pathing/movement/MovementHelper.java | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 0cbf7a5a7..87ed11169 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -655,43 +655,49 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo } static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { - double closestDistance = Double.MAX_VALUE; - Vec3 closestPosition = null; - for (Entity entity : ctx.entities()) { - if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { - Vec3 attackPoint = new Vec3( - Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), - Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), - Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) - ); - double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); - if (distance < closestDistance) { - closestDistance = distance; - closestPosition = attackPoint; + if (Baritone.settings().entityAttackRadius.value != 0d) { + double closestDistance = Double.MAX_VALUE; + Vec3 closestPosition = null; + for (Entity entity : ctx.entities()) { + if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { + Vec3 attackPoint = new Vec3( + Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), + Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), + Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) + ); + double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); + if (distance < closestDistance) { + closestDistance = distance; + closestPosition = attackPoint; + } } } - } - if (Baritone.settings().entityAttackRadius.value != 0d && - closestPosition != null && - Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { - state.setTarget(new MovementState.MovementTarget( - RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), - false - )); - MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); - if (ctx.minecraft().hitResult.getType().equals(HitResult.Type.ENTITY) && - !ctx.player().getCooldowns().isOnCooldown(ctx.player().getMainHandItem().getItem())) { - state.setInput(Input.CLICK_LEFT, true); + if (closestPosition != null && + Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { + state.setTarget(new MovementState.MovementTarget( + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), + false + )); + MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); + HitResult hitResult = ctx.minecraft().hitResult; + if (hitResult != null && hitResult.getType().equals(HitResult.Type.ENTITY)) { + state.setInput(Input.CLICK_LEFT, true); + } + } else { + moveTowardsWithRotation(ctx, state, pos); } + } else { + moveTowardsWithRotation(ctx, state, pos); } - else { - state.setTarget(new MovementTarget( - RotationUtils.calcRotationFromVec3d(ctx.playerHead(), - VecUtils.getBlockPosCenter(pos), - ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), - false - )).setInput(Input.MOVE_FORWARD, true); - } + } + + static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, BlockPos pos) { + state.setTarget(new MovementTarget( + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), + VecUtils.getBlockPosCenter(pos), + ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), + false + )).setInput(Input.MOVE_FORWARD, true); } static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { From 11572145e93537b727b77680f116ac9ea960bb68 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Tue, 5 Aug 2025 15:50:25 -0400 Subject: [PATCH 08/21] Count down on every tick. --- src/main/java/baritone/utils/LeftClickHelper.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/utils/LeftClickHelper.java b/src/main/java/baritone/utils/LeftClickHelper.java index f82367ca3..007a7d256 100644 --- a/src/main/java/baritone/utils/LeftClickHelper.java +++ b/src/main/java/baritone/utils/LeftClickHelper.java @@ -45,22 +45,24 @@ public void stopBreakingBlock() { } public void tick(boolean isLeftClick) { + if (leftClickTimer > 0) { + leftClickTimer--; + } + if (breakDelayTimer > 0) { + breakDelayTimer--; + } HitResult trace = ctx.minecraft().hitResult; if (isLeftClick && trace != null) { switch (trace.getType()) { case ENTITY: stopBreakingBlock(); - if (leftClickTimer > 0) { - leftClickTimer--; - } else if (!Baritone.settings().timedAttacks.value || ctx.player().getAttackStrengthScale(0f) == 1f) { + if (leftClickTimer <= 0 && (!Baritone.settings().timedAttacks.value || ctx.player().getAttackStrengthScale(0f) == 1f)) { leftClickTimer = Baritone.settings().leftClickSpeed.value; KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); } break; case BLOCK: - if (breakDelayTimer > 0) { - breakDelayTimer--; - } else { + if (breakDelayTimer <= 0) { if (!isBreaking) { isBreaking = true; KeyMapping.click(ctx.minecraft().options.keyAttack.getDefaultKey()); From 7639a25b8e10409282c0db42171cba22819a7a8d Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Tue, 5 Aug 2025 16:09:20 -0400 Subject: [PATCH 09/21] Add settings for external killaura and autoaim. --- src/api/java/baritone/api/Settings.java | 10 ++++++++++ .../pathing/movement/MovementHelper.java | 18 +++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 98110acf3..d181436ec 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -421,6 +421,16 @@ public final class Settings { */ public final Setting leftClickSpeed = new Setting<>(6); + /** + * Assume external aiming functionality + */ + public final Setting assumeExternalAutoAim = new Setting<>(false); + + /** + * Assume external attacking functionality + */ + public final Setting assumeExternalKillAura = new Setting<>(false); + /** * How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable */ diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 87ed11169..92abc6d0b 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -674,14 +674,18 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { } if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { - state.setTarget(new MovementState.MovementTarget( - RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), - false - )); + if (!Baritone.settings().assumeExternalAutoAim.value) { + state.setTarget(new MovementState.MovementTarget( + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), + false + )); + } MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); - HitResult hitResult = ctx.minecraft().hitResult; - if (hitResult != null && hitResult.getType().equals(HitResult.Type.ENTITY)) { - state.setInput(Input.CLICK_LEFT, true); + if (!Baritone.settings().assumeExternalKillAura.value) { + HitResult hitResult = ctx.minecraft().hitResult; + if (hitResult != null && hitResult.getType().equals(HitResult.Type.ENTITY)) { + state.setInput(Input.CLICK_LEFT, true); + } } } else { moveTowardsWithRotation(ctx, state, pos); From dff2edf6b3f89607abe81282e54cfa6b8ef0db46 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Tue, 5 Aug 2025 16:41:34 -0400 Subject: [PATCH 10/21] Fix when using freelook --- src/main/java/baritone/pathing/movement/MovementHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 92abc6d0b..6c8e4f371 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -677,7 +677,7 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { if (!Baritone.settings().assumeExternalAutoAim.value) { state.setTarget(new MovementState.MovementTarget( RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), - false + true )); } MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); From 50d382d26738e8deb0f859e67de9355882597330 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Wed, 6 Aug 2025 13:53:03 -0400 Subject: [PATCH 11/21] Add ability to circle around an entity, making sure that Baritone always has somewhere to go and can continue attacking. --- src/api/java/baritone/api/Settings.java | 11 +++++++++++ src/main/java/baritone/process/FollowProcess.java | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index d181436ec..54f73784d 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1252,6 +1252,17 @@ public final class Settings { */ public final Setting followOffsetDistance = new Setting<>(0D); + /** + * The actual GoalNear is set to circle around your selected entity instead of remaining in one place. + * This disregards {@link #followOffsetDirection} when enabled. + */ + public final Setting followCircle = new Setting<>(false); + + /** + * The amount the circle offset is shifted each tick + */ + public final Setting followCircleIncrement = new Setting<>(5F); + /** * The actual GoalNear is set in this direction from the entity you're following. This value is in degrees. */ diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 0be7a4e80..91ecd8a5f 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -47,6 +47,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo private Predicate filter; private List cache; private boolean into; // walk straight into the target, regardless of settings + private float currentCircleDegrees = 0; public FollowProcess(Baritone baritone) { super(baritone); @@ -56,6 +57,8 @@ public FollowProcess(Baritone baritone) { public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { scanWorld(); Goal goal = new GoalComposite(cache.stream().map(this::towards).toArray(Goal[]::new)); + currentCircleDegrees += Baritone.settings().followCircleIncrement.value; + currentCircleDegrees %= 360; return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH); } @@ -64,7 +67,11 @@ private Goal towards(Entity following) { if (Baritone.settings().followOffsetDistance.value == 0 || into) { pos = following.blockPosition(); } else { - GoalXZ g = GoalXZ.fromDirection(following.position(), Baritone.settings().followOffsetDirection.value, Baritone.settings().followOffsetDistance.value); + GoalXZ g = GoalXZ.fromDirection( + following.position(), + Baritone.settings().followCircle.value ? currentCircleDegrees : Baritone.settings().followOffsetDirection.value, + Baritone.settings().followOffsetDistance.value + ); pos = new BetterBlockPos(g.getX(), following.position().y, g.getZ()); } if (into) { From 84417680bd649d7ce98e3a5c16d747bf40097ef2 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Wed, 6 Aug 2025 15:37:23 -0400 Subject: [PATCH 12/21] Change to Vec2. --- .../pathing/movement/MovementHelper.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6c8e4f371..54cc31aca 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -51,6 +51,7 @@ import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import java.util.ArrayList; @@ -720,37 +721,38 @@ static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, case 5 -> state.setInput(Input.MOVE_FORWARD, true).setInput(Input.MOVE_RIGHT, true); case 6 -> state.setInput(Input.MOVE_BACK, true).setInput(Input.MOVE_LEFT, true); case 7 -> state.setInput(Input.MOVE_BACK, true).setInput(Input.MOVE_RIGHT, true); + default -> {} } } private static int getDirectionSelection(Rotation blockRotation, float ax, float az) { float targetAx = Mth.sin(blockRotation.getYaw() * DEG_TO_RAD_F); float targetAz = Mth.cos(blockRotation.getYaw() * DEG_TO_RAD_F); - float[][] options = getDirectionOptions(ax, az); + Vec2[] options = getDirectionOptions(ax, az); int selection = -1; float closestX = 100000; float closestZ = 100000; for (int i = 0; i < options.length; i++) { - if (Mth.abs(targetAx - options[i][0]) + Mth.abs(targetAz - options[i][1]) < closestX + closestZ) { - closestX = Mth.abs(targetAx - options[i][0]); - closestZ = Mth.abs(targetAz - options[i][1]); + if (Mth.abs(targetAx - options[i].x) + Mth.abs(targetAz - options[i].y) < closestX + closestZ) { + closestX = Mth.abs(targetAx - options[i].x); + closestZ = Mth.abs(targetAz - options[i].y); selection = i; } } return selection; } - private static float[][] getDirectionOptions(float ax, float az) { + private static Vec2[] getDirectionOptions(float ax, float az) { boolean canSprint = Baritone.settings().allowSprint.value; - return new float[][]{ - {canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az}, // W - {-ax, -az}, // S - {-az, ax}, // A - {az, -ax}, // D - {(canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax}, // W+A - {(canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax}, // W+D - {-ax - az, -az + ax}, // S+A - {-ax + az, -az - ax} // S+D + return new Vec2[]{ + new Vec2(canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az), // W + new Vec2(-ax, -az), // S + new Vec2(-az, ax), // A + new Vec2(az, -ax), // D + new Vec2((canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax), // W+A + new Vec2((canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax), // W+D + new Vec2(-ax - az, -az + ax), // S+A + new Vec2(-ax + az, -az - ax) // S+D }; } From 3c79565f716add89686c0522703b57bfc072092e Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Wed, 6 Aug 2025 22:05:42 -0400 Subject: [PATCH 13/21] Replace circle offset with cleaner and better method. --- src/api/java/baritone/api/Settings.java | 4 ++-- src/main/java/baritone/process/FollowProcess.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 54f73784d..82fc80a94 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1259,9 +1259,9 @@ public final class Settings { public final Setting followCircle = new Setting<>(false); /** - * The amount the circle offset is shifted each tick + * The yaw amount the target is shifted by */ - public final Setting followCircleIncrement = new Setting<>(5F); + public final Setting followCircleIncrement = new Setting<>(90F); /** * The actual GoalNear is set in this direction from the entity you're following. This value is in degrees. diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 91ecd8a5f..353902f88 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -27,6 +27,7 @@ import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.RotationUtils; import baritone.utils.BaritoneProcessHelper; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; @@ -47,7 +48,6 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo private Predicate filter; private List cache; private boolean into; // walk straight into the target, regardless of settings - private float currentCircleDegrees = 0; public FollowProcess(Baritone baritone) { super(baritone); @@ -57,8 +57,6 @@ public FollowProcess(Baritone baritone) { public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { scanWorld(); Goal goal = new GoalComposite(cache.stream().map(this::towards).toArray(Goal[]::new)); - currentCircleDegrees += Baritone.settings().followCircleIncrement.value; - currentCircleDegrees %= 360; return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH); } @@ -69,7 +67,11 @@ private Goal towards(Entity following) { } else { GoalXZ g = GoalXZ.fromDirection( following.position(), - Baritone.settings().followCircle.value ? currentCircleDegrees : Baritone.settings().followOffsetDirection.value, + Baritone.settings().followCircle.value ? + RotationUtils.calcRotationFromVec3d(following.getEyePosition(), + ctx.playerHead(), + ctx.playerRotations()).getYaw() + Baritone.settings().followCircleIncrement.value : + Baritone.settings().followOffsetDirection.value, Baritone.settings().followOffsetDistance.value ); pos = new BetterBlockPos(g.getX(), following.position().y, g.getZ()); From 09dde3115a95dd0d39be5fba6b85cf3172a5c784 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 7 Aug 2025 08:40:27 -0400 Subject: [PATCH 14/21] Add random direction switch to `FollowProcess`. --- src/api/java/baritone/api/Settings.java | 5 +++++ src/main/java/baritone/process/FollowProcess.java | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 82fc80a94..c37739129 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1263,6 +1263,11 @@ public final class Settings { */ public final Setting followCircleIncrement = new Setting<>(90F); + /** + * The chance every tick that the follow circle direction is switched from 0 to 100 + */ + public final Setting followCircleSwitchDirectionChance = new Setting<>(2.5D); + /** * The actual GoalNear is set in this direction from the entity you're following. This value is in degrees. */ diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 353902f88..ff8257584 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -35,6 +35,7 @@ import net.minecraft.world.item.ItemStack; import java.util.List; +import java.util.Random; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -48,6 +49,8 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo private Predicate filter; private List cache; private boolean into; // walk straight into the target, regardless of settings + private boolean switchDirection = false; + private static final Random random = new Random(); // TODO global random instance public FollowProcess(Baritone baritone) { super(baritone); @@ -57,6 +60,9 @@ public FollowProcess(Baritone baritone) { public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { scanWorld(); Goal goal = new GoalComposite(cache.stream().map(this::towards).toArray(Goal[]::new)); + if (Baritone.settings().followCircleSwitchDirectionChance.value >= random.nextDouble(0, 100)) { + switchDirection = !switchDirection; + } return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH); } @@ -67,10 +73,13 @@ private Goal towards(Entity following) { } else { GoalXZ g = GoalXZ.fromDirection( following.position(), + // I love me some ternary operators Baritone.settings().followCircle.value ? RotationUtils.calcRotationFromVec3d(following.getEyePosition(), ctx.playerHead(), - ctx.playerRotations()).getYaw() + Baritone.settings().followCircleIncrement.value : + ctx.playerRotations()).getYaw() + + (switchDirection ? -Baritone.settings().followCircleIncrement.value : + Baritone.settings().followCircleIncrement.value) : Baritone.settings().followOffsetDirection.value, Baritone.settings().followOffsetDistance.value ); From d9f395c23f2a28547715a1fe611c0c670c663ada Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 7 Aug 2025 10:52:48 -0400 Subject: [PATCH 15/21] Distance calculation nerf to help with aiming :(. --- .../java/baritone/pathing/movement/MovementHelper.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 54cc31aca..32b96be34 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -662,9 +662,9 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { for (Entity entity : ctx.entities()) { if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { Vec3 attackPoint = new Vec3( - Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), + entity.getBoundingBox().getCenter().x(),//Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), - Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) + entity.getBoundingBox().getCenter().z()//Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) ); double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); if (distance < closestDistance) { @@ -673,8 +673,7 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { } } } - if (closestPosition != null && - Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { + if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { if (!Baritone.settings().assumeExternalAutoAim.value) { state.setTarget(new MovementState.MovementTarget( RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), From 717426c82ad713db19fb7ce11b216c5ba9de1958 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 7 Aug 2025 16:06:16 -0400 Subject: [PATCH 16/21] Small change. --- src/main/java/baritone/process/FollowProcess.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index ff8257584..b7486ca30 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -75,7 +75,8 @@ private Goal towards(Entity following) { following.position(), // I love me some ternary operators Baritone.settings().followCircle.value ? - RotationUtils.calcRotationFromVec3d(following.getEyePosition(), + RotationUtils.calcRotationFromVec3d( + following.getEyePosition(), ctx.playerHead(), ctx.playerRotations()).getYaw() + (switchDirection ? -Baritone.settings().followCircleIncrement.value : From bd57b98c13256bde90f3f1879f4cbed7750c5a4f Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Sat, 9 Aug 2025 14:23:07 -0400 Subject: [PATCH 17/21] Baritone is able to attack even if it doesn't have a currently selected path. Useful for `follow` command. --- src/api/java/baritone/api/IBaritone.java | 6 + .../baritone/api/process/IAttackProcess.java | 24 ++++ src/main/java/baritone/Baritone.java | 8 ++ .../pathing/movement/MovementHelper.java | 40 +------ .../movement/movements/MovementAscend.java | 2 +- .../movement/movements/MovementDescend.java | 4 +- .../movement/movements/MovementDiagonal.java | 2 +- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementParkour.java | 6 +- .../movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 4 +- .../java/baritone/process/AttackProcess.java | 112 ++++++++++++++++++ .../baritone/utils/InputOverrideHandler.java | 14 ++- 13 files changed, 173 insertions(+), 53 deletions(-) create mode 100644 src/api/java/baritone/api/process/IAttackProcess.java create mode 100644 src/main/java/baritone/process/AttackProcess.java diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 3c9681532..ea09e0123 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -94,6 +94,12 @@ public interface IBaritone { */ IElytraProcess getElytraProcess(); + /** + * @return The {@link IAttackProcess} instance + * @see IAttackProcess + */ + IAttackProcess getAttackProcess(); + /** * @return The {@link IWorldProvider} instance * @see IWorldProvider diff --git a/src/api/java/baritone/api/process/IAttackProcess.java b/src/api/java/baritone/api/process/IAttackProcess.java new file mode 100644 index 000000000..576773c79 --- /dev/null +++ b/src/api/java/baritone/api/process/IAttackProcess.java @@ -0,0 +1,24 @@ +/* + * 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.process; + +public interface IAttackProcess extends IBaritoneProcess { + boolean isRotating(); + + boolean isAttacking(); +} diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index ad6871413..c23646dcd 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -22,6 +22,7 @@ import baritone.api.Settings; import baritone.api.behavior.IBehavior; import baritone.api.event.listener.IEventBus; +import baritone.api.process.IAttackProcess; import baritone.api.process.IBaritoneProcess; import baritone.api.process.IElytraProcess; import baritone.api.utils.IPlayerContext; @@ -80,6 +81,7 @@ public class Baritone implements IBaritone { private final FarmProcess farmProcess; private final InventoryPauserProcess inventoryPauserProcess; private final IElytraProcess elytraProcess; + private final AttackProcess attackProcess; private final PathingControlManager pathingControlManager; private final SelectionManager selectionManager; @@ -123,6 +125,7 @@ public class Baritone implements IBaritone { this.farmProcess = this.registerProcess(FarmProcess::new); this.inventoryPauserProcess = this.registerProcess(InventoryPauserProcess::new); this.elytraProcess = this.registerProcess(ElytraProcess::create); + this.attackProcess = this.registerProcess(AttackProcess::new); this.registerProcess(BackfillProcess::new); } @@ -240,6 +243,11 @@ public IElytraProcess getElytraProcess() { return this.elytraProcess; } + @Override + public IAttackProcess getAttackProcess() { + return this.attackProcess; + } + @Override public void openClick() { new Thread(() -> { diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 32b96be34..a9fa62328 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -32,8 +32,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.piston.MovingPistonBlock; @@ -655,41 +653,9 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo } } - static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { - if (Baritone.settings().entityAttackRadius.value != 0d) { - double closestDistance = Double.MAX_VALUE; - Vec3 closestPosition = null; - for (Entity entity : ctx.entities()) { - if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { - Vec3 attackPoint = new Vec3( - entity.getBoundingBox().getCenter().x(),//Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), - Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), - entity.getBoundingBox().getCenter().z()//Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) - ); - double distance = ctx.player().getEyePosition().distanceToSqr(attackPoint); - if (distance < closestDistance) { - closestDistance = distance; - closestPosition = attackPoint; - } - } - } - if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { - if (!Baritone.settings().assumeExternalAutoAim.value) { - state.setTarget(new MovementState.MovementTarget( - RotationUtils.calcRotationFromVec3d(ctx.playerHead(), closestPosition, ctx.playerRotations()), - true - )); - } - MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); - if (!Baritone.settings().assumeExternalKillAura.value) { - HitResult hitResult = ctx.minecraft().hitResult; - if (hitResult != null && hitResult.getType().equals(HitResult.Type.ENTITY)) { - state.setInput(Input.CLICK_LEFT, true); - } - } - } else { - moveTowardsWithRotation(ctx, state, pos); - } + static void moveTowards(IBaritone baritone, IPlayerContext ctx, MovementState state, BlockPos pos) { + if (baritone.getAttackProcess().isRotating()) { + MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); } else { moveTowardsWithRotation(ctx, state, pos); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 2ecd9d723..90f000036 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -189,7 +189,7 @@ public MovementState updateState(MovementState state) { return state; } - MovementHelper.moveTowards(ctx, state, dest); + MovementHelper.moveTowards(baritone, ctx, state, dest); state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && jumpingOnto.is(Blocks.MAGMA_BLOCK)); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 3e860e301..3a03f70ab 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -261,9 +261,9 @@ public MovementState updateState(MovementState state) { if (!playerFeet.equals(dest) || ab > 0.25) { if (numTicks++ < 20 && fromStart < 1.25) { - MovementHelper.moveTowards(ctx, state, fakeDest); + MovementHelper.moveTowards(baritone, ctx, state, fakeDest); } else { - MovementHelper.moveTowards(ctx, state, dest); + MovementHelper.moveTowards(baritone, ctx, state, dest); } } return state; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index e7d74f03e..55d964b03 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -278,7 +278,7 @@ public MovementState updateState(MovementState state) { state.setInput(Input.SPRINT, true); } state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> ctx.world().getBlockState(block).is(Blocks.MAGMA_BLOCK))); - MovementHelper.moveTowards(ctx, state, dest); + MovementHelper.moveTowards(baritone, ctx, state, dest); return state; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index a37df38b6..5d47e4b76 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -90,7 +90,7 @@ public MovementState updateState(MovementState state) { if (numTicks++ < 10 && ab < 0.2) { return state; } - MovementHelper.moveTowards(ctx, state, positionsToBreak[0]); + MovementHelper.moveTowards(baritone, ctx, state, positionsToBreak[0]); return state; } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 5ea1e4dcc..89305ae95 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -266,7 +266,7 @@ public MovementState updateState(MovementState state) { state.setInput(Input.SNEAK, true); } - MovementHelper.moveTowards(ctx, state, dest); + MovementHelper.moveTowards(baritone, ctx, state, dest); if (ctx.playerFeet().equals(dest)) { Block d = BlockStateInterface.getBlock(ctx, dest); if (d == Blocks.VINE || d == Blocks.LADDER) { @@ -302,9 +302,9 @@ public MovementState updateState(MovementState state) { } else if (!ctx.playerFeet().equals(dest.relative(direction, -1))) { state.setInput(Input.SPRINT, false); if (ctx.playerFeet().equals(src.relative(direction, -1))) { - MovementHelper.moveTowards(ctx, state, src); + MovementHelper.moveTowards(baritone, ctx, state, src); } else { - MovementHelper.moveTowards(ctx, state, src.relative(direction, -1)); + MovementHelper.moveTowards(baritone, ctx, state, src.relative(direction, -1)); } } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 8007eb767..01c4261a2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -221,7 +221,7 @@ public MovementState updateState(MovementState state) { } */ - MovementHelper.moveTowards(ctx, state, against); + MovementHelper.moveTowards(baritone, ctx, state, against); return state; } else { // Get ready to place a throwaway block diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 1e2dc8457..e8f3c0b3e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -286,7 +286,7 @@ public MovementState updateState(MovementState state) { return state.setStatus(MovementStatus.UNREACHABLE); } } - MovementHelper.moveTowards(ctx, state, against); + MovementHelper.moveTowards(baritone, ctx, state, against); return state; } else { wasTheBridgeBlockAlwaysThere = false; @@ -294,7 +294,7 @@ public MovementState updateState(MovementState state) { if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().position().x), Math.abs(dest.getZ() + 0.5 - ctx.player().position().z)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon - MovementHelper.moveTowards(ctx, state, dest); + MovementHelper.moveTowards(baritone, ctx, state, dest); return state.setInput(Input.MOVE_FORWARD, false) .setInput(Input.MOVE_BACK, true); } diff --git a/src/main/java/baritone/process/AttackProcess.java b/src/main/java/baritone/process/AttackProcess.java new file mode 100644 index 000000000..b6b0a67d1 --- /dev/null +++ b/src/main/java/baritone/process/AttackProcess.java @@ -0,0 +1,112 @@ +/* + * 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.process; + +import baritone.Baritone; +import baritone.api.process.IAttackProcess; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; +import baritone.api.utils.RotationUtils; +import baritone.api.utils.input.Input; +import baritone.utils.BaritoneProcessHelper; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; + +public class AttackProcess extends BaritoneProcessHelper implements IAttackProcess { + private boolean rotating = false; + private boolean attacking = false; + + public AttackProcess(Baritone baritone) { + super(baritone); + } + + @Override + public boolean isActive() { + return ctx.player() != null && ctx.world() != null && Baritone.settings().entityAttackRadius.value != 0D; + } + + @Override + public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { + this.baritone.getInputOverrideHandler().clearAllKeys(); + double closestDistance = Double.MAX_VALUE; + Vec3 closestPosition = null; + for (Entity entity : ctx.entities()) { + if (!entity.is(ctx.player()) && entity instanceof LivingEntity && entity.isAlive() && entity.isAttackable()) { + Vec3 attackPoint = new Vec3( + entity.getBoundingBox().getCenter().x(),//Mth.clamp(ctx.playerHead().x(), entity.getBoundingBox().minX, entity.getBoundingBox().maxX), + Mth.clamp(ctx.playerHead().y(), entity.getBoundingBox().minY, entity.getBoundingBox().maxY), + entity.getBoundingBox().getCenter().z()//Mth.clamp(ctx.playerHead().z(), entity.getBoundingBox().minZ, entity.getBoundingBox().maxZ) + ); + double distance = this.ctx.player().getEyePosition().distanceToSqr(attackPoint); + if (distance < closestDistance) { + closestDistance = distance; + closestPosition = attackPoint; + } + } + } + this.rotating = false; + this.attacking = false; + if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { + if (!Baritone.settings().assumeExternalAutoAim.value) { + this.rotating = true; + this.baritone.getLookBehavior().updateTarget( + RotationUtils.calcRotationFromVec3d(this.ctx.playerHead(), closestPosition, this.ctx.playerRotations()), + true + ); + } + if (!Baritone.settings().assumeExternalKillAura.value) { + HitResult hitResult = ctx.minecraft().hitResult; + if (hitResult != null && hitResult.getType().equals(HitResult.Type.ENTITY)) { + this.attacking = true; + } + } + } + return new PathingCommand(null, PathingCommandType.DEFER); + } + + @Override + public void onLostControl() {} + + @Override + public String displayName0() { + return "Attack"; + } + + @Override + public boolean isTemporary() { + return true; + } + + @Override + public double priority() { + return 5; + } + + @Override + public boolean isRotating() { + return this.rotating; + } + + @Override + public boolean isAttacking() { + return this.attacking; + } +} diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 4a5036d79..1bc5c35e8 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -88,12 +88,16 @@ public void onTick(TickEvent event) { return; } + if (baritone.getAttackProcess().isAttacking()) { + setInputForceState(Input.CLICK_LEFT, true); + } + if (isInputForcedDown(Input.CLICK_LEFT)) { + setInputForceState(Input.CLICK_RIGHT, false); + } + leftClickHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); + blockPlaceHelper.tick(isInputForcedDown(Input.CLICK_RIGHT)); + if (inControl()) { - if (isInputForcedDown(Input.CLICK_LEFT)) { - setInputForceState(Input.CLICK_RIGHT, false); - } - leftClickHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); - blockPlaceHelper.tick(isInputForcedDown(Input.CLICK_RIGHT)); if (ctx.player().input.getClass() != PlayerMovementInput.class) { ctx.player().input = new PlayerMovementInput(this); } From 5d225b8017b8885f4a86685097453c10e84ebcc5 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Sat, 9 Aug 2025 14:45:18 -0400 Subject: [PATCH 18/21] Limit when active to only when there's a path or the `follow` process is also active. --- src/main/java/baritone/process/AttackProcess.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/process/AttackProcess.java b/src/main/java/baritone/process/AttackProcess.java index b6b0a67d1..9812bdb27 100644 --- a/src/main/java/baritone/process/AttackProcess.java +++ b/src/main/java/baritone/process/AttackProcess.java @@ -40,7 +40,12 @@ public AttackProcess(Baritone baritone) { @Override public boolean isActive() { - return ctx.player() != null && ctx.world() != null && Baritone.settings().entityAttackRadius.value != 0D; + this.rotating = false; + this.attacking = false; + return ctx.player() != null && + ctx.world() != null && + Baritone.settings().entityAttackRadius.value != 0D && + (this.baritone.getFollowProcess().isActive() || this.baritone.getPathingBehavior().isPathing()); } @Override @@ -62,8 +67,6 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { } } } - this.rotating = false; - this.attacking = false; if (closestPosition != null && Math.sqrt(closestDistance) <= Baritone.settings().entityAttackRadius.value) { if (!Baritone.settings().assumeExternalAutoAim.value) { this.rotating = true; From 3b05199dab9b941758604ad88d490e84aea97c05 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Sat, 9 Aug 2025 15:22:54 -0400 Subject: [PATCH 19/21] Small change. --- src/main/java/baritone/pathing/movement/MovementHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index a9fa62328..2c10487a7 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -655,7 +655,7 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo static void moveTowards(IBaritone baritone, IPlayerContext ctx, MovementState state, BlockPos pos) { if (baritone.getAttackProcess().isRotating()) { - MovementHelper.moveTowardsWithoutRotation(ctx, state, pos); + moveTowardsWithoutRotation(ctx, state, pos); } else { moveTowardsWithRotation(ctx, state, pos); } From ed0976b89370acb7ac6d340e41d91baa6c4821f8 Mon Sep 17 00:00:00 2001 From: murat Date: Fri, 12 Sep 2025 17:14:45 -0400 Subject: [PATCH 20/21] Fix errors. --- .../baritone/pathing/movement/Movement.java | 3 +++ .../pathing/movement/MovementHelper.java | 20 +++++++++++++------ .../movement/movements/MovementAscend.java | 2 +- .../movement/movements/MovementDescend.java | 4 ++-- .../movement/movements/MovementDiagonal.java | 2 +- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementParkour.java | 6 +++--- .../movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 4 ++-- 9 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 739c8ee89..39e8690dc 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -64,6 +64,8 @@ public abstract class Movement implements IMovement, MovementHelper { private Boolean calculatedWhileLoaded; + protected final boolean isAttacking; + protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) { this.baritone = baritone; this.ctx = baritone.getPlayerContext(); @@ -71,6 +73,7 @@ protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, this.dest = dest; this.positionsToBreak = toBreak; this.positionToPlace = toPlace; + this.isAttacking = baritone.getAttackProcess().isAttacking(); } protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak) { diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index c01fd40e6..4c23bab09 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -650,13 +650,21 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo } } + static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos dest, boolean changeRotation) { + if (!changeRotation) { + state.setTarget(new MovementTarget( + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), + VecUtils.getBlockPosCenter(dest), + ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), + false + )).setInput(Input.MOVE_FORWARD, true); + } else { + moveTowardsWithoutRotation(ctx, state, dest); + } + } + static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { - state.setTarget(new MovementTarget( - RotationUtils.calcRotationFromVec3d(ctx.playerHead(), - VecUtils.getBlockPosCenter(pos), - ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), - false - )).setInput(Input.MOVE_FORWARD, true); + moveTowards(ctx, state, pos, false); } static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, float idealYaw) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 90f000036..8223d4efc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -189,7 +189,7 @@ public MovementState updateState(MovementState state) { return state; } - MovementHelper.moveTowards(baritone, ctx, state, dest); + MovementHelper.moveTowards(ctx, state, dest, isAttacking); state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && jumpingOnto.is(Blocks.MAGMA_BLOCK)); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 3a03f70ab..2e8e160fe 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -261,9 +261,9 @@ public MovementState updateState(MovementState state) { if (!playerFeet.equals(dest) || ab > 0.25) { if (numTicks++ < 20 && fromStart < 1.25) { - MovementHelper.moveTowards(baritone, ctx, state, fakeDest); + MovementHelper.moveTowards(ctx, state, fakeDest, isAttacking); } else { - MovementHelper.moveTowards(baritone, ctx, state, dest); + MovementHelper.moveTowards(ctx, state, dest, isAttacking); } } return state; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 55d964b03..52569feed 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -278,7 +278,7 @@ public MovementState updateState(MovementState state) { state.setInput(Input.SPRINT, true); } state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> ctx.world().getBlockState(block).is(Blocks.MAGMA_BLOCK))); - MovementHelper.moveTowards(baritone, ctx, state, dest); + MovementHelper.moveTowards(ctx, state, dest, isAttacking); return state; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 5d47e4b76..2c73694a6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -90,7 +90,7 @@ public MovementState updateState(MovementState state) { if (numTicks++ < 10 && ab < 0.2) { return state; } - MovementHelper.moveTowards(baritone, ctx, state, positionsToBreak[0]); + MovementHelper.moveTowards(ctx, state, positionsToBreak[0], isAttacking); return state; } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 89305ae95..70747f630 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -266,7 +266,7 @@ public MovementState updateState(MovementState state) { state.setInput(Input.SNEAK, true); } - MovementHelper.moveTowards(baritone, ctx, state, dest); + MovementHelper.moveTowards(ctx, state, dest, isAttacking); if (ctx.playerFeet().equals(dest)) { Block d = BlockStateInterface.getBlock(ctx, dest); if (d == Blocks.VINE || d == Blocks.LADDER) { @@ -302,9 +302,9 @@ public MovementState updateState(MovementState state) { } else if (!ctx.playerFeet().equals(dest.relative(direction, -1))) { state.setInput(Input.SPRINT, false); if (ctx.playerFeet().equals(src.relative(direction, -1))) { - MovementHelper.moveTowards(baritone, ctx, state, src); + MovementHelper.moveTowards(ctx, state, src, isAttacking); } else { - MovementHelper.moveTowards(baritone, ctx, state, src.relative(direction, -1)); + MovementHelper.moveTowards(ctx, state, src.relative(direction, -1), isAttacking); } } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 01c4261a2..8e59526c3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -221,7 +221,7 @@ public MovementState updateState(MovementState state) { } */ - MovementHelper.moveTowards(baritone, ctx, state, against); + MovementHelper.moveTowards(ctx, state, against, isAttacking); return state; } else { // Get ready to place a throwaway block diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 853e95491..bfac7fa76 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -286,7 +286,7 @@ public MovementState updateState(MovementState state) { return state.setStatus(MovementStatus.UNREACHABLE); } } - MovementHelper.moveTowards(baritone, ctx, state, against); + MovementHelper.moveTowards(ctx, state, against, isAttacking); return state; } else { wasTheBridgeBlockAlwaysThere = false; @@ -294,7 +294,7 @@ public MovementState updateState(MovementState state) { if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().position().x), Math.abs(dest.getZ() + 0.5 - ctx.player().position().z)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon - MovementHelper.moveTowards(baritone, ctx, state, dest); + MovementHelper.moveTowards(ctx, state, dest, isAttacking); return state.setInput(Input.MOVE_FORWARD, false) .setInput(Input.MOVE_BACK, true); } From 6e5edf85e18e6b108b41703beeeea4ebabebaf2f Mon Sep 17 00:00:00 2001 From: murat Date: Fri, 12 Sep 2025 17:34:24 -0400 Subject: [PATCH 21/21] Fix attack detection. --- src/main/java/baritone/pathing/movement/Movement.java | 3 --- .../baritone/pathing/movement/movements/MovementAscend.java | 2 +- .../pathing/movement/movements/MovementDescend.java | 4 ++-- .../pathing/movement/movements/MovementDiagonal.java | 2 +- .../pathing/movement/movements/MovementDownward.java | 2 +- .../pathing/movement/movements/MovementParkour.java | 6 +++--- .../baritone/pathing/movement/movements/MovementPillar.java | 2 +- .../pathing/movement/movements/MovementTraverse.java | 4 ++-- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 39e8690dc..739c8ee89 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -64,8 +64,6 @@ public abstract class Movement implements IMovement, MovementHelper { private Boolean calculatedWhileLoaded; - protected final boolean isAttacking; - protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) { this.baritone = baritone; this.ctx = baritone.getPlayerContext(); @@ -73,7 +71,6 @@ protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, this.dest = dest; this.positionsToBreak = toBreak; this.positionToPlace = toPlace; - this.isAttacking = baritone.getAttackProcess().isAttacking(); } protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 8223d4efc..975babe9f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -189,7 +189,7 @@ public MovementState updateState(MovementState state) { return state; } - MovementHelper.moveTowards(ctx, state, dest, isAttacking); + MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating()); state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && jumpingOnto.is(Blocks.MAGMA_BLOCK)); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 2e8e160fe..c33407265 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -261,9 +261,9 @@ public MovementState updateState(MovementState state) { if (!playerFeet.equals(dest) || ab > 0.25) { if (numTicks++ < 20 && fromStart < 1.25) { - MovementHelper.moveTowards(ctx, state, fakeDest, isAttacking); + MovementHelper.moveTowards(ctx, state, fakeDest, baritone.getAttackProcess().isRotating()); } else { - MovementHelper.moveTowards(ctx, state, dest, isAttacking); + MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating()); } } return state; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 52569feed..4893a0d07 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -278,7 +278,7 @@ public MovementState updateState(MovementState state) { state.setInput(Input.SPRINT, true); } state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> ctx.world().getBlockState(block).is(Blocks.MAGMA_BLOCK))); - MovementHelper.moveTowards(ctx, state, dest, isAttacking); + MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating()); return state; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 2c73694a6..2ca925fee 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -90,7 +90,7 @@ public MovementState updateState(MovementState state) { if (numTicks++ < 10 && ab < 0.2) { return state; } - MovementHelper.moveTowards(ctx, state, positionsToBreak[0], isAttacking); + MovementHelper.moveTowards(ctx, state, positionsToBreak[0], baritone.getAttackProcess().isRotating()); return state; } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 70747f630..df0b67bba 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -266,7 +266,7 @@ public MovementState updateState(MovementState state) { state.setInput(Input.SNEAK, true); } - MovementHelper.moveTowards(ctx, state, dest, isAttacking); + MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating()); if (ctx.playerFeet().equals(dest)) { Block d = BlockStateInterface.getBlock(ctx, dest); if (d == Blocks.VINE || d == Blocks.LADDER) { @@ -302,9 +302,9 @@ public MovementState updateState(MovementState state) { } else if (!ctx.playerFeet().equals(dest.relative(direction, -1))) { state.setInput(Input.SPRINT, false); if (ctx.playerFeet().equals(src.relative(direction, -1))) { - MovementHelper.moveTowards(ctx, state, src, isAttacking); + MovementHelper.moveTowards(ctx, state, src, baritone.getAttackProcess().isRotating()); } else { - MovementHelper.moveTowards(ctx, state, src.relative(direction, -1), isAttacking); + MovementHelper.moveTowards(ctx, state, src.relative(direction, -1), baritone.getAttackProcess().isRotating()); } } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 8e59526c3..38a347db8 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -221,7 +221,7 @@ public MovementState updateState(MovementState state) { } */ - MovementHelper.moveTowards(ctx, state, against, isAttacking); + MovementHelper.moveTowards(ctx, state, against, baritone.getAttackProcess().isRotating()); return state; } else { // Get ready to place a throwaway block diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index bfac7fa76..4240f91d2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -286,7 +286,7 @@ public MovementState updateState(MovementState state) { return state.setStatus(MovementStatus.UNREACHABLE); } } - MovementHelper.moveTowards(ctx, state, against, isAttacking); + MovementHelper.moveTowards(ctx, state, against, baritone.getAttackProcess().isRotating()); return state; } else { wasTheBridgeBlockAlwaysThere = false; @@ -294,7 +294,7 @@ public MovementState updateState(MovementState state) { if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().position().x), Math.abs(dest.getZ() + 0.5 - ctx.player().position().z)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon - MovementHelper.moveTowards(ctx, state, dest, isAttacking); + MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating()); return state.setInput(Input.MOVE_FORWARD, false) .setInput(Input.MOVE_BACK, true); }