Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0378096
Make Baritone not look forward while bridging.
Murat65536 May 11, 2025
1078270
Clean up.
Murat65536 May 14, 2025
cbfb329
Add direction-independent movement.
Murat65536 May 23, 2025
72fb0a0
Add default to switch case.
Murat65536 May 24, 2025
83afa11
Fix.
Murat65536 Jul 2, 2025
a30e3ce
Merge branch 'cabaletta:1.19.4' into bridging-improvements
Murat65536 Jul 6, 2025
1911553
Keep original player movement.
Murat65536 Jul 7, 2025
5d8136b
Simplify.
Murat65536 Jul 13, 2025
8ee7a1e
Small change.
Murat65536 Jul 23, 2025
1a3d302
Clean up.
Murat65536 Jul 23, 2025
9c84fa5
Merge branch 'cabaletta:1.19.4' into bridging-improvements
Murat65536 Jul 23, 2025
1c4c3f3
Merge branch 'cabaletta:1.19.4' into bridging-improvements
Murat65536 Jul 24, 2025
9d33858
Small change.
Murat65536 Jul 25, 2025
2ba448c
Merge remote-tracking branch 'origin/bridging-improvements' into brid…
Murat65536 Jul 25, 2025
1029604
Fix bug.
Murat65536 Jul 31, 2025
7b5ba80
Change to Vec2.
Murat65536 Aug 6, 2025
f1e5c44
Replace messy Vec2 with a cleaner record class. Also, remove a messy …
Murat65536 Aug 17, 2025
9714fa4
Condense logic into huge lambda.
Murat65536 Aug 18, 2025
0eb0e67
Condense more.
Murat65536 Aug 18, 2025
a2a6769
Round yaw to 45 degrees when bridging.
Murat65536 Aug 24, 2025
61c0a09
Add 45 degree intervals to yaw change.
Murat65536 Aug 28, 2025
f9ae702
Formatting change.
Murat65536 Aug 28, 2025
ce81d36
Convert to ternary operators.
Murat65536 Aug 29, 2025
0379128
Adjust order.
Murat65536 Aug 30, 2025
714e7af
More minor formatting changes.
Murat65536 Aug 30, 2025
a56f3cf
Clarify yaw distance comment
Murat65536 Sep 11, 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
20 changes: 20 additions & 0 deletions src/api/java/baritone/api/utils/Rotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ public static float normalizeYaw(float yaw) {
return newYaw;
}

/**
* Gets the distance between a starting yaw and an offset yaw.
* Distance can be negative if the offset yaw is behind of the starting yaw.
*
* @param yaw The initial yaw
* @param offsetYaw The offset yaw
* @return The distance between the yaws
*/
public static float yawDistanceFromOffset(float yaw, float offsetYaw) {
if ((yaw > 0 ^ offsetYaw > 0) && ((yaw > 90 || yaw < -90) ^ (offsetYaw > 90 || offsetYaw < -90))) {
if (yaw < 0) {
return 360 + (yaw - offsetYaw);
} else {
return 360 - (yaw - offsetYaw);
}
} else {
return yaw - offsetYaw;
}
}

@Override
public String toString() {
return "Yaw: " + yaw + ", Pitch: " + pitch;
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/baritone/pathing/movement/MovementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import baritone.utils.ToolSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.piston.MovingPistonBlock;
Expand All @@ -50,10 +51,9 @@
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;

import static baritone.api.utils.RotationUtils.DEG_TO_RAD_F;
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
import static baritone.pathing.precompute.Ternary.*;

Expand Down Expand Up @@ -659,6 +659,43 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
)).setInput(Input.MOVE_FORWARD, true);
}

static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, float idealYaw) {
MovementOption.getOptions(
Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
Baritone.settings().allowSprint.value
).min(Comparator.comparing(option -> option.distanceToSq(
Mth.sin(idealYaw * DEG_TO_RAD_F),
Mth.cos(idealYaw * DEG_TO_RAD_F)
))).ifPresent(selection -> selection.setInputs(state));
}

static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
float idealYaw = RotationUtils.calcRotationFromVec3d(
ctx.playerHead(),
VecUtils.getBlockPosCenter(dest),
ctx.playerRotations()
).getYaw();
moveTowardsWithoutRotation(ctx, state, idealYaw);
}

static void moveTowardsWithSlightRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
float idealYaw = RotationUtils.calcRotationFromVec3d(
ctx.playerHead(),
VecUtils.getBlockPosCenter(dest),
ctx.playerRotations()
).getYaw();
float distance = Rotation.yawDistanceFromOffset(ctx.playerRotations().getYaw(), idealYaw) % 45f;
float newYaw = distance > 0f ?
distance > 22.5f ? distance - 45f : distance :
distance < -22.5f ? distance + 45f : distance;
state.setTarget(new MovementTarget(new Rotation(
ctx.playerRotations().getYaw() - newYaw,
ctx.playerRotations().getPitch()
), true));
moveTowardsWithoutRotation(ctx, state, idealYaw);
}

/**
* Returns whether or not the specified block is
* water, regardless of whether or not it is flowing.
Expand Down Expand Up @@ -778,7 +815,7 @@ static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone,
if (ctx.getSelectedBlock().isPresent()) {
BlockPos selectedBlock = ctx.getSelectedBlock().get();
Direction side = ((BlockHitResult) ctx.objectMouseOver()).getDirection();
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
// only way for selectedBlock.equals(placeAt) to be true is if it's replaceable
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.relative(side).equals(placeAt))) {
if (wouldSneak) {
state.setInput(Input.SNEAK, true);
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/baritone/pathing/movement/MovementOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/

package baritone.pathing.movement;

import baritone.api.utils.input.Input;
import net.minecraft.util.Mth;

import java.util.stream.Stream;

public record MovementOption(Input input1, Input input2, float motionX, float motionZ) {
private static final float SPRINT_MULTIPLIER = 1.3f;

public MovementOption(Input input1, float motionX, float motionZ) {
this(input1, null, motionX, motionZ);
}

public void setInputs(MovementState movementState) {
if (input1 != null) {
movementState.setInput(input1, true);
}
if (input2 != null) {
movementState.setInput(input2, true);
}
}

public float distanceToSq(float otherX, float otherZ) {
return Mth.abs(motionX() - otherX) + Mth.abs(motionZ() - otherZ);
}

public static Stream<MovementOption> getOptions(float motionX, float motionZ, boolean canSprint) {
return Stream.of(
new MovementOption(Input.MOVE_FORWARD, canSprint ? motionX * SPRINT_MULTIPLIER : motionX, canSprint ? motionZ * SPRINT_MULTIPLIER : motionZ),
new MovementOption(Input.MOVE_BACK, -motionX, -motionZ),
new MovementOption(Input.MOVE_LEFT, -motionZ, motionX),
new MovementOption(Input.MOVE_RIGHT, motionZ, -motionX),
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_LEFT, (canSprint ? motionX * SPRINT_MULTIPLIER : motionX) - motionZ, (canSprint ? motionZ * SPRINT_MULTIPLIER : motionZ) + motionX),
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_RIGHT, (canSprint ? motionX * SPRINT_MULTIPLIER : motionX) + motionZ, (canSprint ? motionZ * SPRINT_MULTIPLIER : motionZ) - motionX),
new MovementOption(Input.MOVE_BACK, Input.MOVE_LEFT, -motionX - motionZ, -motionZ + motionX),
new MovementOption(Input.MOVE_BACK, Input.MOVE_RIGHT, -motionX + motionZ, -motionZ - motionX)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,8 @@ public MovementState updateState(MovementState state) {
}
return state;
}
MovementHelper.moveTowards(ctx, state, positionsToBreak[0]);
MovementHelper.moveTowardsWithSlightRotation(ctx, state, dest);
return state;
// TODO MovementManager.moveTowardsBlock(to); // move towards not look at because if we are bridging for a couple blocks in a row, it is faster if we dont spin around and walk forwards then spin around and place backwards for every block
}
}

Expand Down