@nxg-org/mineflayer-physics-util 1.8.12 → 1.8.13
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 +3 -1
- package/dist/simulators/baseSimulator.d.ts +12 -12
- package/dist/simulators/basicSim.d.ts +5 -12
- package/dist/simulators/basicSim.js +39 -20
- package/dist/wrapper.d.ts +0 -12
- package/dist/wrapper.js +9 -40
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export declare function initSetup(data: IndexedData): void;
|
|
|
11
11
|
export { EPhysicsCtx, PhysicsWorldSettings } from "./physics/settings";
|
|
12
12
|
export { BaseSimulator } from "./simulators";
|
|
13
13
|
export { EntityPhysics, BotcraftPhysics } from "./physics/engines";
|
|
14
|
-
export { EntityState } from "./physics/states";
|
|
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";
|
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.EntityState = exports.BotcraftPhysics = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsWorldSettings = exports.EPhysicsCtx = void 0;
|
|
3
|
+
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");
|
|
@@ -24,5 +24,7 @@ Object.defineProperty(exports, "EntityPhysics", { enumerable: true, get: functio
|
|
|
24
24
|
Object.defineProperty(exports, "BotcraftPhysics", { enumerable: true, get: function () { return engines_1.BotcraftPhysics; } });
|
|
25
25
|
var states_1 = require("./physics/states");
|
|
26
26
|
Object.defineProperty(exports, "EntityState", { enumerable: true, get: function () { return states_1.EntityState; } });
|
|
27
|
+
Object.defineProperty(exports, "PlayerState", { enumerable: true, get: function () { return states_1.PlayerState; } });
|
|
28
|
+
Object.defineProperty(exports, "PlayerPoses", { enumerable: true, get: function () { return states_1.PlayerPoses; } });
|
|
27
29
|
var player_1 = require("./physics/player");
|
|
28
30
|
Object.defineProperty(exports, "ControlStateHandler", { enumerable: true, get: function () { return player_1.ControlStateHandler; } });
|
|
@@ -4,19 +4,19 @@ import { EntityState, IEntityState } from "../physics/states";
|
|
|
4
4
|
import { IPhysics } from "../physics/engines";
|
|
5
5
|
import { Entity } from "prismarine-entity";
|
|
6
6
|
import { Vec3 } from "vec3";
|
|
7
|
-
export type SimulationGoal = (state:
|
|
8
|
-
export type OnGoalReachFunction = (state:
|
|
9
|
-
export type Controller = (state:
|
|
10
|
-
export declare class BaseSimulator {
|
|
7
|
+
export type SimulationGoal<State extends IEntityState = IEntityState> = (state: State, ticks: number) => boolean | ((state: State) => boolean);
|
|
8
|
+
export type OnGoalReachFunction<State extends IEntityState = IEntityState> = (state: State) => void;
|
|
9
|
+
export type Controller<State extends IEntityState = IEntityState> = (state: State, ticks: number) => void;
|
|
10
|
+
export declare class BaseSimulator<State extends IEntityState = IEntityState> {
|
|
11
11
|
readonly ctx: IPhysics;
|
|
12
12
|
constructor(ctx: IPhysics);
|
|
13
|
-
predictGenerator(simCtx: EPhysicsCtx
|
|
13
|
+
predictGenerator(simCtx: EPhysicsCtx<State>, world: any, ticks?: number, controls?: ControlStateHandler): Generator<IEntityState, EPhysicsCtx<State>, unknown>;
|
|
14
14
|
predictForward(target: Entity, world: any, ticks?: number, controls?: ControlStateHandler): EntityState;
|
|
15
|
-
predictForwardRaw(simCtx: EPhysicsCtx
|
|
16
|
-
simulateUntil(goal: SimulationGoal, onGoalReach: OnGoalReachFunction, controller: Controller, simCtx: EPhysicsCtx
|
|
17
|
-
static getReached(...path: Vec3[]): SimulationGoal
|
|
18
|
-
static getCleanupPosition(...path: Vec3[]): OnGoalReachFunction
|
|
19
|
-
static buildFullController(...controllers: Controller[]): Controller
|
|
20
|
-
static buildAnyGoal(...goals: SimulationGoal[]): SimulationGoal
|
|
21
|
-
static buildAllGoal(...goals: SimulationGoal[]): SimulationGoal
|
|
15
|
+
predictForwardRaw(simCtx: EPhysicsCtx<State>, world: any, ticks?: number, controls?: ControlStateHandler): State;
|
|
16
|
+
simulateUntil(goal: SimulationGoal, onGoalReach: OnGoalReachFunction, controller: Controller, simCtx: EPhysicsCtx<State>, world: any, ticks?: number): State;
|
|
17
|
+
static getReached<State extends IEntityState = IEntityState>(...path: Vec3[]): SimulationGoal<State>;
|
|
18
|
+
static getCleanupPosition<State extends IEntityState = IEntityState>(...path: Vec3[]): OnGoalReachFunction<State>;
|
|
19
|
+
static buildFullController<State extends IEntityState = IEntityState>(...controllers: Controller<State>[]): Controller<State>;
|
|
20
|
+
static buildAnyGoal<State extends IEntityState = IEntityState>(...goals: SimulationGoal<State>[]): SimulationGoal<State>;
|
|
21
|
+
static buildAllGoal<State extends IEntityState = IEntityState>(...goals: SimulationGoal<State>[]): SimulationGoal<State>;
|
|
22
22
|
}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import { Entity } from "prismarine-entity";
|
|
2
1
|
import { IPhysics } from "../physics/engines";
|
|
3
2
|
import { EPhysicsCtx } from "../physics/settings";
|
|
4
3
|
import { Vec3 } from "vec3";
|
|
5
4
|
import { BaseSimulator } from "./baseSimulator";
|
|
6
|
-
import
|
|
7
|
-
export declare class BasicSim extends BaseSimulator {
|
|
5
|
+
import { IEntityState } from "../physics/states";
|
|
6
|
+
export declare class BasicSim<State extends IEntityState = IEntityState> extends BaseSimulator<State> {
|
|
8
7
|
readonly ctx: IPhysics;
|
|
9
8
|
constructor(ctx: IPhysics);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
simUntilOnGroundRaw(mdEntity: md.Entity, world: any, ticks?: number, options?: Partial<Entity>): import("../physics/states").IEntityState;
|
|
14
|
-
simUntilOnGround(entity: Entity, world: any, ticks?: number): import("../physics/states").IEntityState;
|
|
15
|
-
simUntilOnGroundPrebuilt(ctx: EPhysicsCtx, world: any, ticks?: number): import("../physics/states").IEntityState;
|
|
16
|
-
simUntilDestinationRaw(mdEntity: md.Entity, destination: Vec3, world: any, ticks?: number, options?: Partial<Entity>): import("../physics/states").IEntityState;
|
|
17
|
-
simUntilDestination(entity: Entity, destination: Vec3, world: any, ticks?: number): import("../physics/states").IEntityState;
|
|
18
|
-
simUntilDestinationPrebuilt(ctx: EPhysicsCtx, destination: Vec3, world: any, ticks?: number): import("../physics/states").IEntityState;
|
|
9
|
+
simXTicksPrebuilt(ctx: EPhysicsCtx<State>, world: any, ticks: number): State;
|
|
10
|
+
simUntilOnGroundPrebuilt(ctx: EPhysicsCtx<State>, world: any, ticks?: number): State;
|
|
11
|
+
simUntilDestinationPrebuilt(ctx: EPhysicsCtx<State>, destination: Vec3, world: any, ticks?: number): State;
|
|
19
12
|
}
|
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BasicSim = void 0;
|
|
4
|
-
const physicsUtils_1 = require("../util/physicsUtils");
|
|
5
|
-
const settings_1 = require("../physics/settings");
|
|
6
4
|
const baseSimulator_1 = require("./baseSimulator");
|
|
7
5
|
class BasicSim extends baseSimulator_1.BaseSimulator {
|
|
8
6
|
constructor(ctx) {
|
|
9
7
|
super(ctx);
|
|
10
8
|
this.ctx = ctx;
|
|
11
9
|
}
|
|
12
|
-
simXTicksRaw(mdEntity, world, ticks = 5, options = {}) {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
simXTicks(entity, world, ticks) {
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
// public simXTicksRaw(mdEntity: md.Entity, world: any, ticks: number = 5, options: Partial<Entity> = {}) {
|
|
11
|
+
// return this.simXTicks(applyMdToNewEntity(EPhysicsCtx, mdEntity, options), world, ticks);
|
|
12
|
+
// }
|
|
13
|
+
// public simXTicks(entity: Entity, world: any, ticks: number) {
|
|
14
|
+
// return this.simulateUntil(
|
|
15
|
+
// (state) => false,
|
|
16
|
+
// () => {},
|
|
17
|
+
// () => {},
|
|
18
|
+
// EPhysicsCtx.FROM_ENTITY(this.ctx, entity),
|
|
19
|
+
// world,
|
|
20
|
+
// ticks
|
|
21
|
+
// );
|
|
22
|
+
// }
|
|
18
23
|
simXTicksPrebuilt(ctx, world, ticks) {
|
|
19
24
|
return this.simulateUntil((state) => false, () => { }, () => { }, ctx, world, ticks);
|
|
20
25
|
}
|
|
21
|
-
simUntilOnGroundRaw(mdEntity, world, ticks = 5, options = {}) {
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
simUntilOnGround(entity, world, ticks = 5) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// public simUntilOnGroundRaw(mdEntity: md.Entity, world: any, ticks: number = 5, options: Partial<Entity> = {}) {
|
|
27
|
+
// return this.simUntilOnGround(applyMdToNewEntity(EPhysicsCtx, mdEntity, options), world, ticks);
|
|
28
|
+
// }
|
|
29
|
+
// public simUntilOnGround(entity: Entity, world: any, ticks: number = 5) {
|
|
30
|
+
// return this.simulateUntil(
|
|
31
|
+
// (state) => state.onGround === true,
|
|
32
|
+
// () => {},
|
|
33
|
+
// () => {},
|
|
34
|
+
// EPhysicsCtx.FROM_ENTITY(this.ctx, entity),
|
|
35
|
+
// world,
|
|
36
|
+
// ticks
|
|
37
|
+
// );
|
|
38
|
+
// }
|
|
27
39
|
simUntilOnGroundPrebuilt(ctx, world, ticks = 5) {
|
|
28
40
|
return this.simulateUntil((state) => state.onGround === true, () => { }, () => { }, ctx, world, ticks);
|
|
29
41
|
}
|
|
30
|
-
simUntilDestinationRaw(mdEntity, destination, world, ticks = 5, options = {}) {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
simUntilDestination(entity, destination, world, ticks = 10) {
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
// public simUntilDestinationRaw(mdEntity: md.Entity, destination: Vec3, world: any, ticks: number = 5, options: Partial<Entity> = {}) {
|
|
43
|
+
// return this.simUntilDestination(applyMdToNewEntity(EPhysicsCtx, mdEntity, options), destination, world, ticks);
|
|
44
|
+
// }
|
|
45
|
+
// public simUntilDestination(entity: Entity, destination: Vec3, world: any, ticks: number = 10) {
|
|
46
|
+
// return this.simulateUntil(
|
|
47
|
+
// BasicSim.getReached(destination),
|
|
48
|
+
// () => {},
|
|
49
|
+
// () => {},
|
|
50
|
+
// EPhysicsCtx.FROM_ENTITY(this.ctx, entity),
|
|
51
|
+
// world,
|
|
52
|
+
// ticks
|
|
53
|
+
// );
|
|
54
|
+
// }
|
|
36
55
|
simUntilDestinationPrebuilt(ctx, destination, world, ticks = 10) {
|
|
37
56
|
return this.simulateUntil(BasicSim.getReached(destination), () => { }, () => { }, ctx, world, ticks);
|
|
38
57
|
}
|
package/dist/wrapper.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { EntityPhysics, IPhysics } from "./physics/engines";
|
|
2
2
|
import { EPhysicsCtx } from "./physics/settings";
|
|
3
|
-
import { Vec3 } from "vec3";
|
|
4
3
|
import md from "minecraft-data";
|
|
5
4
|
import type { Entity } from "prismarine-entity";
|
|
6
5
|
import type { Bot } from "mineflayer";
|
|
7
|
-
/**
|
|
8
|
-
* Just a convenience thing.
|
|
9
|
-
*/
|
|
10
|
-
export declare enum SimulationTypes {
|
|
11
|
-
UNTIL_GROUND = 0,
|
|
12
|
-
FOR_X_TICKS = 1,
|
|
13
|
-
TO_DESTINATION = 2
|
|
14
|
-
}
|
|
15
6
|
export declare class PhysicsUtilWrapper {
|
|
16
7
|
private bot;
|
|
17
8
|
engine: IPhysics;
|
|
@@ -21,7 +12,4 @@ export declare class PhysicsUtilWrapper {
|
|
|
21
12
|
getPhysicsSim(): EntityPhysics;
|
|
22
13
|
getPhysicsCtx(ctx: IPhysics, entity: Entity): EPhysicsCtx<import(".").EntityState>;
|
|
23
14
|
getPhysicsCtxRaw(ctx: IPhysics, entity: md.Entity, options?: Partial<Entity>): EPhysicsCtx<import(".").EntityState>;
|
|
24
|
-
simulate(simulator: IPhysics, simCtx: EPhysicsCtx, world: any): import("./physics/states").IEntityState;
|
|
25
|
-
exampleSim(entity: Entity, type: SimulationTypes, ticks?: number, destination?: Vec3): import("./physics/states").IEntityState;
|
|
26
|
-
advancedExample(simCtx: EPhysicsCtx, type: SimulationTypes, ticks?: number, destination?: Vec3): import("./physics/states").IEntityState;
|
|
27
15
|
}
|
package/dist/wrapper.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PhysicsUtilWrapper =
|
|
3
|
+
exports.PhysicsUtilWrapper = void 0;
|
|
4
4
|
const engines_1 = require("./physics/engines");
|
|
5
5
|
const settings_1 = require("./physics/settings");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
SimulationTypes[SimulationTypes["TO_DESTINATION"] = 2] = "TO_DESTINATION";
|
|
15
|
-
})(SimulationTypes || (exports.SimulationTypes = SimulationTypes = {}));
|
|
6
|
+
// /**
|
|
7
|
+
// * Just a convenience thing.
|
|
8
|
+
// */
|
|
9
|
+
// export enum SimulationTypes {
|
|
10
|
+
// UNTIL_GROUND,
|
|
11
|
+
// FOR_X_TICKS,
|
|
12
|
+
// TO_DESTINATION,
|
|
13
|
+
// }
|
|
16
14
|
class PhysicsUtilWrapper {
|
|
17
15
|
constructor(bot) {
|
|
18
16
|
this.bot = bot;
|
|
@@ -30,34 +28,5 @@ class PhysicsUtilWrapper {
|
|
|
30
28
|
getPhysicsCtxRaw(ctx, entity, options = {}) {
|
|
31
29
|
return settings_1.EPhysicsCtx.FROM_ENTITY_TYPE(ctx, entity, options);
|
|
32
30
|
}
|
|
33
|
-
simulate(simulator, simCtx, world) {
|
|
34
|
-
return simulator.simulate(simCtx, world);
|
|
35
|
-
}
|
|
36
|
-
exampleSim(entity, type, ticks = 10, destination) {
|
|
37
|
-
const simulator = new simulators_1.BasicSim(new engines_1.EntityPhysics(this.data));
|
|
38
|
-
switch (type) {
|
|
39
|
-
case SimulationTypes.FOR_X_TICKS:
|
|
40
|
-
return simulator.simXTicks(entity, this.bot.world, ticks);
|
|
41
|
-
case SimulationTypes.UNTIL_GROUND:
|
|
42
|
-
return simulator.simUntilOnGround(entity, this.bot.world, ticks);
|
|
43
|
-
case SimulationTypes.TO_DESTINATION:
|
|
44
|
-
if (!destination)
|
|
45
|
-
throw "Invalid destination for example sim.";
|
|
46
|
-
return simulator.simUntilDestination(entity, destination, this.bot.world, ticks);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
advancedExample(simCtx, type, ticks = 10, destination) {
|
|
50
|
-
const simulator = new simulators_1.BasicSim(new engines_1.EntityPhysics(this.data));
|
|
51
|
-
switch (type) {
|
|
52
|
-
case SimulationTypes.FOR_X_TICKS:
|
|
53
|
-
return simulator.simXTicksPrebuilt(simCtx, this.bot.world, ticks);
|
|
54
|
-
case SimulationTypes.UNTIL_GROUND:
|
|
55
|
-
return simulator.simUntilOnGroundPrebuilt(simCtx, this.bot.world, ticks);
|
|
56
|
-
case SimulationTypes.TO_DESTINATION:
|
|
57
|
-
if (!destination)
|
|
58
|
-
throw "Invalid destination for example sim.";
|
|
59
|
-
return simulator.simUntilDestinationPrebuilt(simCtx, destination, this.bot.world, ticks);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
31
|
}
|
|
63
32
|
exports.PhysicsUtilWrapper = PhysicsUtilWrapper;
|