1
+ const mineflayer = require ( 'mineflayer' ) ;
2
+ const { pathfinder, Movements, goals } = require ( 'mineflayer-pathfinder' ) ;
3
+ const GoalNear = goals . GoalNear ;
4
+ const { Vec3 } = require ( 'vec3' ) ;
5
+
6
+ const bot = mineflayer . createBot ( {
7
+ host : 'localhost' ,
8
+ port : 42577 ,
9
+ username : 'lumberjack_Bot'
10
+ } )
11
+
12
+ bot . loadPlugin ( pathfinder ) ;
13
+
14
+ const FARM_POINT_1 = new Vec3 ( 372 , 4 , 153 )
15
+ const FARM_POINT_2 = new Vec3 ( 394 , 14 , 191 )
16
+ const DEPOSIT_CHEST = new Vec3 ( 362 , 5 , 146 )
17
+ const LOG_TYPES = [ ]
18
+
19
+ bot . once ( 'spawn' , ( ) => {
20
+ loadLogTypes ( )
21
+ gatherWood ( )
22
+ } )
23
+
24
+ function loadLogTypes ( ) {
25
+ const mcData = require ( 'minecraft-data' )
26
+ LOG_TYPES . push ( mcData . blocksByName . oak_log . id )
27
+ LOG_TYPES . push ( mcData . blocksByName . spruce_log . id )
28
+ LOG_TYPES . push ( mcData . blocksByName . birch_log . id )
29
+ }
30
+
31
+ function gatherWood ( ) {
32
+ const block = findWood ( block )
33
+ if ( ! block ) {
34
+ setTimeout ( gatherWood , 5000 )
35
+ return
36
+ }
37
+
38
+ chopTree ( block , ( ) => {
39
+
40
+ } )
41
+ }
42
+
43
+ function findWood ( ) {
44
+ for ( let x = FARM_POINT_1 . x ; x <= FARM_POINT_2 . x ; x ++ ) {
45
+ for ( let z = FARM_POINT_1 . z ; z <= FARM_POINT_2 . z ; z ++ ) {
46
+ for ( let y = FARM_POINT_1 . y ; y <= FARM_POINT_2 . y ; y ++ ) {
47
+ const block = bot . blockAt ( new Vec3 ( x , y , z ) )
48
+ if ( ! block ) continue
49
+
50
+ if ( LOG_TYPES . indexOf ( block . type ) > - 1 )
51
+ return block
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ function chopTree ( block , cb ) {
58
+ breakBlock ( block , cb )
59
+ }
60
+
61
+ function breakBlock ( block , cb ) {
62
+ equipTool ( block , ( ) => {
63
+ bot . dig ( block , cb )
64
+ } )
65
+ }
66
+
67
+ function equipTool ( block , cb ) {
68
+ const tool = bot . pathfinder . bestHarvestTool ( block )
69
+ if ( ! tool ) {
70
+ cb ( )
71
+ return
72
+ }
73
+
74
+ bot . equip ( tool , 'hand' , cb )
75
+ }
0 commit comments