Created
January 6, 2022 18:43
-
-
Save SzczurekYT/6f3fb59a75ec2876fd86d14df3d16485 to your computer and use it in GitHub Desktop.
Mineflayer bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from javascript import require, On, Once, AsyncTask, once, off | |
import requests | |
import random | |
mineflayer = require("mineflayer") | |
# word_site = "https://www.mit.edu/~ecprice/wordlist.10000" | |
# Random bot name | |
# response = requests.get(word_site) | |
# WORDS = response.content.splitlines() | |
# BOT_USERNAME = str(random.choice(WORDS)) + "_" + str(random.choice(WORDS)) | |
class Bot(): | |
def __init__(self, name: str, host: str) -> None: | |
self.bot = mineflayer.createBot({ | |
"host": host, | |
"port": 25565, | |
"username": name, | |
"hideErrors": False, | |
"version": "1.17.1",}) | |
once(self.bot, "login") | |
print(name + " logged in!") | |
self.setupPathfinding() | |
def setupPathfinding(self) -> None: | |
self.pathfinder = require("mineflayer-pathfinder") | |
self.bot.loadPlugin(self.pathfinder.pathfinder) | |
mcData = require("minecraft-data")(self.bot.version) | |
movements = self.pathfinder.Movements(self.bot, mcData) | |
self.bot.pathfinder.setMovements(movements) | |
def exit(self) -> None: | |
self.bot.quit() | |
def goto(self, x: int, y: int, z: int): | |
self.bot.pathfinder.setGoal(self.pathfinder.goals.GoalBlock(x, y, z)) | |
def follow(self, entity: mineflayer.Entity, range: int): | |
self.bot.pathfinder.setGoal(self.pathfinder.goals.GoalFollow(entity, range)) | |
def stopMoving(self): | |
self.bot.pathfinder.stop() | |
BOT_USERNAME = "WinterWolf" | |
PASSWORD = "WinterPass" | |
bot = Bot(BOT_USERNAME, "localhost") | |
# bot.chat(f"/zaloguj {PASSWORD}") | |
while True: | |
# Get next command | |
cmd = input("Command bot: ") | |
match cmd: | |
case "stop": | |
bot.exit() | |
exit(0) | |
case "gotoP": | |
who = input("Who should I follow?: ") | |
target = bot.bot.players[who].entity | |
if not target: | |
print("Can't find that player") | |
pass | |
bot.goto(x= target.position["x"], y= target.position["y"], z= target.position["z"]) | |
case "follow": | |
who = input("Who should I follow?: ") | |
target = bot.bot.players[who].entity | |
if not target: | |
print("Can't find that player") | |
pass | |
bot.follow(entity=target, range= 5) | |
case "goto": | |
x = int(input("X: ")) | |
y = int(input("y: ")) | |
z = int(input("z: ")) | |
bot.goto(x=x, y=y, z=z) | |
case "debug": | |
print(bot.bot.players) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment