@nxg-org/mineflayer-physics-util 1.8.17 → 1.8.19

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, applyToPlayerState } 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.applyToPlayerState = 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,6 @@ 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; } });
33
+ Object.defineProperty(exports, "applyToPlayerState", { enumerable: true, get: function () { return physicsUtils_1.applyToPlayerState; } });
@@ -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,19 @@ 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;
68
+ /**
69
+ * Applies the values of the new PlayerState class back onto an old PlayerState object.
70
+ * This updates the oldState in-place.
71
+ * * @param newState The current, updated instance of the new PlayerState class.
72
+ * @param oldState The old PlayerState object to be overwritten.
73
+ */
74
+ export declare function applyToPlayerState(newState: PlayerState, oldState: any): void;
57
75
  export {};
@@ -13,8 +13,11 @@ exports.getStatusEffectNamesForVersion = getStatusEffectNamesForVersion;
13
13
  exports.getEnchantmentNamesForVersion = getEnchantmentNamesForVersion;
14
14
  exports.getBetweenRectangle = getBetweenRectangle;
15
15
  exports.getLookingVector = getLookingVector;
16
+ exports.convertPlayerState = convertPlayerState;
17
+ exports.applyToPlayerState = applyToPlayerState;
16
18
  const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
17
19
  const features_json_1 = __importDefault(require("../physics/info/features.json"));
20
+ const states_1 = require("../physics/states");
18
21
  const vec3_1 = require("vec3");
19
22
  function makeSupportFeature(mcData) {
20
23
  return (feature) => features_json_1.default.some(({ name, versions }) => name === feature && versions.includes(mcData.version.majorVersion));
@@ -166,3 +169,107 @@ function getLookingVector(entity) {
166
169
  lookDir
167
170
  };
168
171
  }
172
+ /**
173
+ * Converts an old PlayerState object into the new PlayerState class format.
174
+ * * @param bot The current Mineflayer bot instance.
175
+ * @param oldState The old PlayerState object to migrate.
176
+ * @param ctx The IPhysics context required by the new PlayerState constructor.
177
+ * @returns A newly formatted PlayerState instance.
178
+ */
179
+ function convertPlayerState(bot, oldState, ctx) {
180
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
181
+ // 1. Initialize the new state.
182
+ // This automatically runs update() and pulls the bot's current real state.
183
+ const newState = new states_1.PlayerState(ctx, bot);
184
+ // 2. Overwrite spatial and velocity data with the old simulated state
185
+ if (oldState.pos)
186
+ newState.pos.set(oldState.pos.x, oldState.pos.y, oldState.pos.z);
187
+ if (oldState.vel)
188
+ newState.vel.set(oldState.vel.x, oldState.vel.y, oldState.vel.z);
189
+ // 3. Map collision and environment flags
190
+ newState.onGround = (_a = oldState.onGround) !== null && _a !== void 0 ? _a : newState.onGround;
191
+ newState.isInWater = (_b = oldState.isInWater) !== null && _b !== void 0 ? _b : newState.isInWater;
192
+ newState.isInLava = (_c = oldState.isInLava) !== null && _c !== void 0 ? _c : newState.isInLava;
193
+ newState.isInWeb = (_d = oldState.isInWeb) !== null && _d !== void 0 ? _d : newState.isInWeb;
194
+ newState.isCollidedHorizontally = (_e = oldState.isCollidedHorizontally) !== null && _e !== void 0 ? _e : newState.isCollidedHorizontally;
195
+ newState.isCollidedVertically = (_f = oldState.isCollidedVertically) !== null && _f !== void 0 ? _f : newState.isCollidedVertically;
196
+ // 4. Map movement and action states
197
+ newState.elytraFlying = (_g = oldState.elytraFlying) !== null && _g !== void 0 ? _g : newState.elytraFlying;
198
+ newState.elytraEquipped = (_h = oldState.elytraEquipped) !== null && _h !== void 0 ? _h : newState.elytraEquipped;
199
+ newState.jumpTicks = (_j = oldState.jumpTicks) !== null && _j !== void 0 ? _j : newState.jumpTicks;
200
+ newState.jumpQueued = (_k = oldState.jumpQueued) !== null && _k !== void 0 ? _k : newState.jumpQueued;
201
+ newState.fireworkRocketDuration = (_l = oldState.fireworkRocketDuration) !== null && _l !== void 0 ? _l : newState.fireworkRocketDuration;
202
+ newState.yaw = (_m = oldState.yaw) !== null && _m !== void 0 ? _m : newState.yaw;
203
+ newState.pitch = (_o = oldState.pitch) !== null && _o !== void 0 ? _o : newState.pitch;
204
+ // 5. Map Control State
205
+ // The old state uses a standard object for controls; the new uses ControlStateHandler.
206
+ if (oldState.control) {
207
+ // Create a fresh clone of the bot's current controls, then overwrite with simulated ones
208
+ newState.control = states_1.ControlStateHandler.COPY_BOT(bot);
209
+ Object.assign(newState.control, oldState.control);
210
+ }
211
+ // 6. Map Attributes, Effects, and Enchantments
212
+ newState.attributes = (_p = oldState.attributes) !== null && _p !== void 0 ? _p : newState.attributes;
213
+ newState.jumpBoost = (_q = oldState.jumpBoost) !== null && _q !== void 0 ? _q : newState.jumpBoost;
214
+ newState.speed = (_r = oldState.speed) !== null && _r !== void 0 ? _r : newState.speed;
215
+ newState.slowness = (_s = oldState.slowness) !== null && _s !== void 0 ? _s : newState.slowness;
216
+ newState.dolphinsGrace = (_t = oldState.dolphinsGrace) !== null && _t !== void 0 ? _t : newState.dolphinsGrace;
217
+ newState.slowFalling = (_u = oldState.slowFalling) !== null && _u !== void 0 ? _u : newState.slowFalling;
218
+ newState.levitation = (_v = oldState.levitation) !== null && _v !== void 0 ? _v : newState.levitation;
219
+ newState.depthStrider = (_w = oldState.depthStrider) !== null && _w !== void 0 ? _w : newState.depthStrider;
220
+ return newState;
221
+ }
222
+ /**
223
+ * Applies the values of the new PlayerState class back onto an old PlayerState object.
224
+ * This updates the oldState in-place.
225
+ * * @param newState The current, updated instance of the new PlayerState class.
226
+ * @param oldState The old PlayerState object to be overwritten.
227
+ */
228
+ function applyToPlayerState(newState, oldState) {
229
+ // 1. Update Spatial and Velocity Data
230
+ // Using .set() preserves the original Vec3 object reference in the old state.
231
+ if (oldState.pos && newState.pos) {
232
+ oldState.pos.set(newState.pos.x, newState.pos.y, newState.pos.z);
233
+ }
234
+ if (oldState.vel && newState.vel) {
235
+ oldState.vel.set(newState.vel.x, newState.vel.y, newState.vel.z);
236
+ }
237
+ // 2. Map Environment & Collision Flags
238
+ oldState.onGround = newState.onGround;
239
+ oldState.isInWater = newState.isInWater;
240
+ oldState.isInLava = newState.isInLava;
241
+ oldState.isInWeb = newState.isInWeb;
242
+ oldState.isCollidedHorizontally = newState.isCollidedHorizontally;
243
+ oldState.isCollidedVertically = newState.isCollidedVertically;
244
+ // 3. Map Movement & Actions
245
+ oldState.elytraFlying = newState.elytraFlying;
246
+ oldState.elytraEquipped = newState.elytraEquipped;
247
+ oldState.jumpTicks = newState.jumpTicks;
248
+ oldState.jumpQueued = newState.jumpQueued;
249
+ oldState.fireworkRocketDuration = newState.fireworkRocketDuration;
250
+ oldState.yaw = newState.yaw;
251
+ oldState.pitch = newState.pitch;
252
+ // 4. Downgrade Control State
253
+ // Extracts standard booleans from the ControlStateHandler so the old state
254
+ // doesn't accidentally inherit class methods.
255
+ if (newState.control) {
256
+ oldState.control = {
257
+ forward: newState.control.forward,
258
+ back: newState.control.back,
259
+ left: newState.control.left,
260
+ right: newState.control.right,
261
+ jump: newState.control.jump,
262
+ sprint: newState.control.sprint,
263
+ sneak: newState.control.sneak
264
+ };
265
+ }
266
+ // 5. Map Attributes, Effects, and Enchantments
267
+ oldState.attributes = newState.attributes;
268
+ oldState.jumpBoost = newState.jumpBoost;
269
+ oldState.speed = newState.speed;
270
+ oldState.slowness = newState.slowness;
271
+ oldState.dolphinsGrace = newState.dolphinsGrace;
272
+ oldState.slowFalling = newState.slowFalling;
273
+ oldState.levitation = newState.levitation;
274
+ oldState.depthStrider = newState.depthStrider;
275
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-physics-util",
3
- "version": "1.8.17",
3
+ "version": "1.8.19",
4
4
  "description": "Provides functionality for more accurate entity and projectile tracking.",
5
5
  "keywords": [
6
6
  "mineflayer",