@nxg-org/mineflayer-physics-util 1.7.0 → 1.7.2

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.
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ declare module "mineflayer" {
8
8
  }
9
9
  export default function loader(bot: Bot): void;
10
10
  export declare function initSetup(data: IndexedData): void;
11
- export { EPhysicsCtx, PhysicsSettings as PhysicsSettings } from "./physics/settings";
11
+ export { EPhysicsCtx, PhysicsWorldSettings } from "./physics/settings";
12
12
  export { BaseSimulator } from "./simulators";
13
13
  export { EntityPhysics } from "./physics/engines";
14
14
  export { EntityState } from "./physics/states";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ControlStateHandler = exports.EntityState = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
3
+ exports.ControlStateHandler = exports.EntityState = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsWorldSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
4
4
  const settings_1 = require("./physics/settings");
5
5
  const wrapper_1 = require("./wrapper");
6
6
  function loader(bot) {
@@ -16,7 +16,7 @@ function initSetup(data) {
16
16
  exports.initSetup = initSetup;
17
17
  var settings_2 = require("./physics/settings");
18
18
  Object.defineProperty(exports, "EPhysicsCtx", { enumerable: true, get: function () { return settings_2.EPhysicsCtx; } });
19
- Object.defineProperty(exports, "PhysicsSettings", { enumerable: true, get: function () { return settings_2.PhysicsSettings; } });
19
+ Object.defineProperty(exports, "PhysicsWorldSettings", { enumerable: true, get: function () { return settings_2.PhysicsWorldSettings; } });
20
20
  var simulators_1 = require("./simulators");
21
21
  Object.defineProperty(exports, "BaseSimulator", { enumerable: true, get: function () { return simulators_1.BaseSimulator; } });
22
22
  var engines_1 = require("./physics/engines");
@@ -310,12 +310,12 @@ class EntityPhysics {
310
310
  if (block) {
311
311
  if (entity.collisionBehavior.blockEffects && this.supportFeature("velocityBlocksOnCollision")) {
312
312
  if (block.type === this.soulsandId) {
313
- vel.x *= entity.settings.soulsandSpeed;
314
- vel.z *= entity.settings.soulsandSpeed;
313
+ vel.x *= entity.worldSettings.soulsandSpeed;
314
+ vel.z *= entity.worldSettings.soulsandSpeed;
315
315
  }
316
316
  else if (block.type === this.honeyblockId) {
317
- vel.x *= entity.settings.honeyblockSpeed;
318
- vel.z *= entity.settings.honeyblockSpeed;
317
+ vel.x *= entity.worldSettings.honeyblockSpeed;
318
+ vel.z *= entity.worldSettings.honeyblockSpeed;
319
319
  }
320
320
  }
321
321
  if (block.type === this.webId) {
@@ -325,7 +325,7 @@ class EntityPhysics {
325
325
  else if (block.type === this.bubblecolumnId) {
326
326
  const down = !block.metadata;
327
327
  const aboveBlock = world.getBlock(cursor.offset(0, 1, 0));
328
- const bubbleDrag = aboveBlock && aboveBlock.type === 0 /* air */ ? entity.settings.bubbleColumnSurfaceDrag : entity.settings.bubbleColumnDrag;
328
+ const bubbleDrag = aboveBlock && aboveBlock.type === 0 /* air */ ? entity.worldSettings.bubbleColumnSurfaceDrag : entity.worldSettings.bubbleColumnDrag;
329
329
  if (down) {
330
330
  vel.y = Math.max(bubbleDrag.maxDown, vel.y - bubbleDrag.down);
331
331
  }
@@ -341,12 +341,12 @@ class EntityPhysics {
341
341
  const blockBelow = world.getBlock(entity.position.floored().offset(0, -0.5, 0));
342
342
  if (blockBelow) {
343
343
  if (blockBelow.type === this.soulsandId) {
344
- vel.x *= entity.settings.soulsandSpeed;
345
- vel.z *= entity.settings.soulsandSpeed;
344
+ vel.x *= entity.worldSettings.soulsandSpeed;
345
+ vel.z *= entity.worldSettings.soulsandSpeed;
346
346
  }
347
347
  else if (blockBelow.type === this.honeyblockId) {
348
- vel.x *= entity.settings.honeyblockSpeed;
349
- vel.z *= entity.settings.honeyblockSpeed;
348
+ vel.x *= entity.worldSettings.honeyblockSpeed;
349
+ vel.z *= entity.worldSettings.honeyblockSpeed;
350
350
  }
351
351
  }
352
352
  }
@@ -517,7 +517,7 @@ class EntityPhysics {
517
517
  }
518
518
  const vel = entity.velocity;
519
519
  const pos = entity.position;
520
- const gravityMultiplier = vel.y <= 0 && entity.state.slowFalling > 0 ? entity.settings.slowFalling : 1;
520
+ const gravityMultiplier = vel.y <= 0 && entity.state.slowFalling > 0 ? entity.worldSettings.slowFalling : 1;
521
521
  // Unsure how to handle this w/ other entities.
522
522
  // this is player-only.
523
523
  if (entity.state.elytraFlying) {
@@ -564,24 +564,24 @@ class EntityPhysics {
564
564
  else {
565
565
  // Create an attribute if the player does not have it
566
566
  //TODO: Generalize to all entities.
567
- playerSpeedAttribute = attributes.createAttributeValue(entity.settings.playerSpeed);
567
+ playerSpeedAttribute = attributes.createAttributeValue(entity.worldSettings.playerSpeed);
568
568
  }
569
569
  // Client-side sprinting (don't rely on server-side sprinting)
570
570
  // setSprinting in LivingEntity.java
571
571
  //TODO: Generalize to all entities.
572
- playerSpeedAttribute = attributes.deleteAttributeModifier(playerSpeedAttribute, entity.settings.sprintingUUID); // always delete sprinting (if it exists)
572
+ playerSpeedAttribute = attributes.deleteAttributeModifier(playerSpeedAttribute, entity.worldSettings.sprintingUUID); // always delete sprinting (if it exists)
573
573
  if (entity.state.control.sprint) {
574
- if (!attributes.checkAttributeModifier(playerSpeedAttribute, entity.settings.sprintingUUID)) {
574
+ if (!attributes.checkAttributeModifier(playerSpeedAttribute, entity.worldSettings.sprintingUUID)) {
575
575
  playerSpeedAttribute = attributes.addAttributeModifier(playerSpeedAttribute, {
576
- uuid: entity.settings.sprintingUUID,
577
- amount: entity.settings.sprintSpeed,
576
+ uuid: entity.worldSettings.sprintingUUID,
577
+ amount: entity.worldSettings.sprintSpeed,
578
578
  operation: 2,
579
579
  });
580
580
  }
581
581
  }
582
582
  // Calculate what the speed is (0.1 if no modification)
583
583
  const attributeSpeed = attributes.getAttributeValue(playerSpeedAttribute);
584
- dragOrFriction = (this.blockSlipperiness[blockUnder.type] || entity.settings.defaultSlipperiness) * 0.91;
584
+ dragOrFriction = (this.blockSlipperiness[blockUnder.type] || entity.worldSettings.defaultSlipperiness) * 0.91;
585
585
  acceleration = attributeSpeed * (0.1627714 / (dragOrFriction * dragOrFriction * dragOrFriction));
586
586
  if (acceleration < 0)
587
587
  acceleration = 0; // acceleration should not be negative
@@ -590,15 +590,15 @@ class EntityPhysics {
590
590
  this.applyHeading(entity, strafe, forward, acceleration);
591
591
  // console.log('vel 1!', vel)
592
592
  if (entity.collisionBehavior.blockEffects && this.isOnLadder(pos, world)) {
593
- vel.x = math.clamp(-entity.settings.ladderMaxSpeed, vel.x, entity.settings.ladderMaxSpeed);
594
- vel.z = math.clamp(-entity.settings.ladderMaxSpeed, vel.z, entity.settings.ladderMaxSpeed);
595
- vel.y = Math.max(vel.y, entity.state.control.sneak ? 0 : -entity.settings.ladderMaxSpeed);
593
+ vel.x = math.clamp(-entity.worldSettings.ladderMaxSpeed, vel.x, entity.worldSettings.ladderMaxSpeed);
594
+ vel.z = math.clamp(-entity.worldSettings.ladderMaxSpeed, vel.z, entity.worldSettings.ladderMaxSpeed);
595
+ vel.y = Math.max(vel.y, entity.state.control.sneak ? 0 : -entity.worldSettings.ladderMaxSpeed);
596
596
  }
597
597
  this.moveEntity(entity, vel.x, vel.y, vel.z, world);
598
598
  if (entity.collisionBehavior.blockEffects &&
599
599
  this.isOnLadder(pos, world) &&
600
600
  (entity.state.isCollidedHorizontally || (this.supportFeature("climbUsingJump") && entity.state.control.jump))) {
601
- vel.y = entity.settings.ladderClimbSpeed; // climb ladder
601
+ vel.y = entity.worldSettings.ladderClimbSpeed; // climb ladder
602
602
  }
603
603
  // Not adding an additional function call. No point.
604
604
  if (entity.gravityThenDrag) {
@@ -652,7 +652,7 @@ class EntityPhysics {
652
652
  vel.z *= horizontalInertia;
653
653
  if (entity.state.isCollidedHorizontally &&
654
654
  this.doesNotCollide(entity, pos.offset(vel.x, vel.y + 0.6 - pos.y + lastY, vel.z), world)) {
655
- vel.y = entity.settings.outOfLiquidImpulse; // jump out of liquid
655
+ vel.y = entity.worldSettings.outOfLiquidImpulse; // jump out of liquid
656
656
  }
657
657
  }
658
658
  }
@@ -670,11 +670,11 @@ class EntityPhysics {
670
670
  entity.state.isInWater = this.isInWaterApplyCurrent(waterBB, vel, world);
671
671
  entity.state.isInLava = this.isMaterialInBB(lavaBB, this.lavaId, world);
672
672
  // Reset velocity component if it falls under the threshold
673
- if (Math.abs(vel.x) < entity.settings.negligeableVelocity)
673
+ if (Math.abs(vel.x) < entity.worldSettings.negligeableVelocity)
674
674
  vel.x = 0;
675
- if (Math.abs(vel.y) < entity.settings.negligeableVelocity)
675
+ if (Math.abs(vel.y) < entity.worldSettings.negligeableVelocity)
676
676
  vel.y = 0;
677
- if (Math.abs(vel.z) < entity.settings.negligeableVelocity)
677
+ if (Math.abs(vel.z) < entity.worldSettings.negligeableVelocity)
678
678
  vel.z = 0;
679
679
  let strafe = 0;
680
680
  let forward = 0;
@@ -688,7 +688,7 @@ class EntityPhysics {
688
688
  }
689
689
  else if (entity.state.onGround && entity.state.jumpTicks === 0) {
690
690
  const blockBelow = world.getBlock(entity.position.floored().offset(0, -0.5, 0));
691
- vel.y = Math.fround(0.42) * (blockBelow && blockBelow.type === this.honeyblockId ? entity.settings.honeyblockJumpSpeed : 1);
691
+ vel.y = Math.fround(0.42) * (blockBelow && blockBelow.type === this.honeyblockId ? entity.worldSettings.honeyblockJumpSpeed : 1);
692
692
  if (entity.state.jumpBoost > 0) {
693
693
  vel.y += 0.1 * entity.state.jumpBoost;
694
694
  }
@@ -697,7 +697,7 @@ class EntityPhysics {
697
697
  vel.x -= Math.sin(yaw) * 0.2;
698
698
  vel.z += Math.cos(yaw) * 0.2;
699
699
  }
700
- entity.state.jumpTicks = entity.settings.autojumpCooldown;
700
+ entity.state.jumpTicks = entity.worldSettings.autojumpCooldown;
701
701
  }
702
702
  }
703
703
  else {
@@ -707,13 +707,13 @@ class EntityPhysics {
707
707
  strafe = (entity.state.control.left - entity.state.control.right) * 0.98;
708
708
  forward = (entity.state.control.forward - entity.state.control.back) * 0.98;
709
709
  if (entity.state.control.sneak) {
710
- strafe *= entity.settings.sneakSpeed;
711
- forward *= entity.settings.sneakSpeed;
710
+ strafe *= entity.worldSettings.sneakSpeed;
711
+ forward *= entity.worldSettings.sneakSpeed;
712
712
  entity.state.control.sprint = false;
713
713
  }
714
714
  if (entity.state.isUsingItem) {
715
- strafe *= entity.settings.usingItemSpeed;
716
- forward *= entity.settings.usingItemSpeed;
715
+ strafe *= entity.worldSettings.usingItemSpeed;
716
+ forward *= entity.worldSettings.usingItemSpeed;
717
717
  entity.state.control.sprint = false;
718
718
  }
719
719
  entity.state.elytraFlying =
@@ -313,12 +313,12 @@ class EntityPhysics {
313
313
  if (block) {
314
314
  if (entity.collisionBehavior.blockEffects && this.supportFeature("velocityBlocksOnCollision")) {
315
315
  if (block.type === this.soulsandId) {
316
- vel.x *= entity.settings.soulsandSpeed;
317
- vel.z *= entity.settings.soulsandSpeed;
316
+ vel.x *= entity.worldSettings.soulsandSpeed;
317
+ vel.z *= entity.worldSettings.soulsandSpeed;
318
318
  }
319
319
  else if (block.type === this.honeyblockId) {
320
- vel.x *= entity.settings.honeyblockSpeed;
321
- vel.z *= entity.settings.honeyblockSpeed;
320
+ vel.x *= entity.worldSettings.honeyblockSpeed;
321
+ vel.z *= entity.worldSettings.honeyblockSpeed;
322
322
  }
323
323
  }
324
324
  if (block.type === this.webId) {
@@ -329,8 +329,8 @@ class EntityPhysics {
329
329
  const down = !block.metadata;
330
330
  const aboveBlock = world.getBlock(cursor.offset(0, 1, 0));
331
331
  const bubbleDrag = aboveBlock && aboveBlock.type === 0 /* air */
332
- ? entity.settings.bubbleColumnSurfaceDrag
333
- : entity.settings.bubbleColumnDrag;
332
+ ? entity.worldSettings.bubbleColumnSurfaceDrag
333
+ : entity.worldSettings.bubbleColumnDrag;
334
334
  if (down) {
335
335
  vel.y = Math.max(bubbleDrag.maxDown, vel.y - bubbleDrag.down);
336
336
  }
@@ -346,12 +346,12 @@ class EntityPhysics {
346
346
  const blockBelow = world.getBlock(entity.position.floored().offset(0, -0.5, 0));
347
347
  if (blockBelow) {
348
348
  if (blockBelow.type === this.soulsandId) {
349
- vel.x *= entity.settings.soulsandSpeed;
350
- vel.z *= entity.settings.soulsandSpeed;
349
+ vel.x *= entity.worldSettings.soulsandSpeed;
350
+ vel.z *= entity.worldSettings.soulsandSpeed;
351
351
  }
352
352
  else if (blockBelow.type === this.honeyblockId) {
353
- vel.x *= entity.settings.honeyblockSpeed;
354
- vel.z *= entity.settings.honeyblockSpeed;
353
+ vel.x *= entity.worldSettings.honeyblockSpeed;
354
+ vel.z *= entity.worldSettings.honeyblockSpeed;
355
355
  }
356
356
  }
357
357
  }
@@ -522,7 +522,7 @@ class EntityPhysics {
522
522
  }
523
523
  const vel = entity.velocity;
524
524
  const pos = entity.position;
525
- const gravityMultiplier = vel.y <= 0 && entity.state.slowFalling > 0 ? entity.settings.slowFalling : 1;
525
+ const gravityMultiplier = vel.y <= 0 && entity.state.slowFalling > 0 ? entity.worldSettings.slowFalling : 1;
526
526
  // Unsure how to handle this w/ other entities.
527
527
  if (!entity.state.isInWater && !entity.state.isInLava) {
528
528
  let acceleration = entity.airborneAccel;
@@ -537,39 +537,39 @@ class EntityPhysics {
537
537
  else {
538
538
  // Create an attribute if the player does not have it
539
539
  //TODO: Generalize to all entities.
540
- playerSpeedAttribute = attributes.createAttributeValue(entity.settings.playerSpeed);
540
+ playerSpeedAttribute = attributes.createAttributeValue(entity.worldSettings.playerSpeed);
541
541
  }
542
542
  // Client-side sprinting (don't rely on server-side sprinting)
543
543
  // setSprinting in LivingEntity.java
544
544
  //TODO: Generalize to all entities.
545
- playerSpeedAttribute = attributes.deleteAttributeModifier(playerSpeedAttribute, entity.settings.sprintingUUID); // always delete sprinting (if it exists)
545
+ playerSpeedAttribute = attributes.deleteAttributeModifier(playerSpeedAttribute, entity.worldSettings.sprintingUUID); // always delete sprinting (if it exists)
546
546
  if (entity.state.control.sprint) {
547
- if (!attributes.checkAttributeModifier(playerSpeedAttribute, entity.settings.sprintingUUID)) {
547
+ if (!attributes.checkAttributeModifier(playerSpeedAttribute, entity.worldSettings.sprintingUUID)) {
548
548
  playerSpeedAttribute = attributes.addAttributeModifier(playerSpeedAttribute, {
549
- uuid: entity.settings.sprintingUUID,
550
- amount: entity.settings.sprintSpeed,
549
+ uuid: entity.worldSettings.sprintingUUID,
550
+ amount: entity.worldSettings.sprintSpeed,
551
551
  operation: 2,
552
552
  });
553
553
  }
554
554
  }
555
555
  // Calculate what the speed is (0.1 if no modification)
556
556
  const attributeSpeed = attributes.getAttributeValue(playerSpeedAttribute);
557
- inertia = (this.blockSlipperiness[blockUnder.type] || entity.settings.defaultSlipperiness) * 0.91;
557
+ inertia = (this.blockSlipperiness[blockUnder.type] || entity.worldSettings.defaultSlipperiness) * 0.91;
558
558
  acceleration = attributeSpeed * (0.1627714 / (inertia * inertia * inertia));
559
559
  if (acceleration < 0)
560
560
  acceleration = 0; // acceleration should not be negative
561
561
  }
562
562
  this.applyHeading(entity, strafe, forward, acceleration);
563
563
  if (entity.collisionBehavior.blockEffects && this.isOnLadder(pos, world)) {
564
- vel.x = math.clamp(-entity.settings.ladderMaxSpeed, vel.x, entity.settings.ladderMaxSpeed);
565
- vel.z = math.clamp(-entity.settings.ladderMaxSpeed, vel.z, entity.settings.ladderMaxSpeed);
566
- vel.y = Math.max(vel.y, entity.state.control.sneak ? 0 : -entity.settings.ladderMaxSpeed);
564
+ vel.x = math.clamp(-entity.worldSettings.ladderMaxSpeed, vel.x, entity.worldSettings.ladderMaxSpeed);
565
+ vel.z = math.clamp(-entity.worldSettings.ladderMaxSpeed, vel.z, entity.worldSettings.ladderMaxSpeed);
566
+ vel.y = Math.max(vel.y, entity.state.control.sneak ? 0 : -entity.worldSettings.ladderMaxSpeed);
567
567
  }
568
568
  this.moveEntity(entity, vel.x, vel.y, vel.z, world);
569
569
  if (entity.collisionBehavior.blockEffects &&
570
570
  this.isOnLadder(pos, world) &&
571
571
  (entity.state.isCollidedHorizontally || (this.supportFeature("climbUsingJump") && entity.state.control.jump))) {
572
- vel.y = entity.settings.ladderClimbSpeed; // climb ladder
572
+ vel.y = entity.worldSettings.ladderClimbSpeed; // climb ladder
573
573
  }
574
574
  // Not adding an additional function call. No point.
575
575
  if (entity.gravityThenDrag) {
@@ -654,7 +654,7 @@ class EntityPhysics {
654
654
  vel.z *= horizontalInertia;
655
655
  if (entity.state.isCollidedHorizontally &&
656
656
  this.doesNotCollide(entity, pos.offset(vel.x, vel.y + 0.6 - pos.y + lastY, vel.z), world)) {
657
- vel.y = entity.settings.outOfLiquidImpulse; // jump out of liquid
657
+ vel.y = entity.worldSettings.outOfLiquidImpulse; // jump out of liquid
658
658
  }
659
659
  }
660
660
  }
@@ -671,11 +671,11 @@ class EntityPhysics {
671
671
  entity.state.isInWater = this.isInWaterApplyCurrent(waterBB, vel, world);
672
672
  entity.state.isInLava = this.isMaterialInBB(lavaBB, this.lavaId, world);
673
673
  // Reset velocity component if it falls under the threshold
674
- if (Math.abs(vel.x) < entity.settings.negligeableVelocity)
674
+ if (Math.abs(vel.x) < entity.worldSettings.negligeableVelocity)
675
675
  vel.x = 0;
676
- if (Math.abs(vel.y) < entity.settings.negligeableVelocity)
676
+ if (Math.abs(vel.y) < entity.worldSettings.negligeableVelocity)
677
677
  vel.y = 0;
678
- if (Math.abs(vel.z) < entity.settings.negligeableVelocity)
678
+ if (Math.abs(vel.z) < entity.worldSettings.negligeableVelocity)
679
679
  vel.z = 0;
680
680
  let strafe = 0;
681
681
  let forward = 0;
@@ -690,7 +690,7 @@ class EntityPhysics {
690
690
  else if (entity.state.onGround && entity.state.jumpTicks === 0) {
691
691
  const blockBelow = world.getBlock(entity.position.floored().offset(0, -0.5, 0));
692
692
  vel.y =
693
- Math.fround(0.42) * (blockBelow && blockBelow.type === this.honeyblockId ? entity.settings.honeyblockJumpSpeed : 1);
693
+ Math.fround(0.42) * (blockBelow && blockBelow.type === this.honeyblockId ? entity.worldSettings.honeyblockJumpSpeed : 1);
694
694
  if (entity.state.jumpBoost > 0) {
695
695
  vel.y += 0.1 * entity.state.jumpBoost;
696
696
  }
@@ -699,7 +699,7 @@ class EntityPhysics {
699
699
  vel.x -= Math.sin(yaw) * 0.2;
700
700
  vel.z += Math.cos(yaw) * 0.2;
701
701
  }
702
- entity.state.jumpTicks = entity.settings.autojumpCooldown;
702
+ entity.state.jumpTicks = entity.worldSettings.autojumpCooldown;
703
703
  }
704
704
  }
705
705
  else {
@@ -711,13 +711,13 @@ class EntityPhysics {
711
711
  forward =
712
712
  (entity.state.control.forward - entity.state.control.back) * 0.98;
713
713
  if (entity.state.control.sneak) {
714
- strafe *= entity.settings.sneakSpeed;
715
- forward *= entity.settings.sneakSpeed;
714
+ strafe *= entity.worldSettings.sneakSpeed;
715
+ forward *= entity.worldSettings.sneakSpeed;
716
716
  entity.state.control.sprint = false;
717
717
  }
718
718
  if (entity.state.isUsingItem) {
719
- strafe *= entity.settings.usingItemSpeed;
720
- forward *= entity.settings.usingItemSpeed;
719
+ strafe *= entity.worldSettings.usingItemSpeed;
720
+ forward *= entity.worldSettings.usingItemSpeed;
721
721
  entity.state.control.sprint = false;
722
722
  }
723
723
  }
@@ -6,7 +6,7 @@ import { Vec3 } from "vec3";
6
6
  import { IPhysics } from "../engines/IPhysics";
7
7
  import { EntityState } from "../states/entityState";
8
8
  import { PlayerPoses } from "../states/poses";
9
- import { PhysicsSettings } from "./physicsSettings";
9
+ import { PhysicsWorldSettings } from "./physicsSettings";
10
10
  export declare const emptyVec: Vec3;
11
11
  type PlayerPoseContext = {
12
12
  [key in PlayerPoses]: {
@@ -20,7 +20,7 @@ type CollisionContext = {
20
20
  };
21
21
  export declare class EPhysicsCtx {
22
22
  readonly ctx: IPhysics;
23
- readonly settings: PhysicsSettings;
23
+ readonly worldSettings: PhysicsWorldSettings;
24
24
  pose: PlayerPoses;
25
25
  readonly state: EntityState;
26
26
  readonly entityType: md.Entity;
@@ -35,26 +35,26 @@ export declare class EPhysicsCtx {
35
35
  static readonly playerPoseContext: PlayerPoseContext;
36
36
  readonly position: Vec3;
37
37
  readonly velocity: Vec3;
38
- readonly stepHeight: number;
39
- readonly gravity: number;
40
- readonly waterGravity: number;
41
- readonly lavaGravity: number;
42
- readonly airdrag: number;
43
- readonly airborneInertia: number;
44
- readonly airborneAccel: number;
45
- readonly waterInertia: number;
46
- readonly lavaInertia: number;
47
- readonly liquidAccel: number;
48
- readonly gravityThenDrag: boolean;
49
- readonly useControls: boolean;
38
+ stepHeight: number;
39
+ gravity: number;
40
+ waterGravity: number;
41
+ lavaGravity: number;
42
+ airdrag: number;
43
+ airborneInertia: number;
44
+ airborneAccel: number;
45
+ waterInertia: number;
46
+ lavaInertia: number;
47
+ liquidAccel: number;
48
+ gravityThenDrag: boolean;
49
+ useControls: boolean;
50
50
  doSolidCollisions: boolean;
51
51
  doLiquidCollisions: boolean;
52
52
  readonly collisionBehavior: CollisionContext;
53
- constructor(ctx: IPhysics, settings: PhysicsSettings, pose: PlayerPoses, state: EntityState, entityType?: md.Entity);
54
- static FROM_BOT(ctx: IPhysics, bot: Bot, settings?: PhysicsSettings): EPhysicsCtx;
55
- static FROM_ENTITY(ctx: IPhysics, entity: Entity, settings?: PhysicsSettings): EPhysicsCtx;
56
- static FROM_ENTITY_TYPE(ctx: IPhysics, entityType: md.Entity, options?: Partial<Entity>, settings?: PhysicsSettings): EPhysicsCtx;
57
- static FROM_ENTITY_STATE(ctx: IPhysics, entityState: EntityState, entityType?: md.Entity, settings?: PhysicsSettings): EPhysicsCtx;
53
+ constructor(ctx: IPhysics, worldSettings: PhysicsWorldSettings, pose: PlayerPoses, state: EntityState, entityType?: md.Entity);
54
+ static FROM_BOT(ctx: IPhysics, bot: Bot, settings?: PhysicsWorldSettings): EPhysicsCtx;
55
+ static FROM_ENTITY(ctx: IPhysics, entity: Entity, settings?: PhysicsWorldSettings): EPhysicsCtx;
56
+ static FROM_ENTITY_TYPE(ctx: IPhysics, entityType: md.Entity, options?: Partial<Entity>, settings?: PhysicsWorldSettings): EPhysicsCtx;
57
+ static FROM_ENTITY_STATE(ctx: IPhysics, entityState: EntityState, entityType?: md.Entity, settings?: PhysicsWorldSettings): EPhysicsCtx;
58
58
  clone(): EPhysicsCtx;
59
59
  get height(): number;
60
60
  get width(): number;
@@ -24,15 +24,15 @@ function load(data) {
24
24
  }
25
25
  exports.emptyVec = new vec3_1.Vec3(0, 0, 0);
26
26
  class EPhysicsCtx {
27
- constructor(ctx, settings, pose, state, entityType = physicsUtils_1.DefaultPlayer) {
27
+ constructor(ctx, worldSettings, pose, state, entityType = physicsUtils_1.DefaultPlayer) {
28
28
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
29
29
  this.ctx = ctx;
30
- this.settings = settings;
30
+ this.worldSettings = worldSettings;
31
31
  this.pose = pose;
32
32
  this.state = state;
33
33
  this.entityType = entityType;
34
34
  this.stepHeight = 0;
35
- this.gravity = 0.0;
35
+ this.gravity = 0.08;
36
36
  this.airdrag = Math.fround(1 - 0.0);
37
37
  this.airborneInertia = 0.91;
38
38
  this.airborneAccel = 0.02;
@@ -145,25 +145,25 @@ class EPhysicsCtx {
145
145
  }
146
146
  }
147
147
  static FROM_BOT(ctx, bot, settings) {
148
- settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsSettings(bot.registry));
148
+ settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsWorldSettings(bot.registry));
149
149
  return new EPhysicsCtx(ctx, settings, getPose(bot.entity), entityState_1.EntityState.CREATE_FROM_BOT(ctx, bot));
150
150
  }
151
151
  static FROM_ENTITY(ctx, entity, settings) {
152
- settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsSettings(ctx.data));
152
+ settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsWorldSettings(ctx.data));
153
153
  return new EPhysicsCtx(ctx, settings, getPose(entity), entityState_1.EntityState.CREATE_FROM_ENTITY(ctx, entity), EPhysicsCtx.entityData[entity.name]);
154
154
  }
155
155
  static FROM_ENTITY_TYPE(ctx, entityType, options = {}, settings) {
156
156
  // unneeded for most entities, use a default.
157
- settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsSettings(ctx.data));
157
+ settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsWorldSettings(ctx.data));
158
158
  const newE = (0, physicsUtils_1.applyMdToNewEntity)(EPhysicsCtx, entityType, options);
159
159
  return new EPhysicsCtx(ctx, settings, poses_1.PlayerPoses.STANDING, entityState_1.EntityState.CREATE_FROM_ENTITY(ctx, newE), entityType);
160
160
  }
161
161
  static FROM_ENTITY_STATE(ctx, entityState, entityType, settings) {
162
- settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsSettings(ctx.data));
162
+ settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsWorldSettings(ctx.data));
163
163
  return new EPhysicsCtx(ctx, settings, entityState.pose, entityState, entityType);
164
164
  }
165
165
  clone() {
166
- return new EPhysicsCtx(this.ctx, this.settings, this.state.pose, this.state.clone(), this.entityType);
166
+ return new EPhysicsCtx(this.ctx, this.worldSettings, this.state.pose, this.state.clone(), this.entityType);
167
167
  }
168
168
  get height() {
169
169
  var _a, _b;
@@ -5,12 +5,10 @@ type BubbleColumnInfo = {
5
5
  up: number;
6
6
  maxUp: number;
7
7
  };
8
- export declare class PhysicsSettings {
8
+ export declare class PhysicsWorldSettings {
9
9
  mcData: md.IndexedData;
10
10
  entityData: md.IndexedData["entitiesByName"];
11
11
  mobData: md.IndexedData["mobs"];
12
- yawSpeed: number;
13
- pitchSpeed: number;
14
12
  playerSpeed: number;
15
13
  stepHeight: number;
16
14
  negligeableVelocity: number;
@@ -19,9 +17,6 @@ export declare class PhysicsSettings {
19
17
  honeyblockJumpSpeed: number;
20
18
  ladderMaxSpeed: number;
21
19
  ladderClimbSpeed: number;
22
- waterInertia: number;
23
- lavaInertia: number;
24
- liquidAcceleration: number;
25
20
  defaultSlipperiness: number;
26
21
  outOfLiquidImpulse: number;
27
22
  autojumpCooldown: number;
@@ -30,8 +25,6 @@ export declare class PhysicsSettings {
30
25
  slowFalling: number;
31
26
  sprintingUUID: string;
32
27
  jumpHeight: number;
33
- airborneInertia: number;
34
- airborneAcceleration: number;
35
28
  sprintSpeed: number;
36
29
  sneakSpeed: number;
37
30
  usingItemSpeed: number;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PhysicsSettings = void 0;
4
- class PhysicsSettings {
3
+ exports.PhysicsWorldSettings = void 0;
4
+ class PhysicsWorldSettings {
5
5
  constructor(mcData) {
6
- this.yawSpeed = 3.0;
7
- this.pitchSpeed = 3.0;
6
+ // public yawSpeed: number = 3.0;
7
+ // public pitchSpeed: number = 3.0;
8
8
  this.playerSpeed = 0.1;
9
9
  this.stepHeight = 0.6; // how much height can the bot step on without jump
10
10
  this.negligeableVelocity = 0.003; // actually 0.005 for 1.8; but seems fine
@@ -13,9 +13,10 @@ class PhysicsSettings {
13
13
  this.honeyblockJumpSpeed = 0.4;
14
14
  this.ladderMaxSpeed = 0.15;
15
15
  this.ladderClimbSpeed = 0.2;
16
- this.waterInertia = 0.8;
17
- this.lavaInertia = 0.5;
18
- this.liquidAcceleration = 0.02;
16
+ // public gravity: number = 0.08;
17
+ // public waterInertia: number = 0.8;
18
+ // public lavaInertia: number = 0.5;
19
+ // public liquidAcceleration: number = 0.02;
19
20
  this.defaultSlipperiness = 0.6;
20
21
  this.outOfLiquidImpulse = 0.3;
21
22
  this.autojumpCooldown = 10; // ticks (0.5s)
@@ -34,8 +35,6 @@ class PhysicsSettings {
34
35
  this.slowFalling = 0.125;
35
36
  this.sprintingUUID = "662a6b8d-da3e-4c1c-8813-96ea6097278d"; // SPEED_MODIFIER_SPRINTING_UUID is from LivingEntity.java
36
37
  this.jumpHeight = Math.fround(0.42);
37
- this.airborneInertia = 0.99;
38
- this.airborneAcceleration = 0.06;
39
38
  this.sprintSpeed = Math.fround(0.3);
40
39
  this.sneakSpeed = 0.3;
41
40
  this.usingItemSpeed = 0.2;
@@ -44,4 +43,4 @@ class PhysicsSettings {
44
43
  this.mobData = mcData["mobs"];
45
44
  }
46
45
  }
47
- exports.PhysicsSettings = PhysicsSettings;
46
+ exports.PhysicsWorldSettings = PhysicsWorldSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -2,7 +2,7 @@ import type { Entity } from "prismarine-entity";
2
2
  import type { Effect } from "mineflayer";
3
3
  import { EntityPhysics } from "../src/physics/engines";
4
4
  import { EntityState } from "../src/physics/states";
5
- import { EPhysicsCtx, PhysicsSettings } from "../src/physics/settings";
5
+ import { EPhysicsCtx, PhysicsWorldSettings } from "../src/physics/settings";
6
6
  import { applyMdToNewEntity } from "../src/util/physicsUtils";
7
7
  import { ControlStateHandler } from "../src/physics/player";
8
8
  import { Vec3 } from "vec3";
@@ -69,8 +69,23 @@ const playerCtx = EPhysicsCtx.FROM_ENTITY_STATE(physics, playerState, playerType
69
69
 
70
70
  // set control state.
71
71
  playerState.control = ControlStateHandler.DEFAULT(); // specific to players and mobs, specify control scheme to apply.
72
- playerState.control.forward = true;
73
72
 
73
+ const orgGravity = playerCtx.worldSettings.gravity;
74
+ // modify gravity to be 0.
75
+ playerCtx.worldSettings.gravity = 0;
76
+
77
+ for (let i = 0; i < 20; i++) {
78
+ physics.simulate(playerCtx, fakeWorld).applyToBot(fakePlayer as any); // (applyToBot since fakePlayer is supposed to be a bot)
79
+ // console.log(fakePlayer.entity.position, fakePlayer.entity.velocity);
80
+ }
81
+
82
+ expect(fakePlayer.entity.position).toEqual(new Vec3(0, groundLevel + 20, 0)); // it works.
83
+
84
+ // now, reset gravity.
85
+ playerCtx.worldSettings.gravity = orgGravity;
86
+
87
+ // set control for forward movement test.
88
+ playerState.control.forward = true;
74
89
 
75
90
  // simulate until on ground.
76
91
  while (!playerCtx.state.onGround) {
@@ -97,4 +112,5 @@ if (playerState.control.forward) {
97
112
  }
98
113
 
99
114
 
115
+
100
116
  console.log(fakePlayer.entity.position); //manual run.