@nxg-org/mineflayer-physics-util 1.5.2 → 1.5.4

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.
@@ -5,7 +5,7 @@ import { Entity } from "prismarine-entity";
5
5
  import { CheapEffects, CheapEnchantments, makeSupportFeature } from "../../util/physicsUtils";
6
6
  import { EPhysicsCtx } from "../settings/entityPhysicsCtx";
7
7
  import { EntityState } from "../states";
8
- export declare type MobsByName = {
8
+ export type MobsByName = {
9
9
  [mobName: string]: Entity;
10
10
  };
11
11
  export interface IPhysics {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -588,6 +592,37 @@ class EntityPhysics {
588
592
  vel.x *= inertia;
589
593
  vel.z *= inertia;
590
594
  }
595
+ else if (entity.state.elytraFlying) {
596
+ const { pitch, sinPitch, cosPitch, lookDir } = (0, physicsUtils_1.getLookingVector)(entity.state);
597
+ const horizontalSpeed = Math.sqrt(vel.x * vel.x + vel.z * vel.z);
598
+ const cosPitchSquared = cosPitch * cosPitch;
599
+ vel.y += entity.gravity * gravityMultiplier * (-1.0 + cosPitchSquared * 0.75);
600
+ // cosPitch is in [0, 1], so cosPitch > 0.0 is just to protect against
601
+ // divide by zero errors
602
+ if (vel.y < 0.0 && cosPitch > 0.0) {
603
+ const movingDownSpeedModifier = vel.y * (-0.1) * cosPitchSquared;
604
+ vel.x += lookDir.x * movingDownSpeedModifier / cosPitch;
605
+ vel.y += movingDownSpeedModifier;
606
+ vel.z += lookDir.z * movingDownSpeedModifier / cosPitch;
607
+ }
608
+ if (pitch < 0.0 && cosPitch > 0.0) {
609
+ const lookDownSpeedModifier = horizontalSpeed * (-sinPitch) * 0.04;
610
+ vel.x += -lookDir.x * lookDownSpeedModifier / cosPitch;
611
+ vel.y += lookDownSpeedModifier * 3.2;
612
+ vel.z += -lookDir.z * lookDownSpeedModifier / cosPitch;
613
+ }
614
+ if (cosPitch > 0.0) {
615
+ vel.x += (lookDir.x / cosPitch * horizontalSpeed - vel.x) * 0.1;
616
+ vel.z += (lookDir.z / cosPitch * horizontalSpeed - vel.z) * 0.1;
617
+ }
618
+ vel.x *= 0.99;
619
+ vel.y *= 0.98;
620
+ vel.z *= 0.99;
621
+ this.moveEntity(entity, world, vel.x, vel.y, vel.z);
622
+ if (entity.state.onGround) {
623
+ entity.state.elytraFlying = false;
624
+ }
625
+ }
591
626
  else {
592
627
  // Water / Lava movement
593
628
  const lastY = pos.y;
@@ -687,6 +722,19 @@ class EntityPhysics {
687
722
  entity.state.control.sprint = false;
688
723
  }
689
724
  }
725
+ entity.state.elytraFlying = entity.state.elytraFlying && entity.state.elytraEquipped && !entity.state.onGround && !entity.state.levitation;
726
+ if (entity.state.fireworkRocketDuration > 0) {
727
+ if (!entity.state.elytraFlying) {
728
+ entity.state.fireworkRocketDuration = 0;
729
+ }
730
+ else {
731
+ const { lookDir } = (0, physicsUtils_1.getLookingVector)(entity.state);
732
+ vel.x += lookDir.x * 0.1 + (lookDir.x * 1.5 - vel.x) * 0.5;
733
+ vel.y += lookDir.y * 0.1 + (lookDir.y * 1.5 - vel.y) * 0.5;
734
+ vel.z += lookDir.z * 0.1 + (lookDir.z * 1.5 - vel.z) * 0.5;
735
+ --entity.state.fireworkRocketDuration;
736
+ }
737
+ }
690
738
  this.moveEntityWithHeading(entity, strafe, forward, world);
691
739
  return entity.state;
692
740
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,9 +1,9 @@
1
- declare type Modifier = {
1
+ type Modifier = {
2
2
  uuid: string;
3
3
  operation: number;
4
4
  amount: number;
5
5
  };
6
- declare type Attribute = {
6
+ type Attribute = {
7
7
  value: number;
8
8
  modifiers: Modifier[];
9
9
  };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -7,13 +7,13 @@ import { IPhysics } from "../engines/IPhysics";
7
7
  import { EntityState } from "../states/entityState";
8
8
  import { PlayerPoses } from "../states/poses";
9
9
  export declare const emptyVec: Vec3;
10
- declare type PlayerPoseContext = {
10
+ type PlayerPoseContext = {
11
11
  [key in PlayerPoses]: {
12
12
  width: number;
13
13
  height: number;
14
14
  };
15
15
  };
16
- declare type CollisionContext = {
16
+ type CollisionContext = {
17
17
  blockEffects: boolean;
18
18
  affectedAfterCollision: boolean;
19
19
  };
@@ -12,7 +12,7 @@ const entityState_1 = require("../states/entityState");
12
12
  const poses_1 = require("../states/poses");
13
13
  const entity_physics_json_1 = __importDefault(require("../info/entity_physics.json"));
14
14
  function getPose(entity) {
15
- const pose = entity.metadata.find((e) => { var _a; return ((_a = e) === null || _a === void 0 ? void 0 : _a.type) === 18; });
15
+ const pose = entity.metadata.find((e) => (e === null || e === void 0 ? void 0 : e.type) === 18);
16
16
  return pose ? pose.value : poses_1.PlayerPoses.STANDING;
17
17
  }
18
18
  function load(data) {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,5 +1,5 @@
1
1
  import md from "minecraft-data";
2
- declare type BubbleColumnInfo = {
2
+ type BubbleColumnInfo = {
3
3
  down: number;
4
4
  maxDown: number;
5
5
  up: number;
@@ -1,11 +1,11 @@
1
1
  import { AABB } from "@nxg-org/mineflayer-util-plugin";
2
- import type { Entity } from "prismarine-entity";
3
2
  import type { Bot, Effect } from "mineflayer";
4
3
  import { Vec3 } from "vec3";
5
4
  import { ControlStateHandler } from "../player/playerControls";
6
5
  import { PlayerState } from "./playerState";
7
6
  import { PlayerPoses } from "./poses";
8
7
  import { IPhysics } from "../engines";
8
+ import { Entity } from "prismarine-entity";
9
9
  export interface EntityStateBuilder {
10
10
  height: number;
11
11
  halfWidth: number;
@@ -19,6 +19,9 @@ export interface EntityStateBuilder {
19
19
  isInWater?: boolean;
20
20
  isInLava?: boolean;
21
21
  isInWeb?: boolean;
22
+ elytraFlying?: boolean;
23
+ elytraEquipped?: boolean;
24
+ fireworkRocketDuration?: number;
22
25
  sneakCollision?: boolean;
23
26
  isCollidedHorizontally?: boolean;
24
27
  isCollidedVertically?: boolean;
@@ -45,12 +48,14 @@ export declare class EntityState implements EntityStateBuilder {
45
48
  isInWater: boolean;
46
49
  isInLava: boolean;
47
50
  isInWeb: boolean;
51
+ elytraFlying: boolean;
52
+ elytraEquipped: boolean;
48
53
  isCollidedHorizontally: boolean;
49
54
  isCollidedVertically: boolean;
50
55
  jumpTicks: number;
51
56
  jumpQueued: boolean;
52
57
  sneakCollision: boolean;
53
- attributes: any;
58
+ attributes: Entity["attributes"];
54
59
  isUsingItem: boolean;
55
60
  isUsingMainHand: boolean;
56
61
  isUsingOffHand: boolean;
@@ -63,6 +68,7 @@ export declare class EntityState implements EntityStateBuilder {
63
68
  depthStrider: number;
64
69
  effects: Effect[];
65
70
  pose: PlayerPoses;
71
+ fireworkRocketDuration: number;
66
72
  constructor(ctx: IPhysics, height: number, halfWidth: number, pos: Vec3, vel: Vec3, onGround: boolean, yaw: number, pitch: number, control?: ControlStateHandler);
67
73
  static CREATE_FROM_BOT(ctx: IPhysics, bot: Bot): EntityState;
68
74
  static CREATE_FROM_ENTITY(ctx: IPhysics, entity: Entity): EntityState;
@@ -29,12 +29,15 @@ class EntityState {
29
29
  this.isInWater = false;
30
30
  this.isInLava = false;
31
31
  this.isInWeb = false;
32
+ this.elytraFlying = false;
33
+ this.elytraEquipped = false;
32
34
  this.isCollidedHorizontally = false;
33
35
  this.isCollidedVertically = false;
34
36
  this.sneakCollision = false; //TODO
35
37
  //not sure what to do here, ngl.
36
38
  this.jumpTicks = 0;
37
39
  this.jumpQueued = false;
40
+ this.fireworkRocketDuration = 0;
38
41
  // Input only (not modified)
39
42
  this.attributes = {}; //TODO
40
43
  this.isUsingItem = false;
@@ -74,10 +77,11 @@ class EntityState {
74
77
  this.control = playerControls_1.ControlStateHandler.COPY_BOT(bot);
75
78
  this.jumpTicks = bot.jumpTicks;
76
79
  this.jumpQueued = bot.jumpQueued;
80
+ this.fireworkRocketDuration = bot.fireworkRocketDuration;
77
81
  return this;
78
82
  }
79
83
  updateFromEntity(entity, all = false) {
80
- var _a, _b;
84
+ var _a, _b, _c;
81
85
  if (all) {
82
86
  // most mobs don't have this defined, so ignore it (only self does).
83
87
  this.vel = entity.velocity.clone();
@@ -85,10 +89,12 @@ class EntityState {
85
89
  this.isInWater = entity.isInWater;
86
90
  this.isInLava = entity.isInLava;
87
91
  this.isInWeb = entity.isInWeb;
92
+ this.elytraFlying = entity.elytraFlying;
88
93
  this.isCollidedHorizontally = entity.isCollidedHorizontally;
89
94
  this.isCollidedVertically = entity.isCollidedVertically;
90
95
  this.sneakCollision = false; //TODO
91
96
  this.attributes || (this.attributes = entity.attributes);
97
+ this.elytraEquipped = entity.equipment[3] && ((_a = entity.equipment[3]) === null || _a === void 0 ? void 0 : _a.name.includes("elytra"));
92
98
  }
93
99
  this.pos = entity.position.clone();
94
100
  //not sure what to do here, ngl.
@@ -114,7 +120,7 @@ class EntityState {
114
120
  const boots = entity.equipment[5];
115
121
  if (boots && boots.nbt) {
116
122
  const simplifiedNbt = prismarine_nbt_1.default.simplify(boots.nbt);
117
- const enchantments = (_b = (_a = simplifiedNbt.Enchantments) !== null && _a !== void 0 ? _a : simplifiedNbt.ench) !== null && _b !== void 0 ? _b : [];
123
+ const enchantments = (_c = (_b = simplifiedNbt.Enchantments) !== null && _b !== void 0 ? _b : simplifiedNbt.ench) !== null && _c !== void 0 ? _c : [];
118
124
  this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
119
125
  }
120
126
  else {
@@ -124,7 +130,7 @@ class EntityState {
124
130
  return this;
125
131
  }
126
132
  updateFromRaw(other) {
127
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
133
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
128
134
  this.onGround = (_a = other.onGround) !== null && _a !== void 0 ? _a : this.onGround;
129
135
  this.sneakCollision = (_b = other.sneakCollision) !== null && _b !== void 0 ? _b : this.sneakCollision;
130
136
  this.isUsingItem = (_c = other.isUsingItem) !== null && _c !== void 0 ? _c : this.isUsingItem;
@@ -136,6 +142,13 @@ class EntityState {
136
142
  this.levitation = (_j = other.levitation) !== null && _j !== void 0 ? _j : this.levitation;
137
143
  this.depthStrider = (_k = other.depthStrider) !== null && _k !== void 0 ? _k : this.depthStrider;
138
144
  this.effects = (_l = other.effects) !== null && _l !== void 0 ? _l : this.effects;
145
+ this.isCollidedHorizontally = (_m = other.isCollidedHorizontally) !== null && _m !== void 0 ? _m : this.isCollidedHorizontally;
146
+ this.isCollidedVertically = (_o = other.isCollidedVertically) !== null && _o !== void 0 ? _o : this.isCollidedVertically;
147
+ this.isInWater = (_p = other.isInWater) !== null && _p !== void 0 ? _p : this.isInWater;
148
+ this.isInLava = (_q = other.isInLava) !== null && _q !== void 0 ? _q : this.isInLava;
149
+ this.isInWeb = (_r = other.isInWeb) !== null && _r !== void 0 ? _r : this.isInWeb;
150
+ this.elytraFlying = (_s = other.elytraFlying) !== null && _s !== void 0 ? _s : this.elytraFlying;
151
+ this.elytraEquipped = (_t = other.elytraEquipped) !== null && _t !== void 0 ? _t : this.elytraEquipped;
139
152
  return this;
140
153
  }
141
154
  applyToBot(bot) {
@@ -145,6 +158,19 @@ class EntityState {
145
158
  bot.entity.yaw = this.yaw;
146
159
  bot.entity.pitch = this.pitch;
147
160
  bot.controlState = this.control;
161
+ bot.jumpTicks = this.jumpTicks;
162
+ bot.jumpQueued = this.jumpQueued;
163
+ bot.fireworkRocketDuration = this.fireworkRocketDuration;
164
+ bot.entity.isInWater = this.isInWater;
165
+ bot.entity.isInLava = this.isInLava;
166
+ bot.entity.isInWeb = this.isInWeb;
167
+ bot.entity.elytraFlying = this.elytraFlying;
168
+ bot.entity.elytraEquipped = this.elytraEquipped;
169
+ bot.entity.isCollidedHorizontally = this.isCollidedHorizontally;
170
+ bot.entity.isCollidedVertically = this.isCollidedVertically;
171
+ bot.entity.sneakCollision = this.sneakCollision;
172
+ bot.entity.pose = this.pose;
173
+ bot.controlState = this.control;
148
174
  return this;
149
175
  }
150
176
  /**
@@ -168,6 +194,9 @@ class EntityState {
168
194
  other.isInWater = this.isInWater;
169
195
  other.isInLava = this.isInLava;
170
196
  other.isInWeb = this.isInWeb;
197
+ other.elytraFlying = this.elytraFlying;
198
+ other.elytraEquipped = this.elytraEquipped;
199
+ other.fireworkRocketDuration = this.fireworkRocketDuration;
171
200
  other.jumpTicks = this.jumpTicks;
172
201
  other.jumpQueued = this.jumpQueued;
173
202
  other.sneakCollision = this.sneakCollision;
@@ -196,6 +225,9 @@ class EntityState {
196
225
  this.isInWater = other.isInWater;
197
226
  this.isInLava = other.isInLava;
198
227
  this.isInWeb = other.isInWeb;
228
+ this.elytraFlying = other.elytraFlying;
229
+ this.elytraEquipped = other.elytraEquipped;
230
+ this.fireworkRocketDuration = other.fireworkRocketDuration;
199
231
  this.jumpTicks = other.jumpTicks;
200
232
  this.jumpQueued = other.jumpQueued;
201
233
  this.sneakCollision = other.sneakCollision;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -4,6 +4,7 @@ import { Vec3 } from "vec3";
4
4
  import { ControlStateHandler } from "../player/playerControls";
5
5
  import { EntityStateBuilder } from "./entityState";
6
6
  import { IPhysics } from "../engines/IPhysics";
7
+ import type { Entity } from "prismarine-entity";
7
8
  export declare class EntityDimensions {
8
9
  readonly width: number;
9
10
  readonly height: number;
@@ -32,12 +33,15 @@ export declare class PlayerState implements EntityStateBuilder {
32
33
  isInWater: boolean;
33
34
  isInLava: boolean;
34
35
  isInWeb: boolean;
36
+ elytraFlying: boolean;
37
+ elytraEquipped: boolean;
38
+ fireworkRocketDuration: number;
35
39
  isCollidedHorizontally: boolean;
36
40
  isCollidedVertically: boolean;
37
41
  jumpTicks: number;
38
42
  jumpQueued: boolean;
39
43
  sneakCollision: boolean;
40
- attributes: any;
44
+ attributes: Entity["attributes"];
41
45
  yaw: number;
42
46
  pitch: number;
43
47
  control: ControlStateHandler;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -67,7 +71,7 @@ exports.EntityDimensions = EntityDimensions;
67
71
  */
68
72
  class PlayerState {
69
73
  constructor(ctx, bot, control) {
70
- var _a, _b, _c, _d;
74
+ var _a, _b, _c, _d, _e;
71
75
  this.height = 1.62;
72
76
  this.halfWidth = 0.3;
73
77
  this.supportFeature = (0, physicsUtils_1.makeSupportFeature)(ctx.data);
@@ -79,12 +83,15 @@ class PlayerState {
79
83
  this.isInWater = bot.entity.isInWater;
80
84
  this.isInLava = bot.entity.isInLava;
81
85
  this.isInWeb = bot.entity.isInWeb;
86
+ this.elytraFlying = bot.entity.elytraFlying;
87
+ this.elytraEquipped = ((_a = bot.inventory.slots[bot.getEquipmentDestSlot('torso')]) === null || _a === void 0 ? void 0 : _a.name) === 'elytra';
88
+ this.fireworkRocketDuration = bot.fireworkRocketDuration;
82
89
  this.isCollidedHorizontally = bot.entity.isCollidedHorizontally;
83
90
  this.isCollidedVertically = bot.entity.isCollidedVertically;
84
91
  this.sneakCollision = false; //TODO
85
92
  //not sure what to do here, ngl.
86
- this.jumpTicks = (_a = bot.jumpTicks) !== null && _a !== void 0 ? _a : 0;
87
- this.jumpQueued = (_b = bot.jumpQueued) !== null && _b !== void 0 ? _b : false;
93
+ this.jumpTicks = (_b = bot.jumpTicks) !== null && _b !== void 0 ? _b : 0;
94
+ this.jumpQueued = (_c = bot.jumpQueued) !== null && _c !== void 0 ? _c : false;
88
95
  // Input only (not modified)
89
96
  this.attributes = bot.entity.attributes;
90
97
  this.yaw = bot.entity.yaw;
@@ -113,7 +120,7 @@ class PlayerState {
113
120
  const boots = bot.entity.equipment[5];
114
121
  if (boots && boots.nbt) {
115
122
  const simplifiedNbt = nbt.simplify(boots.nbt);
116
- const enchantments = (_d = (_c = simplifiedNbt.Enchantments) !== null && _c !== void 0 ? _c : simplifiedNbt.ench) !== null && _d !== void 0 ? _d : [];
123
+ const enchantments = (_e = (_d = simplifiedNbt.Enchantments) !== null && _d !== void 0 ? _d : simplifiedNbt.ench) !== null && _e !== void 0 ? _e : [];
117
124
  this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
118
125
  }
119
126
  else {
@@ -121,7 +128,7 @@ class PlayerState {
121
128
  }
122
129
  }
123
130
  update(bot, control) {
124
- var _a, _b, _c, _d;
131
+ var _a, _b, _c, _d, _e;
125
132
  // const bot.entity = bot instanceof bot.entity ? bot : bot.entity;
126
133
  // Input / Outputs
127
134
  this.pos = bot.entity.position.clone();
@@ -130,11 +137,14 @@ class PlayerState {
130
137
  this.isInWater = bot.entity.isInWater;
131
138
  this.isInLava = bot.entity.isInLava;
132
139
  this.isInWeb = bot.entity.isInWeb;
140
+ this.elytraFlying = bot.entity.elytraFlying;
141
+ this.elytraEquipped = ((_a = bot.inventory.slots[bot.getEquipmentDestSlot('torso')]) === null || _a === void 0 ? void 0 : _a.name) === 'elytra';
142
+ this.fireworkRocketDuration = bot.fireworkRocketDuration;
133
143
  this.isCollidedHorizontally = bot.entity.isCollidedHorizontally;
134
144
  this.isCollidedVertically = bot.entity.isCollidedVertically;
135
145
  // dunno what to do about these, ngl.
136
- this.jumpTicks = (_a = bot.jumpTicks) !== null && _a !== void 0 ? _a : 0;
137
- this.jumpQueued = (_b = bot.jumpQueued) !== null && _b !== void 0 ? _b : false;
146
+ this.jumpTicks = (_b = bot.jumpTicks) !== null && _b !== void 0 ? _b : 0;
147
+ this.jumpQueued = (_c = bot.jumpQueued) !== null && _c !== void 0 ? _c : false;
138
148
  // Input only (not modified)
139
149
  this.attributes = bot.entity.attributes;
140
150
  this.yaw = bot.entity.yaw;
@@ -156,7 +166,7 @@ class PlayerState {
156
166
  const boots = bot.entity.equipment[5];
157
167
  if (boots && boots.nbt) {
158
168
  const simplifiedNbt = nbt.simplify(boots.nbt);
159
- const enchantments = (_d = (_c = simplifiedNbt.Enchantments) !== null && _c !== void 0 ? _c : simplifiedNbt.ench) !== null && _d !== void 0 ? _d : [];
169
+ const enchantments = (_e = (_d = simplifiedNbt.Enchantments) !== null && _d !== void 0 ? _d : simplifiedNbt.ench) !== null && _e !== void 0 ? _e : [];
160
170
  this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
161
171
  }
162
172
  else {
@@ -172,6 +182,9 @@ class PlayerState {
172
182
  bot.entity.isInWater = this.isInWater;
173
183
  bot.entity.isInLava = this.isInLava;
174
184
  bot.entity.isInWeb = this.isInWeb;
185
+ bot.entity.elytraFlying = this.elytraFlying;
186
+ bot.entity.elytraEquipped = this.elytraEquipped;
187
+ bot.fireworkRocketDuration = this.fireworkRocketDuration;
175
188
  bot.entity.isCollidedHorizontally = this.isCollidedHorizontally;
176
189
  bot.entity.isCollidedVertically = this.isCollidedVertically;
177
190
  // dunno what to do about these, ngl.
@@ -190,6 +203,9 @@ class PlayerState {
190
203
  tmp.isInWater = this.isInWater;
191
204
  tmp.isInLava = this.isInLava;
192
205
  tmp.isInWeb = this.isInWeb;
206
+ tmp.elytraFlying = this.elytraFlying;
207
+ tmp.elytraEquipped = this.elytraEquipped;
208
+ tmp.fireworkRocketDuration = this.fireworkRocketDuration;
193
209
  tmp.isCollidedHorizontally = this.isCollidedHorizontally;
194
210
  tmp.isCollidedVertically = this.isCollidedVertically;
195
211
  tmp.sneakCollision = false; //TODO
@@ -224,6 +240,9 @@ class PlayerState {
224
240
  this.isInWater = other.isInWater;
225
241
  this.isInLava = other.isInLava;
226
242
  this.isInWeb = other.isInWeb;
243
+ this.elytraFlying = other.elytraFlying;
244
+ this.elytraEquipped = other.elytraEquipped;
245
+ this.fireworkRocketDuration = other.fireworkRocketDuration;
227
246
  this.isCollidedHorizontally = other.isCollidedHorizontally;
228
247
  this.isCollidedVertically = other.isCollidedVertically;
229
248
  this.sneakCollision = false; //TODO
@@ -4,9 +4,9 @@ import { EntityState } from "../physics/states";
4
4
  import { IPhysics } from "../physics/engines";
5
5
  import { Entity } from "prismarine-entity";
6
6
  import { Vec3 } from "vec3";
7
- export declare type SimulationGoal = (state: EntityState, ticks: number) => boolean | ((state: EntityState) => boolean);
8
- export declare type OnGoalReachFunction = (state: EntityState) => void;
9
- export declare type Controller = (state: EntityState, ticks: number) => void;
7
+ export type SimulationGoal = (state: EntityState, ticks: number) => boolean | ((state: EntityState) => boolean);
8
+ export type OnGoalReachFunction = (state: EntityState) => void;
9
+ export type Controller = (state: EntityState, ticks: number) => void;
10
10
  export declare class BaseSimulator {
11
11
  readonly ctx: IPhysics;
12
12
  constructor(ctx: IPhysics);
@@ -3,4 +3,4 @@ import type { Entity } from "prismarine-entity";
3
3
  import type md from "minecraft-data";
4
4
  export * from "./baseSimulator";
5
5
  export * from "./basicSim";
6
- export declare type SimObjects = Entity | md.Entity | EPhysicsCtx;
6
+ export type SimObjects = Entity | md.Entity | EPhysicsCtx;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -2,6 +2,8 @@ import { Entity } from "prismarine-entity";
2
2
  import { EPhysicsCtx } from "../physics/settings";
3
3
  import { AABB } from "@nxg-org/mineflayer-util-plugin";
4
4
  import md from "minecraft-data";
5
+ import { EntityState } from "../physics/states";
6
+ import { Vec3 } from "vec3";
5
7
  export declare function makeSupportFeature(mcData: md.IndexedData): (feature: string) => boolean;
6
8
  export declare const DefaultPlayer: md.Entity;
7
9
  export declare function applyMdToNewEntity(ctx: typeof EPhysicsCtx, entityType?: md.Entity, options?: Partial<Entity>): Entity;
@@ -31,3 +33,15 @@ export declare function getEnchantmentNamesForVersion(supportFeature: ReturnType
31
33
  depthStriderEnchantmentName: string;
32
34
  };
33
35
  export declare function getBetweenRectangle(src: AABB, dest: AABB): AABB;
36
+ export declare function getLookingVector(entity: EntityState): {
37
+ yaw: number;
38
+ pitch: number;
39
+ sinYaw: number;
40
+ cosYaw: number;
41
+ sinPitch: number;
42
+ cosPitch: number;
43
+ lookX: number;
44
+ lookY: number;
45
+ lookZ: number;
46
+ lookDir: Vec3;
47
+ };
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBetweenRectangle = exports.getEnchantmentNamesForVersion = exports.getStatusEffectNamesForVersion = exports.whichHandIsEntityUsingBoolean = exports.whichHandIsEntityUsing = exports.isEntityUsingItem = exports.CheapEnchantments = exports.CheapEffects = exports.applyMdToNewEntity = exports.DefaultPlayer = exports.makeSupportFeature = void 0;
6
+ exports.getLookingVector = exports.getBetweenRectangle = exports.getEnchantmentNamesForVersion = exports.getStatusEffectNamesForVersion = exports.whichHandIsEntityUsingBoolean = exports.whichHandIsEntityUsing = exports.isEntityUsingItem = exports.CheapEnchantments = exports.CheapEffects = exports.applyMdToNewEntity = exports.DefaultPlayer = exports.makeSupportFeature = void 0;
7
7
  const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
8
8
  const features_json_1 = __importDefault(require("../physics/info/features.json"));
9
+ const vec3_1 = require("vec3");
9
10
  function makeSupportFeature(mcData) {
10
11
  return (feature) => features_json_1.default.some(({ name, versions }) => name === feature && versions.includes(mcData.version.majorVersion));
11
12
  }
@@ -103,3 +104,55 @@ function getBetweenRectangle(src, dest) {
103
104
  return innerAABB;
104
105
  }
105
106
  exports.getBetweenRectangle = getBetweenRectangle;
107
+ function getLookingVector(entity) {
108
+ // given a yaw pitch, we need the looking vector
109
+ // yaw is right handed rotation about y (up) starting from -z (north)
110
+ // pitch is -90 looking down, 90 looking up, 0 looking at horizon
111
+ // lets get its coordinate system.
112
+ // let x' = -z (north)
113
+ // let y' = -x (west)
114
+ // let z' = y (up)
115
+ // the non normalized looking vector in x', y', z' space is
116
+ // x' is cos(yaw)
117
+ // y' is sin(yaw)
118
+ // z' is tan(pitch)
119
+ // substituting back in x, y, z, we get the looking vector in the normal x, y, z space
120
+ // -z = cos(yaw) => z = -cos(yaw)
121
+ // -x = sin(yaw) => x = -sin(yaw)
122
+ // y = tan(pitch)
123
+ // normalizing the vectors, we divide each by |sqrt(x*x + y*y + z*z)|
124
+ // x*x + z*z = sin^2 + cos^2 = 1
125
+ // so |sqrt(xx+yy+zz)| = |sqrt(1+tan^2(pitch))|
126
+ // = |sqrt(1+sin^2(pitch)/cos^2(pitch))|
127
+ // = |sqrt((cos^2+sin^2)/cos^2(pitch))|
128
+ // = |sqrt(1/cos^2(pitch))|
129
+ // = |+/- 1/cos(pitch)|
130
+ // = 1/cos(pitch) since pitch in [-90, 90]
131
+ // the looking vector is therefore
132
+ // x = -sin(yaw) * cos(pitch)
133
+ // y = tan(pitch) * cos(pitch) = sin(pitch)
134
+ // z = -cos(yaw) * cos(pitch)
135
+ const yaw = entity.yaw;
136
+ const pitch = entity.pitch;
137
+ const sinYaw = Math.sin(yaw);
138
+ const cosYaw = Math.cos(yaw);
139
+ const sinPitch = Math.sin(pitch);
140
+ const cosPitch = Math.cos(pitch);
141
+ const lookX = -sinYaw * cosPitch;
142
+ const lookY = sinPitch;
143
+ const lookZ = -cosYaw * cosPitch;
144
+ const lookDir = new vec3_1.Vec3(lookX, lookY, lookZ);
145
+ return {
146
+ yaw,
147
+ pitch,
148
+ sinYaw,
149
+ cosYaw,
150
+ sinPitch,
151
+ cosPitch,
152
+ lookX,
153
+ lookY,
154
+ lookZ,
155
+ lookDir
156
+ };
157
+ }
158
+ exports.getLookingVector = getLookingVector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -21,13 +21,13 @@
21
21
  "test": "ts-node -T tests/fakeWorld.ts"
22
22
  },
23
23
  "dependencies": {
24
- "@nxg-org/mineflayer-util-plugin": "^1.7.11"
24
+ "@nxg-org/mineflayer-util-plugin": "^1.8.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "expect": "^29.5.0",
28
- "mineflayer": "^4.9.0",
28
+ "mineflayer": "^4.17.0",
29
29
  "mineflayer-pathfinder": "^2.4.4",
30
- "prismarine-physics": "^1.6.0",
30
+ "prismarine-entity": "^2.4.0",
31
31
  "typescript": "^4.5.5"
32
32
  }
33
33
  }