Skip to main content

Native Python Minecraft Java bot protocol library.

Project description

BotMine

BotMine is a small native Python library for Minecraft Java bots. It is not a Mineflayer wrapper and does not start Node.js.

The first release focuses on a simple Python API and the protocol pieces needed to connect to offline-mode Java servers, read server status, and disconnect cleanly.

Install

pip install botmine

Shortest bot:

import botmine

bot = botmine.Bot("127.0.0.1", 25565, nickname="Bs", version="26.1.2")
bot.reconnect(True)
bot.say("BotMine online")
bot.command("help")
bot.follow_player("wawca")
bot.wait()

Run the bundled example from the project root:

python -m examples.simple

BotMine has no runtime dependencies outside Python itself. requirements.txt is empty on purpose. The package uses only the Python standard library and does not start JavaScript, Node.js, or Mineflayer.

The same thing with with:

import botmine

with botmine.Bot("127.0.0.1", 25565, nickname="Bs", version="26.1.2") as bot:
    bot.say("BotMine online")
    bot.follow_player("wawca")
    bot.wait()

Settings can also be changed through property():

bot = botmine.Bot("127.0.0.1", 25565, auto_connect=False)
bot.property(nickname="Bs", version="26.1.2", auto_swap_tools=True)
bot.connect()
bot.say("Hello from BotMine")
bot.command("/help")
bot.wait(30)
bot.leave()

follow_player() is packet-level movement, not full pathfinding. It follows a visible player while wait() or run_for() is running. It can jump one-block steps, but it is still not full pathfinding.

Events:

def on_chat(player, message):
    if message == "come":
        bot.follow_player(player)

bot.on("chat", on_chat)
bot.on("join", lambda player: print("join", player))
bot.on("leave", lambda player: print("leave", player))
bot.on("death", lambda message: print("death", message))
bot.on("respawn", lambda: print("respawn"))
bot.on("kicked", lambda reason: print("kicked", reason))

Movement:

bot.goto(x=100, y=64, z=-50)
bot.look_at("wawca")
bot.jump()
bot.sprint(True)
bot.sneak(True)
bot.follow_player("wawca")
bot.follow_stop("wawca")
print(bot.position())

Inventory and item actions:

inv = bot.inventory()
bot.equip("diamond_sword")
bot.use_item()
bot.drop("dirt", count=64)
bot.destroy(x=100, y=64, z=-50)
bot.respawn()

The inventory API is a local snapshot from server packets. equip("name") works only after the server has sent a matching tracked slot. auto_swap_tools can select a known hotbar tool before destroy().

Server snapshot:

info = bot.server_info()
print(info["players_count"])
print(info["nearest_player"])
print(info["spawn"])
print(info["time"])

wait() can also take seconds:

bot.wait(4)

Known Java protocol versions are mapped directly for 1.20.1 through 26.1.2. For version="auto" or a future unknown version label, BotMine uses the server status ping to detect the protocol ID before login.

Current limits

  • Java Edition protocol only.
  • Offline-mode login only. Online-mode/Microsoft authentication is intentionally not faked.
  • The library currently handles login/configuration enough for basic connection, chat, simple movement, tracked inventory actions and clean disconnect. Full pathfinding, signed chat sessions and full game-state tracking are not implemented yet.

Release

Build and check the package before uploading:

python -B -m unittest discover -s tests
python -m build
python -m twine check dist/*

Upload to TestPyPI first:

python -m twine upload --repository testpypi dist/*

Then upload to PyPI:

python -m twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

botmine-0.1.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

botmine-0.1.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file botmine-0.1.0.tar.gz.

File metadata

  • Download URL: botmine-0.1.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for botmine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5172878ec67ea40dd1c56dbb62998fe02ac32410ec80ee9eb52fdb58e6301e6f
MD5 2aba98face8d437cd4a0f637468c4066
BLAKE2b-256 cd4ec3f6c0ff797bc6a11ba4ac402807e2053ea9fc561ecc93a8783498bfe4d2

See more details on using hashes here.

File details

Details for the file botmine-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: botmine-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for botmine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1da5a86513a3401525d01974f48e3667bdb512baf00b3c91b1672b8893256d9b
MD5 f60d2bbadc4744c15843469f7605e885
BLAKE2b-256 37e1f11d42189956d67f1ab6d4dce9f5167ab8efebe55d5871fe6697290f08b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page