@nxg-org/mineflayer-physics-util 1.8.18 → 1.9.0
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/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/physics/engines/botcraft.d.ts +9 -1
- package/dist/physics/engines/botcraft.js +119 -85
- package/dist/physics/engines/entityPhysics.js +5 -5
- package/dist/physics/engines/optimizedPhysics.js +4 -4
- package/dist/physics/settings/physicsSettings.js +1 -1
- package/dist/physics/states/entityState.d.ts +6 -1
- package/dist/physics/states/entityState.js +22 -12
- package/dist/physics/states/index.d.ts +1 -0
- package/dist/physics/states/playerState.d.ts +6 -1
- package/dist/physics/states/playerState.js +29 -19
- package/dist/physics/states/poses.js +4 -4
- package/dist/util/physicsUtils.d.ts +7 -0
- package/dist/util/physicsUtils.js +72 -16
- package/eslint.config.mjs +17 -17
- package/package.json +49 -47
- package/tests/actualBot.ts +0 -201
- package/tests/fakeWorld.test.ts +0 -354
- package/tests/predictBot.ts +0 -73
- package/tests/util/testUtils.ts +0 -68
|
@@ -98,6 +98,15 @@ class PlayerState {
|
|
|
98
98
|
// console.trace('set sprinting', value)
|
|
99
99
|
this._sprinting = value;
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Deprecated compatibility alias for fallFlying.
|
|
103
|
+
*/
|
|
104
|
+
get elytraFlying() {
|
|
105
|
+
return this.fallFlying;
|
|
106
|
+
}
|
|
107
|
+
set elytraFlying(value) {
|
|
108
|
+
this.fallFlying = value;
|
|
109
|
+
}
|
|
101
110
|
get onGroundWithoutSupportingBlock() {
|
|
102
111
|
return this.onGround && !this.supportingBlockPos;
|
|
103
112
|
}
|
|
@@ -126,13 +135,13 @@ class PlayerState {
|
|
|
126
135
|
constructor(ctx, bot, control) {
|
|
127
136
|
this.age = 0;
|
|
128
137
|
this.onGround = false;
|
|
138
|
+
this.lastOnGround = false;
|
|
129
139
|
this.onClimbable = false;
|
|
130
140
|
this.isInWater = false;
|
|
131
141
|
this.isUnderWater = false;
|
|
132
142
|
this.isInLava = false;
|
|
133
143
|
this.isUnderLava = false;
|
|
134
144
|
this.isInWeb = false;
|
|
135
|
-
this.elytraFlying = false;
|
|
136
145
|
this.elytraEquipped = false;
|
|
137
146
|
this.fireworkRocketDuration = 0;
|
|
138
147
|
this.isCollidedHorizontally = false;
|
|
@@ -207,30 +216,30 @@ class PlayerState {
|
|
|
207
216
|
this.update(bot, playerControls_1.ControlStateHandler.COPY_BOT(bot));
|
|
208
217
|
}
|
|
209
218
|
update(bot, control) {
|
|
210
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
219
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
211
220
|
// const bot.entity = bot instanceof bot.entity ? bot : bot.entity;
|
|
212
221
|
// Input / Outputs
|
|
213
222
|
this.pos.set(bot.entity.position.x, bot.entity.position.y, bot.entity.position.z);
|
|
214
223
|
this.vel.set(bot.entity.velocity.x, bot.entity.velocity.y, bot.entity.velocity.z);
|
|
215
224
|
this.supportingBlockPos = (_a = bot.entity.supportingBlockPos) !== null && _a !== void 0 ? _a : null;
|
|
216
225
|
this.onGround = bot.entity.onGround;
|
|
226
|
+
this.lastOnGround = (_b = bot.entity.lastOnGround) !== null && _b !== void 0 ? _b : bot.entity.onGround;
|
|
217
227
|
this.onClimbable = bot.entity.onClimbable;
|
|
218
228
|
this.isInWater = bot.entity.isInWater;
|
|
219
229
|
this.isUnderWater = bot.entity.isUnderWater;
|
|
220
230
|
this.isInLava = bot.entity.isInLava;
|
|
221
231
|
this.isUnderLava = bot.entity.isUnderLava;
|
|
222
232
|
this.isInWeb = bot.entity.isInWeb;
|
|
223
|
-
this.
|
|
224
|
-
this.elytraEquipped = ((_b = bot.inventory.slots[bot.getEquipmentDestSlot('torso')]) === null || _b === void 0 ? void 0 : _b.name) === 'elytra';
|
|
233
|
+
this.elytraEquipped = ((_c = bot.inventory.slots[bot.getEquipmentDestSlot('torso')]) === null || _c === void 0 ? void 0 : _c.name) === 'elytra';
|
|
225
234
|
this.fireworkRocketDuration = bot.fireworkRocketDuration;
|
|
226
235
|
this.isCollidedHorizontally = bot.entity.isCollidedHorizontally;
|
|
227
236
|
this.isCollidedHorizontallyMinor = bot.entity.isCollidedHorizontallyMinor;
|
|
228
237
|
this.isCollidedVertically = bot.entity.isCollidedVertically;
|
|
229
238
|
// dunno what to do about these, ngl.
|
|
230
|
-
this.jumpTicks = (
|
|
231
|
-
this.jumpQueued = (
|
|
232
|
-
this.flyJumpTriggerTime = (
|
|
233
|
-
this.sprintTriggerTime = (
|
|
239
|
+
this.jumpTicks = (_d = bot.jumpTicks) !== null && _d !== void 0 ? _d : 0;
|
|
240
|
+
this.jumpQueued = (_e = bot.jumpQueued) !== null && _e !== void 0 ? _e : false;
|
|
241
|
+
this.flyJumpTriggerTime = (_f = bot.flyJumpTriggerTime) !== null && _f !== void 0 ? _f : 0;
|
|
242
|
+
this.sprintTriggerTime = (_g = bot.sprintTriggerTime) !== null && _g !== void 0 ? _g : 0;
|
|
234
243
|
// Input only (not modified)
|
|
235
244
|
this.attributes = bot.entity.attributes;
|
|
236
245
|
this.yaw = bot.entity.yaw;
|
|
@@ -252,7 +261,7 @@ class PlayerState {
|
|
|
252
261
|
const boots = bot.entity.equipment[5];
|
|
253
262
|
if (boots && boots.nbt) {
|
|
254
263
|
const simplifiedNbt = nbt.simplify(boots.nbt);
|
|
255
|
-
const enchantments = (
|
|
264
|
+
const enchantments = (_j = (_h = simplifiedNbt.Enchantments) !== null && _h !== void 0 ? _h : simplifiedNbt.ench) !== null && _j !== void 0 ? _j : [];
|
|
256
265
|
this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
257
266
|
this.soulSpeed = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.SOUL_SPEED, enchantments);
|
|
258
267
|
}
|
|
@@ -263,7 +272,7 @@ class PlayerState {
|
|
|
263
272
|
const leggings = bot.entity.equipment[3];
|
|
264
273
|
if (leggings && leggings.nbt) {
|
|
265
274
|
const simplifiedNbt = nbt.simplify(leggings.nbt);
|
|
266
|
-
const enchantments = (
|
|
275
|
+
const enchantments = (_l = (_k = simplifiedNbt.Enchantments) !== null && _k !== void 0 ? _k : simplifiedNbt.ench) !== null && _l !== void 0 ? _l : [];
|
|
267
276
|
this.swiftSneak = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.SWIFT_SNEAK, enchantments);
|
|
268
277
|
}
|
|
269
278
|
else {
|
|
@@ -273,10 +282,10 @@ class PlayerState {
|
|
|
273
282
|
this.gameMode = bot.game.gameMode;
|
|
274
283
|
this.food = bot.food;
|
|
275
284
|
// TODO:
|
|
276
|
-
this.swimming = (
|
|
277
|
-
this.sprinting = (
|
|
278
|
-
this.crouching = (
|
|
279
|
-
this.fallFlying = (
|
|
285
|
+
this.swimming = (_m = bot.entity.swimming) !== null && _m !== void 0 ? _m : false;
|
|
286
|
+
this.sprinting = (_o = bot.entity.sprinting) !== null && _o !== void 0 ? _o : false;
|
|
287
|
+
this.crouching = (_p = bot.entity.crouching) !== null && _p !== void 0 ? _p : false;
|
|
288
|
+
this.fallFlying = (_r = (_q = bot.entity.fallFlying) !== null && _q !== void 0 ? _q : bot.entity.elytraFlying) !== null && _r !== void 0 ? _r : false;
|
|
280
289
|
switch (bot.game.gameMode) {
|
|
281
290
|
case "creative":
|
|
282
291
|
this.flySpeed = 0.05;
|
|
@@ -298,18 +307,18 @@ class PlayerState {
|
|
|
298
307
|
return this;
|
|
299
308
|
}
|
|
300
309
|
apply(bot) {
|
|
301
|
-
var _a, _b, _c, _d
|
|
310
|
+
var _a, _b, _c, _d;
|
|
302
311
|
// const bot.entity = bot instanceof bot.entity ? bot : bot.entity;
|
|
303
312
|
bot.entity.position.set(this.pos.x, this.pos.y, this.pos.z);
|
|
304
313
|
bot.entity.velocity.set(this.vel.x, this.vel.y, this.vel.z);
|
|
305
314
|
bot.entity.onGround = this.onGround;
|
|
315
|
+
bot.entity.lastOnGround = this.lastOnGround;
|
|
306
316
|
bot.entity.onClimbable = this.onClimbable;
|
|
307
317
|
bot.entity.isInWater = this.isInWater;
|
|
308
318
|
bot.entity.isUnderWater = this.isUnderWater;
|
|
309
319
|
bot.entity.isInLava = this.isInLava;
|
|
310
320
|
bot.entity.isUnderLava = this.isUnderLava;
|
|
311
321
|
bot.entity.isInWeb = this.isInWeb;
|
|
312
|
-
bot.entity.elytraFlying = this.elytraFlying;
|
|
313
322
|
bot.entity.elytraEquipped = this.elytraEquipped;
|
|
314
323
|
bot.fireworkRocketDuration = this.fireworkRocketDuration;
|
|
315
324
|
bot.entity.isCollidedHorizontally = this.isCollidedHorizontally;
|
|
@@ -330,7 +339,8 @@ class PlayerState {
|
|
|
330
339
|
bot.entity.swimming = (_b = this.swimming) !== null && _b !== void 0 ? _b : false;
|
|
331
340
|
bot.entity.sprinting = (_c = this.sprinting) !== null && _c !== void 0 ? _c : false;
|
|
332
341
|
bot.entity.crouching = (_d = this.crouching) !== null && _d !== void 0 ? _d : false;
|
|
333
|
-
bot.entity.fallFlying =
|
|
342
|
+
bot.entity.fallFlying = this.fallFlying;
|
|
343
|
+
bot.entity.elytraFlying = this.fallFlying;
|
|
334
344
|
bot.entity.attributes = this.attributes;
|
|
335
345
|
this.control.applyControls(bot);
|
|
336
346
|
bot.entity.prevControl = this.prevControl;
|
|
@@ -341,13 +351,13 @@ class PlayerState {
|
|
|
341
351
|
tmp.pos.set(this.pos.x, this.pos.y, this.pos.z);
|
|
342
352
|
tmp.vel.set(this.vel.x, this.vel.y, this.vel.z);
|
|
343
353
|
tmp.onGround = this.onGround;
|
|
354
|
+
tmp.lastOnGround = this.lastOnGround;
|
|
344
355
|
tmp.onClimbable = this.onClimbable;
|
|
345
356
|
tmp.isInWater = this.isInWater;
|
|
346
357
|
tmp.isUnderWater = this.isUnderWater;
|
|
347
358
|
tmp.isInLava = this.isInLava;
|
|
348
359
|
tmp.isUnderLava = this.isUnderLava;
|
|
349
360
|
tmp.isInWeb = this.isInWeb;
|
|
350
|
-
tmp.elytraFlying = this.elytraFlying;
|
|
351
361
|
tmp.elytraEquipped = this.elytraEquipped;
|
|
352
362
|
tmp.fireworkRocketDuration = this.fireworkRocketDuration;
|
|
353
363
|
tmp.isCollidedHorizontally = this.isCollidedHorizontally;
|
|
@@ -397,13 +407,13 @@ class PlayerState {
|
|
|
397
407
|
this.pos.set(other.pos.x, other.pos.y, other.pos.z);
|
|
398
408
|
this.vel.set(other.vel.x, other.vel.y, other.vel.z);
|
|
399
409
|
this.onGround = other.onGround;
|
|
410
|
+
this.lastOnGround = other.lastOnGround;
|
|
400
411
|
this.onClimbable = other.onClimbable;
|
|
401
412
|
this.isInWater = other.isInWater;
|
|
402
413
|
this.isUnderWater = other.isUnderWater;
|
|
403
414
|
this.isInLava = other.isInLava;
|
|
404
415
|
this.isUnderLava = other.isUnderLava;
|
|
405
416
|
this.isInWeb = other.isInWeb;
|
|
406
|
-
this.elytraFlying = other.elytraFlying;
|
|
407
417
|
this.elytraEquipped = other.elytraEquipped;
|
|
408
418
|
this.fireworkRocketDuration = other.fireworkRocketDuration;
|
|
409
419
|
this.isCollidedHorizontally = other.isCollidedHorizontally;
|
|
@@ -17,12 +17,12 @@ var PlayerPoses;
|
|
|
17
17
|
})(PlayerPoses || (exports.PlayerPoses = PlayerPoses = {}));
|
|
18
18
|
exports.playerPoseCtx = {
|
|
19
19
|
0: { width: 0.6, height: 1.8 },
|
|
20
|
-
1: { width: 0.
|
|
21
|
-
2: { width: 0.
|
|
20
|
+
1: { width: 0.6, height: 0.6 },
|
|
21
|
+
2: { width: 0.2, height: 0.2 },
|
|
22
22
|
3: { width: 0.6, height: 0.6 },
|
|
23
23
|
4: { width: 0.6, height: 0.6 },
|
|
24
|
-
5: { width: 0.6, height:
|
|
25
|
-
6: { width: 0.6, height: 1.
|
|
24
|
+
5: { width: 0.6, height: 1.5 },
|
|
25
|
+
6: { width: 0.6, height: 1.8 },
|
|
26
26
|
7: { width: 0.2, height: 0.2 },
|
|
27
27
|
};
|
|
28
28
|
function getCollider(entityPose, middleBottomPos) {
|
|
@@ -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");
|
|
@@ -176,7 +177,7 @@ function getLookingVector(entity) {
|
|
|
176
177
|
* @returns A newly formatted PlayerState instance.
|
|
177
178
|
*/
|
|
178
179
|
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
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
180
181
|
// 1. Initialize the new state.
|
|
181
182
|
// This automatically runs update() and pulls the bot's current real state.
|
|
182
183
|
const newState = new states_1.PlayerState(ctx, bot);
|
|
@@ -193,13 +194,13 @@ function convertPlayerState(bot, oldState, ctx) {
|
|
|
193
194
|
newState.isCollidedHorizontally = (_e = oldState.isCollidedHorizontally) !== null && _e !== void 0 ? _e : newState.isCollidedHorizontally;
|
|
194
195
|
newState.isCollidedVertically = (_f = oldState.isCollidedVertically) !== null && _f !== void 0 ? _f : newState.isCollidedVertically;
|
|
195
196
|
// 4. Map movement and action states
|
|
196
|
-
newState.
|
|
197
|
-
newState.elytraEquipped = (
|
|
198
|
-
newState.jumpTicks = (
|
|
199
|
-
newState.jumpQueued = (
|
|
200
|
-
newState.fireworkRocketDuration = (
|
|
201
|
-
newState.yaw = (
|
|
202
|
-
newState.pitch = (
|
|
197
|
+
newState.fallFlying = (_h = (_g = oldState.fallFlying) !== null && _g !== void 0 ? _g : oldState.elytraFlying) !== null && _h !== void 0 ? _h : newState.fallFlying;
|
|
198
|
+
newState.elytraEquipped = (_j = oldState.elytraEquipped) !== null && _j !== void 0 ? _j : newState.elytraEquipped;
|
|
199
|
+
newState.jumpTicks = (_k = oldState.jumpTicks) !== null && _k !== void 0 ? _k : newState.jumpTicks;
|
|
200
|
+
newState.jumpQueued = (_l = oldState.jumpQueued) !== null && _l !== void 0 ? _l : newState.jumpQueued;
|
|
201
|
+
newState.fireworkRocketDuration = (_m = oldState.fireworkRocketDuration) !== null && _m !== void 0 ? _m : newState.fireworkRocketDuration;
|
|
202
|
+
newState.yaw = (_o = oldState.yaw) !== null && _o !== void 0 ? _o : newState.yaw;
|
|
203
|
+
newState.pitch = (_p = oldState.pitch) !== null && _p !== void 0 ? _p : newState.pitch;
|
|
203
204
|
// 5. Map Control State
|
|
204
205
|
// The old state uses a standard object for controls; the new uses ControlStateHandler.
|
|
205
206
|
if (oldState.control) {
|
|
@@ -208,13 +209,68 @@ function convertPlayerState(bot, oldState, ctx) {
|
|
|
208
209
|
Object.assign(newState.control, oldState.control);
|
|
209
210
|
}
|
|
210
211
|
// 6. Map Attributes, Effects, and Enchantments
|
|
211
|
-
newState.attributes = (
|
|
212
|
-
newState.jumpBoost = (
|
|
213
|
-
newState.speed = (
|
|
214
|
-
newState.slowness = (
|
|
215
|
-
newState.dolphinsGrace = (
|
|
216
|
-
newState.slowFalling = (
|
|
217
|
-
newState.levitation = (
|
|
218
|
-
newState.depthStrider = (
|
|
212
|
+
newState.attributes = (_q = oldState.attributes) !== null && _q !== void 0 ? _q : newState.attributes;
|
|
213
|
+
newState.jumpBoost = (_r = oldState.jumpBoost) !== null && _r !== void 0 ? _r : newState.jumpBoost;
|
|
214
|
+
newState.speed = (_s = oldState.speed) !== null && _s !== void 0 ? _s : newState.speed;
|
|
215
|
+
newState.slowness = (_t = oldState.slowness) !== null && _t !== void 0 ? _t : newState.slowness;
|
|
216
|
+
newState.dolphinsGrace = (_u = oldState.dolphinsGrace) !== null && _u !== void 0 ? _u : newState.dolphinsGrace;
|
|
217
|
+
newState.slowFalling = (_v = oldState.slowFalling) !== null && _v !== void 0 ? _v : newState.slowFalling;
|
|
218
|
+
newState.levitation = (_w = oldState.levitation) !== null && _w !== void 0 ? _w : newState.levitation;
|
|
219
|
+
newState.depthStrider = (_x = oldState.depthStrider) !== null && _x !== void 0 ? _x : 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.fallFlying = newState.fallFlying;
|
|
246
|
+
oldState.elytraFlying = newState.fallFlying;
|
|
247
|
+
oldState.elytraEquipped = newState.elytraEquipped;
|
|
248
|
+
oldState.jumpTicks = newState.jumpTicks;
|
|
249
|
+
oldState.jumpQueued = newState.jumpQueued;
|
|
250
|
+
oldState.fireworkRocketDuration = newState.fireworkRocketDuration;
|
|
251
|
+
oldState.yaw = newState.yaw;
|
|
252
|
+
oldState.pitch = newState.pitch;
|
|
253
|
+
// 4. Downgrade Control State
|
|
254
|
+
// Extracts standard booleans from the ControlStateHandler so the old state
|
|
255
|
+
// doesn't accidentally inherit class methods.
|
|
256
|
+
if (newState.control) {
|
|
257
|
+
oldState.control = {
|
|
258
|
+
forward: newState.control.forward,
|
|
259
|
+
back: newState.control.back,
|
|
260
|
+
left: newState.control.left,
|
|
261
|
+
right: newState.control.right,
|
|
262
|
+
jump: newState.control.jump,
|
|
263
|
+
sprint: newState.control.sprint,
|
|
264
|
+
sneak: newState.control.sneak
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
// 5. Map Attributes, Effects, and Enchantments
|
|
268
|
+
oldState.attributes = newState.attributes;
|
|
269
|
+
oldState.jumpBoost = newState.jumpBoost;
|
|
270
|
+
oldState.speed = newState.speed;
|
|
271
|
+
oldState.slowness = newState.slowness;
|
|
272
|
+
oldState.dolphinsGrace = newState.dolphinsGrace;
|
|
273
|
+
oldState.slowFalling = newState.slowFalling;
|
|
274
|
+
oldState.levitation = newState.levitation;
|
|
275
|
+
oldState.depthStrider = newState.depthStrider;
|
|
276
|
+
}
|
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,47 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@nxg-org/mineflayer-physics-util",
|
|
3
|
+
"version": "1.9.0",
|
|
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
|
+
"dependencies": {
|
|
19
|
+
"@nxg-org/mineflayer-util-plugin": "^1.8.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@eslint/js": "^9.23.0",
|
|
23
|
+
"@types/mocha": "^10.0.10",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.27.0",
|
|
25
|
+
"@typescript-eslint/parser": "^8.27.0",
|
|
26
|
+
"eslint": "^9.23.0",
|
|
27
|
+
"expect": "^29.7.0",
|
|
28
|
+
"globals": "^16.0.0",
|
|
29
|
+
"minecraft-data": "^3.83.1",
|
|
30
|
+
"mineflayer": "link:/home/genpc/github_stuff/mineflayer",
|
|
31
|
+
"mineflayer-pathfinder": "^2.4.4",
|
|
32
|
+
"mocha": "^11.1.0",
|
|
33
|
+
"prismarine-block": "^1.22.0",
|
|
34
|
+
"prismarine-entity": "^2.4.0",
|
|
35
|
+
"prismarine-nbt": "^2.8.0",
|
|
36
|
+
"prismarine-physics": "^1.10.0",
|
|
37
|
+
"prismarine-registry": "^1.11.0",
|
|
38
|
+
"prismarine-world": "^3.6.3",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
40
|
+
"typescript": "^5.8.2",
|
|
41
|
+
"typescript-eslint": "^8.27.0",
|
|
42
|
+
"vec3": "^0.1.10"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
46
|
+
"build": "npx tsc",
|
|
47
|
+
"test": "mocha --require ts-node/register --recursive tests/**/*.test.ts"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/tests/actualBot.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { pathfinder, goals } from "mineflayer-pathfinder";
|
|
2
|
-
import { Bot, createBot } from "mineflayer";
|
|
3
|
-
const physicsInject = require("mineflayer/lib/plugins/physics");
|
|
4
|
-
import loader, { BotcraftPhysics, EntityPhysics, EntityState, EPhysicsCtx } from "../src/index";
|
|
5
|
-
import { PlayerState } from "../src/physics/states";
|
|
6
|
-
|
|
7
|
-
const { Physics } = require("prismarine-physics");
|
|
8
|
-
|
|
9
|
-
const rl = require("readline").createInterface({
|
|
10
|
-
input: process.stdin,
|
|
11
|
-
output: process.stdout,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
let bot1: Bot;
|
|
15
|
-
function buildBot() {
|
|
16
|
-
console.log("hey!");
|
|
17
|
-
|
|
18
|
-
const bot = createBot({
|
|
19
|
-
host: process.argv[2] || 'localhost',
|
|
20
|
-
port: Number(process.argv[3]),
|
|
21
|
-
username: "testingbot",
|
|
22
|
-
version: process.argv[4],
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
bot.on('login', () => {
|
|
26
|
-
bot.chat("Hello! I am a testing bot!");
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
bot.once("spawn", async () => {
|
|
30
|
-
bot.loadPlugin(loader);
|
|
31
|
-
bot.loadPlugin(pathfinder);
|
|
32
|
-
await bot.waitForTicks(20);
|
|
33
|
-
(bot as any).physics.yawSpeed = 50;
|
|
34
|
-
(bot as any).physics.pitchSpeed = 50;
|
|
35
|
-
// setupNewPhysics(bot);
|
|
36
|
-
// setupNewPhysics(bot);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
bot.on('entityMoved', (entity => {
|
|
40
|
-
// if (entity !== bot.entity)
|
|
41
|
-
// console.log(entity.attributes)
|
|
42
|
-
}))
|
|
43
|
-
|
|
44
|
-
let wasOnGround = false;
|
|
45
|
-
const printNextPos = false;
|
|
46
|
-
|
|
47
|
-
bot.on("move", (pos) => {
|
|
48
|
-
// console.log(pos);
|
|
49
|
-
if (bot.entity.onGround && !wasOnGround) {
|
|
50
|
-
// bot.chat("Hit the ground! " + bot.entity.position.toString());
|
|
51
|
-
}
|
|
52
|
-
wasOnGround = bot.entity.onGround;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// print whenever another player hits the ground
|
|
56
|
-
const lastPositions: Record<string, boolean> = {};
|
|
57
|
-
bot.on("entityMoved", (entity) => {
|
|
58
|
-
if (entity.username && entity.username !== bot.username) {
|
|
59
|
-
// check by seeing is y value is an integer
|
|
60
|
-
if (Math.floor(entity.position.y) === entity.position.y && !lastPositions[entity.username]) {
|
|
61
|
-
// check if in liquid
|
|
62
|
-
const block = bot.blockAt(entity.position);
|
|
63
|
-
if (block && (block.type === bot.registry.blocksByName.water.id || block.type === bot.registry.blocksByName.lava.id)) return;
|
|
64
|
-
|
|
65
|
-
bot.chat(`${entity.username} hit the ground! ${entity.position.toString()}`);
|
|
66
|
-
lastPositions[entity.username] = true;
|
|
67
|
-
} else if (Math.floor(entity.position.y) !== entity.position.y) {
|
|
68
|
-
lastPositions[entity.username] = false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
let usingNew = false;
|
|
74
|
-
let oldSimulate: any = null;
|
|
75
|
-
let state: PlayerState | null = null;
|
|
76
|
-
|
|
77
|
-
function setupNewPhysics(bot: Bot) {
|
|
78
|
-
if (usingNew) return;
|
|
79
|
-
usingNew = true;
|
|
80
|
-
oldSimulate = (bot.physics as any).simulatePlayer;
|
|
81
|
-
|
|
82
|
-
const val = new BotcraftPhysics(bot.registry);
|
|
83
|
-
|
|
84
|
-
(EntityState.prototype as any).apply = function (this: EntityState, bot: Bot) {
|
|
85
|
-
console.log(this.control, this.isUsingItem);
|
|
86
|
-
this.applyToBot(bot);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const ctx = EPhysicsCtx.FROM_BOT(val, bot);
|
|
90
|
-
state = ctx.state as PlayerState;
|
|
91
|
-
|
|
92
|
-
// EntityPhysics.prototype.simulate = function (ctx, world) {
|
|
93
|
-
// bot.physics.simulatePlayer(ctx.state, world);
|
|
94
|
-
// }
|
|
95
|
-
|
|
96
|
-
(bot.physics as any).autojumpCooldown = 0;
|
|
97
|
-
// (bot.physics).jumpTicks = 0;
|
|
98
|
-
|
|
99
|
-
(bot.physics as any).simulatePlayer = (...args: any[]) => {
|
|
100
|
-
state!.update(bot);
|
|
101
|
-
ctx.state.jumpTicks = 0; // allow immediate jumping
|
|
102
|
-
return val.simulate(ctx, bot.world);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
bot.on("chat", async (user, message) => {
|
|
107
|
-
const [cmd, ...args] = message.split(" ");
|
|
108
|
-
const author = bot.nearestEntity((e) => e.username === user);
|
|
109
|
-
|
|
110
|
-
switch (cmd) {
|
|
111
|
-
case "using":
|
|
112
|
-
bot.chat(`Using new physics: ${usingNew}`);
|
|
113
|
-
break;
|
|
114
|
-
case "lookatme":
|
|
115
|
-
if (!author) return bot.chat("I can't see you!");
|
|
116
|
-
bot.lookAt(author.position.offset(0, author.height, 0));
|
|
117
|
-
break;
|
|
118
|
-
case "status":
|
|
119
|
-
const str0 = `pos: ${bot.entity.position.toString()}, vel: ${bot.entity.velocity.toString()}, yaw: ${bot.entity.yaw}, pitch: ${bot.entity.pitch}`;
|
|
120
|
-
bot.chat(str0);
|
|
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}`;
|
|
124
|
-
bot.chat(str);
|
|
125
|
-
|
|
126
|
-
if (state != null) {
|
|
127
|
-
const str1 = `crouching: ${state.crouching}, sprinting: ${state.sprinting}`;
|
|
128
|
-
bot.chat(str1);
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
case "use":
|
|
132
|
-
if (bot.usingHeldItem) bot.deactivateItem();
|
|
133
|
-
else bot.activateItem();
|
|
134
|
-
break;
|
|
135
|
-
case "useoff":
|
|
136
|
-
bot.deactivateItem();
|
|
137
|
-
bot.activateItem(true);
|
|
138
|
-
break;
|
|
139
|
-
case "control":
|
|
140
|
-
if (args[0] === "clear") return bot.clearControlStates();
|
|
141
|
-
if (args.length === 1) return bot.setControlState(args[0] as any, !bot.getControlState(args[0] as any));
|
|
142
|
-
bot.setControlState(args[0] as any, args[1] === "true");
|
|
143
|
-
break;
|
|
144
|
-
case "sim":
|
|
145
|
-
// turn all but the mentioned ones off
|
|
146
|
-
const [time, ...controls] = args;
|
|
147
|
-
bot.clearControlStates();
|
|
148
|
-
for (const control of controls) {
|
|
149
|
-
bot.setControlState(control as any, true);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
for (let i = 0; i <= Number(time); i++) {
|
|
153
|
-
console.log(bot.entity.position, bot.entity.velocity, i);
|
|
154
|
-
await bot.waitForTicks(1);
|
|
155
|
-
}
|
|
156
|
-
bot.clearControlStates();
|
|
157
|
-
|
|
158
|
-
break;
|
|
159
|
-
case "reset":
|
|
160
|
-
usingNew = false;
|
|
161
|
-
bot.quit();
|
|
162
|
-
await new Promise((res) => setTimeout(res, 3000));
|
|
163
|
-
bot1 = buildBot();
|
|
164
|
-
|
|
165
|
-
break;
|
|
166
|
-
case "new":
|
|
167
|
-
setupNewPhysics(bot);
|
|
168
|
-
bot.chat("Switched to new physics!");
|
|
169
|
-
break;
|
|
170
|
-
case "jump":
|
|
171
|
-
bot.setControlState("jump", true);
|
|
172
|
-
break;
|
|
173
|
-
case "come":
|
|
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
|
-
}
|
|
180
|
-
case "goto":
|
|
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
|
-
}
|
|
187
|
-
case "stop":
|
|
188
|
-
bot.deactivateItem();
|
|
189
|
-
bot.pathfinder.stop();
|
|
190
|
-
bot.clearControlStates();
|
|
191
|
-
bot.chat("Stopped!");
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
rl.on("line", (line: any) => bot.chat(line));
|
|
197
|
-
|
|
198
|
-
return bot;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
bot1 = buildBot();
|