Condense logic into huge lambda.
This commit is contained in:
@@ -52,9 +52,7 @@ import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
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;
|
||||
@@ -668,25 +666,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||
VecUtils.getBlockPosCenter(dest),
|
||||
ctx.playerRotations());
|
||||
MovementOption selection = getSelection(blockRotation, ax, az);
|
||||
selection.setInputs(state);
|
||||
}
|
||||
|
||||
private static MovementOption 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);
|
||||
MovementOption[] options = getOptions(ax, az);
|
||||
MovementOption selection = null;
|
||||
float closestX = 100000;
|
||||
float closestZ = 100000;
|
||||
for (MovementOption option : options) {
|
||||
if (Mth.abs(targetAx - option.motionX()) + Mth.abs(targetAz - option.motionZ()) < closestX + closestZ) {
|
||||
closestX = Math.abs(targetAx - option.motionX());
|
||||
closestZ = Math.abs(targetAz - option.motionZ());
|
||||
selection = option;
|
||||
}
|
||||
}
|
||||
return selection;
|
||||
Arrays.stream(getOptions(ax, az)).min(Comparator.comparing(option -> option.distanceToSq(
|
||||
Mth.sin(blockRotation.getYaw() * DEG_TO_RAD_F),
|
||||
Mth.cos(blockRotation.getYaw() * DEG_TO_RAD_F)
|
||||
))).ifPresent(selection -> selection.setInputs(state));
|
||||
}
|
||||
|
||||
private static MovementOption[] getOptions(float ax, float az) {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.pathing.movement;
|
||||
|
||||
import baritone.api.utils.input.Input;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public record MovementOption(Input input1, Input input2, float motionX, float motionZ) {
|
||||
|
||||
@@ -33,4 +34,8 @@ public record MovementOption(Input input1, Input input2, float motionX, float mo
|
||||
movementState.setInput(input2, true);
|
||||
}
|
||||
}
|
||||
|
||||
public float distanceToSq(float otherX, float otherZ) {
|
||||
return Mth.abs(motionX() - otherX) + Mth.abs(motionZ() - otherZ);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user