@nxg-org/mineflayer-physics-util 1.8.14 → 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.
- package/.vscode/settings.json +4 -4
- package/README.md +1 -1
- package/dist/physics/engines/botcraft.js +58 -26
- package/dist/physics/states/playerState.js +1 -1
- package/eslint.config.mjs +17 -17
- package/package.json +46 -46
- package/tests/actualBot.ts +201 -198
- package/tests/fakeWorld.test.ts +354 -354
- package/tests/predictBot.ts +73 -73
- package/tests/util/testUtils.ts +67 -67
package/.vscode/settings.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
"print.colourScheme": "GitHub",
|
|
3
|
-
"ecl.launchConfiguration": "not found",
|
|
4
|
-
"ecl.targetCluster": {}
|
|
1
|
+
{
|
|
2
|
+
"print.colourScheme": "GitHub",
|
|
3
|
+
"ecl.launchConfiguration": "not found",
|
|
4
|
+
"ecl.targetCluster": {}
|
|
5
5
|
}
|
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# mineflayer-physics-utils
|
|
1
|
+
# mineflayer-physics-utils
|
|
@@ -223,13 +223,14 @@ class BotcraftPhysics {
|
|
|
223
223
|
physicsTick(ctx, world) {
|
|
224
224
|
// Check for rocket boosting if currently in elytra flying mode
|
|
225
225
|
const entity = ctx.state;
|
|
226
|
-
if (ctx.state.elytraFlying) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
226
|
+
// if (ctx.state.elytraFlying) {
|
|
227
|
+
// // TODO: entity check for fireworks
|
|
228
|
+
// // TODO: check if firework is attached to player
|
|
229
|
+
// if (false) {
|
|
230
|
+
// // player->speed += player->front_vector * 0.1 + (player->front_vector * 1.5 - player->speed) * 0.5;
|
|
231
|
+
// }
|
|
232
|
+
// }
|
|
233
|
+
// for now, only check if this is a player.
|
|
233
234
|
const playerFlag = ctx.entityType.type === "player";
|
|
234
235
|
this.fluidPhysics(ctx, world, true);
|
|
235
236
|
this.fluidPhysics(ctx, world, false);
|
|
@@ -796,31 +797,49 @@ class BotcraftPhysics {
|
|
|
796
797
|
getMovementSpeedAttribute(entity) {
|
|
797
798
|
const isSprinting = entity.state instanceof states_1.PlayerState && entity.state.sprinting;
|
|
798
799
|
let attribute;
|
|
799
|
-
//
|
|
800
|
+
// In 1.21+, this should map to 'minecraft:movement_speed'
|
|
800
801
|
if (entity.state.attributes && entity.state.attributes[this.movementSpeedAttribute]) {
|
|
801
|
-
// Use server-side player attributes
|
|
802
802
|
attribute = entity.state.attributes[this.movementSpeedAttribute];
|
|
803
803
|
}
|
|
804
804
|
else {
|
|
805
|
-
// Create
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
// setSprinting in Livingentity.state.java
|
|
811
|
-
//TODO: Generalize to all entities.
|
|
812
|
-
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);
|
|
813
810
|
if (isSprinting) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
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
|
+
});
|
|
821
817
|
}
|
|
822
|
-
//
|
|
823
|
-
const
|
|
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
|
+
});
|
|
840
|
+
}
|
|
841
|
+
// Calculate the final speed and cast the entire result to a 32-bit float
|
|
842
|
+
const attributeSpeed = Math.fround(attributes.getAttributeValue(attribute));
|
|
824
843
|
return attributeSpeed;
|
|
825
844
|
}
|
|
826
845
|
/**
|
|
@@ -940,8 +959,21 @@ class BotcraftPhysics {
|
|
|
940
959
|
if (player.onGround) {
|
|
941
960
|
player.fallFlying = false;
|
|
942
961
|
}
|
|
962
|
+
// Potentially not the correct place for this logic, but it is easier to implement here for now. This is the firework boost from elytra flying.
|
|
963
|
+
if (player.fireworkRocketDuration > 0) {
|
|
964
|
+
const { lookDir } = (0, physicsUtils_1.getLookingVector)(player);
|
|
965
|
+
player.vel.x += lookDir.x * 0.1 + (lookDir.x * 1.5 - player.vel.x) * 0.5;
|
|
966
|
+
player.vel.y += lookDir.y * 0.1 + (lookDir.y * 1.5 - player.vel.y) * 0.5;
|
|
967
|
+
player.vel.z += lookDir.z * 0.1 + (lookDir.z * 1.5 - player.vel.z) * 0.5;
|
|
968
|
+
--player.fireworkRocketDuration;
|
|
969
|
+
}
|
|
970
|
+
// we're on ground or in air, not flying.
|
|
943
971
|
}
|
|
944
972
|
else {
|
|
973
|
+
// clear firework boost if on ground or in air without flying, otherwise it can cause issues with movement.
|
|
974
|
+
if (player.fireworkRocketDuration > 0) {
|
|
975
|
+
player.fireworkRocketDuration = 0;
|
|
976
|
+
}
|
|
945
977
|
const blockBelow = world.getBlock(this.getBlockBelowAffectingMovement(player, world));
|
|
946
978
|
// deviation. using our stores slipperiness values.
|
|
947
979
|
const friction = blockBelow
|
package/eslint.config.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { defineConfig } from "eslint/config";
|
|
2
|
-
import globals from "globals";
|
|
3
|
-
import js from "@eslint/js";
|
|
4
|
-
import tseslint from "typescript-eslint";
|
|
5
|
-
|
|
6
|
-
export default defineConfig([
|
|
7
|
-
{
|
|
8
|
-
files: ["**/*.{ts,tsx}"], // Only check TypeScript files
|
|
9
|
-
languageOptions: { globals: globals.browser }
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
files: ["**/*.{ts,tsx}"], // Only check TypeScript files
|
|
13
|
-
plugins: { js },
|
|
14
|
-
extends: ["js/recommended"]
|
|
15
|
-
},
|
|
16
|
-
tseslint.configs.recommended,
|
|
17
|
-
]);
|
|
1
|
+
import { defineConfig } from "eslint/config";
|
|
2
|
+
import globals from "globals";
|
|
3
|
+
import js from "@eslint/js";
|
|
4
|
+
import tseslint from "typescript-eslint";
|
|
5
|
+
|
|
6
|
+
export default defineConfig([
|
|
7
|
+
{
|
|
8
|
+
files: ["**/*.{ts,tsx}"], // Only check TypeScript files
|
|
9
|
+
languageOptions: { globals: globals.browser }
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
files: ["**/*.{ts,tsx}"], // Only check TypeScript files
|
|
13
|
+
plugins: { js },
|
|
14
|
+
extends: ["js/recommended"]
|
|
15
|
+
},
|
|
16
|
+
tseslint.configs.recommended,
|
|
17
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nxg-org/mineflayer-physics-util",
|
|
3
|
-
"version": "1.8.
|
|
4
|
-
"description": "Provides functionality for more accurate entity and projectile tracking.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"mineflayer",
|
|
7
|
-
"mineflayer-plugin",
|
|
8
|
-
"mineflayer-tracker"
|
|
9
|
-
],
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/nxg-org/mineflayer-physics-utils.git"
|
|
13
|
-
},
|
|
14
|
-
"license": "GPL-3.0",
|
|
15
|
-
"author": "generel_schwerz",
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"types": "dist/index.d.ts",
|
|
18
|
-
"scripts": {
|
|
19
|
-
"lint": "eslint . --ext .ts,.tsx",
|
|
20
|
-
"build": "npx tsc",
|
|
21
|
-
"prepublishOnly": "npm run build",
|
|
22
|
-
"test": "mocha --require ts-node/register --recursive tests/**/*.test.ts"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@nxg-org/mineflayer-util-plugin": "^1.8.2"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@eslint/js": "^9.23.0",
|
|
29
|
-
"@types/mocha": "^10.0.10",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^8.27.0",
|
|
31
|
-
"@typescript-eslint/parser": "^8.27.0",
|
|
32
|
-
"eslint": "^9.23.0",
|
|
33
|
-
"expect": "^29.7.0",
|
|
34
|
-
"globals": "^16.0.0",
|
|
35
|
-
"minecraft-data": "^3.83.1",
|
|
36
|
-
"mineflayer": "^4.26.0",
|
|
37
|
-
"mineflayer-pathfinder": "^2.4.4",
|
|
38
|
-
"mocha": "^11.1.0",
|
|
39
|
-
"prismarine-entity": "^2.4.0",
|
|
40
|
-
"prismarine-registry": "^1.11.0",
|
|
41
|
-
"ts-node": "^10.9.2",
|
|
42
|
-
"typescript": "^5.8.2",
|
|
43
|
-
"typescript-eslint": "^8.27.0"
|
|
44
|
-
},
|
|
45
|
-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@nxg-org/mineflayer-physics-util",
|
|
3
|
+
"version": "1.8.16",
|
|
4
|
+
"description": "Provides functionality for more accurate entity and projectile tracking.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mineflayer",
|
|
7
|
+
"mineflayer-plugin",
|
|
8
|
+
"mineflayer-tracker"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/nxg-org/mineflayer-physics-utils.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "GPL-3.0",
|
|
15
|
+
"author": "generel_schwerz",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
20
|
+
"build": "npx tsc",
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"test": "mocha --require ts-node/register --recursive tests/**/*.test.ts"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nxg-org/mineflayer-util-plugin": "^1.8.2"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@eslint/js": "^9.23.0",
|
|
29
|
+
"@types/mocha": "^10.0.10",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.27.0",
|
|
31
|
+
"@typescript-eslint/parser": "^8.27.0",
|
|
32
|
+
"eslint": "^9.23.0",
|
|
33
|
+
"expect": "^29.7.0",
|
|
34
|
+
"globals": "^16.0.0",
|
|
35
|
+
"minecraft-data": "^3.83.1",
|
|
36
|
+
"mineflayer": "^4.26.0",
|
|
37
|
+
"mineflayer-pathfinder": "^2.4.4",
|
|
38
|
+
"mocha": "^11.1.0",
|
|
39
|
+
"prismarine-entity": "^2.4.0",
|
|
40
|
+
"prismarine-registry": "^1.11.0",
|
|
41
|
+
"ts-node": "^10.9.2",
|
|
42
|
+
"typescript": "^5.8.2",
|
|
43
|
+
"typescript-eslint": "^8.27.0"
|
|
44
|
+
},
|
|
45
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
46
|
+
}
|