|
| 1 | +[](https://www.minecraft.net/store/minecraft-java-edition) |
| 2 | +\ |
| 3 | +[](https://crates.io/crates/mcfunction-debugger) |
| 4 | + |
1 | 5 | # mcfunction-debugger |
2 | 6 |
|
3 | 7 | mcfunction-debugger is a debugger for Minecraft's *.mcfunction files that does not require any Minecraft mods. |
4 | 8 |
|
5 | | -## Debug your datapack in three steps |
| 9 | +## Status |
| 10 | + |
| 11 | +This project has reached a minimum-viable product level of quality. |
| 12 | +It offers a command line interface but does not integrate with an editor. |
| 13 | +We already started implementing the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/) to provide an extension for [Visual Studio Code](https://code.visualstudio.com/) which will also include additional features like stepping through the code and showing current scoreboard values, but this will take some time. |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +You can debug any datapack with the following five steps: |
6 | 18 |
|
7 | 19 | 1. Add `# breakpoint` lines in your *.mcfunction files |
8 | | -2. Generate a debug datapack and load it in Minecraft |
9 | | -3. Start debugging any of your functions by executing the command `/function debug:<your_namespace>/<your_function>` |
| 20 | +2. Generate a debug datapack |
| 21 | +3. Load the debug datapack in Minecraft |
| 22 | +4. Start debugging any of your functions with: `/function debug:<your_namespace>/<your_function>` |
| 23 | +5. When finished, uninstall the debug datapack with: `/function debug:uninstall` |
| 24 | + |
| 25 | +A more detailed description can be found [here](docs/usage.md). |
| 26 | + |
| 27 | +## Installation |
| 28 | + |
| 29 | +### Using precompiled binaries |
| 30 | + |
| 31 | +Precompiled binaries are available under [releases](https://github.com/vanilla-technologies/mcfunction-debugger/releases). |
| 32 | +We recommend saving the `mcfunction-debugger` binary to Minecraft's `saves` directory for ease of use. |
| 33 | +On Windows this is located at `%APPDATA%\.minecraft\saves`. |
| 34 | + |
| 35 | +### Installing from source |
| 36 | + |
| 37 | +mcfunction-debugger is written in Rust so to build it from source you need to [install Rust](https://www.rust-lang.org/tools/install). |
| 38 | + |
| 39 | +You can then install it from [crates.io](https://crates.io/crates/mcfunction-debugger) by running: |
| 40 | +``` |
| 41 | +cargo install mcfunction-debugger |
| 42 | +``` |
| 43 | + |
| 44 | +Or from GitHub by running: |
| 45 | +``` |
| 46 | +cargo install --git https://github.com/vanilla-technologies/mcfunction-debugger.git |
| 47 | +``` |
| 48 | + |
| 49 | +To uninstall run: |
| 50 | +``` |
| 51 | +cargo uninstall mcfunction-debugger |
| 52 | +``` |
| 53 | + |
| 54 | +## Planned features |
| 55 | + |
| 56 | +These features are planned, but not yet implemented: |
| 57 | + |
| 58 | +* Support function tags [#12](https://github.com/vanilla-technologies/mcfunction-debugger/issues/12) |
| 59 | +* Allow users to supply a `commands.json` file for newer or older versions of Minecraft [#42](https://github.com/vanilla-technologies/mcfunction-debugger/issues/42) |
| 60 | +* Freezing the `gametime` while suspended [#18](https://github.com/vanilla-technologies/mcfunction-debugger/issues/18) |
| 61 | +* Freezing the age of all entities while suspended (this is currently only done for area_effect_clouds) [#24](https://github.com/vanilla-technologies/mcfunction-debugger/issues/24) |
| 62 | +* Support debugging multiple datapacks at once [#9](https://github.com/vanilla-technologies/mcfunction-debugger/issues/9) |
| 63 | +* Support debugging `load.json` and `tick.json` [#8](https://github.com/vanilla-technologies/mcfunction-debugger/issues/8) |
| 64 | +* Support storing the `result`/`success` of a `function` command with `execute store` [#11](https://github.com/vanilla-technologies/mcfunction-debugger/issues/11) |
| 65 | +* Setting `randomTickSpeed` to 0 while suspended [#14](https://github.com/vanilla-technologies/mcfunction-debugger/issues/14) |
| 66 | + |
| 67 | +## Caveats |
| 68 | + |
| 69 | +Unfortunately a program can always behave slightly differently when being debugged. |
| 70 | +Here are some problems you might encounter with mcfunction-debugger. |
10 | 71 |
|
11 | | -## Generating a debug datapack |
| 72 | +### Operating on Dead Entities |
12 | 73 |
|
13 | | -Currently it is necessary to [install Rust](https://www.rust-lang.org/tools/install) and clone this reporsitory in order to generate a debug datapack. |
14 | | -Executables for Windows, Linux and Mac will be provided with the first release. |
| 74 | +In a Minecraft function you can kill an entity and then continue using it. |
| 75 | +For example, consider the following datapack: |
15 | 76 |
|
16 | | -Build an executable for Windows with following command: |
| 77 | +`example:sacrifice_pig`: |
| 78 | +``` |
| 79 | +summon pig ~ ~ ~ {Tags: [sacrifice]} |
| 80 | +execute as @e[type=pig,tag=sacrifice] run function example:perform_necromancy |
| 81 | +``` |
17 | 82 |
|
18 | | -`cargo build --release` |
| 83 | +`example:perform_necromancy`: |
| 84 | +``` |
| 85 | +say I am still alive |
| 86 | +function example:kill_me |
| 87 | +say I am dead inside |
| 88 | +``` |
19 | 89 |
|
20 | | -and run it with |
| 90 | +`example:kill_me`: |
| 91 | +``` |
| 92 | +kill @s |
| 93 | +``` |
21 | 94 |
|
22 | | -`mcfunction-debugger [FLAGS] [OPTIONS] --input <DATAPACK> --output <DATAPACK>` |
| 95 | +After the function `example:kill_me` is executed the pig is dead, yet it speaks to us from the other side. |
| 96 | +This cannot be handled by the debugger. |
| 97 | +If you try to debug the function `example:sacrifice_pig` it will crash: |
| 98 | +``` |
| 99 | +[Pig] I am still alive |
| 100 | +Selected entity was killed! |
| 101 | +Start a new debugging session with '/function debug:<your_namespace>/<your_function>' |
| 102 | +Executed 145 commands from function 'debug:example/sacrifice_pig' |
| 103 | +``` |
23 | 104 |
|
24 | | -### Flags |
| 105 | +### Hitting the Maximum Command Chain Length |
25 | 106 |
|
26 | | -* `shadow`: When this is set to true the generated datapack will additionally contain functions with the same name as the functions in the input datapack. |
27 | | -These functions will simply forward to the appropriate function in the `debug` namespace. When using this make sure to disable the input datapack to avoid name clashes.\ |
28 | | -\ |
29 | | -This can be helpful when executing a function from a command block, because you don't have to change the function call to debug the function. Note however that calling a debug function inside an execute prevents the debugger to suspend the execute. For example if the command `execute as @e run function my_namespace:my_function` hits a breakpoint in my_function if there is more than one entity my_function will be called again, resulting in an error like: "Cannot start debugging my_namespace:my_function, because a function is already suspended at a breakpoint!". |
| 107 | +By default Minecraft only executes up to 65536 commands per tick. |
| 108 | +Since the debug datapack needs to run many commands in addition to the commands of your datapack, you might hit this limit when debugging a very large datapack. |
| 109 | +You can tell by looking at how many commands where executed from the function. |
| 110 | +When you see something like: |
| 111 | +``` |
| 112 | +Executed 65536 commands from function 'debug:resume' |
| 113 | +``` |
| 114 | +You should stop the debug session with `/function debug:stop` and add more breakpoints to avoid running so many commands at once or increase the command limit with: |
| 115 | +``` |
| 116 | +/gamerule maxCommandChainLength 2147483647 |
| 117 | +``` |
30 | 118 |
|
| 119 | +### Chunkloading |
31 | 120 |
|
32 | | -### Options |
| 121 | +If a chunk that contains an entity required for debugging is unloaded, while a function is suspended on a breakpoint, the debug session will crash, if you try to resume the execution. |
33 | 122 |
|
34 | | -* `input`: The datapack to generate a debug datapack for. This has to be a directory containing a `pack.mcmeta` file. |
35 | | -* `log-level`: The log level can also be configured via the environment variable `LOG_LEVEL`. |
36 | | -* `namespace`: The internal namespace of the generated datapack.\ |
37 | | -Default value: `mcfd`.\ |
38 | | -The namespace is used for all internal functions in the generated datapack and as a prefix for all scoreboard objectives and tags. By specifying a different namespace with max. 7 characters you can avoid name clashes. The generated functions in the `debug` namespace such as `debug:install` and `debug:resume` are unaffected by this option. |
39 | | -* `output`: The directory that should become the generated debug datapack. |
40 | | -On Windows this is typically a directory in the datapacks directory of your world, for example: \ |
41 | | -`%APPDATA%\.minecraft\\saves\\Your-World\\datapacks\\debug-my-datapack` |
| 123 | +This can for example happen if you go far away or if the function operates in a chunk that is only loaded temporarily (for instance by a `teleport` command or by going through a portal). |
0 commit comments