@nxg-org/mineflayer-physics-util 1.2.2 → 1.3.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/lib/index.d.ts +2 -1
- package/lib/index.js +3 -3
- package/lib/physics/engines/IPhysics.d.ts +2 -2
- package/lib/physics/engines/entityPhysics.d.ts +2 -2
- package/lib/physics/engines/entityPhysics.js +18 -11
- package/lib/physics/info/entity_physics.json +142 -0
- package/lib/physics/settings/entityPhysicsCtx.d.ts +6 -1
- package/lib/physics/settings/entityPhysicsCtx.js +62 -106
- package/lib/physics/settings/physicsSettings.js +2 -2
- package/lib/physics/states/entityState.js +18 -16
- package/lib/physics/states/playerState.js +14 -14
- package/lib/simulators/baseSimulator.d.ts +3 -4
- package/lib/tests/fakeWorld.js +14 -3
- package/lib/util/physicsUtils.d.ts +2 -1
- package/lib/util/physicsUtils.js +10 -2
- package/package.json +3 -6
- package/lib/tests/all.d.ts +0 -0
- package/lib/tests/all.js +0 -1
- package/lib/tests/example.d.ts +0 -1
- package/lib/tests/example.js +0 -14
- package/lib/tests/testSim.d.ts +0 -1
- package/lib/tests/testSim.js +0 -45
- package/lib/tests/usingInterface.d.ts +0 -1
- package/lib/tests/usingInterface.js +0 -22
package/lib/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export default function loader(bot: Bot): void;
|
|
|
10
10
|
export declare function initSetup(data: IndexedData): void;
|
|
11
11
|
export { EPhysicsCtx, PhysicsSettings } from "./physics/settings";
|
|
12
12
|
export { BaseSimulator } from "./simulators";
|
|
13
|
-
export {
|
|
13
|
+
export { EntityPhysics } from "./physics/engines";
|
|
14
14
|
export { EntityState } from "./physics/states";
|
|
15
|
+
export type { SimulationGoal, Controller, OnGoalReachFunction } from "./simulators";
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EntityState = exports.BaseSimulator = exports.PhysicsSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
|
|
6
|
+
exports.EntityState = exports.EntityPhysics = exports.BaseSimulator = exports.PhysicsSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
|
|
7
7
|
const settings_1 = require("./physics/settings");
|
|
8
8
|
const wrapper_1 = require("./wrapper");
|
|
9
9
|
const prismarine_registry_1 = __importDefault(require("prismarine-registry"));
|
|
@@ -11,9 +11,7 @@ function loader(bot) {
|
|
|
11
11
|
if (!bot.physicsUtil) {
|
|
12
12
|
initSetup((0, prismarine_registry_1.default)(bot.version));
|
|
13
13
|
bot.physicsUtil = new wrapper_1.PhysicsUtilWrapper(bot);
|
|
14
|
-
console.log(bot.physicsUtil);
|
|
15
14
|
}
|
|
16
|
-
console.log(bot);
|
|
17
15
|
}
|
|
18
16
|
exports.default = loader;
|
|
19
17
|
function initSetup(data) {
|
|
@@ -26,5 +24,7 @@ Object.defineProperty(exports, "EPhysicsCtx", { enumerable: true, get: function
|
|
|
26
24
|
Object.defineProperty(exports, "PhysicsSettings", { enumerable: true, get: function () { return settings_2.PhysicsSettings; } });
|
|
27
25
|
var simulators_1 = require("./simulators");
|
|
28
26
|
Object.defineProperty(exports, "BaseSimulator", { enumerable: true, get: function () { return simulators_1.BaseSimulator; } });
|
|
27
|
+
var engines_1 = require("./physics/engines");
|
|
28
|
+
Object.defineProperty(exports, "EntityPhysics", { enumerable: true, get: function () { return engines_1.EntityPhysics; } });
|
|
29
29
|
var states_1 = require("./physics/states");
|
|
30
30
|
Object.defineProperty(exports, "EntityState", { enumerable: true, get: function () { return states_1.EntityState; } });
|
|
@@ -11,8 +11,8 @@ export declare type MobsByName = {
|
|
|
11
11
|
export interface IPhysics {
|
|
12
12
|
data: IndexedData;
|
|
13
13
|
supportFeature: ReturnType<typeof makeSupportFeature>;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
getEffectLevel: (effect: CheapEffects, effects: Effect[]) => number;
|
|
15
|
+
getEnchantmentLevel: (effect: CheapEnchantments, enchantments: any[]) => number;
|
|
16
16
|
getUnderlyingBlockBBs(queryBB: AABB, world: any): AABB[];
|
|
17
17
|
getSurroundingBBs(queryBB: AABB, world: any): AABB[];
|
|
18
18
|
simulate(simCtx: EPhysicsCtx, world: any): EntityState;
|
|
@@ -52,8 +52,8 @@ export declare class EntityPhysics implements IPhysics {
|
|
|
52
52
|
adjustPositionHeight(entity: EPhysicsCtx, pos: Vec3, world: any): void;
|
|
53
53
|
moveEntity(entity: EPhysicsCtx, dx: number, dy: number, dz: number, world: any): void;
|
|
54
54
|
applyHeading(entity: EPhysicsCtx, strafe: number, forward: number, multiplier: number): void;
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
getEffectLevel(wantedEffect: CheapEffects, effects: Effect[]): number;
|
|
56
|
+
getEnchantmentLevel(wantedEnchantment: CheapEnchantments, enchantments: any[]): any;
|
|
57
57
|
isOnLadder(pos: {
|
|
58
58
|
x: number;
|
|
59
59
|
y: number;
|
|
@@ -144,13 +144,14 @@ class EntityPhysics {
|
|
|
144
144
|
pos.y += dy;
|
|
145
145
|
}
|
|
146
146
|
moveEntity(entity, dx, dy, dz, world /*prismarine-world*/) {
|
|
147
|
+
var _a;
|
|
147
148
|
if (!this.shouldMoveEntity(entity)) {
|
|
148
149
|
entity.velocity.set(0, 0, 0);
|
|
149
150
|
return;
|
|
150
151
|
}
|
|
151
152
|
const vel = entity.velocity;
|
|
152
153
|
const pos = entity.position;
|
|
153
|
-
if (entity.state.isInWeb && !entity.entityType.name.includes("arrow")) {
|
|
154
|
+
if (entity.state.isInWeb && !((_a = entity.entityType) === null || _a === void 0 ? void 0 : _a.name.includes("arrow"))) {
|
|
154
155
|
dx *= 0.25;
|
|
155
156
|
dy *= 0.05;
|
|
156
157
|
dz *= 0.25;
|
|
@@ -353,8 +354,10 @@ class EntityPhysics {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
applyHeading(entity, strafe, forward, multiplier) {
|
|
356
|
-
if (!this.shouldMoveEntity(entity))
|
|
357
|
+
if (!this.shouldMoveEntity(entity)) {
|
|
358
|
+
entity.velocity.set(0, 0, 0);
|
|
357
359
|
return;
|
|
360
|
+
}
|
|
358
361
|
let speed = Math.sqrt(strafe * strafe + forward * forward);
|
|
359
362
|
if (speed < 0.01)
|
|
360
363
|
return;
|
|
@@ -368,7 +371,7 @@ class EntityPhysics {
|
|
|
368
371
|
vel.x += strafe * cos - forward * sin;
|
|
369
372
|
vel.z += forward * cos + strafe * sin;
|
|
370
373
|
}
|
|
371
|
-
|
|
374
|
+
getEffectLevel(wantedEffect, effects) {
|
|
372
375
|
const effectDescriptor = this.data.effectsByName[this.statusEffectNames[wantedEffect]];
|
|
373
376
|
if (!effectDescriptor) {
|
|
374
377
|
return 0;
|
|
@@ -379,7 +382,7 @@ class EntityPhysics {
|
|
|
379
382
|
}
|
|
380
383
|
return effectInfo.amplifier + 1;
|
|
381
384
|
}
|
|
382
|
-
|
|
385
|
+
getEnchantmentLevel(wantedEnchantment, enchantments) {
|
|
383
386
|
const enchantmentName = this.enchantmentNames[wantedEnchantment];
|
|
384
387
|
const enchantmentDescriptor = this.data.enchantmentsByName[enchantmentName];
|
|
385
388
|
if (!enchantmentDescriptor) {
|
|
@@ -519,8 +522,8 @@ class EntityPhysics {
|
|
|
519
522
|
const gravityMultiplier = vel.y <= 0 && entity.state.slowFalling > 0 ? physicsSettings_1.PhysicsSettings.slowFalling : 1;
|
|
520
523
|
// Unsure how to handle this w/ other entities.
|
|
521
524
|
if (!entity.state.isInWater && !entity.state.isInLava) {
|
|
522
|
-
let acceleration =
|
|
523
|
-
let inertia =
|
|
525
|
+
let acceleration = entity.airborneAccel;
|
|
526
|
+
let inertia = entity.airborneInertia;
|
|
524
527
|
const blockUnder = world.getBlock(pos.offset(0, -1, 0));
|
|
525
528
|
if (entity.state.onGround && blockUnder) {
|
|
526
529
|
let playerSpeedAttribute;
|
|
@@ -588,8 +591,8 @@ class EntityPhysics {
|
|
|
588
591
|
else {
|
|
589
592
|
// Water / Lava movement
|
|
590
593
|
const lastY = pos.y;
|
|
591
|
-
let acceleration =
|
|
592
|
-
const inertia = entity.state.isInWater ?
|
|
594
|
+
let acceleration = entity.liquidAccel;
|
|
595
|
+
const inertia = entity.state.isInWater ? entity.waterInertia : entity.lavaInertia;
|
|
593
596
|
let horizontalInertia = inertia;
|
|
594
597
|
if (entity.state.isInWater) {
|
|
595
598
|
let strider = Math.min(entity.state.depthStrider, 3);
|
|
@@ -640,6 +643,8 @@ class EntityPhysics {
|
|
|
640
643
|
vel.y = 0;
|
|
641
644
|
if (Math.abs(vel.z) < physicsSettings_1.PhysicsSettings.negligeableVelocity)
|
|
642
645
|
vel.z = 0;
|
|
646
|
+
let strafe = 0;
|
|
647
|
+
let forward = 0;
|
|
643
648
|
// Handle inputs
|
|
644
649
|
if (entity.useControls) {
|
|
645
650
|
if (entity.state.controlState.jump || entity.state.jumpQueued) {
|
|
@@ -667,8 +672,10 @@ class EntityPhysics {
|
|
|
667
672
|
entity.state.jumpTicks = 0; // reset autojump cooldown
|
|
668
673
|
}
|
|
669
674
|
entity.state.jumpQueued = false;
|
|
670
|
-
|
|
671
|
-
|
|
675
|
+
strafe =
|
|
676
|
+
(entity.state.controlState.right - entity.state.controlState.left) * 0.98;
|
|
677
|
+
forward =
|
|
678
|
+
(entity.state.controlState.forward - entity.state.controlState.back) * 0.98;
|
|
672
679
|
if (entity.state.controlState.sneak) {
|
|
673
680
|
strafe *= physicsSettings_1.PhysicsSettings.sneakSpeed;
|
|
674
681
|
forward *= physicsSettings_1.PhysicsSettings.sneakSpeed;
|
|
@@ -679,8 +686,8 @@ class EntityPhysics {
|
|
|
679
686
|
forward *= physicsSettings_1.PhysicsSettings.usingItemSpeed;
|
|
680
687
|
entity.state.controlState.sprint = false;
|
|
681
688
|
}
|
|
682
|
-
this.moveEntityWithHeading(entity, strafe, forward, world);
|
|
683
689
|
}
|
|
690
|
+
this.moveEntityWithHeading(entity, strafe, forward, world);
|
|
684
691
|
return entity.state;
|
|
685
692
|
}
|
|
686
693
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"living_entities": {
|
|
3
|
+
"names": ["player", "zombie", "skeleton", "creeper", "spider", "enderman", "slime", "magma_cube"],
|
|
4
|
+
"default": {
|
|
5
|
+
"gravityThenDrag": true,
|
|
6
|
+
"useControls": true,
|
|
7
|
+
"stepHeight": 1,
|
|
8
|
+
"gravity": 0.08,
|
|
9
|
+
"airdrag": 0.9800000190734863,
|
|
10
|
+
"airborneInertia": 0.91,
|
|
11
|
+
"airborneAccel": 0.02,
|
|
12
|
+
"waterInertia": 0.8,
|
|
13
|
+
"lavaInertia": 0.5,
|
|
14
|
+
"liquidAccel": 0.02,
|
|
15
|
+
"collisionBehavior": {
|
|
16
|
+
"blockEffects": true,
|
|
17
|
+
"affectedAfterCollision": true
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"player": {
|
|
21
|
+
"stepHeight": 0.6
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"projectiles": {
|
|
25
|
+
"names": ["arrow", "trident", "egg", "snowball", "potion", "ender_pearl", "experience_bottle", "llama_spit", "fishing_bobber"],
|
|
26
|
+
"default": {
|
|
27
|
+
"gravityThenDrag": false,
|
|
28
|
+
"useControls": false,
|
|
29
|
+
"stepHeight": 0,
|
|
30
|
+
"gravity": 0.03,
|
|
31
|
+
"airdrag": 0.9800000190734863,
|
|
32
|
+
"airborneInertia": 0.99,
|
|
33
|
+
"airborneAccel": 0.02,
|
|
34
|
+
"waterInertia": 0.6,
|
|
35
|
+
"lavaInertia": 1,
|
|
36
|
+
"liquidAccel": 0.02,
|
|
37
|
+
"collisionBehavior": {
|
|
38
|
+
"blockEffects": false,
|
|
39
|
+
"affectedAfterCollision": false
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"arrow": {
|
|
43
|
+
"gravity": 0.05,
|
|
44
|
+
"airdrag": 0.9900000095367432
|
|
45
|
+
},
|
|
46
|
+
"trident": {
|
|
47
|
+
"gravity": 0.05,
|
|
48
|
+
"airdrag": 0.9900000095367432,
|
|
49
|
+
"waterInertia": 0.99
|
|
50
|
+
},
|
|
51
|
+
"llama_spit": {
|
|
52
|
+
"gravity": 0.06,
|
|
53
|
+
"airdrag": 0.9900000095367432
|
|
54
|
+
},
|
|
55
|
+
"experience_bottle": {
|
|
56
|
+
"gravity": 0.03
|
|
57
|
+
},
|
|
58
|
+
"fishing_bobber": {
|
|
59
|
+
"airdrag": 0.9200000166893005
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"dead_vehicles": {
|
|
63
|
+
"names": ["minecart", "boat"],
|
|
64
|
+
"default": {
|
|
65
|
+
"gravityThenDrag": true,
|
|
66
|
+
"useControls": false,
|
|
67
|
+
"stepHeight": 0,
|
|
68
|
+
"gravity": 0.04,
|
|
69
|
+
"airdrag": 0.949999988079071,
|
|
70
|
+
"airborneInertia": 0.91,
|
|
71
|
+
"airborneAccel": 0.02,
|
|
72
|
+
"waterInertia": 0.8,
|
|
73
|
+
"lavaInertia": 0.5,
|
|
74
|
+
"liquidAccel": 0.02,
|
|
75
|
+
"collisionBehavior": {
|
|
76
|
+
"blockEffects": false,
|
|
77
|
+
"affectedAfterCollision": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"boat": {
|
|
81
|
+
"gravity": 0.04,
|
|
82
|
+
"airdrag": 1
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"shot_entities": {
|
|
86
|
+
"names": ["fireball", "skull"],
|
|
87
|
+
"default": {
|
|
88
|
+
"gravityThenDrag": true,
|
|
89
|
+
"useControls": false,
|
|
90
|
+
"stepHeight": 0,
|
|
91
|
+
"gravity": 0,
|
|
92
|
+
"airdrag": 0,
|
|
93
|
+
"airborneInertia": 1,
|
|
94
|
+
"airborneAccel": 0,
|
|
95
|
+
"waterInertia": 1,
|
|
96
|
+
"lavaInertia": 1,
|
|
97
|
+
"liquidAccel": 0,
|
|
98
|
+
"collisionBehavior": {
|
|
99
|
+
"blockEffects": false,
|
|
100
|
+
"affectedAfterCollision": false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"blocks": {
|
|
105
|
+
"names": ["falling_block", "tnt"],
|
|
106
|
+
"default": {
|
|
107
|
+
"gravityThenDrag": false,
|
|
108
|
+
"useControls": false,
|
|
109
|
+
"stepHeight": 0,
|
|
110
|
+
"gravity": 0.04,
|
|
111
|
+
"airdrag": 0.9800000190734863,
|
|
112
|
+
"airborneInertia": 1,
|
|
113
|
+
"airborneAccel": 0.02,
|
|
114
|
+
"waterInertia": 0.8,
|
|
115
|
+
"lavaInertia": 0.5,
|
|
116
|
+
"liquidAccel": 0.02,
|
|
117
|
+
"collisionBehavior": {
|
|
118
|
+
"blockEffects": false,
|
|
119
|
+
"affectedAfterCollision": false
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"other": {
|
|
124
|
+
"names": ["experience_orb"],
|
|
125
|
+
"default": {
|
|
126
|
+
"gravityThenDrag": false,
|
|
127
|
+
"useControls": false,
|
|
128
|
+
"stepHeight": 0,
|
|
129
|
+
"gravity": 0.03,
|
|
130
|
+
"airdrag": 0.9800000190734863,
|
|
131
|
+
"airborneInertia": 1,
|
|
132
|
+
"airborneAccel": 0,
|
|
133
|
+
"waterInertia": 1,
|
|
134
|
+
"lavaInertia": 0,
|
|
135
|
+
"liquidAccel": 0,
|
|
136
|
+
"collisionBehavior": {
|
|
137
|
+
"blockEffects": true,
|
|
138
|
+
"affectedAfterCollision": true
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -37,10 +37,15 @@ export declare class EPhysicsCtx {
|
|
|
37
37
|
readonly waterGravity: number;
|
|
38
38
|
readonly lavaGravity: number;
|
|
39
39
|
readonly airdrag: number;
|
|
40
|
+
readonly airborneInertia: number;
|
|
41
|
+
readonly airborneAccel: number;
|
|
42
|
+
readonly waterInertia: number;
|
|
43
|
+
readonly lavaInertia: number;
|
|
44
|
+
readonly liquidAccel: number;
|
|
40
45
|
readonly gravityThenDrag: boolean;
|
|
41
46
|
readonly useControls: boolean;
|
|
42
47
|
readonly collisionBehavior: CollisionContext;
|
|
43
|
-
constructor(ctx: IPhysics, pose: PlayerPoses, state: EntityState, entityType
|
|
48
|
+
constructor(ctx: IPhysics, pose: PlayerPoses, state: EntityState, entityType?: md.Entity);
|
|
44
49
|
static FROM_ENTITY(ctx: IPhysics, entity: Entity): EPhysicsCtx;
|
|
45
50
|
static FROM_ENTITY_TYPE(ctx: IPhysics, entityType: md.Entity, options?: Partial<Entity>): EPhysicsCtx;
|
|
46
51
|
static FROM_ENTITY_STATE(ctx: IPhysics, entityState: EntityState, entityType: md.Entity): EPhysicsCtx;
|
|
@@ -10,6 +10,7 @@ const entityState_1 = require("../states/entityState");
|
|
|
10
10
|
const physicsUtils_1 = require("../../util/physicsUtils");
|
|
11
11
|
const prismarine_entity_1 = __importDefault(require("prismarine-entity"));
|
|
12
12
|
const vec3_1 = require("vec3");
|
|
13
|
+
const entity_physics_json_1 = __importDefault(require("../info/entity_physics.json"));
|
|
13
14
|
function getPose(entity) {
|
|
14
15
|
const pose = entity.metadata.find((e) => e.type === 18);
|
|
15
16
|
return pose ? pose.value : poses_1.PlayerPoses.STANDING;
|
|
@@ -22,8 +23,8 @@ function load(data) {
|
|
|
22
23
|
}
|
|
23
24
|
exports.emptyVec = new vec3_1.Vec3(0, 0, 0);
|
|
24
25
|
class EPhysicsCtx {
|
|
25
|
-
constructor(ctx, pose, state, entityType) {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o
|
|
26
|
+
constructor(ctx, pose, state, entityType = physicsUtils_1.DefaultPlayer) {
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
27
28
|
this.ctx = ctx;
|
|
28
29
|
this.pose = pose;
|
|
29
30
|
this.state = state;
|
|
@@ -31,6 +32,11 @@ class EPhysicsCtx {
|
|
|
31
32
|
this.stepHeight = 0;
|
|
32
33
|
this.gravity = 0.0;
|
|
33
34
|
this.airdrag = Math.fround(1 - 0.0);
|
|
35
|
+
this.airborneInertia = 0.91;
|
|
36
|
+
this.airborneAccel = 0.02;
|
|
37
|
+
this.waterInertia = 0.8;
|
|
38
|
+
this.lavaInertia = 0.5;
|
|
39
|
+
this.liquidAccel = 0.02;
|
|
34
40
|
this.gravityThenDrag = false;
|
|
35
41
|
this.useControls = false;
|
|
36
42
|
this.collisionBehavior = {
|
|
@@ -40,129 +46,79 @@ class EPhysicsCtx {
|
|
|
40
46
|
this.position = state.position;
|
|
41
47
|
this.velocity = state.velocity;
|
|
42
48
|
if (entityType.type === "player" || !!EPhysicsCtx.mobData[entityType.id]) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.useControls = true;
|
|
47
|
-
this.stepHeight = entityType.type === "player" ? 0.6 : 1.0;
|
|
48
|
-
this.collisionBehavior = {
|
|
49
|
-
blockEffects: true,
|
|
50
|
-
affectedAfterCollision: true,
|
|
51
|
-
};
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
const additional = entity_physics_json_1.default.living_entities[entityType.type];
|
|
51
|
+
Object.assign(this, entity_physics_json_1.default.living_entities.default, additional);
|
|
52
52
|
}
|
|
53
|
-
if (
|
|
54
|
-
this
|
|
55
|
-
this.airdrag = Math.fround(1 - 0.01);
|
|
53
|
+
else if (entityType.name.includes("experience_orb")) {
|
|
54
|
+
Object.assign(this, entity_physics_json_1.default.other.default);
|
|
56
55
|
}
|
|
57
|
-
if (
|
|
58
|
-
this.
|
|
59
|
-
this.airdrag = Math.fround(1 - 0.01);
|
|
56
|
+
else if (entityType.name.includes("spit")) {
|
|
57
|
+
Object.assign(this, entity_physics_json_1.default.projectiles.default, entity_physics_json_1.default.projectiles.llama_spit);
|
|
60
58
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.gravityThenDrag = true;
|
|
69
|
-
this.useControls = true;
|
|
70
|
-
this.stepHeight = 1.0;
|
|
71
|
-
this.collisionBehavior = {
|
|
72
|
-
blockEffects: true,
|
|
73
|
-
affectedAfterCollision: true,
|
|
74
|
-
};
|
|
75
|
-
case "projectile":
|
|
76
|
-
this.gravity = 0.03;
|
|
77
|
-
this.airdrag = Math.fround(1 - 0.01);
|
|
78
|
-
this.collisionBehavior = {
|
|
79
|
-
blockEffects: false,
|
|
80
|
-
affectedAfterCollision: false,
|
|
81
|
-
};
|
|
82
|
-
case "orb":
|
|
83
|
-
this.gravity = 0.03;
|
|
84
|
-
this.airdrag = Math.fround(1 - 0.02);
|
|
85
|
-
this.collisionBehavior = {
|
|
86
|
-
blockEffects: false,
|
|
87
|
-
affectedAfterCollision: true,
|
|
88
|
-
};
|
|
89
|
-
case "other":
|
|
90
|
-
if ((_c = entityType.name) === null || _c === void 0 ? void 0 : _c.includes("minecart")) {
|
|
91
|
-
this.gravity = 0.04;
|
|
92
|
-
this.airdrag = Math.fround(1 - 0.05);
|
|
93
|
-
this.collisionBehavior = {
|
|
94
|
-
blockEffects: false,
|
|
95
|
-
affectedAfterCollision: true,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
else if (((_d = entityType.name) === null || _d === void 0 ? void 0 : _d.includes("block")) || ((_e = entityType.name) === null || _e === void 0 ? void 0 : _e.includes("tnt"))) {
|
|
99
|
-
this.gravity = 0.04;
|
|
59
|
+
else {
|
|
60
|
+
switch (entityType.type) {
|
|
61
|
+
case "water_creature":
|
|
62
|
+
case "animal":
|
|
63
|
+
case "hostile":
|
|
64
|
+
case "mob":
|
|
65
|
+
this.gravity = 0.08;
|
|
100
66
|
this.airdrag = Math.fround(1 - 0.02);
|
|
67
|
+
this.gravityThenDrag = true;
|
|
68
|
+
this.useControls = true;
|
|
69
|
+
this.stepHeight = 1.0;
|
|
101
70
|
this.collisionBehavior = {
|
|
102
|
-
blockEffects:
|
|
103
|
-
affectedAfterCollision: true,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
else if ((_f = entityType.name) === null || _f === void 0 ? void 0 : _f.includes("boat")) {
|
|
107
|
-
this.gravity = 0.04;
|
|
108
|
-
this.airdrag = Math.fround(1 - 0);
|
|
109
|
-
this.collisionBehavior = {
|
|
110
|
-
blockEffects: false,
|
|
71
|
+
blockEffects: true,
|
|
111
72
|
affectedAfterCollision: true,
|
|
112
73
|
};
|
|
113
|
-
|
|
114
|
-
else if (((_g = entityType.name) === null || _g === void 0 ? void 0 : _g.includes("egg")) ||
|
|
115
|
-
((_h = entityType.name) === null || _h === void 0 ? void 0 : _h.includes("snowball")) ||
|
|
116
|
-
((_j = entityType.name) === null || _j === void 0 ? void 0 : _j.includes("potion")) ||
|
|
117
|
-
((_k = entityType.name) === null || _k === void 0 ? void 0 : _k.includes("pearl"))) {
|
|
74
|
+
case "projectile":
|
|
118
75
|
this.gravity = 0.03;
|
|
119
76
|
this.airdrag = Math.fround(1 - 0.01);
|
|
77
|
+
this.airborneInertia = 0.99;
|
|
78
|
+
this.airborneAccel = 0.06;
|
|
79
|
+
this.waterInertia = 0.25;
|
|
80
|
+
this.lavaInertia = 0;
|
|
81
|
+
this.liquidAccel = 0.02;
|
|
120
82
|
this.collisionBehavior = {
|
|
121
83
|
blockEffects: false,
|
|
122
84
|
affectedAfterCollision: false,
|
|
123
85
|
};
|
|
124
|
-
|
|
125
|
-
else if ((_l = entityType.name) === null || _l === void 0 ? void 0 : _l.includes("orb")) {
|
|
86
|
+
case "orb":
|
|
126
87
|
this.gravity = 0.03;
|
|
127
88
|
this.airdrag = Math.fround(1 - 0.02);
|
|
128
89
|
this.collisionBehavior = {
|
|
129
90
|
blockEffects: false,
|
|
130
91
|
affectedAfterCollision: true,
|
|
131
92
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.collisionBehavior = {
|
|
162
|
-
blockEffects: false,
|
|
163
|
-
affectedAfterCollision: false,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
93
|
+
case "other":
|
|
94
|
+
if (entityType.name.includes("minecart") || entityType.name.includes("boat")) {
|
|
95
|
+
Object.assign(this, entity_physics_json_1.default.dead_vehicles.default, entityType.name === "boat" ? entity_physics_json_1.default.dead_vehicles.boat : undefined);
|
|
96
|
+
}
|
|
97
|
+
else if (((_a = entityType.name) === null || _a === void 0 ? void 0 : _a.includes("block")) || ((_b = entityType.name) === null || _b === void 0 ? void 0 : _b.includes("tnt"))) {
|
|
98
|
+
Object.assign(this, entity_physics_json_1.default.blocks.default);
|
|
99
|
+
}
|
|
100
|
+
else if (((_c = entityType.name) === null || _c === void 0 ? void 0 : _c.includes("egg")) ||
|
|
101
|
+
((_d = entityType.name) === null || _d === void 0 ? void 0 : _d.includes("snowball")) ||
|
|
102
|
+
((_e = entityType.name) === null || _e === void 0 ? void 0 : _e.includes("potion")) ||
|
|
103
|
+
((_f = entityType.name) === null || _f === void 0 ? void 0 : _f.includes("pearl"))) {
|
|
104
|
+
Object.assign(this, entity_physics_json_1.default.projectiles.default);
|
|
105
|
+
}
|
|
106
|
+
else if ((_g = entityType.name) === null || _g === void 0 ? void 0 : _g.includes("orb")) {
|
|
107
|
+
Object.assign(this, entity_physics_json_1.default.other.default);
|
|
108
|
+
}
|
|
109
|
+
else if ((_h = entityType.name) === null || _h === void 0 ? void 0 : _h.includes("bobber")) {
|
|
110
|
+
Object.assign(this, entity_physics_json_1.default.projectiles.default, entity_physics_json_1.default.projectiles.fishing_bobber);
|
|
111
|
+
}
|
|
112
|
+
else if ((_j = entityType.name) === null || _j === void 0 ? void 0 : _j.includes("spit")) {
|
|
113
|
+
Object.assign(this, entity_physics_json_1.default.projectiles.default, entity_physics_json_1.default.projectiles.llama_spit);
|
|
114
|
+
}
|
|
115
|
+
else if (((_k = entityType.name) === null || _k === void 0 ? void 0 : _k.includes("arrow")) || ((_l = entityType.name) === null || _l === void 0 ? void 0 : _l.includes("trident"))) {
|
|
116
|
+
Object.assign(this, entity_physics_json_1.default.projectiles.default, entityType.name.includes("arrow") ? entity_physics_json_1.default.projectiles.arrow : entity_physics_json_1.default.projectiles.trident);
|
|
117
|
+
}
|
|
118
|
+
else if (((_m = entityType.name) === null || _m === void 0 ? void 0 : _m.includes("fireball")) || ((_o = entityType.name) === null || _o === void 0 ? void 0 : _o.includes("skull"))) {
|
|
119
|
+
Object.assign(this, entity_physics_json_1.default.shot_entities.default);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
166
122
|
}
|
|
167
123
|
if (ctx.supportFeature("independentLiquidGravity")) {
|
|
168
124
|
this.waterGravity = 0.02;
|
|
@@ -41,8 +41,8 @@ PhysicsSettings.bubbleColumnDrag = {
|
|
|
41
41
|
PhysicsSettings.slowFalling = 0.125;
|
|
42
42
|
PhysicsSettings.sprintingUUID = "662a6b8d-da3e-4c1c-8813-96ea6097278d"; // SPEED_MODIFIER_SPRINTING_UUID is from LivingEntity.java
|
|
43
43
|
PhysicsSettings.jumpHeight = Math.fround(0.42);
|
|
44
|
-
PhysicsSettings.airborneInertia = 0.
|
|
45
|
-
PhysicsSettings.airborneAcceleration = 0.
|
|
44
|
+
PhysicsSettings.airborneInertia = 0.99;
|
|
45
|
+
PhysicsSettings.airborneAcceleration = 0.06;
|
|
46
46
|
PhysicsSettings.sprintSpeed = Math.fround(0.3);
|
|
47
47
|
PhysicsSettings.sneakSpeed = 0.3;
|
|
48
48
|
PhysicsSettings.usingItemSpeed = 0.2;
|
|
@@ -76,17 +76,17 @@ class EntityState {
|
|
|
76
76
|
this.isUsingItem = (0, physicsUtils_1.isEntityUsingItem)(bot.entity);
|
|
77
77
|
this.attributes = bot.entity.attributes;
|
|
78
78
|
this.effects = bot.entity.effects;
|
|
79
|
-
this.jumpBoost = this.ctx.
|
|
80
|
-
this.speed = this.ctx.
|
|
81
|
-
this.slowness = this.ctx.
|
|
82
|
-
this.dolphinsGrace = this.ctx.
|
|
83
|
-
this.slowFalling = this.ctx.
|
|
84
|
-
this.levitation = this.ctx.
|
|
79
|
+
this.jumpBoost = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.JUMP_BOOST, this.effects);
|
|
80
|
+
this.speed = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SPEED, this.effects);
|
|
81
|
+
this.slowness = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOWNESS, this.effects);
|
|
82
|
+
this.dolphinsGrace = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.DOLPHINS_GRACE, this.effects);
|
|
83
|
+
this.slowFalling = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOW_FALLING, this.effects);
|
|
84
|
+
this.levitation = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.LEVITATION, this.effects);
|
|
85
85
|
const boots = bot.entity.equipment[5];
|
|
86
86
|
if (boots && boots.nbt) {
|
|
87
87
|
const simplifiedNbt = prismarine_nbt_1.default.simplify(boots.nbt);
|
|
88
88
|
const enchantments = (_b = (_a = simplifiedNbt.Enchantments) !== null && _a !== void 0 ? _a : simplifiedNbt.ench) !== null && _b !== void 0 ? _b : [];
|
|
89
|
-
this.depthStrider = this.ctx.
|
|
89
|
+
this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
this.depthStrider = 0;
|
|
@@ -117,19 +117,19 @@ class EntityState {
|
|
|
117
117
|
this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(entity) && this.isUsingItem;
|
|
118
118
|
// effects
|
|
119
119
|
this.effects = entity.effects;
|
|
120
|
-
this.jumpBoost = this.ctx.
|
|
121
|
-
this.speed = this.ctx.
|
|
122
|
-
this.slowness = this.ctx.
|
|
123
|
-
this.dolphinsGrace = this.ctx.
|
|
124
|
-
this.slowFalling = this.ctx.
|
|
125
|
-
this.levitation = this.ctx.
|
|
120
|
+
this.jumpBoost = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.JUMP_BOOST, this.effects);
|
|
121
|
+
this.speed = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SPEED, this.effects);
|
|
122
|
+
this.slowness = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOWNESS, this.effects);
|
|
123
|
+
this.dolphinsGrace = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.DOLPHINS_GRACE, this.effects);
|
|
124
|
+
this.slowFalling = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOW_FALLING, this.effects);
|
|
125
|
+
this.levitation = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.LEVITATION, this.effects);
|
|
126
126
|
// armour enchantments
|
|
127
127
|
//const boots = bot.inventory.slots[8];
|
|
128
128
|
const boots = entity.equipment[5];
|
|
129
129
|
if (boots && boots.nbt) {
|
|
130
130
|
const simplifiedNbt = prismarine_nbt_1.default.simplify(boots.nbt);
|
|
131
131
|
const enchantments = (_b = (_a = simplifiedNbt.Enchantments) !== null && _a !== void 0 ? _a : simplifiedNbt.ench) !== null && _b !== void 0 ? _b : [];
|
|
132
|
-
this.depthStrider = this.ctx.
|
|
132
|
+
this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
135
135
|
this.depthStrider = 0;
|
|
@@ -165,8 +165,10 @@ class EntityState {
|
|
|
165
165
|
* No idea when you'd use this.
|
|
166
166
|
*/
|
|
167
167
|
applyToEntity(entity) {
|
|
168
|
-
entity.position
|
|
169
|
-
entity.velocity
|
|
168
|
+
entity.position = this.position;
|
|
169
|
+
entity.velocity = this.velocity;
|
|
170
|
+
// entity.position.set(this.position.x, this.position.y, this.position.z);
|
|
171
|
+
// entity.velocity.set(this.velocity.x, this.velocity.y, this.velocity.z);
|
|
170
172
|
entity.onGround = this.onGround;
|
|
171
173
|
entity.yaw = this.yaw;
|
|
172
174
|
entity.pitch = this.pitch;
|
|
@@ -96,12 +96,12 @@ class PlayerState {
|
|
|
96
96
|
// effects
|
|
97
97
|
this.effects = bot.entity.effects;
|
|
98
98
|
this.statusEffectNames = (0, physicsUtils_1.getStatusEffectNamesForVersion)(this.supportFeature);
|
|
99
|
-
this.jumpBoost = this.ctx.
|
|
100
|
-
this.speed = this.ctx.
|
|
101
|
-
this.slowness = this.ctx.
|
|
102
|
-
this.dolphinsGrace = this.ctx.
|
|
103
|
-
this.slowFalling = this.ctx.
|
|
104
|
-
this.levitation = this.ctx.
|
|
99
|
+
this.jumpBoost = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.JUMP_BOOST, this.effects);
|
|
100
|
+
this.speed = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SPEED, this.effects);
|
|
101
|
+
this.slowness = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOWNESS, this.effects);
|
|
102
|
+
this.dolphinsGrace = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.DOLPHINS_GRACE, this.effects);
|
|
103
|
+
this.slowFalling = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOW_FALLING, this.effects);
|
|
104
|
+
this.levitation = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.LEVITATION, this.effects);
|
|
105
105
|
// this.jumpBoost = ctx.getEffectLevel(this.statusEffectNames.jumpBoostEffectName, this.effects);
|
|
106
106
|
// this.speed = ctx.getEffectLevel(this.statusEffectNames.speedEffectName, this.effects);
|
|
107
107
|
// this.slowness = ctx.getEffectLevel(this.statusEffectNames.slownessEffectName, this.effects);
|
|
@@ -114,7 +114,7 @@ class PlayerState {
|
|
|
114
114
|
if (boots && boots.nbt) {
|
|
115
115
|
const simplifiedNbt = nbt.simplify(boots.nbt);
|
|
116
116
|
const enchantments = (_d = (_c = simplifiedNbt.Enchantments) !== null && _c !== void 0 ? _c : simplifiedNbt.ench) !== null && _d !== void 0 ? _d : [];
|
|
117
|
-
this.depthStrider = this.ctx.
|
|
117
|
+
this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
120
120
|
this.depthStrider = 0;
|
|
@@ -145,19 +145,19 @@ class PlayerState {
|
|
|
145
145
|
this.isUsingOffHand = (0, physicsUtils_1.whichHandIsEntityUsingBoolean)(bot.entity) && this.isUsingItem;
|
|
146
146
|
// effects
|
|
147
147
|
this.effects = bot.entity.effects;
|
|
148
|
-
this.jumpBoost = this.ctx.
|
|
149
|
-
this.speed = this.ctx.
|
|
150
|
-
this.slowness = this.ctx.
|
|
151
|
-
this.dolphinsGrace = this.ctx.
|
|
152
|
-
this.slowFalling = this.ctx.
|
|
153
|
-
this.levitation = this.ctx.
|
|
148
|
+
this.jumpBoost = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.JUMP_BOOST, this.effects);
|
|
149
|
+
this.speed = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SPEED, this.effects);
|
|
150
|
+
this.slowness = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOWNESS, this.effects);
|
|
151
|
+
this.dolphinsGrace = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.DOLPHINS_GRACE, this.effects);
|
|
152
|
+
this.slowFalling = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.SLOW_FALLING, this.effects);
|
|
153
|
+
this.levitation = this.ctx.getEffectLevel(physicsUtils_1.CheapEffects.LEVITATION, this.effects);
|
|
154
154
|
// armour enchantments
|
|
155
155
|
//const boots = bot.inventory.slots[8];
|
|
156
156
|
const boots = bot.entity.equipment[5];
|
|
157
157
|
if (boots && boots.nbt) {
|
|
158
158
|
const simplifiedNbt = nbt.simplify(boots.nbt);
|
|
159
159
|
const enchantments = (_d = (_c = simplifiedNbt.Enchantments) !== null && _c !== void 0 ? _c : simplifiedNbt.ench) !== null && _d !== void 0 ? _d : [];
|
|
160
|
-
this.depthStrider = this.ctx.
|
|
160
|
+
this.depthStrider = this.ctx.getEnchantmentLevel(physicsUtils_1.CheapEnchantments.DEPTH_STRIDER, enchantments);
|
|
161
161
|
}
|
|
162
162
|
else {
|
|
163
163
|
this.depthStrider = 0;
|
|
@@ -4,9 +4,9 @@ import { EntityState } from "../physics/states";
|
|
|
4
4
|
import { IPhysics } from "../physics/engines";
|
|
5
5
|
import { Entity } from "prismarine-entity";
|
|
6
6
|
import { Vec3 } from "vec3";
|
|
7
|
-
declare type SimulationGoal = (state: EntityState) => boolean;
|
|
8
|
-
declare type OnGoalReachFunction = (state: EntityState) => void;
|
|
9
|
-
declare type Controller = (state: EntityState, ticks: number) => void;
|
|
7
|
+
export declare type SimulationGoal = (state: EntityState) => boolean;
|
|
8
|
+
export declare type OnGoalReachFunction = (state: EntityState) => void;
|
|
9
|
+
export declare type Controller = (state: EntityState, ticks: number) => void;
|
|
10
10
|
export declare abstract class BaseSimulator {
|
|
11
11
|
readonly ctx: IPhysics;
|
|
12
12
|
constructor(ctx: IPhysics);
|
|
@@ -17,4 +17,3 @@ export declare abstract class BaseSimulator {
|
|
|
17
17
|
static getCleanupPosition(...path: Vec3[]): OnGoalReachFunction;
|
|
18
18
|
static buildFullController(...controllers: Controller[]): Controller;
|
|
19
19
|
}
|
|
20
|
-
export {};
|
package/lib/tests/fakeWorld.js
CHANGED
|
@@ -11,7 +11,6 @@ const player_1 = require("../physics/player");
|
|
|
11
11
|
const vec3_1 = require("vec3");
|
|
12
12
|
const minecraft_data_1 = __importDefault(require("minecraft-data"));
|
|
13
13
|
const prismarine_block_1 = __importDefault(require("prismarine-block"));
|
|
14
|
-
const expect_1 = __importDefault(require("expect"));
|
|
15
14
|
const index_1 = require("../index");
|
|
16
15
|
const mcData = (0, minecraft_data_1.default)("1.17.1");
|
|
17
16
|
const Block = prismarine_block_1.default("1.17.1");
|
|
@@ -58,9 +57,21 @@ const playerState = states_1.EntityState.CREATE_FROM_ENTITY(physics, fakePlayer.
|
|
|
58
57
|
const playerCtx = settings_1.EPhysicsCtx.FROM_ENTITY_STATE(physics, playerState, playerType); // create wrapper context (supplies AABB, pose info, etc).
|
|
59
58
|
// set control state.
|
|
60
59
|
playerState.controlState = player_1.ControlStateHandler.DEFAULT(); // specific to players and mobs, specify control scheme to apply.
|
|
60
|
+
playerState.controlState.forward = true;
|
|
61
61
|
// simulate until on ground.
|
|
62
|
-
while (!
|
|
62
|
+
while (!playerCtx.state.onGround) {
|
|
63
63
|
physics.simulate(playerCtx, fakeWorld).applyToBot(fakePlayer); // (applyToBot since fakePlayer is supposed to be a bot)
|
|
64
|
+
console.log(fakePlayer.entity.position, fakePlayer.entity.velocity);
|
|
65
|
+
}
|
|
66
|
+
playerCtx.state.controlState.set("jump", true);
|
|
67
|
+
for (let i = 0; i < 12; i++) {
|
|
68
|
+
physics.simulate(playerCtx, fakeWorld).applyToBot(fakePlayer); // (applyToBot since fakePlayer is supposed to be a bot)
|
|
69
|
+
console.log(fakePlayer.entity.position, fakePlayer.entity.velocity);
|
|
70
|
+
}
|
|
71
|
+
if (playerState.controlState.forward) {
|
|
72
|
+
// expect(fakePlayer.entity.position).toEqual(new Vec3(0, 60, -3.4508449226731694)); // it works.
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// expect(fakePlayer.entity.position).toEqual(new Vec3(0, 60, 0)); // it works.
|
|
64
76
|
}
|
|
65
|
-
(0, expect_1.default)(fakePlayer.entity.position).toEqual(new vec3_1.Vec3(0, 60, 0)); // it works.
|
|
66
77
|
console.log(fakePlayer.entity.position); //manual run.
|
|
@@ -3,7 +3,8 @@ import { EPhysicsCtx } from "../physics/settings";
|
|
|
3
3
|
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
4
4
|
import md from "minecraft-data";
|
|
5
5
|
export declare function makeSupportFeature(mcData: md.IndexedData): (feature: string) => boolean;
|
|
6
|
-
export declare
|
|
6
|
+
export declare const DefaultPlayer: md.Entity;
|
|
7
|
+
export declare function applyMdToNewEntity(ctx: typeof EPhysicsCtx, entityType?: md.Entity, options?: Partial<Entity>): Entity;
|
|
7
8
|
export declare enum CheapEffects {
|
|
8
9
|
SPEED = 0,
|
|
9
10
|
JUMP_BOOST = 1,
|
package/lib/util/physicsUtils.js
CHANGED
|
@@ -3,14 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getBetweenRectangle = exports.getEnchantmentNamesForVersion = exports.getStatusEffectNamesForVersion = exports.whichHandIsEntityUsingBoolean = exports.whichHandIsEntityUsing = exports.isEntityUsingItem = exports.CheapEnchantments = exports.CheapEffects = exports.applyMdToNewEntity = exports.makeSupportFeature = void 0;
|
|
6
|
+
exports.getBetweenRectangle = exports.getEnchantmentNamesForVersion = exports.getStatusEffectNamesForVersion = exports.whichHandIsEntityUsingBoolean = exports.whichHandIsEntityUsing = exports.isEntityUsingItem = exports.CheapEnchantments = exports.CheapEffects = exports.applyMdToNewEntity = exports.DefaultPlayer = exports.makeSupportFeature = void 0;
|
|
7
7
|
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
8
8
|
const features_json_1 = __importDefault(require("../physics/info/features.json"));
|
|
9
9
|
function makeSupportFeature(mcData) {
|
|
10
10
|
return (feature) => features_json_1.default.some(({ name, versions }) => name === feature && versions.includes(mcData.version.majorVersion));
|
|
11
11
|
}
|
|
12
12
|
exports.makeSupportFeature = makeSupportFeature;
|
|
13
|
-
|
|
13
|
+
exports.DefaultPlayer = {
|
|
14
|
+
displayName: "Player",
|
|
15
|
+
height: 1.8,
|
|
16
|
+
width: 0.6,
|
|
17
|
+
type: "player",
|
|
18
|
+
name: "player",
|
|
19
|
+
id: -1
|
|
20
|
+
};
|
|
21
|
+
function applyMdToNewEntity(ctx, entityType = exports.DefaultPlayer, options = {}) {
|
|
14
22
|
var _a, _b;
|
|
15
23
|
//entityType.category
|
|
16
24
|
// entityType.internalId
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxg-org/mineflayer-physics-util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Provides functionality for more accurate entity and projectile tracking.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mineflayer",
|
|
@@ -18,22 +18,19 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "npx tsc",
|
|
20
20
|
"prepublish": "npm run build",
|
|
21
|
-
"test": "node --trace-warnings lib/tests/
|
|
21
|
+
"test": "node --trace-warnings lib/tests/fakeWorld.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@nxg-org/mineflayer-util-plugin": "^1.3.17",
|
|
25
|
-
"expect": "^27.5.1",
|
|
26
|
-
"minecraft-data": "^2.113.0",
|
|
27
|
-
"mineflayer": "^4.0.0",
|
|
28
25
|
"prismarine-block": "^1.13.1",
|
|
29
26
|
"prismarine-entity": "^2.0.0",
|
|
30
27
|
"prismarine-item": "^1.11.1",
|
|
31
|
-
"prismarine-physics": "^1.3.1",
|
|
32
28
|
"prismarine-registry": "^1.1.0",
|
|
33
29
|
"vec3": "^0.1.7"
|
|
34
30
|
},
|
|
35
31
|
"devDependencies": {
|
|
36
32
|
"@types/node": "^17.0.4",
|
|
33
|
+
"expect": "^29.3.1",
|
|
37
34
|
"typescript": "^4.5.5"
|
|
38
35
|
}
|
|
39
36
|
}
|
package/lib/tests/all.d.ts
DELETED
|
File without changes
|
package/lib/tests/all.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/tests/example.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/tests/example.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
const mineflayer_1 = require("mineflayer");
|
|
7
|
-
const index_1 = __importDefault(require("../index"));
|
|
8
|
-
const bot = (0, mineflayer_1.createBot)({
|
|
9
|
-
username: "bruh",
|
|
10
|
-
host: "minecraft.next-gen.dev",
|
|
11
|
-
version: "1.17.1"
|
|
12
|
-
});
|
|
13
|
-
bot.loadPlugin(index_1.default);
|
|
14
|
-
// expect(player.entity.position).toEqual(new Vec3(0, 60, 0))
|
package/lib/tests/testSim.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/tests/testSim.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const engines_1 = require("../physics/engines");
|
|
16
|
-
const states_1 = require("../physics/states");
|
|
17
|
-
const settings_1 = require("../physics/settings");
|
|
18
|
-
const physicsUtils_1 = require("../util/physicsUtils");
|
|
19
|
-
const player_1 = require("../physics/player");
|
|
20
|
-
const vec3_1 = require("vec3");
|
|
21
|
-
const expect_1 = __importDefault(require("expect"));
|
|
22
|
-
const index_1 = require("../index");
|
|
23
|
-
const simulators_1 = require("../simulators");
|
|
24
|
-
const testUtils_1 = __importDefault(require("./util/testUtils"));
|
|
25
|
-
//init (imports mcData to necessary modules).
|
|
26
|
-
const { mcData, Block, fakeWorld, createFakePlayer } = (0, testUtils_1.default)("1.17.1");
|
|
27
|
-
(0, index_1.initSetup)(mcData);
|
|
28
|
-
//create fake bot
|
|
29
|
-
const playerType = mcData.entitiesByName["player"]; // specify type we will be simulating.
|
|
30
|
-
const fakePlayer = createFakePlayer(new vec3_1.Vec3(0, 80, 0)); // call function supplied by prismarine-physics
|
|
31
|
-
fakePlayer.entity = (0, physicsUtils_1.applyMdToNewEntity)(settings_1.EPhysicsCtx, playerType, fakePlayer.entity); // ensure compatibility.
|
|
32
|
-
// create physics context.
|
|
33
|
-
const physics = new engines_1.EntityPhysics(mcData); // creates entity physics w/ environments specific to this entity.
|
|
34
|
-
const simulator = new simulators_1.BasicSim(physics); // creates a wrapper around physics supplying basic simulation info.
|
|
35
|
-
// create entity-specific physics context.
|
|
36
|
-
const playerState = states_1.EntityState.CREATE_FROM_ENTITY(physics, fakePlayer.entity); // creates a simulation-compatible state.
|
|
37
|
-
const playerCtx = settings_1.EPhysicsCtx.FROM_ENTITY_STATE(physics, playerState, playerType); // create wrapper context (supplies AABB, pose info, etc).
|
|
38
|
-
// set control state.
|
|
39
|
-
playerState.controlState = player_1.ControlStateHandler.DEFAULT(); // specific to players and mobs, specify control scheme to apply.
|
|
40
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
const result = yield simulator.simUntilOnGroundPrebuilt(playerCtx, fakeWorld, 50); // get resulting state (same as original)
|
|
42
|
-
result.applyToBot(fakePlayer); // apply to fake bot
|
|
43
|
-
(0, expect_1.default)(fakePlayer.entity.position).toEqual(new vec3_1.Vec3(0, 60, 0)); // it works.
|
|
44
|
-
console.log(fakePlayer.entity.position); //manual run.
|
|
45
|
-
}))();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
const testUtils_1 = __importDefault(require("./util/testUtils"));
|
|
7
|
-
const expect_1 = __importDefault(require("expect"));
|
|
8
|
-
const vec3_1 = require("vec3");
|
|
9
|
-
const wrapper_1 = require("../wrapper");
|
|
10
|
-
const { mcData, Block, Entity, fakeWorld, createFakePlayer, createFakeEntity, modifyEntity } = (0, testUtils_1.default)("1.17.1");
|
|
11
|
-
//create fake bot
|
|
12
|
-
const bot = createFakePlayer(new vec3_1.Vec3(0, 60, 0)); // call function supplied by prismarine-physics
|
|
13
|
-
const physicsUtil = new wrapper_1.PhysicsUtilWrapper(bot);
|
|
14
|
-
const fakeEntity = createFakeEntity("player", new vec3_1.Vec3(0, 80, 0));
|
|
15
|
-
physicsUtil.exampleSim(fakeEntity, wrapper_1.SimulationTypes.UNTIL_GROUND, 40).applyToEntity(fakeEntity);
|
|
16
|
-
(0, expect_1.default)(fakeEntity.position).toEqual(new vec3_1.Vec3(0, 60, 0)); // it works.
|
|
17
|
-
console.log(fakeEntity.position); //manual run.
|
|
18
|
-
modifyEntity("cat", fakeEntity);
|
|
19
|
-
const ctx = physicsUtil.getPhysicsCtx(physicsUtil.engine, fakeEntity);
|
|
20
|
-
ctx.state.controlState.set("forward", true);
|
|
21
|
-
physicsUtil.advancedExample(ctx, wrapper_1.SimulationTypes.FOR_X_TICKS, 40).applyToEntity(fakeEntity);
|
|
22
|
-
console.log(fakeEntity.position); //manual run.
|