Replace manual calculation with util method

This commit is contained in:
Brady 2023-06-24 21:57:00 -07:00
parent 2ccd464a49
commit 615266ed96
No known key found for this signature in database
GPG Key ID: 73A788379A197567
1 changed files with 6 additions and 11 deletions

View File

@ -769,12 +769,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
final Rotation rotation = aimProcessor.nextRotation(
RotationUtils.calcRotationFromVec3d(Vec3d.ZERO, delta, ctx.playerRotations()).withPitch(pitch)
);
motion = step(motion, rotation.getPitch(), rotation.getYaw(), firework && i > 0);
motion = step(motion, rotation, firework && i > 0);
delta = delta.subtract(motion);
final AxisAlignedBB inMotion = hitbox.expand(motion.x, motion.y, motion.z)
// Additional padding for safety
.grow(0.01, 0.01, 0.01);
// Collision box while the player is in motion, with additional padding for safety
final AxisAlignedBB inMotion = hitbox.expand(motion.x, motion.y, motion.z).grow(0.01);
for (int x = MathHelper.floor(inMotion.minX); x < MathHelper.ceil(inMotion.maxX); x++) {
for (int y = MathHelper.floor(inMotion.minY); y < MathHelper.ceil(inMotion.maxY); y++) {
@ -800,15 +799,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
return bestPitch;
}
private static Vec3d step(Vec3d motion, float rotationPitch, float rotationYaw, boolean firework) {
private static Vec3d step(final Vec3d motion, final Rotation rotation, final boolean firework) {
double motionX = motion.x;
double motionY = motion.y;
double motionZ = motion.z;
float flatZ = MathHelper.cos((-rotationYaw * RotationUtils.DEG_TO_RAD_F) - (float) Math.PI);
float flatX = MathHelper.sin((-rotationYaw * RotationUtils.DEG_TO_RAD_F) - (float) Math.PI);
float pitchBase = -MathHelper.cos(-rotationPitch * RotationUtils.DEG_TO_RAD_F);
float pitchHeight = MathHelper.sin(-rotationPitch * RotationUtils.DEG_TO_RAD_F);
Vec3d lookDirection = new Vec3d(flatX * pitchBase, pitchHeight, flatZ * pitchBase);
final Vec3d lookDirection = RotationUtils.calcLookDirectionFromRotation(rotation);
if (firework) {
// See EntityFireworkRocket
@ -817,7 +812,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
motionZ += lookDirection.z * 0.1 + (lookDirection.z * 1.5 - motionZ) * 0.5;
}
float pitchRadians = rotationPitch * RotationUtils.DEG_TO_RAD_F;
float pitchRadians = rotation.getPitch() * RotationUtils.DEG_TO_RAD_F;
double pitchBase2 = Math.sqrt(lookDirection.x * lookDirection.x + lookDirection.z * lookDirection.z);
double flatMotion = Math.sqrt(motionX * motionX + motionZ * motionZ);
double thisIsAlwaysOne = lookDirection.length();