1
1
const mineflayer = require ( 'mineflayer' )
2
2
const { pathfinder, Movements, goals } = require ( 'mineflayer-pathfinder' )
3
3
const GoalFollow = goals . GoalFollow
4
+ const GoalBlock = goals . GoalBlock
4
5
5
6
const bot = mineflayer . createBot ( {
6
7
host : 'localhost' ,
7
- port : 36573 ,
8
+ port : 40947 ,
8
9
username : 'pathfinder_Bot'
9
10
} )
10
11
@@ -28,4 +29,27 @@ function followPlayer() {
28
29
bot . pathfinder . setGoal ( goal , true )
29
30
}
30
31
31
- bot . once ( 'spawn' , followPlayer )
32
+ function locateEmeraldBlock ( ) {
33
+ const mcData = require ( 'minecraft-data' ) ( bot . version )
34
+ const movements = new Movements ( bot , mcData )
35
+ movements . scafoldingBlocks = [ ]
36
+ bot . pathfinder . setMovements ( movements )
37
+
38
+ const emeraldBlock = bot . findBlock ( {
39
+ matching : mcData . blocksByName . emerald_block . id ,
40
+ maxDistance : 32
41
+ } )
42
+
43
+ if ( ! emeraldBlock ) {
44
+ bot . chat ( "I can't see any emerald blocks!" )
45
+ return
46
+ }
47
+
48
+ const x = emeraldBlock . position . x
49
+ const y = emeraldBlock . position . y + 1
50
+ const z = emeraldBlock . position . z
51
+ const goal = new GoalBlock ( x , y , z )
52
+ bot . pathfinder . setGoal ( goal )
53
+ }
54
+
55
+ bot . once ( 'spawn' , locateEmeraldBlock )
0 commit comments