Skip to content

Commit abb86c6

Browse files
committed
Pathfinding v2
1 parent 15c3fcd commit abb86c6

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

pathfinder_Bot/index.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const mineflayer = require('mineflayer')
22
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
33
const GoalFollow = goals.GoalFollow
4+
const GoalBlock = goals.GoalBlock
45

56
const bot = mineflayer.createBot({
67
host: 'localhost',
7-
port: 36573,
8+
port: 40947,
89
username: 'pathfinder_Bot'
910
})
1011

@@ -28,4 +29,27 @@ function followPlayer() {
2829
bot.pathfinder.setGoal(goal, true)
2930
}
3031

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

Comments
 (0)