A powerful Minecraft command library
Project description
Mecha
A powerful Minecraft command library.
from mecha import Mecha
mc = Mecha()
function = """
execute
as @a # For each "player",
at @s # start at their feet.
anchored eyes # Looking through their eyes,
facing 0 0 0 # face perfectly at the target
anchored feet # (go back to the feet)
positioned ^ ^ ^1 # and move one block forward.
rotated as @s # Face the direction the player
# is actually facing,
positioned ^ ^ ^-1 # and move one block back.
if entity @s[distance=..0.6] # Check if we're close to the
# player's feet.
run
say I'm facing the target!
"""
ast = mc.parse(function, multiline=True)
print(mc.serialize(ast)) # execute as @a at @s anchored eyes facing ...
Introduction
This package provides everything you need for working with Minecraft commands in Python, whether you're looking to process commands or build abstractions on top.
Features
- Extensible and version-agnostic
mcfunctionparser - Clean, immutable and hashable abstract syntax tree with source location
- Command config resolver that flattens and enumerates all the valid command prototypes
- Powerful rule dispatcher for processing specific ast nodes
- Composable ast visitors and reducers
- Execute arbitrary compilation passes in your
beetpipeline - (soon) Expressive command API for writing commands in Python
Credits
- A few test cases are adapted from
SPYGlass - Multiline example by
AjaxGb(MCC discord) - Multiline syntax derived from the
hangmanplugin - Partially inspired by
Trident
Installation
The package can be installed with pip.
$ pip install mecha
Contributing
Contributions are welcome. Make sure to first open an issue discussing the problem or the new feature before creating a pull request. The project uses poetry.
$ poetry install
You can run the tests with poetry run pytest.
$ poetry run pytest
The project must type-check with pyright. If you're using VSCode the pylance extension should report diagnostics automatically. You can also install the type-checker locally with npm install and run it from the command-line.
$ npm run watch
$ npm run check
The code follows the black code style. Import statements are sorted with isort.
$ poetry run isort mecha tests
$ poetry run black mecha tests
$ poetry run black --check mecha tests
License - MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mecha-0.12.1.tar.gz.
File metadata
- Download URL: mecha-0.12.1.tar.gz
- Upload date:
- Size: 68.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc939c0653ec530d0d1ea7c918e5f6a245b17ca761990151ebd6933bfce1fccf
|
|
| MD5 |
d8e9dda189a7cf8168e712080273c475
|
|
| BLAKE2b-256 |
d64a751a577d9e93d5f81f9d9296745ecb85acf6f1c25c8a95bbf4928c6df0e8
|
File details
Details for the file mecha-0.12.1-py3-none-any.whl.
File metadata
- Download URL: mecha-0.12.1-py3-none-any.whl
- Upload date:
- Size: 79.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
632e10072e40bba0df178cf4dd8d1953830f602d5e52dfba3f2f1da9bde4fd9d
|
|
| MD5 |
f208ba2daf2b59620c873faa8c19b73d
|
|
| BLAKE2b-256 |
6b3157c22fe872bd69851f23da5ab33ddd9e2e5c13e66f7b52ad57ba51d4e4bc
|