@nxg-org/mineflayer-physics-util 1.7.13 → 1.8.0

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.
@@ -740,6 +740,7 @@ class BotcraftPhysics {
740
740
  * @returns
741
741
  */
742
742
  getMovementSpeedAttribute(entity) {
743
+ const isSprinting = entity.state instanceof states_1.PlayerState && entity.state.sprinting;
743
744
  let attribute;
744
745
  if (entity.state.attributes && entity.state.attributes[this.movementSpeedAttribute]) {
745
746
  // Use server-side player attributes
@@ -754,7 +755,7 @@ class BotcraftPhysics {
754
755
  // setSprinting in Livingentity.state.java
755
756
  //TODO: Generalize to all entities.
756
757
  attribute = attributes.deleteAttributeModifier(attribute, entity.worldSettings.sprintingUUID); // always delete sprinting (if it exists)
757
- if (entity.state.control.sprint) {
758
+ if (isSprinting) {
758
759
  if (!attributes.checkAttributeModifier(attribute, entity.worldSettings.sprintingUUID)) {
759
760
  attribute = attributes.addAttributeModifier(attribute, {
760
761
  uuid: entity.worldSettings.sprintingUUID,
@@ -901,7 +902,7 @@ class BotcraftPhysics {
901
902
  else {
902
903
  inputStrength = 0.02;
903
904
  // DEVIATION: taken from p-physics, fixes motion!
904
- if (player.control.sprint) {
905
+ if (player.sprinting) {
905
906
  const airSprintFactor = ctx.airborneAccel * 0.3;
906
907
  inputStrength += airSprintFactor;
907
908
  }
@@ -1272,7 +1273,14 @@ class BotcraftPhysics {
1272
1273
  movedAABB.translate(thisAxis == 0 ? movementLst[0] : 0, thisAxis == 1 ? movementLst[1] : 0, thisAxis == 2 ? movementLst[2] : 0);
1273
1274
  }
1274
1275
  applyInputs(inputStrength, player) {
1275
- // console.log("current input strength of normal movement", inputStrength, player.onGround, player.sprinting, player.control)
1276
+ // Add slowdown when using items (like food)
1277
+ if (player.isUsingItem) {
1278
+ inputStrength *= 0.2;
1279
+ }
1280
+ // Use flySpeed for horizontal movement when flying
1281
+ if (player.flying) {
1282
+ inputStrength *= player.flySpeed * 40;
1283
+ }
1276
1284
  const inputVector = new vec3_1.Vec3(player.heading.strafe, 0, player.heading.forward);
1277
1285
  const sqrNorm = Math.pow(inputVector.norm(), 2);
1278
1286
  if (sqrNorm < 1e-7) {
@@ -193,7 +193,7 @@ class PlayerState {
193
193
  this.update(bot, playerControls_1.ControlStateHandler.COPY_BOT(bot));
194
194
  }
195
195
  update(bot, control) {
196
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
196
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
197
197
  // const bot.entity = bot instanceof bot.entity ? bot : bot.entity;
198
198
  // Input / Outputs
199
199
  this.pos.set(bot.entity.position.x, bot.entity.position.y, bot.entity.position.z);
@@ -220,7 +220,7 @@ class PlayerState {
220
220
  this.yaw = bot.entity.yaw;
221
221
  this.pitch = bot.entity.pitch;
222
222
  this.control = control !== null && control !== void 0 ? control : playerControls_1.ControlStateHandler.COPY_BOT(bot); // prevControl only updated internally.
223
- this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(bot.entity, this.ctx.supportFeature);
223
+ this.isUsingItem = bot.usingHeldItem; /* || isEntityUsingItem(bot.entity, this.ctx.supportFeature); */
224
224
  this.isUsingMainHand = !(0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity, this.ctx.supportFeature) && this.isUsingItem;
225
225
  this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity, this.ctx.supportFeature) && this.isUsingItem;
226
226
  // effects
@@ -257,11 +257,10 @@ class PlayerState {
257
257
  this.gameMode = bot.game.gameMode;
258
258
  this.food = bot.food;
259
259
  // TODO:
260
- this.flying = (_k = bot.entity.flying) !== null && _k !== void 0 ? _k : false;
261
- this.swimming = (_l = bot.entity.swimming) !== null && _l !== void 0 ? _l : false;
262
- this.sprinting = (_m = bot.entity.sprinting) !== null && _m !== void 0 ? _m : false;
263
- this.crouching = (_o = bot.entity.crouching) !== null && _o !== void 0 ? _o : false;
264
- this.fallFlying = (_p = bot.entity.fallFlying) !== null && _p !== void 0 ? _p : false;
260
+ this.swimming = (_k = bot.entity.swimming) !== null && _k !== void 0 ? _k : false;
261
+ this.sprinting = bot.controlState.sprint;
262
+ this.crouching = bot.controlState.sneak;
263
+ this.fallFlying = (_l = bot.entity.fallFlying) !== null && _l !== void 0 ? _l : false;
265
264
  switch (bot.game.gameMode) {
266
265
  case "creative":
267
266
  this.flySpeed = 0.05;
@@ -274,11 +273,12 @@ class PlayerState {
274
273
  case "survival":
275
274
  case "adventure":
276
275
  this.flySpeed = 0;
277
- this.mayFly = false;
276
+ this.mayFly = bot.entity.canFly;
278
277
  break;
279
278
  default:
280
279
  throw new Error("Unknown game mode: " + bot.game.gameMode);
281
280
  }
281
+ this.flying = !!bot.entity.flying && this.mayFly;
282
282
  return this;
283
283
  }
284
284
  apply(bot) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.7.13",
3
+ "version": "1.8.0",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -27,12 +27,13 @@
27
27
  "@types/mocha": "^10.0.10",
28
28
  "expect": "^29.7.0",
29
29
  "minecraft-data": "^3.83.1",
30
- "mineflayer": "^4.22.0",
30
+ "mineflayer": "github:GenerelSchwerz/mineflayer",
31
31
  "mineflayer-pathfinder": "^2.4.4",
32
32
  "mocha": "^11.1.0",
33
33
  "prismarine-entity": "^2.4.0",
34
34
  "prismarine-registry": "^1.11.0",
35
35
  "ts-node": "^10.9.2",
36
36
  "typescript": "^4.5.5"
37
- }
37
+ },
38
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
38
39
  }