Package: mecha
MechaA powerful Minecraft command library.frommechaimportMechamc=Mecha()function="""executeas @a                        # For each "player",at @s                        # start at their feet.anchored eyes                # Looking through their eyes,facing 0 0 0                 # face perfectly at the targetanchored 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.runsay I'm facing the target!"""ast=mc.parse(function,multiline=True)print(mc.serialize(ast))# execute as @a at @s anchored eyes facing ...IntroductionThis package provides everything you need for working with Minecraft commands in Python, whether you're looking to process commands or build abstractions on top.FeaturesExtensible and version-agnosticmcfunctionparserClean, immutable and hashable abstract syntax tree with source locationCommand config resolver that flattens and enumerates all the valid command prototypesPowerful rule dispatcher for processing specific ast nodesComposable ast visitors and reducersComes with useful syntactic extensions like relative locations, nesting and implicit executeCompile-time scripting withBolt, a subset of Python integrated into command syntaxRich function analyzer for keeping track of command statisticsExecute arbitrary compilation passes in yourbeetpipeline(soon)Expressive command API for writing commands in PythonCreditsA few test cases are adapted fromSPYGlassMultiline example byAjaxGb(MCC discord)Multiline syntax derived from thehangmanpluginPartially inspired byTridentInstallationThe package can be installed withpip.$pipinstallmechaCommand-line utility$mecha--help
Usage:mecha[OPTIONS][SOURCE]...Validatedatapacksand.mcfunctionfiles.

Options:-m,--minecraftVERSIONMinecraftversion.-l,--logLEVELConfigureoutputverbosity.-s,--statsCollectstatistics.-j,--jsonFILENAMEOutputjson.-v,--versionShowtheversionandexit.-h,--helpShowthismessageandexit.You can use the command-line utility to check data packs and function files for errors. The command arguments can be zipped and unzipped data packs, individual function files, and if you specify a directory that's not a data pack it will recursively grab all the.mcfunctionfiles in the directory. You can use the--minecraftoption to select between versions1.16,1.17, and1.18.$mechapath/to/my_data_pack
ValidatingwithmechavX.X.X

ERROR|mechaExpectedcurly'}'butgotbracket']'.|path/to/my_data_pack/data/demo/functions/foo.mcfunction:5:34|4||5|sayhello@a[scores={foo=1,bar=2]|:^

Error:Reported1error.The--statsoption will output a report that shows how many commands, selectors and scoreboards were used. You can also use the--jsonoption to output the raw statistics in a json file.INFO   | stats  Analyzed 1 function
       | -------------------------------------------------------------------------------
       | Total commands (1 behind execute)                                      |      4
       | -------------------------------------------------------------------------------
       |        /scoreboard                                                     |      3
       |                    objectives add <objective> <criteria>               |      1
       |                    players set <targets> <objective> <score>           |      1
       |                    players operation <targets> <targetObjective> <o... |      1
       |        /setblock (1 behind execute)                                    |      1
       |        /execute                                                        |      1
       |                 if score <target> <targetObjective> matches <range>... |      1
       |                 as <targets> <subcommand>                              |      1
       |                 run <subcommand>                                       |      1
       | -------------------------------------------------------------------------------
       | Total selectors                                                        |      3
       | -------------------------------------------------------------------------------
       |        @e                                                              |      2
       |           [tag]                                                        |      2
       |           [scores]                                                     |      1
       |        @s                                                              |      1
       |        @e with missing or inverted type                                |      2
       | -------------------------------------------------------------------------------
       | Scoreboard objectives                                                  |      2
       | -------------------------------------------------------------------------------
       |        my_consts (dummy)                                               |      3
       |                  10                                                    |      2
       |        foo                                                             |      3Github actionYou can usemechato check your data packs and function files for errors without having to install anything using themcbeet/check-commandsgithub action.# .github/workflows/check-commands.yml
name: Check commands
on: [push]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: mcbeet/check-commands@v1
        with:
          source: .This allows you to make sure that your commands don't contain any error when you push to your repository. For more details check out theaction README.ContributingContributions are welcome. Make sure to first open an issue discussing the problem or the new feature before creating a pull request. The project usespoetry.$poetryinstallYou can run the tests withpoetry run pytest.$poetryrunpytestThe project must type-check withpyright. If you're using VSCode thepylanceextension should report diagnostics automatically. You can also install the type-checker locally withnpm installand run it from the command-line.$npmrunwatch
$npmruncheckThe code follows theblackcode style. Import statements are sorted withisort.$poetryrunisortmechatests
$poetryrunblackmechatests
$poetryrunblack--checkmechatestsLicense -MIT