@nxg-org/mineflayer-physics-util 1.8.18 → 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 +1 -1
- package/dist/index.js +2 -1
- package/dist/util/physicsUtils.d.ts +7 -0
- package/dist/util/physicsUtils.js +55 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +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";
|
|
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.convertPlayerState = 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");
|
|
@@ -30,3 +30,4 @@ var player_1 = require("./physics/player");
|
|
|
30
30
|
Object.defineProperty(exports, "ControlStateHandler", { enumerable: true, get: function () { return player_1.ControlStateHandler; } });
|
|
31
31
|
var physicsUtils_1 = require("./util/physicsUtils");
|
|
32
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; } });
|
|
@@ -65,4 +65,11 @@ export declare function getLookingVector(entity: {
|
|
|
65
65
|
* @returns A newly formatted PlayerState instance.
|
|
66
66
|
*/
|
|
67
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;
|
|
68
75
|
export {};
|
|
@@ -14,6 +14,7 @@ exports.getEnchantmentNamesForVersion = getEnchantmentNamesForVersion;
|
|
|
14
14
|
exports.getBetweenRectangle = getBetweenRectangle;
|
|
15
15
|
exports.getLookingVector = getLookingVector;
|
|
16
16
|
exports.convertPlayerState = convertPlayerState;
|
|
17
|
+
exports.applyToPlayerState = applyToPlayerState;
|
|
17
18
|
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
18
19
|
const features_json_1 = __importDefault(require("../physics/info/features.json"));
|
|
19
20
|
const states_1 = require("../physics/states");
|
|
@@ -218,3 +219,57 @@ function convertPlayerState(bot, oldState, ctx) {
|
|
|
218
219
|
newState.depthStrider = (_w = oldState.depthStrider) !== null && _w !== void 0 ? _w : newState.depthStrider;
|
|
219
220
|
return newState;
|
|
220
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
|
+
}
|