forked from PrismarineJS/mineflayer-pathfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
389 lines (330 loc) · 11.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import { Bot } from 'mineflayer';
import { IndexedData } from 'minecraft-data';
import { Item } from 'prismarine-item';
import { Vec3 } from 'vec3';
import { Block } from 'prismarine-block';
import { Entity } from 'prismarine-entity';
import { World } from 'prismarine-world'
import AStar from './lib/astar';
declare module 'mineflayer-pathfinder' {
export function pathfinder(bot: Bot): void;
export interface Pathfinder {
thinkTimeout: number;
/** ms, amount of thinking per tick (max 50 ms) */
tickTimeout: number;
readonly goal: goals.Goal | null;
readonly movements: Movements;
bestHarvestTool(block: Block): Item | null;
getPathTo(
movements: Movements,
goal: goals.Goal,
timeout?: number
): ComputedPath;
getPathFromTo(
movements: Movements,
startPos: Vec3 | null,
goal: goals.Goal,
options?: {
optimizePath?: boolean,
resetEntityIntersects?: boolean,
timeout?: number,
tickTimeout?: number,
searchRadius?: number,
startMove?: Move
}
): IterableIterator<{ result: ComputedPath, astarContext: AStar }>
setGoal(goal: goals.Goal | null, dynamic?: boolean): void;
setMovements(movements: Movements): void;
goto(goal: goals.Goal, callback?: Callback): Promise<void>;
stop(): void;
isMoving(): boolean;
isMining(): boolean;
isBuilding(): boolean;
}
export namespace goals {
export abstract class Goal {
public abstract heuristic(node: Move): number;
public abstract isEnd(node: Move): boolean;
public hasChanged(): boolean;
public isValid(): boolean;
}
export class GoalBlock extends Goal {
public constructor(x: number, y: number, z: number);
public x: number;
public y: number;
public z: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalNear extends Goal {
public constructor(x: number, y: number, z: number, range: number);
public x: number;
public y: number;
public z: number;
public rangeSq: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalXZ extends Goal {
public constructor(x: number, z: number);
public x: number;
public z: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalNearXZ extends Goal {
public constructor(x: number, z: number, range: number);
public x: number;
public z: number;
public rangeSq: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalY extends Goal {
public constructor(y: number);
public y: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalGetToBlock extends Goal {
public constructor(x: number, y: number, z: number);
public x: number;
public y: number;
public z: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalCompositeAny<T extends Goal> extends Goal {
public constructor(goals: T[] = []);
public goals: T[];
public push(goal: Goal): void;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalCompositeAll<T extends Goal> extends Goal {
public constructor(goals: T[] = []);
public goals: T[];
public push(goal: Goal): void;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalInvert extends Goal {
public constructor(goal: Goal);
public goal: Goal;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalFollow extends Goal {
public constructor(entity: Entity, range: number);
public x: number;
public y: number;
public z: number;
public entity: Entity;
public rangeSq: number;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalPlaceBlock extends Goal {
public options: {
range: number;
LOS: boolean;
faces: [Vec3, Vec3, Vec3, Vec3, Vec3, Vec3];
facing: number;
half: boolean;
}
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
public constructor(pos: Vec3, world: World, options: GoalPlaceBlockOptions)
}
export class GoalLookAtBlock extends Goal {
public constructor(pos: Vec3, world: World, options?: { reach?: number, entityHeight?: number })
public pos: Vec3;
public reach: number;
public entityHeight: number;
public world: World;
public heuristic(node: Move): number;
public isEnd(node: Move): boolean;
public hasChanged(): boolean;
}
export class GoalBreakBlock extends GoalLookAtBlock {}
}
export class Movements {
public constructor(bot: Bot);
public bot: Bot;
public canDig: boolean;
public canOpenDoors: boolean;
public dontCreateFlow: boolean;
public dontMineUnderFallingBlock: boolean;
public allow1by1towers: boolean;
public allowFreeMotion: boolean;
public allowParkour: boolean;
public allowSprinting: boolean;
/**
* Test for entities that may obstruct path or prevent block placement. Grabs updated entities every new path
*/
public allowEntityDetection: boolean;
/**
* Set of entities (by mcdata name) to completely avoid when using entity detection
*/
public entitiesToAvoid: Set<string>;
/**
* Set of entities (by mcdata name) to ignore when using entity detection
*/
public passableEntities: Set<string>;
/**
* Set of blocks (by mcdata name) that pathfinder should not attempt to place blocks or 'right click' on
*/
public interactableBlocks: Set<string>;
public blocksCantBreak: Set<number>;
public blocksToAvoid: Set<number>;
public liquids: Set<number>;
public gravityBlocks: Set<number>;
public climbables: Set<number>
public emptyBlocks: Set<number>
public replaceables: Set<number>
public fences: Set<number>
public carpets: Set<number>
public openable: Set<number>
public scafoldingBlocks: number[];
public maxDropDown: number;
public infiniteLiquidDropdownDistance: boolean;
public digCost: number;
public placeCost: number;
/**
* Extra cost multiplier for moving through an entity hitbox (besides passable ones).
*/
public entityCost: number;
/** Exclusion Area that adds extra cost or prevents the bot from stepping onto positions included.
* @example
* ```js
movements.exclusionAreas = [(block) => {
return block.type === someIdType ? 100 : 0 // Prevents the bot from breaking a specific block. By adding 100 to the cost.
},
(block) => {
return someVec3Pos.distanceTo(block.position) < 5 ? 100 : 0 // Prevents the bot from getting near to a specific location
}]
``` */
public exclusionAreasStep: [(block: SafeBlock) => number];
/**
* Exclusion area for blocks to break. Works in the same way as {@link exclusionAreasStep} does.
*/
public exclusionAreasBreak: [(block: SafeBlock) => number];
/**
* Exclusion area for placing blocks. Note only works for positions not block values as placed blocks are determined by the bots inventory content. Works in the same way as {@link exclusionAreasStep} does.
*/
public exclusionAreasPlace: [(block: SafeBlock) => number];
/**
* A dictionary of the number of entities intersecting each floored block coordinate.
* Updated automatically each path but, you may mix in your own entries before calculating a path if desired (generally for testing).
* To prevent this from being cleared automatically before generating a path see getPathFromTo()
* formatted entityIntersections['x,y,z'] = #ents
*/
public entityIntersections: {string: number};
public exclusionPlace(block: SafeBlock): number;
public exclusionStep(block: SafeBlock): number;
public exclusionBreak(block: SafeBlock): number;
public countScaffoldingItems(): number;
public getScaffoldingItem(): Item | null;
public clearCollisionIndex(): void;
/**
* Finds blocks intersected by entity bounding boxes
* and sets the number of ents intersecting in a dict.
* Ignores entities that do not affect block placement
*/
public updateCollisionIndex(): void;
/**
* Gets number of entities who's bounding box intersects the node + offset
* @param {import('vec3').Vec3} pos node position
* @param {number} dx X axis offset
* @param {number} dy Y axis offset
* @param {number} dz Z axis offset
* @returns {number} Number of entities intersecting block
*/
public getNumEntitiesAt(pos: Vec3, dx: number, dy: number, dz: number): number;
public getBlock(pos: Vec3, dx: number, dy: number, dz: number): SafeBlock;
public safeToBreak(block: SafeBlock): boolean;
public safeOrBreak(block: SafeBlock): number;
public getMoveJumpUp(node: Move, dir: XZCoordinates, neighbors: Move[]): void;
public getMoveForward(node: Move, dir: XZCoordinates, neighbors: Move[]): void;
public getMoveDiagonal(node: Move, dir: XZCoordinates, neighbors: Move[]): void;
public getMoveDropDown(node: Move, dir: XZCoordinates, neighbors: Move[]): void;
public getMoveParkourForward(node: Move, dir: XZCoordinates, neighbors: Move[]): void;
public getMoveJumpUp(node: Move, dir: XZCoordinates, neighbors: Move[]): void;
public getMoveUp(node: Move, neighbors: Move[]): void;
public getMoveDown(node: Move, neighbors: Move[]): void;
public getLandingBlock(node: Move, dir: XZCoordinates): SafeBlock;
public getNeighbors(node: Move): Move[];
}
// this is a class, but its not exported so we use an interface
export interface Move extends XYZCoordinates {
remainingBlocks: number;
cost: number;
toBreak: Move[];
toPlace: Move[];
parkour: boolean;
hash: string;
}
type Callback = (error?: Error) => void;
interface PathBase {
cost: number;
time: number;
visitedNodes: number;
generatedNodes: number;
path: Move[];
}
export interface ComputedPath extends PathBase {
status: 'noPath' | 'timeout' | 'success';
}
export interface PartiallyComputedPath extends PathBase {
status: 'noPath' | 'timeout' | 'success' | 'partial';
}
export interface XZCoordinates {
x: number;
z: number;
}
export interface XYZCoordinates extends XZCoordinates {
y: number;
}
export interface SafeBlock extends Block {
safe: boolean;
physical: boolean;
liquid: boolean;
height: number;
replaceable: boolean;
climbable: boolean;
openable: boolean;
}
export interface GoalPlaceBlockOptions {
range: number;
LOS: boolean;
faces: Vec3[];
facing: 'north' | 'east' | 'south' | 'west' | 'up' | 'down';
}
}
declare module 'mineflayer' {
interface BotEvents {
goal_reached: (goal: Goal) => void;
path_update: (path: PartiallyComputedPath) => void;
goal_updated: (goal: Goal, dynamic: boolean) => void;
path_reset: (
reason: 'goal_updated' | 'movements_updated' |
'block_updated' | 'chunk_loaded' | 'goal_moved' | 'dig_error' |
'no_scaffolding_blocks' | 'place_error' | 'stuck'
) => void;
path_stop: () => void;
}
interface Bot {
pathfinder: Pathfinder
}
}