@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
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# mineflayer-physics-utils
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IndexedData } from "minecraft-data";
|
|
2
|
+
import type { Bot } from "mineflayer";
|
|
3
|
+
import { PhysicsUtilWrapper } from "./wrapper";
|
|
4
|
+
declare module "mineflayer" {
|
|
5
|
+
interface Bot {
|
|
6
|
+
physicsUtil: PhysicsUtilWrapper;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export default function loader(bot: Bot): void;
|
|
10
|
+
export declare function initSetup(data: IndexedData): void;
|
|
11
|
+
export { EPhysicsCtx, PhysicsSettings } from "./physics/settings";
|
|
12
|
+
export { BaseSimulator } from "./simulators";
|
|
13
|
+
export { IPhysics } from "./physics/engines";
|
|
14
|
+
export { EntityState } from "./physics/states";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 = exports.BaseSimulator = exports.PhysicsSettings = exports.EPhysicsCtx = exports.initSetup = void 0;
|
|
7
|
+
const settings_1 = require("./physics/settings");
|
|
8
|
+
const wrapper_1 = require("./wrapper");
|
|
9
|
+
const prismarine_registry_1 = __importDefault(require("prismarine-registry"));
|
|
10
|
+
function loader(bot) {
|
|
11
|
+
if (!bot.physicsUtil) {
|
|
12
|
+
initSetup((0, prismarine_registry_1.default)(bot.version));
|
|
13
|
+
bot.physicsUtil = new wrapper_1.PhysicsUtilWrapper(bot);
|
|
14
|
+
console.log(bot.physicsUtil);
|
|
15
|
+
}
|
|
16
|
+
console.log(bot);
|
|
17
|
+
}
|
|
18
|
+
exports.default = loader;
|
|
19
|
+
function initSetup(data) {
|
|
20
|
+
settings_1.EPhysicsCtx.loadData(data);
|
|
21
|
+
settings_1.PhysicsSettings.loadData(data);
|
|
22
|
+
}
|
|
23
|
+
exports.initSetup = initSetup;
|
|
24
|
+
var settings_2 = require("./physics/settings");
|
|
25
|
+
Object.defineProperty(exports, "EPhysicsCtx", { enumerable: true, get: function () { return settings_2.EPhysicsCtx; } });
|
|
26
|
+
Object.defineProperty(exports, "PhysicsSettings", { enumerable: true, get: function () { return settings_2.PhysicsSettings; } });
|
|
27
|
+
var simulators_1 = require("./simulators");
|
|
28
|
+
Object.defineProperty(exports, "BaseSimulator", { enumerable: true, get: function () { return simulators_1.BaseSimulator; } });
|
|
29
|
+
var states_1 = require("./physics/states");
|
|
30
|
+
Object.defineProperty(exports, "EntityState", { enumerable: true, get: function () { return states_1.EntityState; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
2
|
+
import { IndexedData } from "minecraft-data";
|
|
3
|
+
import { Effect } from "mineflayer";
|
|
4
|
+
import { Entity } from "prismarine-entity";
|
|
5
|
+
import { PhysicsSettings } from "../settings/physicsSettings";
|
|
6
|
+
import { EPhysicsCtx } from "../settings/entityPhysicsCtx";
|
|
7
|
+
import { CheapEffects, CheapEnchantments, makeSupportFeature } from "../../util/physicsUtils";
|
|
8
|
+
import { EntityState } from "../states";
|
|
9
|
+
export declare type MobsByName = {
|
|
10
|
+
[mobName: string]: Entity;
|
|
11
|
+
};
|
|
12
|
+
export interface IPhysics {
|
|
13
|
+
settings: PhysicsSettings;
|
|
14
|
+
perEntityCtx: typeof EPhysicsCtx;
|
|
15
|
+
data: IndexedData;
|
|
16
|
+
supportFeature: ReturnType<typeof makeSupportFeature>;
|
|
17
|
+
getEffectLevel: (effect: string, effects: Effect[]) => number;
|
|
18
|
+
getEnchantmentLevel: (effect: string, enchantments: any[]) => number;
|
|
19
|
+
getEffectLevelCustom: (effect: CheapEffects, effects: Effect[]) => number;
|
|
20
|
+
getEnchantmentLevelCustom: (effect: CheapEnchantments, enchantments: any[]) => number;
|
|
21
|
+
getUnderlyingBlockBBs(queryBB: AABB, world: any): AABB[];
|
|
22
|
+
getSurroundingBBs(queryBB: AABB, world: any): AABB[];
|
|
23
|
+
simulatePlayer(simCtx: EPhysicsCtx, world: any): EntityState;
|
|
24
|
+
readonly statusEffectNames: {
|
|
25
|
+
[type in CheapEffects]: string;
|
|
26
|
+
};
|
|
27
|
+
readonly enchantmentNames: {
|
|
28
|
+
[type in CheapEnchantments]: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Vec3 } from "vec3";
|
|
2
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
3
|
+
import md from "minecraft-data";
|
|
4
|
+
import { Effect, Entity } from "prismarine-entity";
|
|
5
|
+
import { Block } from "prismarine-block";
|
|
6
|
+
import { NormalizedEnchant } from "prismarine-item";
|
|
7
|
+
import { CheapEffects, CheapEnchantments, makeSupportFeature } from "../../util/physicsUtils";
|
|
8
|
+
import { EntityState } from "../states/entityState";
|
|
9
|
+
import { IPhysics } from "./IPhysics";
|
|
10
|
+
import { PhysicsSettings } from "../settings/physicsSettings";
|
|
11
|
+
import { EPhysicsCtx } from "../settings/entityPhysicsCtx";
|
|
12
|
+
/**
|
|
13
|
+
* Looking at this code, it's too specified towards players.
|
|
14
|
+
*
|
|
15
|
+
* I will eventually split this code into PlayerState and bot.entityState, where bot.entityState contains fewer controls.
|
|
16
|
+
*/
|
|
17
|
+
export declare class EntityPhysics<T extends md.Entity> implements IPhysics {
|
|
18
|
+
data: md.IndexedData;
|
|
19
|
+
entity: T;
|
|
20
|
+
movementSpeedAttribute: any;
|
|
21
|
+
supportFeature: ReturnType<typeof makeSupportFeature>;
|
|
22
|
+
blockSlipperiness: {
|
|
23
|
+
[name: string]: number;
|
|
24
|
+
};
|
|
25
|
+
protected slimeBlockId: number;
|
|
26
|
+
protected soulsandId: number;
|
|
27
|
+
protected honeyblockId: number;
|
|
28
|
+
protected webId: number;
|
|
29
|
+
protected waterId: number;
|
|
30
|
+
protected lavaId: number;
|
|
31
|
+
protected ladderId: number;
|
|
32
|
+
protected vineId: number;
|
|
33
|
+
protected bubblecolumnId: number;
|
|
34
|
+
protected waterLike: Set<number>;
|
|
35
|
+
readonly statusEffectNames: {
|
|
36
|
+
[type in CheapEffects]: string;
|
|
37
|
+
};
|
|
38
|
+
readonly enchantmentNames: {
|
|
39
|
+
[type in CheapEnchantments]: string;
|
|
40
|
+
};
|
|
41
|
+
settings: PhysicsSettings;
|
|
42
|
+
perEntityCtx: typeof EPhysicsCtx;
|
|
43
|
+
constructor(mcData: md.IndexedData, entity: T);
|
|
44
|
+
static FROM_ENTITY(mcData: md.IndexedData, entity: Entity): EntityPhysics<md.Entity>;
|
|
45
|
+
getPlayerBB(entity: EPhysicsCtx, pos: {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
z: number;
|
|
49
|
+
}): AABB;
|
|
50
|
+
setPositionToBB(entity: EPhysicsCtx, bb: AABB, pos: {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
z: number;
|
|
54
|
+
}): void;
|
|
55
|
+
getUnderlyingBlockBBs(queryBB: AABB, world: any): AABB[];
|
|
56
|
+
getSurroundingBBs(queryBB: AABB, world: any): AABB[];
|
|
57
|
+
adjustPositionHeight(entity: EPhysicsCtx, pos: Vec3, world: any): void;
|
|
58
|
+
moveEntity(entity: EPhysicsCtx, dx: number, dy: number, dz: number, world: any): void;
|
|
59
|
+
applyHeading(entity: EPhysicsCtx, strafe: number, forward: number, multiplier: number): Vec3 | undefined;
|
|
60
|
+
getEffectLevelCustom(wantedEffect: CheapEffects, effects: Effect[]): number;
|
|
61
|
+
getEnchantmentLevelCustom(wantedEnchantment: CheapEnchantments, enchantments: any[]): any;
|
|
62
|
+
getEffectLevel(effectName: string, effects: Effect[]): number;
|
|
63
|
+
/**
|
|
64
|
+
* Slightly modified since I cannot find the typing.
|
|
65
|
+
*/
|
|
66
|
+
getEnchantmentLevelTest(enchantmentName: string, enchantments: NormalizedEnchant[]): number;
|
|
67
|
+
getEnchantmentLevel(enchantmentName: string, enchantments: any[]): any;
|
|
68
|
+
isOnLadder(pos: {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
z: number;
|
|
72
|
+
}, world: any): any;
|
|
73
|
+
doesNotCollide(entity: EPhysicsCtx, pos: {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
z: number;
|
|
77
|
+
}, world: any): boolean;
|
|
78
|
+
isMaterialInBB(queryBB: AABB, type: number, world: any): boolean;
|
|
79
|
+
getWaterInBB(bb: AABB, world: any): any[];
|
|
80
|
+
getLiquidHeightPcent(block: Block): number;
|
|
81
|
+
getRenderedDepth(block: Block): number;
|
|
82
|
+
getFlow(block: Block, world: any): Vec3;
|
|
83
|
+
isInWaterApplyCurrent(bb: AABB, vel: {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
z: number;
|
|
87
|
+
}, world: any): boolean;
|
|
88
|
+
moveEntityWithHeading(entity: EPhysicsCtx, strafe: number, forward: number, world: any): void;
|
|
89
|
+
simulatePlayer(entity: EPhysicsCtx, world: any): EntityState;
|
|
90
|
+
}
|