-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathmineflayer.py
42 lines (35 loc) · 1.09 KB
/
mineflayer.py
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
from javascript import require, On
mineflayer = require('mineflayer')
pathfinder = require('mineflayer-pathfinder')
RANGE_GOAL = 1
BOT_USERNAME = 'python'
bot = mineflayer.createBot({
'host': '127.0.0.1',
'port': 25565,
'username': BOT_USERNAME
})
bot.loadPlugin(pathfinder.pathfinder)
print("Started mineflayer")
@On(bot, 'spawn')
def handle(*args):
print("I spawned 👋")
mcData = require('minecraft-data')(bot.version)
movements = pathfinder.Movements(bot, mcData)
@On(bot, 'chat')
def handleMsg(this, sender, message, *args):
print("Got message", sender, message)
if sender and (sender != BOT_USERNAME):
bot.chat('Hi, you said ' + message)
if 'come' in message:
player = bot.players[sender]
print("Target", player)
target = player.entity
if not target:
bot.chat("I don't see you !")
return
pos = target.position
bot.pathfinder.setMovements(movements)
bot.pathfinder.setGoal(pathfinder.goals.GoalNear(pos.x, pos.y, pos.z, RANGE_GOAL))
@On(bot, "end")
def handle(*args):
print("Bot ended!", args)