@nxg-org/mineflayer-physics-util 1.8.15 → 1.8.16

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.
@@ -797,31 +797,49 @@ class BotcraftPhysics {
797
797
  getMovementSpeedAttribute(entity) {
798
798
  const isSprinting = entity.state instanceof states_1.PlayerState && entity.state.sprinting;
799
799
  let attribute;
800
- // console.log(JSON.stringify(entity.state.attributes), this.movementSpeedAttribute, entity.state.attributes[this.movementSpeedAttribute])
800
+ // In 1.21+, this should map to 'minecraft:movement_speed'
801
801
  if (entity.state.attributes && entity.state.attributes[this.movementSpeedAttribute]) {
802
- // Use server-side player attributes
803
802
  attribute = entity.state.attributes[this.movementSpeedAttribute];
804
803
  }
805
804
  else {
806
- // Create an attribute if the player does not have it
807
- //TODO: Generalize to all entities.
808
- attribute = attributes.createAttributeValue(entity.worldSettings.playerSpeed);
809
- }
810
- // Client-side sprinting (don't rely on server-side sprinting)
811
- // setSprinting in Livingentity.state.java
812
- //TODO: Generalize to all entities.
813
- attribute = attributes.deleteAttributeModifier(attribute, entity.worldSettings.sprintingUUID); // always delete sprinting (if it exists)
805
+ // Create fallback if server hasn't sent it
806
+ attribute = attributes.createAttributeValue(Math.fround(entity.worldSettings.playerSpeed));
807
+ }
808
+ // --- SPRINTING ---
809
+ attribute = attributes.deleteAttributeModifier(attribute, entity.worldSettings.sprintingUUID);
814
810
  if (isSprinting) {
815
- if (!attributes.checkAttributeModifier(attribute, entity.worldSettings.sprintingUUID)) {
816
- attribute = attributes.addAttributeModifier(attribute, {
817
- uuid: entity.worldSettings.sprintingUUID,
818
- amount: entity.worldSettings.sprintSpeed,
819
- operation: 2,
820
- });
821
- }
811
+ attribute = attributes.addAttributeModifier(attribute, {
812
+ uuid: entity.worldSettings.sprintingUUID,
813
+ // Math.fround(0.3) perfectly resolves to 0.30000001192092896
814
+ amount: Math.fround(0.3),
815
+ operation: 2,
816
+ });
817
+ }
818
+ // --- SPEED EFFECT ---
819
+ const SPEED_UUID = "91AEAA56-376B-4498-935B-2F7F68070635";
820
+ attribute = attributes.deleteAttributeModifier(attribute, SPEED_UUID);
821
+ const speedLevel = this.getEffectLevel(physicsUtils_1.CheapEffects.SPEED, entity.state.effects);
822
+ if (speedLevel > 0) {
823
+ attribute = attributes.addAttributeModifier(attribute, {
824
+ uuid: SPEED_UUID,
825
+ // Truncate the 0.2 first, then multiply, then truncate again (how Java float math works)
826
+ amount: Math.fround(Math.fround(0.2) * speedLevel),
827
+ operation: 2,
828
+ });
829
+ }
830
+ // --- SLOWNESS EFFECT ---
831
+ const SLOWNESS_UUID = "7107DE5E-7CE8-4030-940E-514C1F160890";
832
+ attribute = attributes.deleteAttributeModifier(attribute, SLOWNESS_UUID);
833
+ const slownessLevel = this.getEffectLevel(physicsUtils_1.CheapEffects.SLOWNESS, entity.state.effects);
834
+ if (slownessLevel > 0) {
835
+ attribute = attributes.addAttributeModifier(attribute, {
836
+ uuid: SLOWNESS_UUID,
837
+ amount: Math.fround(Math.fround(-0.15) * slownessLevel),
838
+ operation: 2,
839
+ });
822
840
  }
823
- // Calculate what the speed is (0.1 if no modification)
824
- const attributeSpeed = attributes.getAttributeValue(attribute);
841
+ // Calculate the final speed and cast the entire result to a 32-bit float
842
+ const attributeSpeed = Math.fround(attributes.getAttributeValue(attribute));
825
843
  return attributeSpeed;
826
844
  }
827
845
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.8.15",
3
+ "version": "1.8.16",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -32,7 +32,7 @@ function buildBot() {
32
32
  await bot.waitForTicks(20);
33
33
  (bot as any).physics.yawSpeed = 50;
34
34
  (bot as any).physics.pitchSpeed = 50;
35
- setupNewPhysics(bot);
35
+ // setupNewPhysics(bot);
36
36
  // setupNewPhysics(bot);
37
37
  });
38
38
 
@@ -118,10 +118,9 @@ function buildBot() {
118
118
  case "status":
119
119
  const str0 = `pos: ${bot.entity.position.toString()}, vel: ${bot.entity.velocity.toString()}, yaw: ${bot.entity.yaw}, pitch: ${bot.entity.pitch}`;
120
120
  bot.chat(str0);
121
-
122
- const str = `onGround: ${bot.entity.onGround}, hCol: ${(bot.entity as any).isCollidedHorizontally}, vCol: ${
123
- (bot.entity as any).isCollidedVertically
124
- }, inWater: ${(bot.entity as any).isInWater}, inLava: ${(bot.entity as any).isInLava}`;
121
+
122
+ const str = `onGround: ${bot.entity.onGround}, hCol: ${(bot.entity as any).isCollidedHorizontally}, vCol: ${(bot.entity as any).isCollidedVertically
123
+ }, inWater: ${(bot.entity as any).isInWater}, inLava: ${(bot.entity as any).isInLava}`;
125
124
  bot.chat(str);
126
125
 
127
126
  if (state != null) {
@@ -172,15 +171,19 @@ function buildBot() {
172
171
  bot.setControlState("jump", true);
173
172
  break;
174
173
  case "come":
175
- if (!author) return bot.chat(`Cannot see ${user}!`);
176
- const goal0 = new goals.GoalNear(author.position.x, author.position.y, author.position.z, 3);
177
- bot.pathfinder.setGoal(goal0);
178
- break;
174
+ {
175
+ if (!author) return bot.chat(`Cannot see ${user}!`);
176
+ const goal0 = new goals.GoalNear(author.position.x, author.position.y, author.position.z, 3);
177
+ bot.pathfinder.setGoal(goal0);
178
+ break;
179
+ }
179
180
  case "goto":
180
- if (!author) return bot.chat(`Cannot see ${user}!`);
181
- const goal1 = new goals.GoalNear(Number(args[0]), Number(args[1]), Number(args[2]), 3);
182
- bot.pathfinder.setGoal(goal1);
183
- break;
181
+ {
182
+ if (!author) return bot.chat(`Cannot see ${user}!`);
183
+ const goal1 = new goals.GoalNear(Number(args[0]), Number(args[1]), Number(args[2]), 3);
184
+ bot.pathfinder.setGoal(goal1);
185
+ break;
186
+ }
184
187
  case "stop":
185
188
  bot.deactivateItem();
186
189
  bot.pathfinder.stop();