Skip to content

Instantly share code, notes, and snippets.

@extremeheat
Created June 22, 2021 08:49
Show Gist options
  • Save extremeheat/782b21f5f5b040ba35df710839483e7a to your computer and use it in GitHub Desktop.
Save extremeheat/782b21f5f5b040ba35df710839483e7a to your computer and use it in GitHub Desktop.
mineflayer bot in python
from JSPyBridge 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(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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment