@nxg-org/mineflayer-physics-util 1.8.16 → 1.8.18
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/dist/index.d.ts
CHANGED
|
@@ -14,3 +14,4 @@ export { EntityPhysics, BotcraftPhysics } from "./physics/engines";
|
|
|
14
14
|
export { EntityState, PlayerState, PlayerPoses, IEntityState } from "./physics/states";
|
|
15
15
|
export { ControlStateHandler } from "./physics/player";
|
|
16
16
|
export type { SimulationGoal, Controller, OnGoalReachFunction } from "./simulators";
|
|
17
|
+
export { convertPlayerState } from "./util/physicsUtils";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControlStateHandler = exports.PlayerPoses = exports.PlayerState = exports.EntityState = exports.BotcraftPhysics = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsWorldSettings = exports.EPhysicsCtx = void 0;
|
|
3
|
+
exports.convertPlayerState = exports.ControlStateHandler = exports.PlayerPoses = exports.PlayerState = exports.EntityState = exports.BotcraftPhysics = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsWorldSettings = exports.EPhysicsCtx = void 0;
|
|
4
4
|
exports.default = loader;
|
|
5
5
|
exports.initSetup = initSetup;
|
|
6
6
|
const settings_1 = require("./physics/settings");
|
|
@@ -28,3 +28,5 @@ Object.defineProperty(exports, "PlayerState", { enumerable: true, get: function
|
|
|
28
28
|
Object.defineProperty(exports, "PlayerPoses", { enumerable: true, get: function () { return states_1.PlayerPoses; } });
|
|
29
29
|
var player_1 = require("./physics/player");
|
|
30
30
|
Object.defineProperty(exports, "ControlStateHandler", { enumerable: true, get: function () { return player_1.ControlStateHandler; } });
|
|
31
|
+
var physicsUtils_1 = require("./util/physicsUtils");
|
|
32
|
+
Object.defineProperty(exports, "convertPlayerState", { enumerable: true, get: function () { return physicsUtils_1.convertPlayerState; } });
|
|
@@ -157,7 +157,9 @@ class EPhysicsCtx {
|
|
|
157
157
|
return new EPhysicsCtx(ctx, settings, poses_1.PlayerPoses.STANDING, states_1.EntityState.CREATE_FROM_ENTITY(ctx, newE), entityType);
|
|
158
158
|
}
|
|
159
159
|
static FROM_ENTITY_STATE(ctx, entityState, entityType, settings) {
|
|
160
|
+
var _a;
|
|
160
161
|
settings !== null && settings !== void 0 ? settings : (settings = new physicsSettings_1.PhysicsWorldSettings(ctx.data));
|
|
162
|
+
(_a = entityState.pose) !== null && _a !== void 0 ? _a : (entityState.pose = poses_1.PlayerPoses.STANDING);
|
|
161
163
|
return new EPhysicsCtx(ctx, settings, entityState.pose, entityState, entityType);
|
|
162
164
|
}
|
|
163
165
|
clone() {
|
|
@@ -2,7 +2,10 @@ import { Entity } from "prismarine-entity";
|
|
|
2
2
|
import { EPhysicsCtx } from "../physics/settings";
|
|
3
3
|
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
4
4
|
import md from "minecraft-data";
|
|
5
|
+
import { PlayerState } from "../physics/states";
|
|
5
6
|
import { Vec3 } from "vec3";
|
|
7
|
+
import { IPhysics } from "../physics/engines";
|
|
8
|
+
import { Bot } from "mineflayer";
|
|
6
9
|
export declare function makeSupportFeature(mcData: md.IndexedData): (feature: string) => boolean;
|
|
7
10
|
type SupportFeature = ReturnType<typeof makeSupportFeature>;
|
|
8
11
|
export declare const DefaultPlayer: md.Entity;
|
|
@@ -54,4 +57,12 @@ export declare function getLookingVector(entity: {
|
|
|
54
57
|
lookZ: number;
|
|
55
58
|
lookDir: Vec3;
|
|
56
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Converts an old PlayerState object into the new PlayerState class format.
|
|
62
|
+
* * @param bot The current Mineflayer bot instance.
|
|
63
|
+
* @param oldState The old PlayerState object to migrate.
|
|
64
|
+
* @param ctx The IPhysics context required by the new PlayerState constructor.
|
|
65
|
+
* @returns A newly formatted PlayerState instance.
|
|
66
|
+
*/
|
|
67
|
+
export declare function convertPlayerState(bot: Bot, oldState: any, ctx: IPhysics): PlayerState;
|
|
57
68
|
export {};
|
|
@@ -13,8 +13,10 @@ exports.getStatusEffectNamesForVersion = getStatusEffectNamesForVersion;
|
|
|
13
13
|
exports.getEnchantmentNamesForVersion = getEnchantmentNamesForVersion;
|
|
14
14
|
exports.getBetweenRectangle = getBetweenRectangle;
|
|
15
15
|
exports.getLookingVector = getLookingVector;
|
|
16
|
+
exports.convertPlayerState = convertPlayerState;
|
|
16
17
|
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
17
18
|
const features_json_1 = __importDefault(require("../physics/info/features.json"));
|
|
19
|
+
const states_1 = require("../physics/states");
|
|
18
20
|
const vec3_1 = require("vec3");
|
|
19
21
|
function makeSupportFeature(mcData) {
|
|
20
22
|
return (feature) => features_json_1.default.some(({ name, versions }) => name === feature && versions.includes(mcData.version.majorVersion));
|
|
@@ -166,3 +168,53 @@ function getLookingVector(entity) {
|
|
|
166
168
|
lookDir
|
|
167
169
|
};
|
|
168
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Converts an old PlayerState object into the new PlayerState class format.
|
|
173
|
+
* * @param bot The current Mineflayer bot instance.
|
|
174
|
+
* @param oldState The old PlayerState object to migrate.
|
|
175
|
+
* @param ctx The IPhysics context required by the new PlayerState constructor.
|
|
176
|
+
* @returns A newly formatted PlayerState instance.
|
|
177
|
+
*/
|
|
178
|
+
function convertPlayerState(bot, oldState, ctx) {
|
|
179
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
180
|
+
// 1. Initialize the new state.
|
|
181
|
+
// This automatically runs update() and pulls the bot's current real state.
|
|
182
|
+
const newState = new states_1.PlayerState(ctx, bot);
|
|
183
|
+
// 2. Overwrite spatial and velocity data with the old simulated state
|
|
184
|
+
if (oldState.pos)
|
|
185
|
+
newState.pos.set(oldState.pos.x, oldState.pos.y, oldState.pos.z);
|
|
186
|
+
if (oldState.vel)
|
|
187
|
+
newState.vel.set(oldState.vel.x, oldState.vel.y, oldState.vel.z);
|
|
188
|
+
// 3. Map collision and environment flags
|
|
189
|
+
newState.onGround = (_a = oldState.onGround) !== null && _a !== void 0 ? _a : newState.onGround;
|
|
190
|
+
newState.isInWater = (_b = oldState.isInWater) !== null && _b !== void 0 ? _b : newState.isInWater;
|
|
191
|
+
newState.isInLava = (_c = oldState.isInLava) !== null && _c !== void 0 ? _c : newState.isInLava;
|
|
192
|
+
newState.isInWeb = (_d = oldState.isInWeb) !== null && _d !== void 0 ? _d : newState.isInWeb;
|
|
193
|
+
newState.isCollidedHorizontally = (_e = oldState.isCollidedHorizontally) !== null && _e !== void 0 ? _e : newState.isCollidedHorizontally;
|
|
194
|
+
newState.isCollidedVertically = (_f = oldState.isCollidedVertically) !== null && _f !== void 0 ? _f : newState.isCollidedVertically;
|
|
195
|
+
// 4. Map movement and action states
|
|
196
|
+
newState.elytraFlying = (_g = oldState.elytraFlying) !== null && _g !== void 0 ? _g : newState.elytraFlying;
|
|
197
|
+
newState.elytraEquipped = (_h = oldState.elytraEquipped) !== null && _h !== void 0 ? _h : newState.elytraEquipped;
|
|
198
|
+
newState.jumpTicks = (_j = oldState.jumpTicks) !== null && _j !== void 0 ? _j : newState.jumpTicks;
|
|
199
|
+
newState.jumpQueued = (_k = oldState.jumpQueued) !== null && _k !== void 0 ? _k : newState.jumpQueued;
|
|
200
|
+
newState.fireworkRocketDuration = (_l = oldState.fireworkRocketDuration) !== null && _l !== void 0 ? _l : newState.fireworkRocketDuration;
|
|
201
|
+
newState.yaw = (_m = oldState.yaw) !== null && _m !== void 0 ? _m : newState.yaw;
|
|
202
|
+
newState.pitch = (_o = oldState.pitch) !== null && _o !== void 0 ? _o : newState.pitch;
|
|
203
|
+
// 5. Map Control State
|
|
204
|
+
// The old state uses a standard object for controls; the new uses ControlStateHandler.
|
|
205
|
+
if (oldState.control) {
|
|
206
|
+
// Create a fresh clone of the bot's current controls, then overwrite with simulated ones
|
|
207
|
+
newState.control = states_1.ControlStateHandler.COPY_BOT(bot);
|
|
208
|
+
Object.assign(newState.control, oldState.control);
|
|
209
|
+
}
|
|
210
|
+
// 6. Map Attributes, Effects, and Enchantments
|
|
211
|
+
newState.attributes = (_p = oldState.attributes) !== null && _p !== void 0 ? _p : newState.attributes;
|
|
212
|
+
newState.jumpBoost = (_q = oldState.jumpBoost) !== null && _q !== void 0 ? _q : newState.jumpBoost;
|
|
213
|
+
newState.speed = (_r = oldState.speed) !== null && _r !== void 0 ? _r : newState.speed;
|
|
214
|
+
newState.slowness = (_s = oldState.slowness) !== null && _s !== void 0 ? _s : newState.slowness;
|
|
215
|
+
newState.dolphinsGrace = (_t = oldState.dolphinsGrace) !== null && _t !== void 0 ? _t : newState.dolphinsGrace;
|
|
216
|
+
newState.slowFalling = (_u = oldState.slowFalling) !== null && _u !== void 0 ? _u : newState.slowFalling;
|
|
217
|
+
newState.levitation = (_v = oldState.levitation) !== null && _v !== void 0 ? _v : newState.levitation;
|
|
218
|
+
newState.depthStrider = (_w = oldState.depthStrider) !== null && _w !== void 0 ? _w : newState.depthStrider;
|
|
219
|
+
return newState;
|
|
220
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxg-org/mineflayer-physics-util",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.18",
|
|
4
4
|
"description": "Provides functionality for more accurate entity and projectile tracking.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mineflayer",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"mineflayer-pathfinder": "^2.4.4",
|
|
38
38
|
"mocha": "^11.1.0",
|
|
39
39
|
"prismarine-entity": "^2.4.0",
|
|
40
|
+
"prismarine-physics": "^1.10.0",
|
|
40
41
|
"prismarine-registry": "^1.11.0",
|
|
41
42
|
"ts-node": "^10.9.2",
|
|
42
43
|
"typescript": "^5.8.2",
|