@nxg-org/mineflayer-physics-util 1.5.9 → 1.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -520,7 +520,39 @@ class EntityPhysics {
520
520
  const pos = entity.position;
521
521
  const gravityMultiplier = vel.y <= 0 && entity.state.slowFalling > 0 ? physicsSettings_1.PhysicsSettings.slowFalling : 1;
522
522
  // Unsure how to handle this w/ other entities.
523
- if (!entity.state.isInWater && !entity.state.isInLava) {
523
+ // this is player-only.
524
+ if (entity.state.elytraFlying) {
525
+ const { pitch, sinPitch, cosPitch, lookDir } = (0, physicsUtils_1.getLookingVector)(entity.state);
526
+ const horizontalSpeed = Math.sqrt(vel.x * vel.x + vel.z * vel.z);
527
+ const cosPitchSquared = cosPitch * cosPitch;
528
+ vel.y += entity.gravity * gravityMultiplier * (-1.0 + cosPitchSquared * 0.75);
529
+ // cosPitch is in [0, 1], so cosPitch > 0.0 is just to protect against
530
+ // divide by zero errors
531
+ if (vel.y < 0.0 && cosPitch > 0.0) {
532
+ const movingDownSpeedModifier = vel.y * -0.1 * cosPitchSquared;
533
+ vel.x += (lookDir.x * movingDownSpeedModifier) / cosPitch;
534
+ vel.y += movingDownSpeedModifier;
535
+ vel.z += (lookDir.z * movingDownSpeedModifier) / cosPitch;
536
+ }
537
+ if (pitch < 0.0 && cosPitch > 0.0) {
538
+ const lookDownSpeedModifier = horizontalSpeed * -sinPitch * 0.04;
539
+ vel.x += (-lookDir.x * lookDownSpeedModifier) / cosPitch;
540
+ vel.y += lookDownSpeedModifier * 3.2;
541
+ vel.z += (-lookDir.z * lookDownSpeedModifier) / cosPitch;
542
+ }
543
+ if (cosPitch > 0.0) {
544
+ vel.x += ((lookDir.x / cosPitch) * horizontalSpeed - vel.x) * 0.1;
545
+ vel.z += ((lookDir.z / cosPitch) * horizontalSpeed - vel.z) * 0.1;
546
+ }
547
+ vel.x *= 0.99;
548
+ vel.y *= 0.98;
549
+ vel.z *= 0.99;
550
+ this.moveEntity(entity, vel.x, vel.y, vel.z, world);
551
+ if (entity.state.onGround) {
552
+ entity.state.elytraFlying = false;
553
+ }
554
+ }
555
+ else if (!entity.state.isInWater && !entity.state.isInLava) {
524
556
  let acceleration = entity.airborneAccel;
525
557
  let dragOrFriction = entity.airborneInertia; // equivalent to drag in the air. It is not actually inertia. Bad name.
526
558
  const blockUnder = world.getBlock(pos.offset(0, -1, 0));
@@ -589,38 +621,6 @@ class EntityPhysics {
589
621
  vel.x *= dragOrFriction;
590
622
  vel.z *= dragOrFriction;
591
623
  }
592
- // this is player-only.
593
- else if (entity.state.elytraFlying) {
594
- const { pitch, sinPitch, cosPitch, lookDir } = (0, physicsUtils_1.getLookingVector)(entity.state);
595
- const horizontalSpeed = Math.sqrt(vel.x * vel.x + vel.z * vel.z);
596
- const cosPitchSquared = cosPitch * cosPitch;
597
- vel.y += entity.gravity * gravityMultiplier * (-1.0 + cosPitchSquared * 0.75);
598
- // cosPitch is in [0, 1], so cosPitch > 0.0 is just to protect against
599
- // divide by zero errors
600
- if (vel.y < 0.0 && cosPitch > 0.0) {
601
- const movingDownSpeedModifier = vel.y * -0.1 * cosPitchSquared;
602
- vel.x += (lookDir.x * movingDownSpeedModifier) / cosPitch;
603
- vel.y += movingDownSpeedModifier;
604
- vel.z += (lookDir.z * movingDownSpeedModifier) / cosPitch;
605
- }
606
- if (pitch < 0.0 && cosPitch > 0.0) {
607
- const lookDownSpeedModifier = horizontalSpeed * -sinPitch * 0.04;
608
- vel.x += (-lookDir.x * lookDownSpeedModifier) / cosPitch;
609
- vel.y += lookDownSpeedModifier * 3.2;
610
- vel.z += (-lookDir.z * lookDownSpeedModifier) / cosPitch;
611
- }
612
- if (cosPitch > 0.0) {
613
- vel.x += ((lookDir.x / cosPitch) * horizontalSpeed - vel.x) * 0.1;
614
- vel.z += ((lookDir.z / cosPitch) * horizontalSpeed - vel.z) * 0.1;
615
- }
616
- vel.x *= 0.99;
617
- vel.y *= 0.98;
618
- vel.z *= 0.99;
619
- this.moveEntity(entity, world, vel.x, vel.y, vel.z);
620
- if (entity.state.onGround) {
621
- entity.state.elytraFlying = false;
622
- }
623
- }
624
624
  else {
625
625
  // Water / Lava movement
626
626
  const lastY = pos.y;
@@ -95,6 +95,7 @@ class EntityState {
95
95
  this.sneakCollision = false; //TODO
96
96
  this.attributes || (this.attributes = entity.attributes);
97
97
  this.elytraEquipped = entity.equipment[4] && ((_a = entity.equipment[4]) === null || _a === void 0 ? void 0 : _a.name.includes("elytra"));
98
+ this.elytraFlying = this.elytraEquipped && this.elytraFlying;
98
99
  }
99
100
  this.pos = entity.position.clone();
100
101
  //not sure what to do here, ngl.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.5.9",
3
+ "version": "1.5.10",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",