@nxg-org/mineflayer-physics-util 1.5.0 → 1.5.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "print.colourScheme": "GitHub"
3
+ }
package/dist/index.d.ts CHANGED
@@ -4,7 +4,6 @@ import { PhysicsUtilWrapper } from "./wrapper";
4
4
  declare module "mineflayer" {
5
5
  interface Bot {
6
6
  physicsUtil: PhysicsUtilWrapper;
7
- registry: IndexedData;
8
7
  }
9
8
  }
10
9
  export default function loader(bot: Bot): void;
@@ -165,7 +165,7 @@ class EntityPhysics {
165
165
  const oldVelY = dy;
166
166
  let oldVelZ = dz;
167
167
  const oldOldVelZ = dz;
168
- if (entity.useControls && entity.state.controlState.sneak && entity.state.onGround) {
168
+ if (entity.useControls && entity.state.control.sneak && entity.state.onGround) {
169
169
  const step = 0.05;
170
170
  // In the 3 loops bellow, y offset should be -1, but that doesnt reproduce vanilla behavior.
171
171
  for (; dx !== 0 && this.getSurroundingBBs(this.getEntityBB(entity, pos).translate(dx, 0, 0), world).length === 0; oldVelX = dx) {
@@ -293,7 +293,7 @@ class EntityPhysics {
293
293
  if (entity.collisionBehavior.blockEffects &&
294
294
  blockAtFeet &&
295
295
  blockAtFeet.type === this.slimeBlockId &&
296
- !entity.state.controlState.sneak) {
296
+ !entity.state.control.sneak) {
297
297
  vel.y = -vel.y;
298
298
  }
299
299
  else {
@@ -540,7 +540,7 @@ class EntityPhysics {
540
540
  // setSprinting in LivingEntity.java
541
541
  //TODO: Generalize to all entities.
542
542
  playerSpeedAttribute = attributes.deleteAttributeModifier(playerSpeedAttribute, physicsSettings_1.PhysicsSettings.sprintingUUID); // always delete sprinting (if it exists)
543
- if (entity.state.controlState.sprint) {
543
+ if (entity.state.control.sprint) {
544
544
  if (!attributes.checkAttributeModifier(playerSpeedAttribute, physicsSettings_1.PhysicsSettings.sprintingUUID)) {
545
545
  playerSpeedAttribute = attributes.addAttributeModifier(playerSpeedAttribute, {
546
546
  uuid: physicsSettings_1.PhysicsSettings.sprintingUUID,
@@ -560,12 +560,12 @@ class EntityPhysics {
560
560
  if (entity.collisionBehavior.blockEffects && this.isOnLadder(pos, world)) {
561
561
  vel.x = math.clamp(-physicsSettings_1.PhysicsSettings.ladderMaxSpeed, vel.x, physicsSettings_1.PhysicsSettings.ladderMaxSpeed);
562
562
  vel.z = math.clamp(-physicsSettings_1.PhysicsSettings.ladderMaxSpeed, vel.z, physicsSettings_1.PhysicsSettings.ladderMaxSpeed);
563
- vel.y = Math.max(vel.y, entity.state.controlState.sneak ? 0 : -physicsSettings_1.PhysicsSettings.ladderMaxSpeed);
563
+ vel.y = Math.max(vel.y, entity.state.control.sneak ? 0 : -physicsSettings_1.PhysicsSettings.ladderMaxSpeed);
564
564
  }
565
565
  this.moveEntity(entity, vel.x, vel.y, vel.z, world);
566
566
  if (entity.collisionBehavior.blockEffects &&
567
567
  this.isOnLadder(pos, world) &&
568
- (entity.state.isCollidedHorizontally || (this.supportFeature("climbUsingJump") && entity.state.controlState.jump))) {
568
+ (entity.state.isCollidedHorizontally || (this.supportFeature("climbUsingJump") && entity.state.control.jump))) {
569
569
  vel.y = physicsSettings_1.PhysicsSettings.ladderClimbSpeed; // climb ladder
570
570
  }
571
571
  // Not adding an additional function call. No point.
@@ -647,7 +647,7 @@ class EntityPhysics {
647
647
  let forward = 0;
648
648
  // Handle inputs
649
649
  if (entity.useControls) {
650
- if (entity.state.controlState.jump || entity.state.jumpQueued) {
650
+ if (entity.state.control.jump || entity.state.jumpQueued) {
651
651
  if (entity.state.jumpTicks > 0)
652
652
  entity.state.jumpTicks--;
653
653
  if (entity.state.isInWater || entity.state.isInLava) {
@@ -660,7 +660,7 @@ class EntityPhysics {
660
660
  if (entity.state.jumpBoost > 0) {
661
661
  vel.y += 0.1 * entity.state.jumpBoost;
662
662
  }
663
- if (entity.state.controlState.sprint) {
663
+ if (entity.state.control.sprint) {
664
664
  const yaw = Math.PI - entity.state.yaw;
665
665
  vel.x -= Math.sin(yaw) * 0.2;
666
666
  vel.z += Math.cos(yaw) * 0.2;
@@ -673,18 +673,18 @@ class EntityPhysics {
673
673
  }
674
674
  entity.state.jumpQueued = false;
675
675
  strafe =
676
- (entity.state.controlState.left - entity.state.controlState.right) * 0.98;
676
+ (entity.state.control.left - entity.state.control.right) * 0.98;
677
677
  forward =
678
- (entity.state.controlState.forward - entity.state.controlState.back) * 0.98;
679
- if (entity.state.controlState.sneak) {
678
+ (entity.state.control.forward - entity.state.control.back) * 0.98;
679
+ if (entity.state.control.sneak) {
680
680
  strafe *= physicsSettings_1.PhysicsSettings.sneakSpeed;
681
681
  forward *= physicsSettings_1.PhysicsSettings.sneakSpeed;
682
- entity.state.controlState.sprint = false;
682
+ entity.state.control.sprint = false;
683
683
  }
684
684
  if (entity.state.isUsingItem) {
685
685
  strafe *= physicsSettings_1.PhysicsSettings.usingItemSpeed;
686
686
  forward *= physicsSettings_1.PhysicsSettings.usingItemSpeed;
687
- entity.state.controlState.sprint = false;
687
+ entity.state.control.sprint = false;
688
688
  }
689
689
  }
690
690
  this.moveEntityWithHeading(entity, strafe, forward, world);
@@ -20,7 +20,7 @@ class ControlStateHandler {
20
20
  return new ControlStateHandler(bot.controlState.forward, bot.controlState.back, bot.controlState.left, bot.controlState.right, bot.controlState.jump, bot.controlState.sprint, bot.controlState.sneak);
21
21
  }
22
22
  static COPY_STATE(state) {
23
- return new ControlStateHandler(state.controlState.forward, state.controlState.back, state.controlState.left, state.controlState.right, state.controlState.jump, state.controlState.sprint, state.controlState.sneak);
23
+ return new ControlStateHandler(state.control.forward, state.control.back, state.control.left, state.control.right, state.control.jump, state.control.sprint, state.control.sneak);
24
24
  }
25
25
  set(state, wanted) {
26
26
  this[state] = wanted;
@@ -86,7 +86,7 @@ class PlayerControls extends ControlStateHandler {
86
86
  return new PlayerControls(bot.controlState.forward, bot.controlState.back, bot.controlState.left, bot.controlState.right, bot.controlState.jump, bot.controlState.sprint, bot.controlState.sneak, bot.util.entity.isMainHandActive(), bot.util.entity.isOffHandActive(), bot.entity.yaw, bot.entity.pitch, false);
87
87
  }
88
88
  static COPY_STATE(state) {
89
- return new PlayerControls(state.controlState.forward, state.controlState.back, state.controlState.left, state.controlState.right, state.controlState.jump, state.controlState.sprint, state.controlState.sneak, state.isUsingMainHand, state.isUsingOffHand, state.yaw, state.pitch, false);
89
+ return new PlayerControls(state.control.forward, state.control.back, state.control.left, state.control.right, state.control.jump, state.control.sprint, state.control.sneak, state.isUsingMainHand, state.isUsingOffHand, state.yaw, state.pitch, false);
90
90
  }
91
91
  clone() {
92
92
  return new PlayerControls(this.forward, this.back, this.left, this.right, this.jump, this.sprint, this.sneak, this.leftClick, this.rightClick, this.yaw, this.pitch, this.force);
@@ -43,8 +43,8 @@ class EPhysicsCtx {
43
43
  blockEffects: false,
44
44
  affectedAfterCollision: true,
45
45
  };
46
- this.position = state.position;
47
- this.velocity = state.velocity;
46
+ this.position = state.pos;
47
+ this.velocity = state.vel;
48
48
  if (entityType.type === "player" || !!EPhysicsCtx.mobData[entityType.id]) {
49
49
  // @ts-expect-error
50
50
  const additional = entity_physics_json_1.default.living_entities[entityType.type];
@@ -150,18 +150,18 @@ class EPhysicsCtx {
150
150
  return new EPhysicsCtx(this.ctx, this.state.pose, this.state.clone(), this.entityType);
151
151
  }
152
152
  get height() {
153
- var _a;
153
+ var _a, _b;
154
154
  if (this.entityType.type === "player") {
155
- return EPhysicsCtx.playerPoseContext[this.pose].height;
155
+ return EPhysicsCtx.playerPoseContext[(_a = this.pose) !== null && _a !== void 0 ? _a : 0].height;
156
156
  }
157
- return (_a = this.entityType.height) !== null && _a !== void 0 ? _a : 0;
157
+ return (_b = this.entityType.height) !== null && _b !== void 0 ? _b : 0;
158
158
  }
159
159
  get width() {
160
- var _a;
160
+ var _a, _b;
161
161
  if (this.entityType.type === "player") {
162
- return EPhysicsCtx.playerPoseContext[this.pose].width;
162
+ return EPhysicsCtx.playerPoseContext[(_a = this.pose) !== null && _a !== void 0 ? _a : 0].width;
163
163
  }
164
- return (_a = this.entityType.width) !== null && _a !== void 0 ? _a : 0;
164
+ return (_b = this.entityType.width) !== null && _b !== void 0 ? _b : 0;
165
165
  }
166
166
  getHalfWidth() {
167
167
  return this.width / 2;
@@ -9,11 +9,11 @@ import { IPhysics } from "../engines";
9
9
  export interface EntityStateBuilder {
10
10
  height: number;
11
11
  halfWidth: number;
12
- position: Vec3;
13
- velocity: Vec3;
12
+ pos: Vec3;
13
+ vel: Vec3;
14
14
  pitch: number;
15
15
  yaw: number;
16
- controlState: ControlStateHandler;
16
+ control: ControlStateHandler;
17
17
  onGround: boolean;
18
18
  isUsingItem?: boolean;
19
19
  isInWater?: boolean;
@@ -35,12 +35,12 @@ export declare class EntityState implements EntityStateBuilder {
35
35
  ctx: IPhysics;
36
36
  height: number;
37
37
  halfWidth: number;
38
- position: Vec3;
39
- velocity: Vec3;
38
+ pos: Vec3;
39
+ vel: Vec3;
40
40
  onGround: boolean;
41
- controlState: ControlStateHandler;
42
41
  yaw: number;
43
42
  pitch: number;
43
+ control: ControlStateHandler;
44
44
  age: number;
45
45
  isInWater: boolean;
46
46
  isInLava: boolean;
@@ -63,7 +63,7 @@ export declare class EntityState implements EntityStateBuilder {
63
63
  depthStrider: number;
64
64
  effects: Effect[];
65
65
  pose: PlayerPoses;
66
- constructor(ctx: IPhysics, height: number, halfWidth: number, position: Vec3, velocity: Vec3, onGround: boolean, controlState: ControlStateHandler, yaw: number, pitch: number);
66
+ constructor(ctx: IPhysics, height: number, halfWidth: number, pos: Vec3, vel: Vec3, onGround: boolean, yaw: number, pitch: number, control?: ControlStateHandler);
67
67
  static CREATE_FROM_BOT(ctx: IPhysics, bot: Bot): EntityState;
68
68
  static CREATE_FROM_ENTITY(ctx: IPhysics, entity: Entity): EntityState;
69
69
  static CREATE_FROM_PLAYER_STATE(ctx: IPhysics, state: PlayerState): EntityState;
@@ -14,16 +14,16 @@ const emptyVec = new vec3_1.Vec3(0, 0, 0);
14
14
  class EntityState {
15
15
  // public effects: Effect[];
16
16
  // public statusEffectNames;
17
- constructor(ctx, height, halfWidth, position, velocity, onGround, controlState, yaw, pitch) {
17
+ constructor(ctx, height, halfWidth, pos, vel, onGround, yaw, pitch, control = playerControls_1.ControlStateHandler.DEFAULT()) {
18
18
  this.ctx = ctx;
19
19
  this.height = height;
20
20
  this.halfWidth = halfWidth;
21
- this.position = position;
22
- this.velocity = velocity;
21
+ this.pos = pos;
22
+ this.vel = vel;
23
23
  this.onGround = onGround;
24
- this.controlState = controlState;
25
24
  this.yaw = yaw;
26
25
  this.pitch = pitch;
26
+ this.control = control;
27
27
  // may keep this, may not. Who knows?
28
28
  this.age = 0;
29
29
  this.isInWater = false;
@@ -52,13 +52,13 @@ class EntityState {
52
52
  this.pose = poses_1.PlayerPoses.STANDING;
53
53
  }
54
54
  static CREATE_FROM_BOT(ctx, bot) {
55
- return new EntityState(ctx, bot.entity.height, bot.entity.width / 2, bot.entity.position.clone(), bot.entity.velocity.clone(), bot.entity.onGround, playerControls_1.ControlStateHandler.COPY_BOT(bot), bot.entity.yaw, bot.entity.pitch).updateFromBot(bot);
55
+ return new EntityState(ctx, bot.entity.height, bot.entity.width / 2, bot.entity.position.clone(), bot.entity.velocity.clone(), bot.entity.onGround, bot.entity.yaw, bot.entity.pitch, playerControls_1.ControlStateHandler.COPY_BOT(bot)).updateFromBot(bot);
56
56
  }
57
57
  static CREATE_FROM_ENTITY(ctx, entity) {
58
- return new EntityState(ctx, entity.height, entity.width / 2, entity.position.clone(), entity.velocity.clone(), entity.onGround, playerControls_1.ControlStateHandler.DEFAULT(), entity.yaw, entity.pitch).updateFromEntity(entity);
58
+ return new EntityState(ctx, entity.height, entity.width / 2, entity.position.clone(), entity.velocity.clone(), entity.onGround, entity.yaw, entity.pitch, playerControls_1.ControlStateHandler.DEFAULT()).updateFromEntity(entity);
59
59
  }
60
60
  static CREATE_FROM_PLAYER_STATE(ctx, state) {
61
- return new EntityState(ctx, state.height, state.halfWidth, state.position.clone(), state.velocity.clone(), state.onGround, state.controlState.clone(), state.yaw, state.pitch).updateFromRaw(state);
61
+ return new EntityState(ctx, state.height, state.halfWidth, state.pos.clone(), state.vel.clone(), state.onGround, state.yaw, state.pitch, state.control.clone()).updateFromRaw(state);
62
62
  }
63
63
  /**
64
64
  * Slightly different from the other two, use a pre-built object (assuming cloned) material.
@@ -67,11 +67,11 @@ class EntityState {
67
67
  * @returns PhysicsState
68
68
  */
69
69
  static CREATE_RAW(ctx, raw) {
70
- return new EntityState(ctx, raw.height, raw.halfWidth, raw.position, raw.velocity, raw.onGround, raw.controlState, raw.yaw, raw.pitch);
70
+ return new EntityState(ctx, raw.height, raw.halfWidth, raw.pos, raw.vel, raw.onGround, raw.yaw, raw.pitch, raw.control);
71
71
  }
72
72
  updateFromBot(bot) {
73
73
  this.updateFromEntity(bot.entity, true);
74
- this.controlState = playerControls_1.ControlStateHandler.COPY_BOT(bot);
74
+ this.control = playerControls_1.ControlStateHandler.COPY_BOT(bot);
75
75
  this.jumpTicks = bot.jumpTicks;
76
76
  this.jumpQueued = bot.jumpQueued;
77
77
  return this;
@@ -80,7 +80,7 @@ class EntityState {
80
80
  var _a, _b;
81
81
  if (all) {
82
82
  // most mobs don't have this defined, so ignore it (only self does).
83
- this.velocity = entity.velocity.clone();
83
+ this.vel = entity.velocity.clone();
84
84
  this.onGround = entity.onGround;
85
85
  this.isInWater = entity.isInWater;
86
86
  this.isInLava = entity.isInLava;
@@ -90,14 +90,14 @@ class EntityState {
90
90
  this.sneakCollision = false; //TODO
91
91
  this.attributes || (this.attributes = entity.attributes);
92
92
  }
93
- this.position = entity.position.clone();
93
+ this.pos = entity.position.clone();
94
94
  //not sure what to do here, ngl.
95
95
  this.jumpTicks || (this.jumpTicks = 0);
96
96
  this.jumpQueued || (this.jumpQueued = false);
97
97
  // Input only (not modified)
98
98
  this.yaw = entity.yaw;
99
99
  this.pitch = entity.pitch;
100
- this.controlState || (this.controlState = playerControls_1.ControlStateHandler.DEFAULT());
100
+ this.control || (this.control = playerControls_1.ControlStateHandler.DEFAULT());
101
101
  this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(entity);
102
102
  this.isUsingMainHand = !(0, physicsUtils_1.whichHandIsEntityUsingBoolean)(entity) && this.isUsingItem;
103
103
  this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(entity) && this.isUsingItem;
@@ -139,20 +139,20 @@ class EntityState {
139
139
  return this;
140
140
  }
141
141
  applyToBot(bot) {
142
- bot.entity.position.set(this.position.x, this.position.y, this.position.z);
143
- bot.entity.velocity.set(this.velocity.x, this.velocity.y, this.velocity.z);
142
+ bot.entity.position.set(this.pos.x, this.pos.y, this.pos.z);
143
+ bot.entity.velocity.set(this.vel.x, this.vel.y, this.vel.z);
144
144
  bot.entity.onGround = this.onGround;
145
145
  bot.entity.yaw = this.yaw;
146
146
  bot.entity.pitch = this.pitch;
147
- bot.controlState = this.controlState;
147
+ bot.controlState = this.control;
148
148
  return this;
149
149
  }
150
150
  /**
151
151
  * No idea when you'd use this.
152
152
  */
153
153
  applyToEntity(entity) {
154
- entity.position = this.position;
155
- entity.velocity = this.velocity;
154
+ entity.position = this.pos;
155
+ entity.velocity = this.vel;
156
156
  // entity.position.set(this.position.x, this.position.y, this.position.z);
157
157
  // entity.velocity.set(this.velocity.x, this.velocity.y, this.velocity.z);
158
158
  entity.onGround = this.onGround;
@@ -161,7 +161,7 @@ class EntityState {
161
161
  return this;
162
162
  }
163
163
  clone() {
164
- const other = new EntityState(this.ctx, this.height, this.halfWidth, this.position.clone(), this.velocity.clone(), this.onGround, this.controlState.clone(), this.yaw, this.pitch);
164
+ const other = new EntityState(this.ctx, this.height, this.halfWidth, this.pos.clone(), this.vel.clone(), this.onGround, this.yaw, this.pitch, this.control.clone());
165
165
  other.age = this.age;
166
166
  other.isCollidedHorizontally = this.isCollidedHorizontally;
167
167
  other.isCollidedVertically = this.isCollidedVertically;
@@ -188,8 +188,8 @@ class EntityState {
188
188
  }
189
189
  merge(other) {
190
190
  this.age = other.age;
191
- this.position = other.position.clone();
192
- this.velocity = other.velocity.clone();
191
+ this.pos = other.pos.clone();
192
+ this.vel = other.vel.clone();
193
193
  this.onGround = other.onGround;
194
194
  this.isCollidedHorizontally = other.isCollidedHorizontally;
195
195
  this.isCollidedVertically = other.isCollidedVertically;
@@ -215,7 +215,7 @@ class EntityState {
215
215
  return this;
216
216
  }
217
217
  clearControlStates() {
218
- this.controlState = playerControls_1.ControlStateHandler.DEFAULT();
218
+ this.control = playerControls_1.ControlStateHandler.DEFAULT();
219
219
  return this;
220
220
  }
221
221
  /**
@@ -224,7 +224,7 @@ class EntityState {
224
224
  */
225
225
  getAABB() {
226
226
  const w = this.halfWidth;
227
- return new mineflayer_util_plugin_1.AABB(this.position.x - w, this.position.y, this.position.z - w, this.position.x + w, this.position.y + this.height, this.position.z + w);
227
+ return new mineflayer_util_plugin_1.AABB(this.pos.x - w, this.pos.y, this.pos.z - w, this.pos.x + w, this.pos.y + this.height, this.pos.z + w);
228
228
  }
229
229
  getUnderlyingBlockBBs(world /*prismarine-world*/) {
230
230
  const queryBB = this.getAABB();
@@ -26,8 +26,8 @@ export declare class PlayerState implements EntityStateBuilder {
26
26
  readonly bot: Bot;
27
27
  height: number;
28
28
  halfWidth: number;
29
- position: Vec3;
30
- velocity: Vec3;
29
+ pos: Vec3;
30
+ vel: Vec3;
31
31
  onGround: boolean;
32
32
  isInWater: boolean;
33
33
  isInLava: boolean;
@@ -40,7 +40,7 @@ export declare class PlayerState implements EntityStateBuilder {
40
40
  attributes: any;
41
41
  yaw: number;
42
42
  pitch: number;
43
- controlState: ControlStateHandler;
43
+ control: ControlStateHandler;
44
44
  isUsingItem: boolean;
45
45
  isUsingMainHand: boolean;
46
46
  isUsingOffHand: boolean;
@@ -73,8 +73,8 @@ class PlayerState {
73
73
  this.supportFeature = (0, physicsUtils_1.makeSupportFeature)(ctx.data);
74
74
  this.ctx = ctx;
75
75
  this.bot = bot;
76
- this.position = bot.entity.position.clone();
77
- this.velocity = bot.entity.velocity.clone();
76
+ this.pos = bot.entity.position.clone();
77
+ this.vel = bot.entity.velocity.clone();
78
78
  this.onGround = bot.entity.onGround;
79
79
  this.isInWater = bot.entity.isInWater;
80
80
  this.isInLava = bot.entity.isInLava;
@@ -89,7 +89,7 @@ class PlayerState {
89
89
  this.attributes = bot.entity.attributes;
90
90
  this.yaw = bot.entity.yaw;
91
91
  this.pitch = bot.entity.pitch;
92
- this.controlState = control !== null && control !== void 0 ? control : playerControls_1.ControlStateHandler.DEFAULT();
92
+ this.control = control !== null && control !== void 0 ? control : playerControls_1.ControlStateHandler.DEFAULT();
93
93
  this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(bot.entity);
94
94
  this.isUsingMainHand = !(0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity) && this.isUsingItem;
95
95
  this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity) && this.isUsingItem;
@@ -124,8 +124,8 @@ class PlayerState {
124
124
  var _a, _b, _c, _d;
125
125
  // const bot.entity = bot instanceof bot.entity ? bot : bot.entity;
126
126
  // Input / Outputs
127
- this.position = bot.entity.position.clone();
128
- this.velocity = bot.entity.velocity.clone();
127
+ this.pos = bot.entity.position.clone();
128
+ this.vel = bot.entity.velocity.clone();
129
129
  this.onGround = bot.entity.onGround;
130
130
  this.isInWater = bot.entity.isInWater;
131
131
  this.isInLava = bot.entity.isInLava;
@@ -139,7 +139,7 @@ class PlayerState {
139
139
  this.attributes = bot.entity.attributes;
140
140
  this.yaw = bot.entity.yaw;
141
141
  this.pitch = bot.entity.pitch;
142
- this.controlState = control !== null && control !== void 0 ? control : this.controlState;
142
+ this.control = control !== null && control !== void 0 ? control : this.control;
143
143
  this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(bot.entity);
144
144
  this.isUsingMainHand = !(0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity) && this.isUsingItem;
145
145
  this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity) && this.isUsingItem;
@@ -166,8 +166,8 @@ class PlayerState {
166
166
  }
167
167
  apply(bot) {
168
168
  // const bot.entity = bot instanceof bot.entity ? bot : bot.entity;
169
- bot.entity.position = this.position;
170
- bot.entity.velocity = this.velocity;
169
+ bot.entity.position = this.pos;
170
+ bot.entity.velocity = this.vel;
171
171
  bot.entity.onGround = this.onGround;
172
172
  bot.entity.isInWater = this.isInWater;
173
173
  bot.entity.isInLava = this.isInLava;
@@ -179,13 +179,13 @@ class PlayerState {
179
179
  bot.jumpQueued = this.jumpQueued;
180
180
  bot.entity.yaw = this.yaw;
181
181
  bot.entity.pitch = this.pitch;
182
- bot.controlState = this.controlState;
182
+ bot.controlState = this.control;
183
183
  }
184
184
  clone() {
185
185
  var _a, _b;
186
- const tmp = new PlayerState(this.ctx, this.bot, this.controlState);
187
- tmp.position = this.position.clone();
188
- tmp.velocity = this.velocity.clone();
186
+ const tmp = new PlayerState(this.ctx, this.bot, this.control);
187
+ tmp.pos = this.pos.clone();
188
+ tmp.vel = this.vel.clone();
189
189
  tmp.onGround = this.onGround;
190
190
  tmp.isInWater = this.isInWater;
191
191
  tmp.isInLava = this.isInLava;
@@ -200,7 +200,7 @@ class PlayerState {
200
200
  tmp.attributes = this.attributes;
201
201
  tmp.yaw = this.yaw;
202
202
  tmp.pitch = this.pitch;
203
- tmp.controlState = this.controlState;
203
+ tmp.control = this.control;
204
204
  tmp.isUsingItem = this.isUsingItem;
205
205
  tmp.isUsingMainHand = this.isUsingMainHand;
206
206
  tmp.isUsingOffHand = this.isUsingOffHand;
@@ -218,8 +218,8 @@ class PlayerState {
218
218
  }
219
219
  merge(other) {
220
220
  var _a, _b;
221
- this.position = other.position.clone();
222
- this.velocity = other.velocity.clone();
221
+ this.pos = other.pos.clone();
222
+ this.vel = other.vel.clone();
223
223
  this.onGround = other.onGround;
224
224
  this.isInWater = other.isInWater;
225
225
  this.isInLava = other.isInLava;
@@ -234,7 +234,7 @@ class PlayerState {
234
234
  this.attributes = other.attributes;
235
235
  this.yaw = other.yaw;
236
236
  this.pitch = other.pitch;
237
- this.controlState = other.controlState.clone();
237
+ this.control = other.control.clone();
238
238
  this.isUsingItem = other.isUsingItem;
239
239
  this.isUsingMainHand = other.isUsingMainHand;
240
240
  this.isUsingOffHand = other.isUsingOffHand;
@@ -251,12 +251,12 @@ class PlayerState {
251
251
  return this;
252
252
  }
253
253
  clearControlStates() {
254
- this.controlState = defaultMoves;
254
+ this.control = defaultMoves;
255
255
  return this;
256
256
  }
257
257
  getAABB() {
258
258
  const w = this.halfWidth;
259
- return new mineflayer_util_plugin_1.AABB(this.position.x - w, this.position.y, this.position.z - w, this.position.x + w, this.position.y + this.height, this.position.z + w);
259
+ return new mineflayer_util_plugin_1.AABB(this.pos.x - w, this.pos.y, this.pos.z - w, this.pos.x + w, this.pos.y + this.height, this.pos.z + w);
260
260
  }
261
261
  getUnderlyingBlockBBs(world /*prismarine-world*/) {
262
262
  const queryBB = this.getAABB();
@@ -7,7 +7,7 @@ import { Vec3 } from "vec3";
7
7
  export declare type SimulationGoal = (state: EntityState, ticks: number) => boolean | ((state: EntityState) => boolean);
8
8
  export declare type OnGoalReachFunction = (state: EntityState) => void;
9
9
  export declare type Controller = (state: EntityState, ticks: number) => void;
10
- export declare abstract class BaseSimulator {
10
+ export declare class BaseSimulator {
11
11
  readonly ctx: IPhysics;
12
12
  constructor(ctx: IPhysics);
13
13
  predictGenerator(simCtx: EPhysicsCtx, world: any, ticks?: number, controls?: ControlStateHandler): Generator<EntityState, EPhysicsCtx, unknown>;
@@ -7,7 +7,7 @@ class BaseSimulator {
7
7
  this.ctx = ctx;
8
8
  }
9
9
  *predictGenerator(simCtx, world, ticks = 1, controls) {
10
- simCtx.state.controlState = controls !== null && controls !== void 0 ? controls : simCtx.state.controlState;
10
+ simCtx.state.control = controls !== null && controls !== void 0 ? controls : simCtx.state.control;
11
11
  for (let current = 0; current < ticks; current++) {
12
12
  yield this.ctx.simulate(simCtx, world);
13
13
  }
@@ -15,14 +15,14 @@ class BaseSimulator {
15
15
  }
16
16
  predictForward(target, world, ticks = 1, controls) {
17
17
  const simCtx = settings_1.EPhysicsCtx.FROM_ENTITY(this.ctx, target);
18
- simCtx.state.controlState = controls !== null && controls !== void 0 ? controls : simCtx.state.controlState;
18
+ simCtx.state.control = controls !== null && controls !== void 0 ? controls : simCtx.state.control;
19
19
  for (let current = 0; current < ticks; current++) {
20
20
  this.ctx.simulate(simCtx, world);
21
21
  }
22
22
  return simCtx.state;
23
23
  }
24
24
  predictForwardRaw(simCtx, world, ticks = 1, controls) {
25
- simCtx.state.controlState = controls !== null && controls !== void 0 ? controls : simCtx.state.controlState;
25
+ simCtx.state.control = controls !== null && controls !== void 0 ? controls : simCtx.state.control;
26
26
  for (let current = 0; current < ticks; current++) {
27
27
  this.ctx.simulate(simCtx, world);
28
28
  }
@@ -34,8 +34,6 @@ class BaseSimulator {
34
34
  onGoalReach(simCtx.state);
35
35
  break;
36
36
  }
37
- if (simCtx.state.isInLava)
38
- break;
39
37
  controller(simCtx.state, i);
40
38
  this.ctx.simulate(simCtx, world);
41
39
  simCtx.state.age++;
@@ -44,7 +42,7 @@ class BaseSimulator {
44
42
  }
45
43
  static getReached(...path) {
46
44
  return (state) => {
47
- const delta = path[0].minus(state.position);
45
+ const delta = path[0].minus(state.pos);
48
46
  return Math.abs(delta.x) <= 0.35 && Math.abs(delta.z) <= 0.35 && Math.abs(delta.y) < 1 && (state.onGround || state.isInWater);
49
47
  };
50
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -24,7 +24,10 @@
24
24
  "@nxg-org/mineflayer-util-plugin": "^1.7.11"
25
25
  },
26
26
  "devDependencies": {
27
- "mineflayer": "^4.6.0",
27
+ "expect": "^29.5.0",
28
+ "mineflayer": "^4.9.0",
29
+ "mineflayer-pathfinder": "^2.4.4",
30
+ "prismarine-physics": "^1.6.0",
28
31
  "typescript": "^4.5.5"
29
32
  }
30
33
  }
@@ -0,0 +1,61 @@
1
+ import {pathfinder, goals} from 'mineflayer-pathfinder'
2
+ import { Bot, createBot } from 'mineflayer'
3
+ import loader, { EntityPhysics, EntityState, EPhysicsCtx } from '../src/index'
4
+
5
+
6
+ const {Physics} = require('prismarine-physics')
7
+
8
+ const bot: Bot = createBot({
9
+ host: process.argv[2],
10
+ port: Number(process.argv[3]),
11
+ username: "testingbot"
12
+ })
13
+
14
+ bot.once('spawn', () => {
15
+ bot.loadPlugin(loader)
16
+ bot.loadPlugin(pathfinder)
17
+ })
18
+
19
+
20
+ bot.on("chat", (user, message) => {
21
+ const [cmd, ...args] = message.split(' ')
22
+ const author = bot.nearestEntity(e=>e.username===user);
23
+
24
+
25
+
26
+ switch (cmd) {
27
+ case "original":
28
+ bot.physics = new Physics(bot.registry, bot.world);
29
+ break;
30
+ case "new":
31
+ // rough patching in custom physics for the time being.
32
+ const fuck0 = new EntityPhysics(bot.registry)
33
+ bot.physics = fuck0 as any;
34
+ (bot.physics as any).simulatePlayer = (state: EntityState, world: any /* prismarine-world*/) => {
35
+ const entity = EPhysicsCtx.FROM_ENTITY_STATE(fuck0, state)
36
+ return fuck0.simulate(entity, world);
37
+ }
38
+ break;
39
+ case "come":
40
+ if (!author) return bot.chat(`Cannot see ${user}!`);
41
+ const goal0 = new goals.GoalNear(author.position.x, author.position.y, author.position.z, 3);
42
+ bot.pathfinder.setGoal(goal0);
43
+ break;
44
+ case "goto":
45
+ if (!author) return bot.chat(`Cannot see ${user}!`);
46
+ const goal1 = new goals.GoalNear(Number(args[0]), Number(args[1]), Number(args[2]), 3);
47
+ bot.pathfinder.setGoal(goal1);
48
+ break;
49
+ case "stop":
50
+ bot.pathfinder.stop();
51
+ bot.chat('Stopped!')
52
+ break;
53
+
54
+
55
+
56
+
57
+
58
+ }
59
+
60
+
61
+ })