@nxg-org/mineflayer-physics-util 1.5.6 → 1.5.8

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.
@@ -662,8 +662,9 @@ class EntityPhysics {
662
662
  }
663
663
  const vel = entity.velocity;
664
664
  const pos = entity.position;
665
- const waterBB = this.getEntityBB(entity, pos).contract(0.001, 0.401, 0.001);
666
- const lavaBB = this.getEntityBB(entity, pos).contract(0.1, 0.4, 0.1);
665
+ const offset = vel.y < 0 ? 0.4 : 0;
666
+ const waterBB = this.getEntityBB(entity, pos).contract(0.001, offset + 0.001, 0.001);
667
+ const lavaBB = this.getEntityBB(entity, pos).contract(0.1, offset, 0.1);
667
668
  // assume that if we shouldn't move entity, isInWater and isInLava are already properly set.
668
669
  entity.state.isInWater = this.isInWaterApplyCurrent(waterBB, vel, world);
669
670
  entity.state.isInLava = this.isMaterialInBB(lavaBB, this.lavaId, world);
@@ -96,6 +96,8 @@ export declare class EntityState implements EntityStateBuilder {
96
96
  * @returns AABB
97
97
  */
98
98
  getAABB(): AABB;
99
+ lookAt(vec3: Vec3): void;
100
+ look(yaw: number, pitch: number): void;
99
101
  getUnderlyingBlockBBs(world: any): AABB[];
100
102
  getSurroundingBBs(world: any): AABB[];
101
103
  }
@@ -258,6 +258,17 @@ class EntityState {
258
258
  const w = this.halfWidth;
259
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
+ lookAt(vec3) {
262
+ const dx = vec3.x - this.pos.x;
263
+ const dy = vec3.y - this.pos.y;
264
+ const dz = vec3.z - this.pos.z;
265
+ this.yaw = Math.atan2(dz, dx) * 180 / Math.PI - 90;
266
+ this.pitch = -Math.atan2(dy, Math.sqrt(dx * dx + dz * dz)) * 180 / Math.PI;
267
+ }
268
+ look(yaw, pitch) {
269
+ this.yaw = yaw;
270
+ this.pitch = pitch;
271
+ }
261
272
  getUnderlyingBlockBBs(world /*prismarine-world*/) {
262
273
  const queryBB = this.getAABB();
263
274
  return this.ctx.getUnderlyingBlockBBs(queryBB, world);
@@ -26,6 +26,7 @@ export declare class EntityDimensions {
26
26
  export declare class PlayerState implements EntityStateBuilder {
27
27
  readonly bot: Bot;
28
28
  height: number;
29
+ eyeHeight: number;
29
30
  halfWidth: number;
30
31
  pos: Vec3;
31
32
  vel: Vec3;
@@ -72,7 +72,8 @@ exports.EntityDimensions = EntityDimensions;
72
72
  class PlayerState {
73
73
  constructor(ctx, bot, control) {
74
74
  var _a, _b, _c, _d, _e;
75
- this.height = 1.62;
75
+ this.height = 1.8;
76
+ this.eyeHeight = 1.62;
76
77
  this.halfWidth = 0.3;
77
78
  this.supportFeature = (0, physicsUtils_1.makeSupportFeature)(ctx.data);
78
79
  this.ctx = ctx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -17,7 +17,7 @@
17
17
  "types": "dist/index.d.ts",
18
18
  "scripts": {
19
19
  "build": "npx tsc",
20
- "prepublish": "npm run build",
20
+ "prepublishOnly": "npm run build",
21
21
  "test": "ts-node -T tests/fakeWorld.ts"
22
22
  },
23
23
  "dependencies": {
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "expect": "^29.5.0",
28
- "mineflayer": "^4.17.0",
28
+ "mineflayer": "^4.18.0",
29
29
  "mineflayer-pathfinder": "^2.4.4",
30
30
  "prismarine-entity": "^2.4.0",
31
31
  "typescript": "^4.5.5"
@@ -11,12 +11,22 @@ const bot: Bot = createBot({
11
11
  username: "testingbot"
12
12
  })
13
13
 
14
- bot.once('spawn', () => {
14
+ bot.once('spawn', async () => {
15
15
  bot.loadPlugin(loader)
16
16
  bot.loadPlugin(pathfinder)
17
+ await bot.waitForTicks(20)
18
+ bot.chat('rocky1928')
17
19
  })
18
20
 
19
21
 
22
+ const rl = require('readline').createInterface({
23
+ input: process.stdin,
24
+ output: process.stdout
25
+
26
+ })
27
+
28
+ rl.on('line', (line: any) => bot.chat(line))
29
+
20
30
  bot.on("chat", (user, message) => {
21
31
  const [cmd, ...args] = message.split(' ')
22
32
  const author = bot.nearestEntity(e=>e.username===user);
@@ -28,14 +38,24 @@ bot.on("chat", (user, message) => {
28
38
  bot.physics = new Physics(bot.registry, bot.world);
29
39
  break;
30
40
  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
- }
41
+ const val = new EntityPhysics(bot.registry)
42
+ const oldSim = (bot.physics as any).simulatePlayer;
43
+
44
+ (EntityState.prototype as any).apply = function (bot: Bot) {
45
+ this.applyToBot(bot);
46
+ };
47
+ (bot.physics as any).simulatePlayer = (...args: any[]) => {
48
+ // bot.jumpTicks = 0
49
+ const ctx = EPhysicsCtx.FROM_BOT(val, bot)
50
+ ctx.state.jumpTicks = 0; // allow immediate jumping
51
+ // ctx.state.control.set('sneak', true)
52
+ return val.simulate(ctx, bot.world);
53
+ return oldSim(...args);
54
+ };
38
55
  break;
56
+ case "jump":
57
+ bot.setControlState('jump', true)
58
+ break
39
59
  case "come":
40
60
  if (!author) return bot.chat(`Cannot see ${user}!`);
41
61
  const goal0 = new goals.GoalNear(author.position.x, author.position.y, author.position.z, 3);
@@ -48,6 +68,7 @@ bot.on("chat", (user, message) => {
48
68
  break;
49
69
  case "stop":
50
70
  bot.pathfinder.stop();
71
+ bot.clearControlStates();
51
72
  bot.chat('Stopped!')
52
73
  break;
53
74