Simplify.

This commit is contained in:
Murat65536
2025-07-13 10:09:16 -04:00
parent 191155315b
commit 5d8136b02e

View File

@@ -50,10 +50,12 @@ import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
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.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
import static baritone.pathing.precompute.Ternary.*; import static baritone.pathing.precompute.Ternary.*;
@@ -661,34 +663,12 @@ public interface MovementHelper extends ActionCosts, Helper {
static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, BlockPos dest, Rotation rotation) { static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, BlockPos dest, Rotation rotation) {
state.setTarget(new MovementTarget(rotation, true)); state.setTarget(new MovementTarget(rotation, true));
boolean canSprint = Baritone.settings().allowSprint.value; float ax = Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F);
float ax = Mth.sin((float)Math.toRadians(ctx.playerRotations().getYaw())); float az = Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F);
float az = Mth.cos((float)Math.toRadians(ctx.playerRotations().getYaw()));
Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
VecUtils.getBlockPosCenter(dest), VecUtils.getBlockPosCenter(dest),
ctx.playerRotations()); ctx.playerRotations());
float targetAx = Mth.sin((float)Math.toRadians(blockRotation.getYaw())); int selection = getSelection(blockRotation, ax, az);
float targetAz = Mth.cos((float)Math.toRadians(blockRotation.getYaw()));
float[][] options = {
{canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az}, // W
{-ax, -az}, // S
{-az, az}, // 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
};
int selection = -1;
float closestX = 100000;
float closestZ = 100000;
for (int i = 0; i < options.length; i++) {
if (Math.abs(targetAx - options[i][0]) + Math.abs(targetAz - options[i][1]) < closestX + closestZ) {
closestX = Math.abs(targetAx - options[i][0]);
closestZ = Math.abs(targetAz - options[i][1]);
selection = i;
}
}
switch (selection) { switch (selection) {
case 0: case 0:
state.setInput(Input.MOVE_FORWARD, true); state.setInput(Input.MOVE_FORWARD, true);
@@ -719,6 +699,37 @@ public interface MovementHelper extends ActionCosts, Helper {
} }
} }
private static int getSelection(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);
int selection = -1;
float closestX = 100000;
float closestZ = 100000;
for (int i = 0; i < options.length; i++) {
if (Math.abs(targetAx - options[i][0]) + Math.abs(targetAz - options[i][1]) < closestX + closestZ) {
closestX = Math.abs(targetAx - options[i][0]);
closestZ = Math.abs(targetAz - options[i][1]);
selection = i;
}
}
return selection;
}
private static float[] @NotNull [] getOptions(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, az}, // 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
};
}
/** /**
* Returns whether or not the specified block is * Returns whether or not the specified block is
* water, regardless of whether or not it is flowing. * water, regardless of whether or not it is flowing.
@@ -838,7 +849,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (ctx.getSelectedBlock().isPresent()) { if (ctx.getSelectedBlock().isPresent()) {
BlockPos selectedBlock = ctx.getSelectedBlock().get(); BlockPos selectedBlock = ctx.getSelectedBlock().get();
Direction side = ((BlockHitResult) ctx.objectMouseOver()).getDirection(); 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 (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.relative(side).equals(placeAt))) {
if (wouldSneak) { if (wouldSneak) {
state.setInput(Input.SNEAK, true); state.setInput(Input.SNEAK, true);