Files
minecraft-bot/README.md
T
2026-11-04 17:29:52 +00:00

207 lines
6.4 KiB
Markdown

# Mosfet Minecraft Bot
A Minecraft 26.3 bot written in Python that uses an offline-mode account to
play. The connection path targets protocol 777; older Minecraft protocol
versions are not supported.
The original bot included wood/sand/crop farming, villager trading, eating,
sleeping, and threat avoidance. On the current 26.3 runtime, path following and
crop harvest/replant are migrated; other legacy jobs remain unavailable until
ported to protocol 777.
## Requirements and setup
- Python 3.11+
- The locally updated pyCraft checkout at `../pyCraft`
From the repository root, create and activate a virtual environment, then
install the connection-mode dependencies:
```
$ python3 -m venv .venv
$ source .venv/bin/activate
$ python -m pip install astar flask flask-cors munch watchdog -e ../pyCraft
```
## Running
Run the bot directly with Python. For the Protospace offline-mode server:
```
$ SERVER=127.0.0.1 python mosfet.py
```
`mosfet.py` defaults to that server, player name `mosfet1`, and the current
AuthMe password. Override `SERVER`, `PORT`, `PLAYER_NAME`, or `GAME_PASSWORD`
through environment variables as needed. Microsoft authentication is not used.
The dashboard is served at `/` (normally `http://localhost:3300`) and can be
rebuilt with `npm --prefix web_interface run build`. It uses bundled Minecraft
item icons where available, then fetches and caches missing textures from the
26.3 asset CDN. If no texture is available, it displays a two-letter
placeholder.
Inventory item icons are from https://mcitemgallery.com/
Python edits under `mosfet/` are hot-reloaded in place; the player connection is
kept alive. Edits to connection/bootstrap files are reported as deferred until
the next manual start, rather than triggering an automatic reconnect.
The 26.3 client now handles AuthMe, chat commands, chunk/world-state caching,
modern block/item/entity data, entity tracking, inventory/component sync,
path-following movement (`1goto x y z`), inventory draining (`1drain`), and the
crop harvest/replant loop (`1farm crops`). Other inventory/window actions and
the farming/trading jobs remain disabled until their 26.3 packets are migrated.
The default server is `127.0.0.1`; set `SERVER` explicitly only when you
intentionally want another server.
## Usage
[How to Cache Items](docs/cache_items.md)
[How to Grab Supplies](docs/grab_supplies.md)
## Commands
The command prefix character is the last character of the bot's name. For
example, if the bot's name is `mattstack`, then you would issue commands like
`kfarm wood` or `kpos`. This lets you run multiple bots on the same server.
In the following examples, we'll assume the bot's name is `mosfet1`, so commands
would be ran like `1farm wood` or `1pos`.
The exception are the below public commands, they can optionally be prefixed with `!`
and all bots will run the command.
The current 26.3 command path handles public chat. Private-message routing is
not migrated yet. Verified commands are `!ping`, `!pos`, `!loaded`, `!info x y
z`, `!inv` (basic slot/count data), `1drain`, addressed path movement such as
`1goto x y z`, and `1farm crops`. The command catalog below is retained from
the legacy bot; other inventory actions, arbitrary block interaction, and the
other farming/trading commands are not yet available on 26.3. Common item
components (names, damage, enchantments, book
contents, and shulker contents) are decoded; unrecognized component types are
marked partial rather than silently discarded.
### Public Commands
These can be ran by anyone, all bots will reply.
`!help` - prints this whole help message to console
`!help [command]` - replies in-game explaining command
`!ping` - replies with "pong"
`!echo [data]` - replies with "data"
`!pos` - replies with position and dimension
`!afk` - goes AFK with /afk
`!unafk` - goes not AFK with /afk
`!error` - raises an error
`!inv` - replies and prints current inventory
`!time` - replies with Minecraft world time
`!count [id]` - counts the number of items with that id
`!loaded` - replies with the current loaded area
`!players` - prints the current players
`!players clear` - clears the current player list
`!objects` - prints the current items on ground
`!objects clear` - clears the current object list
`!mobs` - prints the current mobs
`!mobs clear` - clears the current mob list
`!monsters` - prints the current monsters
`!villagers` - prints the current villagers
`!threats` - prints the dangerous monsters within 20 blocks
`!threats [num]` - prints the dangerous monsters within num blocks
`"zzz" or !zzz` - bot does /afk to let others sleep
`!tree` - replies with the closest tree
`!block x y z` - replies what block is at (x, y, z)
### Bot-specific Commands
These will only run for the bot they are addressed to. Replace `1` with the last character of the bot's name.
`1respawn` - respawns the bot if it's dead
`1gather wood` - gathers wood from the world
`1gather sand` - gathers sand from the world
`1farm wood` - farms wood from a certain area
`1farm sand` - farms sand from a certain area
`1farm wart` - farms netherwart from a certain area
`1farm crop` - farms mature crops from a certain area
`1loiter` - stands still but eats, sleeps, and flees
`1trade` - sells items to villagers to get emeralds
`1stop` - stops the current job and resets bot
`1drop` - drops the current stack its holding
`1select [id]` - moves item with id into main hand
`1dump [id]` - drops all items matching id
`1drain` - drops all items in inventory
`1fill [x] [y] [z] [x] [y] [z]` - fills the cuboid with the block at the first coordinate
`1here` - bot comes to your location
`1goto [x] [y] [z]` - sends the bot to coordinate (x, y, z)
`1close` - closes the current Minecraft window
`1click [slot] [button] [mode]` - clicks the current window
`1use` - use the item it's currently holding
`1interact [entity id]` - interacts with that entity
### Authorized Commands
These dangerous commands can only be ran by the bot owner.
`1print [expression]` - replies with Python eval(expression)
`1exit` - exits the program
## License
This program is free and open-source software licensed under the MIT License.
Please see the `LICENSE` file for details.
That means you have the right to study, change, and distribute the software and
source code to anyone and for any purpose. You deserve these rights. Please take
advantage of them because I like pull requests and would love to see this code
put to use.
## Acknowledgements
Thanks to Isaia, sose, and the devs behind pyCraft.