@nxg-org/mineflayer-physics-util 1.2.1
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/README.md +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +30 -0
- package/lib/physics/engines/IPhysics.d.ts +30 -0
- package/lib/physics/engines/IPhysics.js +2 -0
- package/lib/physics/engines/entityPhysics.d.ts +90 -0
- package/lib/physics/engines/entityPhysics.js +697 -0
- package/lib/physics/engines/index.d.ts +2 -0
- package/lib/physics/engines/index.js +14 -0
- package/lib/physics/info/attributes.d.ts +15 -0
- package/lib/physics/info/attributes.js +55 -0
- package/lib/physics/info/features.json +32 -0
- package/lib/physics/info/math.d.ts +1 -0
- package/lib/physics/info/math.js +7 -0
- package/lib/physics/player/index.d.ts +1 -0
- package/lib/physics/player/index.js +13 -0
- package/lib/physics/player/playerControls.d.ts +41 -0
- package/lib/physics/player/playerControls.js +122 -0
- package/lib/physics/settings/entityPhysicsCtx.d.ts +52 -0
- package/lib/physics/settings/entityPhysicsCtx.js +95 -0
- package/lib/physics/settings/index.d.ts +2 -0
- package/lib/physics/settings/index.js +14 -0
- package/lib/physics/settings/physicsSettings.d.ts +54 -0
- package/lib/physics/settings/physicsSettings.js +169 -0
- package/lib/physics/states/entityState.d.ts +95 -0
- package/lib/physics/states/entityState.js +250 -0
- package/lib/physics/states/index.d.ts +3 -0
- package/lib/physics/states/index.js +15 -0
- package/lib/physics/states/playerState.d.ts +74 -0
- package/lib/physics/states/playerState.js +269 -0
- package/lib/physics/states/poses.d.ts +10 -0
- package/lib/physics/states/poses.js +15 -0
- package/lib/simulators/baseSimulator.d.ts +20 -0
- package/lib/simulators/baseSimulator.js +82 -0
- package/lib/simulators/basicSim.d.ts +21 -0
- package/lib/simulators/basicSim.js +102 -0
- package/lib/simulators/index.d.ts +6 -0
- package/lib/simulators/index.js +14 -0
- package/lib/tests/example.d.ts +1 -0
- package/lib/tests/example.js +14 -0
- package/lib/tests/fakeWorld.d.ts +1 -0
- package/lib/tests/fakeWorld.js +66 -0
- package/lib/tests/testSim.d.ts +1 -0
- package/lib/tests/testSim.js +45 -0
- package/lib/tests/usingInterface.d.ts +1 -0
- package/lib/tests/usingInterface.js +29 -0
- package/lib/tests/util/testUtils.d.ts +23 -0
- package/lib/tests/util/testUtils.js +46 -0
- package/lib/util/mathUtil.d.ts +1 -0
- package/lib/util/mathUtil.js +9 -0
- package/lib/util/physicsUtils.d.ts +32 -0
- package/lib/util/physicsUtils.js +96 -0
- package/lib/wrapper.d.ts +28 -0
- package/lib/wrapper.js +70 -0
- package/package.json +40 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhysicsSettings = void 0;
|
|
4
|
+
function load(data) {
|
|
5
|
+
PhysicsSettings.mcData = data;
|
|
6
|
+
PhysicsSettings.entityData = data["entitiesByName"];
|
|
7
|
+
PhysicsSettings.mobData = data["mobs"];
|
|
8
|
+
}
|
|
9
|
+
class PhysicsSettings {
|
|
10
|
+
constructor(ctx, gravity, terminalVelocity, airdrag, airborneInertia, airborneAcceleration, dragAfterAcceleration = false, useControls = false, sprintSpeed = 0.3, sneakSpeed = 0.3, usingItemSpeed = 0.2) {
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
this.gravity = gravity;
|
|
13
|
+
this.terminalVelocity = terminalVelocity;
|
|
14
|
+
this.airdrag = airdrag;
|
|
15
|
+
this.airborneInertia = airborneInertia;
|
|
16
|
+
this.airborneAcceleration = airborneAcceleration;
|
|
17
|
+
this.dragAfterAcceleration = dragAfterAcceleration;
|
|
18
|
+
this.useControls = useControls;
|
|
19
|
+
this.sprintSpeed = sprintSpeed;
|
|
20
|
+
this.sneakSpeed = sneakSpeed;
|
|
21
|
+
this.usingItemSpeed = usingItemSpeed;
|
|
22
|
+
this.yawSpeed = 3.0;
|
|
23
|
+
this.pitchSpeed = 3.0;
|
|
24
|
+
this.playerSpeed = 0.1;
|
|
25
|
+
this.stepHeight = 0.6; // how much height can the bot step on without jump
|
|
26
|
+
this.negligeableVelocity = 0.003; // actually 0.005 for 1.8; but seems fine
|
|
27
|
+
this.soulsandSpeed = 0.4;
|
|
28
|
+
this.honeyblockSpeed = 0.4;
|
|
29
|
+
this.honeyblockJumpSpeed = 0.4;
|
|
30
|
+
this.ladderMaxSpeed = 0.15;
|
|
31
|
+
this.ladderClimbSpeed = 0.2;
|
|
32
|
+
this.waterInertia = 0.8;
|
|
33
|
+
this.lavaInertia = 0.5;
|
|
34
|
+
this.liquidAcceleration = 0.02;
|
|
35
|
+
this.defaultSlipperiness = 0.6;
|
|
36
|
+
this.outOfLiquidImpulse = 0.3;
|
|
37
|
+
this.autojumpCooldown = 10; // ticks (0.5s)
|
|
38
|
+
this.bubbleColumnSurfaceDrag = {
|
|
39
|
+
down: 0.03,
|
|
40
|
+
maxDown: -0.9,
|
|
41
|
+
up: 0.1,
|
|
42
|
+
maxUp: 1.8,
|
|
43
|
+
};
|
|
44
|
+
this.bubbleColumnDrag = {
|
|
45
|
+
down: 0.03,
|
|
46
|
+
maxDown: -0.3,
|
|
47
|
+
up: 0.06,
|
|
48
|
+
maxUp: 0.7,
|
|
49
|
+
};
|
|
50
|
+
this.slowFalling = 0.125;
|
|
51
|
+
this.sprintingUUID = "662a6b8d-da3e-4c1c-8813-96ea6097278d"; // SPEED_MODIFIER_SPRINTING_UUID is from LivingEntity.java
|
|
52
|
+
this.jumpHeight = Math.fround(0.42);
|
|
53
|
+
this.movementSpeedAttribute = ctx.data.attributesByName.movementSpeed.resource;
|
|
54
|
+
if (ctx.supportFeature("independentLiquidGravity")) {
|
|
55
|
+
this.waterGravity = 0.02;
|
|
56
|
+
this.lavaGravity = 0.02;
|
|
57
|
+
}
|
|
58
|
+
else if (ctx.supportFeature("proportionalLiquidGravity")) {
|
|
59
|
+
this.waterGravity = this.gravity / 16;
|
|
60
|
+
this.lavaGravity = this.gravity / 4;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.waterGravity = 0.005;
|
|
64
|
+
this.lavaGravity = 0.02;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// entities: IndexedData["entitiesByName"],
|
|
68
|
+
//TODO: Perhaps get from type? Import indexedData to do it?
|
|
69
|
+
static FROM_ENTITY(ctx, baseEntity) {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
71
|
+
switch (baseEntity.type) {
|
|
72
|
+
case "player":
|
|
73
|
+
return new PhysicsSettings(ctx, 0.08, 3.92, Math.fround(1 - 0.02), 0.91, 0.02, true, true);
|
|
74
|
+
case "mob":
|
|
75
|
+
return new PhysicsSettings(ctx, 0.08, 3.92, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
76
|
+
case "orb":
|
|
77
|
+
return new PhysicsSettings(ctx, 0.03, 1.5, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
78
|
+
case "other":
|
|
79
|
+
if (((_a = baseEntity.name) === null || _a === void 0 ? void 0 : _a.includes("block")) || ((_b = baseEntity.name) === null || _b === void 0 ? void 0 : _b.includes("tnt"))) {
|
|
80
|
+
return new PhysicsSettings(ctx, 0.04, 2.0, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
81
|
+
}
|
|
82
|
+
else if ((_c = baseEntity.name) === null || _c === void 0 ? void 0 : _c.includes("minecart")) {
|
|
83
|
+
return new PhysicsSettings(ctx, 0.04, 0.76, Math.fround(1 - 0.05), 0.91, 0.02);
|
|
84
|
+
}
|
|
85
|
+
else if ((_d = baseEntity.name) === null || _d === void 0 ? void 0 : _d.includes("boat")) {
|
|
86
|
+
return new PhysicsSettings(ctx, 0.04, Infinity, 0, 0.91, 0.02);
|
|
87
|
+
}
|
|
88
|
+
else if (((_e = baseEntity.name) === null || _e === void 0 ? void 0 : _e.includes("egg")) ||
|
|
89
|
+
((_f = baseEntity.name) === null || _f === void 0 ? void 0 : _f.includes("snowball")) ||
|
|
90
|
+
((_g = baseEntity.name) === null || _g === void 0 ? void 0 : _g.includes("potion")) ||
|
|
91
|
+
((_h = baseEntity.name) === null || _h === void 0 ? void 0 : _h.includes("pearl"))) {
|
|
92
|
+
return new PhysicsSettings(ctx, 0.03, 3.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
93
|
+
}
|
|
94
|
+
else if ((_j = baseEntity.name) === null || _j === void 0 ? void 0 : _j.includes("orb")) {
|
|
95
|
+
return new PhysicsSettings(ctx, 0.03, 1.5, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
96
|
+
}
|
|
97
|
+
else if ((_k = baseEntity.name) === null || _k === void 0 ? void 0 : _k.includes("bobber")) {
|
|
98
|
+
return new PhysicsSettings(ctx, 0.03, 0.375, Math.fround(1 - 0.08), 0.91, 0.02);
|
|
99
|
+
}
|
|
100
|
+
else if ((_l = baseEntity.name) === null || _l === void 0 ? void 0 : _l.includes("spit")) {
|
|
101
|
+
return new PhysicsSettings(ctx, 0.06, 6.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
102
|
+
}
|
|
103
|
+
else if (((_m = baseEntity.name) === null || _m === void 0 ? void 0 : _m.includes("arrow")) || ((_o = baseEntity.name) === null || _o === void 0 ? void 0 : _o.includes("trident"))) {
|
|
104
|
+
return new PhysicsSettings(ctx, 0.05, 5.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
105
|
+
}
|
|
106
|
+
else if (((_p = baseEntity.name) === null || _p === void 0 ? void 0 : _p.includes("fireball")) || ((_q = baseEntity.name) === null || _q === void 0 ? void 0 : _q.includes("skull"))) {
|
|
107
|
+
return new PhysicsSettings(ctx, 0.0, 1.9, Math.fround(1 - 0.05), 0.91, 0.02, true);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return new PhysicsSettings(ctx, 0.08, 3.92, Math.fround(1 - 0.02), 0.91, 0.02, true, true);
|
|
111
|
+
}
|
|
112
|
+
static FROM_MD_ENTITY(ctx, mdEntity) {
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
114
|
+
if (mdEntity.type === "player" || !!PhysicsSettings.mobData[mdEntity.id]) {
|
|
115
|
+
return new PhysicsSettings(ctx, 0.08, 3.92, Math.fround(1 - 0.02), 0.91, 0.02, true, true);
|
|
116
|
+
}
|
|
117
|
+
if ((_a = mdEntity.name) === null || _a === void 0 ? void 0 : _a.includes("experience_bottle")) {
|
|
118
|
+
return new PhysicsSettings(ctx, 0.06, 6.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
119
|
+
}
|
|
120
|
+
if ((_b = mdEntity.name) === null || _b === void 0 ? void 0 : _b.includes("spit")) {
|
|
121
|
+
return new PhysicsSettings(ctx, 0.06, 6.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
122
|
+
}
|
|
123
|
+
switch (mdEntity.type) {
|
|
124
|
+
case "water_creature":
|
|
125
|
+
case "animal":
|
|
126
|
+
case "hostile":
|
|
127
|
+
case "mob":
|
|
128
|
+
return new PhysicsSettings(ctx, 0.08, 3.92, Math.fround(1 - 0.02), 0.91, 0.02, true, true);
|
|
129
|
+
case "projectile":
|
|
130
|
+
return new PhysicsSettings(ctx, 0.03, 3.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
131
|
+
case "orb":
|
|
132
|
+
return new PhysicsSettings(ctx, 0.03, 1.5, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
133
|
+
case "other":
|
|
134
|
+
if ((_c = mdEntity.name) === null || _c === void 0 ? void 0 : _c.includes("minecart")) {
|
|
135
|
+
return new PhysicsSettings(ctx, 0.04, 0.76, Math.fround(1 - 0.05), 0.91, 0.02);
|
|
136
|
+
}
|
|
137
|
+
else if (((_d = mdEntity.name) === null || _d === void 0 ? void 0 : _d.includes("block")) || ((_e = mdEntity.name) === null || _e === void 0 ? void 0 : _e.includes("tnt"))) {
|
|
138
|
+
return new PhysicsSettings(ctx, 0.04, 2.0, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
139
|
+
}
|
|
140
|
+
else if ((_f = mdEntity.name) === null || _f === void 0 ? void 0 : _f.includes("boat")) {
|
|
141
|
+
return new PhysicsSettings(ctx, 0.04, Infinity, 0, 0.91, 0.02);
|
|
142
|
+
}
|
|
143
|
+
else if (((_g = mdEntity.name) === null || _g === void 0 ? void 0 : _g.includes("egg")) ||
|
|
144
|
+
((_h = mdEntity.name) === null || _h === void 0 ? void 0 : _h.includes("snowball")) ||
|
|
145
|
+
((_j = mdEntity.name) === null || _j === void 0 ? void 0 : _j.includes("potion")) ||
|
|
146
|
+
((_k = mdEntity.name) === null || _k === void 0 ? void 0 : _k.includes("pearl"))) {
|
|
147
|
+
return new PhysicsSettings(ctx, 0.03, 3.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
148
|
+
}
|
|
149
|
+
else if ((_l = mdEntity.name) === null || _l === void 0 ? void 0 : _l.includes("orb")) {
|
|
150
|
+
return new PhysicsSettings(ctx, 0.03, 1.5, Math.fround(1 - 0.02), 0.91, 0.02);
|
|
151
|
+
}
|
|
152
|
+
else if ((_m = mdEntity.name) === null || _m === void 0 ? void 0 : _m.includes("bobber")) {
|
|
153
|
+
return new PhysicsSettings(ctx, 0.03, 0.375, Math.fround(1 - 0.08), 0.91, 0.02);
|
|
154
|
+
}
|
|
155
|
+
else if ((_o = mdEntity.name) === null || _o === void 0 ? void 0 : _o.includes("spit")) {
|
|
156
|
+
return new PhysicsSettings(ctx, 0.06, 6.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
157
|
+
}
|
|
158
|
+
else if (((_p = mdEntity.name) === null || _p === void 0 ? void 0 : _p.includes("arrow")) || ((_q = mdEntity.name) === null || _q === void 0 ? void 0 : _q.includes("trident"))) {
|
|
159
|
+
return new PhysicsSettings(ctx, 0.05, 5.0, Math.fround(1 - 0.01), 0.91, 0.02);
|
|
160
|
+
}
|
|
161
|
+
else if (((_r = mdEntity.name) === null || _r === void 0 ? void 0 : _r.includes("fireball")) || ((_s = mdEntity.name) === null || _s === void 0 ? void 0 : _s.includes("skull"))) {
|
|
162
|
+
return new PhysicsSettings(ctx, 0.0, 1.9, Math.fround(1 - 0.05), 0.91, 0.02, true);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return new PhysicsSettings(ctx, 0.08, 3.92, Math.fround(1 - 0.02), 0.91, 0.02, true, true);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.PhysicsSettings = PhysicsSettings;
|
|
169
|
+
PhysicsSettings.loadData = load;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
2
|
+
import type { Entity } from "prismarine-entity";
|
|
3
|
+
import type { Bot, Effect } from "mineflayer";
|
|
4
|
+
import { Vec3 } from "vec3";
|
|
5
|
+
import { ControlStateHandler } from "../player/playerControls";
|
|
6
|
+
import { PlayerState } from "./playerState";
|
|
7
|
+
import { PlayerPoses } from "./poses";
|
|
8
|
+
import { IPhysics } from "../engines";
|
|
9
|
+
export interface EntityStateBuilder {
|
|
10
|
+
height: number;
|
|
11
|
+
halfWidth: number;
|
|
12
|
+
position: Vec3;
|
|
13
|
+
velocity: Vec3;
|
|
14
|
+
pitch: number;
|
|
15
|
+
yaw: number;
|
|
16
|
+
controlState: ControlStateHandler;
|
|
17
|
+
onGround: boolean;
|
|
18
|
+
isUsingItem?: boolean;
|
|
19
|
+
isInWater?: boolean;
|
|
20
|
+
isInLava?: boolean;
|
|
21
|
+
isInWeb?: boolean;
|
|
22
|
+
sneakCollision?: boolean;
|
|
23
|
+
isCollidedHorizontally?: boolean;
|
|
24
|
+
isCollidedVertically?: boolean;
|
|
25
|
+
effects?: Effect[];
|
|
26
|
+
jumpBoost?: number;
|
|
27
|
+
speed?: number;
|
|
28
|
+
slowness?: number;
|
|
29
|
+
dolphinsGrace?: number;
|
|
30
|
+
slowFalling?: number;
|
|
31
|
+
levitation?: number;
|
|
32
|
+
depthStrider?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare class EntityState implements EntityStateBuilder {
|
|
35
|
+
ctx: IPhysics;
|
|
36
|
+
height: number;
|
|
37
|
+
halfWidth: number;
|
|
38
|
+
position: Vec3;
|
|
39
|
+
velocity: Vec3;
|
|
40
|
+
onGround: boolean;
|
|
41
|
+
controlState: ControlStateHandler;
|
|
42
|
+
yaw: number;
|
|
43
|
+
pitch: number;
|
|
44
|
+
age: number;
|
|
45
|
+
isInWater: boolean;
|
|
46
|
+
isInLava: boolean;
|
|
47
|
+
isInWeb: boolean;
|
|
48
|
+
isCollidedHorizontally: boolean;
|
|
49
|
+
isCollidedVertically: boolean;
|
|
50
|
+
jumpTicks: number;
|
|
51
|
+
jumpQueued: boolean;
|
|
52
|
+
sneakCollision: boolean;
|
|
53
|
+
attributes: any;
|
|
54
|
+
isUsingItem: boolean;
|
|
55
|
+
isUsingMainHand: boolean;
|
|
56
|
+
isUsingOffHand: boolean;
|
|
57
|
+
jumpBoost: number;
|
|
58
|
+
speed: number;
|
|
59
|
+
slowness: number;
|
|
60
|
+
dolphinsGrace: number;
|
|
61
|
+
slowFalling: number;
|
|
62
|
+
levitation: number;
|
|
63
|
+
depthStrider: number;
|
|
64
|
+
effects: Effect[];
|
|
65
|
+
pose: PlayerPoses;
|
|
66
|
+
constructor(ctx: IPhysics, height: number, halfWidth: number, position: Vec3, velocity: Vec3, onGround: boolean, controlState: ControlStateHandler, yaw: number, pitch: number);
|
|
67
|
+
static CREATE_FROM_BOT(ctx: IPhysics, bot: Bot): EntityState;
|
|
68
|
+
static CREATE_FROM_ENTITY(ctx: IPhysics, entity: Entity): EntityState;
|
|
69
|
+
static CREATE_FROM_PLAYER_STATE(ctx: IPhysics, state: PlayerState): EntityState;
|
|
70
|
+
/**
|
|
71
|
+
* Slightly different from the other two, use a pre-built object (assuming cloned) material.
|
|
72
|
+
* @param ctx Physics instance.
|
|
73
|
+
* @param raw CONSUMEABLE, build this with clones.
|
|
74
|
+
* @returns PhysicsState
|
|
75
|
+
*/
|
|
76
|
+
static CREATE_RAW(ctx: IPhysics, raw: EntityStateBuilder): EntityState;
|
|
77
|
+
updateFromBot(bot: Bot): EntityState;
|
|
78
|
+
updateFromEntity(entity: Entity): this;
|
|
79
|
+
updateFromRaw(other: EntityStateBuilder): this;
|
|
80
|
+
applyToBot(bot: Bot): this;
|
|
81
|
+
/**
|
|
82
|
+
* No idea when you'd use this.
|
|
83
|
+
*/
|
|
84
|
+
applyToEntity(entity: Entity): this;
|
|
85
|
+
clone(): EntityState;
|
|
86
|
+
merge(other: EntityState): this;
|
|
87
|
+
clearControlStates(): EntityState;
|
|
88
|
+
/**
|
|
89
|
+
* needs to be updated.
|
|
90
|
+
* @returns AABB
|
|
91
|
+
*/
|
|
92
|
+
getAABB(): AABB;
|
|
93
|
+
getUnderlyingBlockBBs(world: any): AABB[];
|
|
94
|
+
getSurroundingBBs(world: any): AABB[];
|
|
95
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EntityState = void 0;
|
|
7
|
+
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
8
|
+
const physicsUtils_1 = require("../../util/physicsUtils");
|
|
9
|
+
const vec3_1 = require("vec3");
|
|
10
|
+
const playerControls_1 = require("../player/playerControls");
|
|
11
|
+
const poses_1 = require("./poses");
|
|
12
|
+
const prismarine_nbt_1 = __importDefault(require("prismarine-nbt"));
|
|
13
|
+
const emptyVec = new vec3_1.Vec3(0, 0, 0);
|
|
14
|
+
class EntityState {
|
|
15
|
+
// public effects: Effect[];
|
|
16
|
+
// public statusEffectNames;
|
|
17
|
+
constructor(ctx, height, halfWidth, position, velocity, onGround, controlState, yaw, pitch) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
this.height = height;
|
|
20
|
+
this.halfWidth = halfWidth;
|
|
21
|
+
this.position = position;
|
|
22
|
+
this.velocity = velocity;
|
|
23
|
+
this.onGround = onGround;
|
|
24
|
+
this.controlState = controlState;
|
|
25
|
+
this.yaw = yaw;
|
|
26
|
+
this.pitch = pitch;
|
|
27
|
+
// may keep this, may not. Who knows?
|
|
28
|
+
this.age = 0;
|
|
29
|
+
this.isInWater = false;
|
|
30
|
+
this.isInLava = false;
|
|
31
|
+
this.isInWeb = false;
|
|
32
|
+
this.isCollidedHorizontally = false;
|
|
33
|
+
this.isCollidedVertically = false;
|
|
34
|
+
this.sneakCollision = false; //TODO
|
|
35
|
+
//not sure what to do here, ngl.
|
|
36
|
+
this.jumpTicks = 0;
|
|
37
|
+
this.jumpQueued = false;
|
|
38
|
+
// Input only (not modified)
|
|
39
|
+
this.attributes = {}; //TODO
|
|
40
|
+
this.isUsingItem = false;
|
|
41
|
+
this.isUsingMainHand = false;
|
|
42
|
+
this.isUsingOffHand = false;
|
|
43
|
+
// effects
|
|
44
|
+
this.effects = [];
|
|
45
|
+
this.jumpBoost = 0;
|
|
46
|
+
this.speed = 0;
|
|
47
|
+
this.slowness = 0;
|
|
48
|
+
this.dolphinsGrace = 0;
|
|
49
|
+
this.slowFalling = 0;
|
|
50
|
+
this.levitation = 0;
|
|
51
|
+
this.depthStrider = 0;
|
|
52
|
+
this.pose = poses_1.PlayerPoses.STANDING;
|
|
53
|
+
}
|
|
54
|
+
static CREATE_FROM_BOT(ctx, bot) {
|
|
55
|
+
return new EntityState(ctx, bot.entity.height, bot.entity.width / 2, bot.entity.position.clone(), bot.entity.velocity.clone(), bot.entity.onGround, playerControls_1.ControlStateHandler.COPY_BOT(bot), bot.entity.yaw, bot.entity.pitch).updateFromBot(bot);
|
|
56
|
+
}
|
|
57
|
+
static CREATE_FROM_ENTITY(ctx, entity) {
|
|
58
|
+
return new EntityState(ctx, entity.height, entity.width / 2, entity.position.clone(), entity.velocity.clone(), entity.onGround, playerControls_1.ControlStateHandler.DEFAULT(), entity.yaw, entity.pitch).updateFromEntity(entity);
|
|
59
|
+
}
|
|
60
|
+
static CREATE_FROM_PLAYER_STATE(ctx, state) {
|
|
61
|
+
return new EntityState(ctx, state.height, state.halfWidth, state.position.clone(), state.velocity.clone(), state.onGround, state.controlState.clone(), state.yaw, state.pitch).updateFromRaw(state);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Slightly different from the other two, use a pre-built object (assuming cloned) material.
|
|
65
|
+
* @param ctx Physics instance.
|
|
66
|
+
* @param raw CONSUMEABLE, build this with clones.
|
|
67
|
+
* @returns PhysicsState
|
|
68
|
+
*/
|
|
69
|
+
static CREATE_RAW(ctx, raw) {
|
|
70
|
+
return new EntityState(ctx, raw.height, raw.halfWidth, raw.position, raw.velocity, raw.onGround, raw.controlState, raw.yaw, raw.pitch);
|
|
71
|
+
}
|
|
72
|
+
updateFromBot(bot) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
this.controlState = playerControls_1.ControlStateHandler.COPY_BOT(bot);
|
|
75
|
+
this.onGround = this.onGround;
|
|
76
|
+
this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(bot.entity);
|
|
77
|
+
this.attributes = bot.entity.attributes;
|
|
78
|
+
this.effects = bot.entity.effects;
|
|
79
|
+
this.jumpBoost = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.JUMP_BOOST, this.effects);
|
|
80
|
+
this.speed = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.SPEED, this.effects);
|
|
81
|
+
this.slowness = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.SLOWNESS, this.effects);
|
|
82
|
+
this.dolphinsGrace = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.DOLPHINS_GRACE, this.effects);
|
|
83
|
+
this.slowFalling = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.SLOW_FALLING, this.effects);
|
|
84
|
+
this.levitation = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.LEVITATION, this.effects);
|
|
85
|
+
const boots = bot.entity.equipment[5];
|
|
86
|
+
if (boots && boots.nbt) {
|
|
87
|
+
const simplifiedNbt = prismarine_nbt_1.default.simplify(boots.nbt);
|
|
88
|
+
const enchantments = (_b = (_a = simplifiedNbt.Enchantments) !== null && _a !== void 0 ? _a : simplifiedNbt.ench) !== null && _b !== void 0 ? _b : [];
|
|
89
|
+
this.depthStrider = this.ctx.getEnchantmentLevelCustom(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.depthStrider = 0;
|
|
93
|
+
}
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
updateFromEntity(entity) {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
this.position = entity.position.clone();
|
|
99
|
+
this.velocity = entity.velocity.clone();
|
|
100
|
+
this.onGround = entity.onGround;
|
|
101
|
+
this.isInWater = entity.isInWater;
|
|
102
|
+
this.isInLava = entity.isInLava;
|
|
103
|
+
this.isInWeb = entity.isInWeb;
|
|
104
|
+
this.isCollidedHorizontally = entity.isCollidedHorizontally;
|
|
105
|
+
this.isCollidedVertically = entity.isCollidedVertically;
|
|
106
|
+
this.sneakCollision = false; //TODO
|
|
107
|
+
//not sure what to do here, ngl.
|
|
108
|
+
this.jumpTicks = 0;
|
|
109
|
+
this.jumpQueued = false;
|
|
110
|
+
// Input only (not modified)
|
|
111
|
+
this.attributes = entity.attributes;
|
|
112
|
+
this.yaw = entity.yaw;
|
|
113
|
+
this.pitch = entity.pitch;
|
|
114
|
+
this.controlState = playerControls_1.ControlStateHandler.DEFAULT();
|
|
115
|
+
this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(entity);
|
|
116
|
+
this.isUsingMainHand = !(0, physicsUtils_1.whichHandIsEntityUsingBoolean)(entity) && this.isUsingItem;
|
|
117
|
+
this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(entity) && this.isUsingItem;
|
|
118
|
+
// effects
|
|
119
|
+
this.effects = entity.effects;
|
|
120
|
+
this.jumpBoost = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.JUMP_BOOST, this.effects);
|
|
121
|
+
this.speed = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.SPEED, this.effects);
|
|
122
|
+
this.slowness = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.SLOWNESS, this.effects);
|
|
123
|
+
this.dolphinsGrace = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.DOLPHINS_GRACE, this.effects);
|
|
124
|
+
this.slowFalling = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.SLOW_FALLING, this.effects);
|
|
125
|
+
this.levitation = this.ctx.getEffectLevelCustom(physicsUtils_1.CheapEffects.LEVITATION, this.effects);
|
|
126
|
+
// armour enchantments
|
|
127
|
+
//const boots = bot.inventory.slots[8];
|
|
128
|
+
const boots = entity.equipment[5];
|
|
129
|
+
if (boots && boots.nbt) {
|
|
130
|
+
const simplifiedNbt = prismarine_nbt_1.default.simplify(boots.nbt);
|
|
131
|
+
const enchantments = (_b = (_a = simplifiedNbt.Enchantments) !== null && _a !== void 0 ? _a : simplifiedNbt.ench) !== null && _b !== void 0 ? _b : [];
|
|
132
|
+
this.depthStrider = this.ctx.getEnchantmentLevelCustom(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.depthStrider = 0;
|
|
136
|
+
}
|
|
137
|
+
this.pose = poses_1.PlayerPoses.STANDING;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
updateFromRaw(other) {
|
|
141
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
142
|
+
this.onGround = (_a = other.onGround) !== null && _a !== void 0 ? _a : this.onGround;
|
|
143
|
+
this.sneakCollision = (_b = other.sneakCollision) !== null && _b !== void 0 ? _b : this.sneakCollision;
|
|
144
|
+
this.isUsingItem = (_c = other.isUsingItem) !== null && _c !== void 0 ? _c : this.isUsingItem;
|
|
145
|
+
this.jumpBoost = (_d = other.jumpBoost) !== null && _d !== void 0 ? _d : this.jumpBoost;
|
|
146
|
+
this.speed = (_e = other.speed) !== null && _e !== void 0 ? _e : this.speed;
|
|
147
|
+
this.slowness = (_f = other.slowness) !== null && _f !== void 0 ? _f : this.slowness;
|
|
148
|
+
this.dolphinsGrace = (_g = other.dolphinsGrace) !== null && _g !== void 0 ? _g : this.dolphinsGrace;
|
|
149
|
+
this.slowFalling = (_h = other.slowFalling) !== null && _h !== void 0 ? _h : this.slowFalling;
|
|
150
|
+
this.levitation = (_j = other.levitation) !== null && _j !== void 0 ? _j : this.levitation;
|
|
151
|
+
this.depthStrider = (_k = other.depthStrider) !== null && _k !== void 0 ? _k : this.depthStrider;
|
|
152
|
+
this.effects = (_l = other.effects) !== null && _l !== void 0 ? _l : this.effects;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
applyToBot(bot) {
|
|
156
|
+
bot.entity.position = this.position;
|
|
157
|
+
bot.entity.velocity = this.velocity;
|
|
158
|
+
bot.entity.onGround = this.onGround;
|
|
159
|
+
bot.entity.yaw = this.yaw;
|
|
160
|
+
bot.entity.pitch = this.pitch;
|
|
161
|
+
bot.controlState = this.controlState;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* No idea when you'd use this.
|
|
166
|
+
*/
|
|
167
|
+
applyToEntity(entity) {
|
|
168
|
+
entity.position = this.position;
|
|
169
|
+
entity.velocity = this.velocity;
|
|
170
|
+
entity.onGround = this.onGround;
|
|
171
|
+
entity.yaw = this.yaw;
|
|
172
|
+
entity.pitch = this.pitch;
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
clone() {
|
|
176
|
+
const other = new EntityState(this.ctx, this.height, this.halfWidth, this.position.clone(), this.velocity.clone(), this.onGround, this.controlState.clone(), this.yaw, this.pitch);
|
|
177
|
+
other.age = this.age;
|
|
178
|
+
other.isCollidedHorizontally = this.isCollidedHorizontally;
|
|
179
|
+
other.isCollidedVertically = this.isCollidedVertically;
|
|
180
|
+
other.isInWater = this.isInWater;
|
|
181
|
+
other.isInLava = this.isInLava;
|
|
182
|
+
other.isInWeb = this.isInWeb;
|
|
183
|
+
other.jumpTicks = this.jumpTicks;
|
|
184
|
+
other.jumpQueued = this.jumpQueued;
|
|
185
|
+
other.sneakCollision = this.sneakCollision;
|
|
186
|
+
other.attributes = this.attributes;
|
|
187
|
+
other.isUsingItem = this.isUsingItem;
|
|
188
|
+
other.isUsingMainHand = this.isUsingMainHand;
|
|
189
|
+
other.isUsingOffHand = this.isUsingOffHand;
|
|
190
|
+
other.jumpBoost = this.jumpBoost;
|
|
191
|
+
other.speed = this.speed;
|
|
192
|
+
other.slowness = this.slowness;
|
|
193
|
+
other.dolphinsGrace = this.dolphinsGrace;
|
|
194
|
+
other.slowFalling = this.slowFalling;
|
|
195
|
+
other.levitation = this.levitation;
|
|
196
|
+
other.depthStrider = this.depthStrider;
|
|
197
|
+
other.effects = this.effects;
|
|
198
|
+
other.pose = this.pose;
|
|
199
|
+
return other;
|
|
200
|
+
}
|
|
201
|
+
merge(other) {
|
|
202
|
+
this.age = other.age;
|
|
203
|
+
this.position = other.position.clone();
|
|
204
|
+
this.velocity = other.velocity.clone();
|
|
205
|
+
this.onGround = other.onGround;
|
|
206
|
+
this.isCollidedHorizontally = other.isCollidedHorizontally;
|
|
207
|
+
this.isCollidedVertically = other.isCollidedVertically;
|
|
208
|
+
this.isInWater = other.isInWater;
|
|
209
|
+
this.isInLava = other.isInLava;
|
|
210
|
+
this.isInWeb = other.isInWeb;
|
|
211
|
+
this.jumpTicks = other.jumpTicks;
|
|
212
|
+
this.jumpQueued = other.jumpQueued;
|
|
213
|
+
this.sneakCollision = other.sneakCollision;
|
|
214
|
+
this.attributes = other.attributes;
|
|
215
|
+
this.isUsingItem = other.isUsingItem;
|
|
216
|
+
this.isUsingMainHand = other.isUsingMainHand;
|
|
217
|
+
this.isUsingOffHand = other.isUsingOffHand;
|
|
218
|
+
this.jumpBoost = other.jumpBoost;
|
|
219
|
+
this.speed = other.speed;
|
|
220
|
+
this.slowness = other.slowness;
|
|
221
|
+
this.dolphinsGrace = other.dolphinsGrace;
|
|
222
|
+
this.slowFalling = other.slowFalling;
|
|
223
|
+
this.levitation = other.levitation;
|
|
224
|
+
this.depthStrider = other.depthStrider;
|
|
225
|
+
this.effects = other.effects;
|
|
226
|
+
this.pose = other.pose;
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
clearControlStates() {
|
|
230
|
+
this.controlState = playerControls_1.ControlStateHandler.DEFAULT();
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* needs to be updated.
|
|
235
|
+
* @returns AABB
|
|
236
|
+
*/
|
|
237
|
+
getAABB() {
|
|
238
|
+
const w = this.halfWidth;
|
|
239
|
+
return new mineflayer_util_plugin_1.AABB(this.position.x - w, this.position.y, this.position.z - w, this.position.x + w, this.position.y + this.height, this.position.z + w);
|
|
240
|
+
}
|
|
241
|
+
getUnderlyingBlockBBs(world /*prismarine-world*/) {
|
|
242
|
+
const queryBB = this.getAABB();
|
|
243
|
+
return this.ctx.getUnderlyingBlockBBs(queryBB, world);
|
|
244
|
+
}
|
|
245
|
+
getSurroundingBBs(world /*prismarine-world*/) {
|
|
246
|
+
const queryBB = this.getAABB();
|
|
247
|
+
return this.ctx.getSurroundingBBs(queryBB, world);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.EntityState = EntityState;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./entityState"), exports);
|
|
14
|
+
__exportStar(require("./playerState"), exports);
|
|
15
|
+
__exportStar(require("./poses"), exports);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Bot, Effect } from "mineflayer";
|
|
2
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
3
|
+
import { Vec3 } from "vec3";
|
|
4
|
+
import { ControlStateHandler } from "../player/playerControls";
|
|
5
|
+
import { EntityStateBuilder } from "./entityState";
|
|
6
|
+
import { IPhysics } from "../engines/IPhysics";
|
|
7
|
+
export declare class EntityDimensions {
|
|
8
|
+
readonly width: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
readonly fixed: boolean;
|
|
11
|
+
constructor(width: number, height: number, fixed: boolean);
|
|
12
|
+
static scalable(f: number, f2: number): EntityDimensions;
|
|
13
|
+
static fixed(f: number, f2: number): EntityDimensions;
|
|
14
|
+
makeBoundingBox(vec3: Vec3): AABB;
|
|
15
|
+
makeBoundingBoxCoords(d: number, d2: number, d3: number): AABB;
|
|
16
|
+
scale(f: number): EntityDimensions;
|
|
17
|
+
scaleRaw(f: number, f2: number): EntityDimensions;
|
|
18
|
+
toString(): String;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Looking at this code, it's too specified towards players.
|
|
22
|
+
*
|
|
23
|
+
* I will eventually split this code into PlayerState and bot.entityState, where bot.entityState contains fewer controls.
|
|
24
|
+
*/
|
|
25
|
+
export declare class PlayerState implements EntityStateBuilder {
|
|
26
|
+
readonly bot: Bot;
|
|
27
|
+
height: number;
|
|
28
|
+
halfWidth: number;
|
|
29
|
+
position: Vec3;
|
|
30
|
+
velocity: Vec3;
|
|
31
|
+
onGround: boolean;
|
|
32
|
+
isInWater: boolean;
|
|
33
|
+
isInLava: boolean;
|
|
34
|
+
isInWeb: boolean;
|
|
35
|
+
isCollidedHorizontally: boolean;
|
|
36
|
+
isCollidedVertically: boolean;
|
|
37
|
+
jumpTicks: number;
|
|
38
|
+
jumpQueued: boolean;
|
|
39
|
+
sneakCollision: boolean;
|
|
40
|
+
attributes: any;
|
|
41
|
+
yaw: number;
|
|
42
|
+
pitch: number;
|
|
43
|
+
controlState: ControlStateHandler;
|
|
44
|
+
isUsingItem: boolean;
|
|
45
|
+
isUsingMainHand: boolean;
|
|
46
|
+
isUsingOffHand: boolean;
|
|
47
|
+
jumpBoost: number;
|
|
48
|
+
speed: number;
|
|
49
|
+
slowness: number;
|
|
50
|
+
dolphinsGrace: number;
|
|
51
|
+
slowFalling: number;
|
|
52
|
+
levitation: number;
|
|
53
|
+
depthStrider: number;
|
|
54
|
+
effects: Effect[];
|
|
55
|
+
statusEffectNames: {
|
|
56
|
+
jumpBoostEffectName: string;
|
|
57
|
+
speedEffectName: string;
|
|
58
|
+
slownessEffectName: string;
|
|
59
|
+
dolphinsGraceEffectName: string;
|
|
60
|
+
slowFallingEffectName: string;
|
|
61
|
+
levitationEffectName: string;
|
|
62
|
+
};
|
|
63
|
+
readonly ctx: IPhysics;
|
|
64
|
+
private readonly supportFeature;
|
|
65
|
+
constructor(ctx: IPhysics, bot: Bot, control?: ControlStateHandler);
|
|
66
|
+
update(bot: Bot, control?: ControlStateHandler): PlayerState;
|
|
67
|
+
apply(bot: Bot): void;
|
|
68
|
+
clone(): PlayerState;
|
|
69
|
+
merge(other: PlayerState): this;
|
|
70
|
+
clearControlStates(): PlayerState;
|
|
71
|
+
getAABB(): AABB;
|
|
72
|
+
getUnderlyingBlockBBs(world: any): AABB[];
|
|
73
|
+
getSurroundingBBs(world: any): AABB[];
|
|
74
|
+
}
|