@nxg-org/mineflayer-physics-util 1.7.1 → 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.
@@ -35,22 +35,21 @@ 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 waterGravity: number;
40
- readonly lavaGravity: number;
41
- readonly airdrag: number;
42
- readonly airborneInertia: number;
43
- readonly airborneAccel: number;
44
- readonly waterInertia: number;
45
- readonly lavaInertia: number;
46
- readonly liquidAccel: number;
47
- readonly gravityThenDrag: boolean;
48
- 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;
49
50
  doSolidCollisions: boolean;
50
51
  doLiquidCollisions: boolean;
51
52
  readonly collisionBehavior: CollisionContext;
52
- get gravity(): number;
53
- set gravity(value: number);
54
53
  constructor(ctx: IPhysics, worldSettings: PhysicsWorldSettings, pose: PlayerPoses, state: EntityState, entityType?: md.Entity);
55
54
  static FROM_BOT(ctx: IPhysics, bot: Bot, settings?: PhysicsWorldSettings): EPhysicsCtx;
56
55
  static FROM_ENTITY(ctx: IPhysics, entity: Entity, settings?: PhysicsWorldSettings): EPhysicsCtx;
@@ -24,13 +24,6 @@ function load(data) {
24
24
  }
25
25
  exports.emptyVec = new vec3_1.Vec3(0, 0, 0);
26
26
  class EPhysicsCtx {
27
- // since this can dynamically change, this needs to be accessed via the passed-in settings object.
28
- get gravity() {
29
- return this.worldSettings.gravity;
30
- }
31
- set gravity(value) {
32
- this.worldSettings.gravity = value;
33
- }
34
27
  constructor(ctx, worldSettings, pose, state, entityType = physicsUtils_1.DefaultPlayer) {
35
28
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36
29
  this.ctx = ctx;
@@ -39,6 +32,7 @@ class EPhysicsCtx {
39
32
  this.state = state;
40
33
  this.entityType = entityType;
41
34
  this.stepHeight = 0;
35
+ this.gravity = 0.08;
42
36
  this.airdrag = Math.fround(1 - 0.0);
43
37
  this.airborneInertia = 0.91;
44
38
  this.airborneAccel = 0.02;
@@ -9,9 +9,6 @@ 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
- gravity: number;
15
12
  playerSpeed: number;
16
13
  stepHeight: number;
17
14
  negligeableVelocity: number;
@@ -20,9 +17,6 @@ export declare class PhysicsWorldSettings {
20
17
  honeyblockJumpSpeed: number;
21
18
  ladderMaxSpeed: number;
22
19
  ladderClimbSpeed: number;
23
- waterInertia: number;
24
- lavaInertia: number;
25
- liquidAcceleration: number;
26
20
  defaultSlipperiness: number;
27
21
  outOfLiquidImpulse: number;
28
22
  autojumpCooldown: number;
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PhysicsWorldSettings = void 0;
4
4
  class PhysicsWorldSettings {
5
5
  constructor(mcData) {
6
- this.yawSpeed = 3.0;
7
- this.pitchSpeed = 3.0;
8
- this.gravity = 0.08;
6
+ // public yawSpeed: number = 3.0;
7
+ // public pitchSpeed: number = 3.0;
9
8
  this.playerSpeed = 0.1;
10
9
  this.stepHeight = 0.6; // how much height can the bot step on without jump
11
10
  this.negligeableVelocity = 0.003; // actually 0.005 for 1.8; but seems fine
@@ -14,9 +13,10 @@ class PhysicsWorldSettings {
14
13
  this.honeyblockJumpSpeed = 0.4;
15
14
  this.ladderMaxSpeed = 0.15;
16
15
  this.ladderClimbSpeed = 0.2;
17
- this.waterInertia = 0.8;
18
- this.lavaInertia = 0.5;
19
- 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;
20
20
  this.defaultSlipperiness = 0.6;
21
21
  this.outOfLiquidImpulse = 0.3;
22
22
  this.autojumpCooldown = 10; // ticks (0.5s)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -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.