@nxg-org/mineflayer-physics-util 1.7.2 → 1.7.4
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 +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/physics/engines/IPhysics.d.ts +2 -3
- package/dist/physics/engines/botcraft.d.ts +122 -0
- package/dist/physics/engines/botcraft.js +1265 -0
- package/dist/physics/engines/entityPhysics.d.ts +2 -2
- package/dist/physics/engines/entityPhysics.js +21 -13
- package/dist/physics/engines/index.d.ts +1 -0
- package/dist/physics/engines/index.js +1 -0
- package/dist/physics/engines/optimizedPhysics.d.ts +2 -2
- package/dist/physics/engines/optimizedPhysics.js +1 -1
- package/dist/physics/info/entity_physics.json +2 -1
- package/dist/physics/info/features.json +11 -1
- package/dist/physics/player/playerControls.d.ts +1 -0
- package/dist/physics/player/playerControls.js +10 -0
- package/dist/physics/settings/entityPhysicsCtx.d.ts +6 -16
- package/dist/physics/settings/entityPhysicsCtx.js +8 -34
- package/dist/physics/settings/physicsSettings.d.ts +0 -1
- package/dist/physics/settings/physicsSettings.js +1 -2
- package/dist/physics/states/entityState.d.ts +7 -34
- package/dist/physics/states/entityState.js +30 -30
- package/dist/physics/states/index.d.ts +45 -0
- package/dist/physics/states/index.js +7 -0
- package/dist/physics/states/playerState.d.ts +62 -18
- package/dist/physics/states/playerState.js +233 -82
- package/dist/physics/states/poses.d.ts +14 -0
- package/dist/physics/states/poses.js +17 -1
- package/dist/simulators/baseSimulator.d.ts +8 -8
- package/dist/simulators/baseSimulator.js +1 -1
- package/dist/simulators/basicSim.d.ts +9 -9
- package/dist/util/physicsUtils.d.ts +18 -8
- package/dist/util/physicsUtils.js +16 -6
- package/dist/wrapper.d.ts +3 -3
- package/package.json +7 -3
- package/tests/actualBot.ts +29 -6
- package/tests/fakeWorld.test.ts +246 -0
- package/tests/fakeWorld.ts +0 -116
package/.vscode/settings.json
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default function loader(bot: Bot): void;
|
|
|
10
10
|
export declare function initSetup(data: IndexedData): void;
|
|
11
11
|
export { EPhysicsCtx, PhysicsWorldSettings } from "./physics/settings";
|
|
12
12
|
export { BaseSimulator } from "./simulators";
|
|
13
|
-
export { EntityPhysics } from "./physics/engines";
|
|
13
|
+
export { EntityPhysics, BotcraftPhysics } from "./physics/engines";
|
|
14
14
|
export { EntityState } 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.EntityPhysics = exports.BaseSimulator = exports.PhysicsWorldSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
|
|
3
|
+
exports.ControlStateHandler = exports.EntityState = exports.BotcraftPhysics = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsWorldSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
|
|
4
4
|
const settings_1 = require("./physics/settings");
|
|
5
5
|
const wrapper_1 = require("./wrapper");
|
|
6
6
|
function loader(bot) {
|
|
@@ -21,6 +21,7 @@ var simulators_1 = require("./simulators");
|
|
|
21
21
|
Object.defineProperty(exports, "BaseSimulator", { enumerable: true, get: function () { return simulators_1.BaseSimulator; } });
|
|
22
22
|
var engines_1 = require("./physics/engines");
|
|
23
23
|
Object.defineProperty(exports, "EntityPhysics", { enumerable: true, get: function () { return engines_1.EntityPhysics; } });
|
|
24
|
+
Object.defineProperty(exports, "BotcraftPhysics", { enumerable: true, get: function () { return engines_1.BotcraftPhysics; } });
|
|
24
25
|
var states_1 = require("./physics/states");
|
|
25
26
|
Object.defineProperty(exports, "EntityState", { enumerable: true, get: function () { return states_1.EntityState; } });
|
|
26
27
|
var player_1 = require("./physics/player");
|
|
@@ -4,7 +4,7 @@ import { Effect } from "mineflayer";
|
|
|
4
4
|
import { Entity } from "prismarine-entity";
|
|
5
5
|
import { CheapEffects, CheapEnchantments, makeSupportFeature } from "../../util/physicsUtils";
|
|
6
6
|
import { EPhysicsCtx } from "../settings/entityPhysicsCtx";
|
|
7
|
-
import {
|
|
7
|
+
import { IEntityState } from "../states";
|
|
8
8
|
export type MobsByName = {
|
|
9
9
|
[mobName: string]: Entity;
|
|
10
10
|
};
|
|
@@ -13,9 +13,8 @@ export interface IPhysics {
|
|
|
13
13
|
supportFeature: ReturnType<typeof makeSupportFeature>;
|
|
14
14
|
getEffectLevel: (effect: CheapEffects, effects: Effect[]) => number;
|
|
15
15
|
getEnchantmentLevel: (effect: CheapEnchantments, enchantments: any[]) => number;
|
|
16
|
-
getUnderlyingBlockBBs(queryBB: AABB, world: any): AABB[];
|
|
17
16
|
getSurroundingBBs(queryBB: AABB, world: any): AABB[];
|
|
18
|
-
simulate(simCtx: EPhysicsCtx, world: any):
|
|
17
|
+
simulate(simCtx: EPhysicsCtx, world: any): IEntityState;
|
|
19
18
|
readonly statusEffectNames: {
|
|
20
19
|
[type in CheapEffects]: string;
|
|
21
20
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
2
|
+
import md from "minecraft-data";
|
|
3
|
+
import { Block } from "prismarine-block";
|
|
4
|
+
import { Effect } from "prismarine-entity";
|
|
5
|
+
import { Vec3 } from "vec3";
|
|
6
|
+
import { CheapEffects, CheapEnchantments, makeSupportFeature } from "../../util/physicsUtils";
|
|
7
|
+
import { EPhysicsCtx } from "../settings/entityPhysicsCtx";
|
|
8
|
+
import { IEntityState } from "../states";
|
|
9
|
+
import { IPhysics } from "./IPhysics";
|
|
10
|
+
import { PlayerState } from "../states";
|
|
11
|
+
type World = {
|
|
12
|
+
getBlock: (pos: Vec3) => Block;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Looking at this code, it's too specified towards players.
|
|
16
|
+
*
|
|
17
|
+
* I will eventually split this code into PlayerState and bot.entityState, where bot.entityState contains fewer controls.
|
|
18
|
+
*/
|
|
19
|
+
export declare class BotcraftPhysics implements IPhysics {
|
|
20
|
+
data: md.IndexedData;
|
|
21
|
+
movementSpeedAttribute: string;
|
|
22
|
+
jumpStrengthAttribute: string;
|
|
23
|
+
movementEfficiencyAttribute: string;
|
|
24
|
+
waterMovementEfficiencyAttribute: string;
|
|
25
|
+
stepHeightAttribute: string;
|
|
26
|
+
supportFeature: ReturnType<typeof makeSupportFeature>;
|
|
27
|
+
blockSlipperiness: {
|
|
28
|
+
[name: string]: number;
|
|
29
|
+
};
|
|
30
|
+
protected bedId: number;
|
|
31
|
+
protected slimeBlockId: number;
|
|
32
|
+
protected soulsandId: number;
|
|
33
|
+
protected berryBushId: number;
|
|
34
|
+
protected powderSnowId: number;
|
|
35
|
+
protected honeyblockId: number;
|
|
36
|
+
protected webId: number;
|
|
37
|
+
protected waterId: number;
|
|
38
|
+
protected lavaId: number;
|
|
39
|
+
protected ladderId: number;
|
|
40
|
+
protected vineId: number;
|
|
41
|
+
protected scaffoldId: number;
|
|
42
|
+
protected bubblecolumnId: number;
|
|
43
|
+
protected waterLike: Set<number>;
|
|
44
|
+
readonly statusEffectNames: {
|
|
45
|
+
[type in CheapEffects]: string;
|
|
46
|
+
};
|
|
47
|
+
readonly enchantmentNames: {
|
|
48
|
+
[type in CheapEnchantments]: string;
|
|
49
|
+
};
|
|
50
|
+
constructor(mcData: md.IndexedData);
|
|
51
|
+
getEntityBB(entity: EPhysicsCtx, pos: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
z: number;
|
|
55
|
+
}): AABB;
|
|
56
|
+
setPositionToBB(entity: EPhysicsCtx, bb: AABB, pos: {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
z: number;
|
|
60
|
+
}): void;
|
|
61
|
+
getSurroundingBBs(queryBB: AABB, world: World): AABB[];
|
|
62
|
+
getWaterInBB(bb: AABB, world: any): any[];
|
|
63
|
+
getEffectLevel(wantedEffect: CheapEffects, effects: Effect[]): number;
|
|
64
|
+
getEnchantmentLevel(wantedEnchantment: CheapEnchantments, enchantments: any[]): any;
|
|
65
|
+
private verGreaterThan;
|
|
66
|
+
private verLessThan;
|
|
67
|
+
private worldIsFree;
|
|
68
|
+
/**
|
|
69
|
+
* 1:1 copy of the original physicsTick function from botcraft
|
|
70
|
+
* https://github.com/adepierre/Botcraft/blob/6c572071b0237c27a85211a246ce10565ef4d80f/botcraft/src/Game/Physics/PhysicsManager.cpp#L277
|
|
71
|
+
*
|
|
72
|
+
*
|
|
73
|
+
* @param ctx
|
|
74
|
+
* @param world
|
|
75
|
+
*/
|
|
76
|
+
private physicsTick;
|
|
77
|
+
/**
|
|
78
|
+
* Assume later than 1.13.2 before calling this function.
|
|
79
|
+
* @param player
|
|
80
|
+
* @param world
|
|
81
|
+
*/
|
|
82
|
+
private updatePoses;
|
|
83
|
+
private fluidPhysics;
|
|
84
|
+
getFlow(block: Block, world: World): Vec3;
|
|
85
|
+
getLiquidHeightPcent(block: Block): number;
|
|
86
|
+
getRenderedDepth(block: Block): number;
|
|
87
|
+
private updateSwimming;
|
|
88
|
+
private localPlayerAIStep;
|
|
89
|
+
private inputsToCrouch;
|
|
90
|
+
private isSwimmingAndNotFlying;
|
|
91
|
+
private inputsToSprint;
|
|
92
|
+
/**
|
|
93
|
+
* TODO: almost certainly unfinished.
|
|
94
|
+
* @param player
|
|
95
|
+
* @param value
|
|
96
|
+
*/
|
|
97
|
+
setSprinting(ctx: EPhysicsCtx, value: boolean): void;
|
|
98
|
+
private inputsToFly;
|
|
99
|
+
private inputsToJump;
|
|
100
|
+
private getBlockBelowAffectingMovement;
|
|
101
|
+
/**
|
|
102
|
+
* Taken from original physics impl.
|
|
103
|
+
* @param entity
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
getMovementSpeedAttribute(entity: EPhysicsCtx): number;
|
|
107
|
+
/**
|
|
108
|
+
* Assume EPhysicsCtx is wrapping a PlayerState.
|
|
109
|
+
* @param ctx
|
|
110
|
+
* @param world
|
|
111
|
+
*/
|
|
112
|
+
movePlayer(ctx: EPhysicsCtx, world: World): void;
|
|
113
|
+
applyMovement(ctx: EPhysicsCtx, world: World): void;
|
|
114
|
+
checkInsideBlocks(player: PlayerState, world: World): void;
|
|
115
|
+
collideBoundingBox(world: World, bb: AABB, movement: Vec3): Vec3;
|
|
116
|
+
collideOneAxis(movedAABB: AABB, movement: Vec3, axis: number, colliders: AABB[]): void;
|
|
117
|
+
applyInputs(inputStrength: number, player: PlayerState): void;
|
|
118
|
+
isInClimbable(player: PlayerState, world: World): boolean;
|
|
119
|
+
getSupportingBlockPos(world: World, feetSliceAABB: AABB): Vec3 | null;
|
|
120
|
+
simulate(entity: EPhysicsCtx, world: World): IEntityState;
|
|
121
|
+
}
|
|
122
|
+
export {};
|