Skip to content
Draft

Attac #4838

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7dc4372
Add basic functionality for looking at entities.
Murat65536 Jul 31, 2025
83b2e1f
Try to add attacking.
Murat65536 Aug 1, 2025
3631d99
Ummm... attacking kind of works???
Murat65536 Aug 3, 2025
811d419
Some renaming.
Murat65536 Aug 3, 2025
f55aeb4
Update that allows for timed clicks.
Murat65536 Aug 5, 2025
f9c2d9d
Add settings for spamming + clean.
Murat65536 Aug 5, 2025
fddf47d
Clean up.
Murat65536 Aug 5, 2025
1157214
Count down on every tick.
Murat65536 Aug 5, 2025
7639a25
Add settings for external killaura and autoaim.
Murat65536 Aug 5, 2025
dff2edf
Fix when using freelook
Murat65536 Aug 5, 2025
50d382d
Add ability to circle around an entity, making sure that Baritone alw…
Murat65536 Aug 6, 2025
8441768
Change to Vec2.
Murat65536 Aug 6, 2025
3c79565
Replace circle offset with cleaner and better method.
Murat65536 Aug 7, 2025
09dde31
Add random direction switch to `FollowProcess`.
Murat65536 Aug 7, 2025
d9f395c
Distance calculation nerf to help with aiming :(.
Murat65536 Aug 7, 2025
717426c
Small change.
Murat65536 Aug 7, 2025
bd57b98
Baritone is able to attack even if it doesn't have a currently select…
Murat65536 Aug 9, 2025
5d225b8
Limit when active to only when there's a path or the `follow` process…
Murat65536 Aug 9, 2025
3b05199
Small change.
Murat65536 Aug 9, 2025
8726a9a
Merge branch '1.19.4' of https://github.com/cabaletta/baritone into hunt
Murat65536 Sep 12, 2025
ed0976b
Fix errors.
Murat65536 Sep 12, 2025
6e5edf8
Fix attack detection.
Murat65536 Sep 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api/java/baritone/api/IBaritone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,26 @@ public final class Settings {
*/
public final Setting<Integer> blockBreakSpeed = new Setting<>(6);

/**
* Determines if Baritone waits for the attack cooldown to recharge completely before attacking
*/
public final Setting<Boolean> timedAttacks = new Setting<>(true);

/**
* Determines how many ticks between left clicks are allowed.
*/
public final Setting<Integer> leftClickSpeed = new Setting<>(6);

/**
* Assume external aiming functionality
*/
public final Setting<Boolean> assumeExternalAutoAim = new Setting<>(false);

/**
* Assume external attacking functionality
*/
public final Setting<Boolean> assumeExternalKillAura = new Setting<>(false);

/**
* How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable
*/
Expand Down Expand Up @@ -1232,6 +1252,22 @@ public final class Settings {
*/
public final Setting<Double> 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<Boolean> followCircle = new Setting<>(false);

/**
* The yaw amount the target is shifted by
*/
public final Setting<Float> followCircleIncrement = new Setting<>(90F);

/**
* The chance every tick that the follow circle direction is switched from 0 to 100
*/
public final Setting<Double> followCircleSwitchDirectionChance = new Setting<>(2.5D);

/**
* The actual GoalNear is set in this direction from the entity you're following. This value is in degrees.
*/
Expand All @@ -1247,6 +1283,13 @@ public final class Settings {
*/
public final Setting<Integer> followTargetMaxDistance = new Setting<>(0);

/**
* The distance until you start locking on and attacking entities.
* <p>
* This doesn't change the direction you go, just the direction you face.
*/
public final Setting<Double> 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
Expand Down
24 changes: 24 additions & 0 deletions src/api/java/baritone/api/process/IAttackProcess.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

package baritone.api.process;

public interface IAttackProcess extends IBaritoneProcess {
boolean isRotating();

boolean isAttacking();
}
2 changes: 1 addition & 1 deletion src/api/java/baritone/api/utils/RayTraceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/baritone/Baritone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -240,6 +243,11 @@ public IElytraProcess getElytraProcess() {
return this.elytraProcess;
}

@Override
public IAttackProcess getAttackProcess() {
return this.attackProcess;
}

@Override
public void openClick() {
new Thread(() -> {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/baritone/behavior/PathingBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -363,7 +362,7 @@ public void secretInternalSegmentCancel() {
current = null;
next = null;
baritone.getInputOverrideHandler().clearAllKeys();
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
baritone.getInputOverrideHandler().getLeftClickHelper().stopBreakingBlock();
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/baritone/pathing/movement/MovementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public MovementState updateState(MovementState state) {

return state;
}
MovementHelper.moveTowards(ctx, state, dest);
MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating());

state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && jumpingOnto.is(Blocks.MAGMA_BLOCK));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(ctx, state, fakeDest, baritone.getAttackProcess().isRotating());
} else {
MovementHelper.moveTowards(ctx, state, dest);
MovementHelper.moveTowards(ctx, state, dest, baritone.getAttackProcess().isRotating());
}
}
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(ctx, state, dest, baritone.getAttackProcess().isRotating());
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(ctx, state, positionsToBreak[0], baritone.getAttackProcess().isRotating());
return state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public MovementState updateState(MovementState state) {
state.setInput(Input.SNEAK, true);
}

MovementHelper.moveTowards(ctx, state, dest);
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) {
Expand Down Expand Up @@ -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(ctx, state, src, baritone.getAttackProcess().isRotating());
} else {
MovementHelper.moveTowards(ctx, state, src.relative(direction, -1));
MovementHelper.moveTowards(ctx, state, src.relative(direction, -1), baritone.getAttackProcess().isRotating());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public MovementState updateState(MovementState state) {
}
*/

MovementHelper.moveTowards(ctx, state, against);
MovementHelper.moveTowards(ctx, state, against, baritone.getAttackProcess().isRotating());
return state;
} else {
// Get ready to place a throwaway block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ public MovementState updateState(MovementState state) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
}
MovementHelper.moveTowards(ctx, state, against);
MovementHelper.moveTowards(ctx, state, against, baritone.getAttackProcess().isRotating());
return state;
} else {
wasTheBridgeBlockAlwaysThere = false;
Block standingOn = BlockStateInterface.get(ctx, feet.below()).getBlock();
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(ctx, state, dest, baritone.getAttackProcess().isRotating());
return state.setInput(Input.MOVE_FORWARD, false)
.setInput(Input.MOVE_BACK, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baritone/pathing/path/PathExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading