|
1 | | -# Datapack Breakpoint |
| 1 | +# Sniffer |
2 | 2 |
|
3 | | -English | [简体中文](README_zh.md) |
| 3 | +## Overview |
4 | 4 |
|
5 | | -## Introduce |
| 5 | +Sniffer is a debug adapter for Minecraft datapacks that allows you to debug your `.mcfunction` files directly from Visual Studio Code. It provides features like breakpoints, step execution, and variable inspection to make datapack development easier and more efficient. |
6 | 6 |
|
7 | | -This is a fabric mod for Minecraft 1.21, which allows you to set breakpoints in the game and "freeze" the game when |
8 | | -the breakpoint is reached. |
| 7 | +## Features |
9 | 8 |
|
10 | | -## Usage |
| 9 | +- Set breakpoints in `.mcfunction` files |
| 10 | +- Connect to a running Minecraft instance |
| 11 | +- Inspect game state during debugging |
| 12 | +- Step through command execution |
| 13 | +- Path mapping between Minecraft and local files |
11 | 14 |
|
12 | | -* Set a breakpoint |
| 15 | +## Requirements |
13 | 16 |
|
14 | | -In datapack, you can insert `#breakpoint` into .mcfunction file to set a breakpoint. For example: |
| 17 | +- Minecraft with Fabric Loader |
| 18 | +- Visual Studio Code |
15 | 19 |
|
16 | | -```mcfunction |
17 | | -#test:test |
18 | 20 |
|
19 | | -say 1 |
20 | | -say 2 |
21 | | -#breakpoint |
22 | | -say 3 |
23 | | -say 4 |
24 | | -``` |
25 | | - |
26 | | -In this case, after the game executes `say 2`, the game will be "frozen" because it meets the breakpoint. |
| 21 | +<!-- ## Installation |
27 | 22 |
|
28 | | -When the game is "frozen", you can still move around, do whatever you want, just like execute the command `tick freeze`. |
29 | | -So you can check the game state, or do some debugging. |
| 23 | +### Minecraft Mod Installation |
30 | 24 |
|
31 | | -* Step |
| 25 | +1. Install [Fabric Loader](https://fabricmc.net/use/) for your Minecraft version |
| 26 | +2. Download the Sniffer mod JAR from the [releases page](https://github.com/mcbookshelf/sniffer/releases) |
| 27 | +3. Place the JAR file in your Minecraft `mods` folder |
| 28 | +4. Launch Minecraft with Fabric |
32 | 29 |
|
33 | | -When the game is "frozen", you can use the command `/breakpoint step` to execute the next command. In above example, |
34 | | -after the game meets the breakpoint, you can use `/breakpoint step` to execute `say 3`, and then use `/breakpoint step` |
35 | | -to execute `say 4`. When all commands are executed, the game will be unfrozen and continue running. |
| 30 | +### VSCode Extension Installation |
36 | 31 |
|
37 | | -* Continue |
| 32 | +1. Open Visual Studio Code |
| 33 | +2. Go to the Extensions view (Ctrl+Shift+X) |
| 34 | +3. Search for "Sniffer" |
| 35 | +4. Click Install --> |
38 | 36 |
|
39 | | -When the game is "frozen", you can use the command `/breakpoint move` to unfreeze the game and continue running. |
| 37 | +## Mod Configuration |
| 38 | +The mod can be configured through the in-game configuration screen, accessible via Mod Menu. |
| 39 | +You can also configure the mod in the `config/sniffer.json` file. |
| 40 | +The following options are available: |
40 | 41 |
|
41 | | -* Get Macro Arguments |
| 42 | +### Debug Server Settings |
| 43 | +- **Server Port**: The port number for the debug server (default: 25599) |
| 44 | +- **Server path**: The path to the debug server (default: `/dap`) |
42 | 45 |
|
43 | | -By using `/breakpoint get <key>`, you can get the value of the macro argument if the game is executing a macro function. |
44 | | -For example: |
| 46 | +## Connecting to Minecraft |
45 | 47 |
|
46 | | -```mcfunction |
47 | | -#test:test_macro |
| 48 | +1. Open your datapack project in VSCode |
| 49 | +2. Create a `.vscode/launch.json` file with the following configuration: |
48 | 50 |
|
49 | | -say start |
50 | | -#breakpoint |
51 | | -$say $(msg) |
52 | | -say end |
| 51 | +```json |
| 52 | +{ |
| 53 | + "version": "0.2.0", |
| 54 | + "configurations": [ |
| 55 | + { |
| 56 | + "type": "sniffer", |
| 57 | + "request": "attach", |
| 58 | + "name": "Connect to Minecraft", |
| 59 | + "address": "ws://localhost:25599/dap" |
| 60 | + } |
| 61 | + ] |
| 62 | +} |
53 | 63 | ``` |
54 | 64 |
|
55 | | -After executing `function test:test_macro {"msg":"test"}`, we passed the value `test` to the macro argument `msg` and |
56 | | -then the game will pause before `$say $(msg)`. At this time, you can use `/breakpoint get msg` to get the value `test`. |
| 65 | +3. Start Minecraft with the Sniffer mod installed |
| 66 | +4. In VSCode, press F5 or click the "Run and Debug" button |
| 67 | +5. Select "Connect to Minecraft" from the dropdown menu |
57 | 68 |
|
58 | | -* Get Function Stack |
| 69 | +You can now place breakpoints in your `.mcfunction` files and execute it from the game to step through the code. |
59 | 70 |
|
60 | | -By using `/breakpoint stack`, you can get the function stack of the current game. For example, if we have following two |
61 | | -functions: |
| 71 | +## Usage in Minecraft |
62 | 72 |
|
63 | | -```mcfunction |
64 | | -#test:test1 |
| 73 | +The debugger can be controlled directly from Minecraft using the following commands: |
65 | 74 |
|
66 | | -say 1 |
67 | | -function test:test2 |
68 | | -say 2 |
| 75 | +- `/breakpoint continue`: Resume execution after hitting a breakpoint |
| 76 | +- `/breakpoint step`: Execute the next command and pause |
| 77 | +- `/breakpoint step_over`: Skip to the next command in the current function |
| 78 | +- `/breakpoint step_out`: Continue execution until the current function returns |
69 | 79 |
|
70 | | -#test: test2 |
71 | | -say A |
72 | | -#breakpoint |
73 | | -say B |
74 | | -``` |
| 80 | +All commands require operator permissions (level 2) to use. |
| 81 | + |
| 82 | +When execution is paused at a breakpoint, the gametick will be freezed. |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +## Development |
| 87 | + |
| 88 | +### Project Structure |
75 | 89 |
|
76 | | -When the game pauses at the breakpoint, you can use `/breakpoint stack` and the function stack will be printed in the |
77 | | -chat screen: |
| 90 | +- `src/main`: Main mod code for Minecraft |
| 91 | +- `src/client`: Client-side mod code |
| 92 | +- `vscode`: VSCode extension source code |
78 | 93 |
|
| 94 | +### Building the Project |
| 95 | + |
| 96 | +To build the Minecraft mod: |
| 97 | + |
| 98 | +```bash |
| 99 | +./gradlew build |
79 | 100 | ``` |
80 | | -test:test2 |
81 | | -test:test |
82 | 101 |
|
| 102 | +To build the VSCode extension: |
| 103 | + |
| 104 | +```bash |
| 105 | +cd vscode |
| 106 | +npm install |
| 107 | +npm run build |
83 | 108 | ``` |
84 | 109 |
|
85 | | -* Run command in current context |
| 110 | +## License |
| 111 | + |
| 112 | +This project is licensed under the MPL-2.0 License - see the [LICENSE](LICENSE) file for details. |
| 113 | + |
| 114 | +## Contributing |
| 115 | + |
| 116 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 117 | + |
| 118 | +## Acknowledgements |
86 | 119 |
|
87 | | -By using `/breakpoint run <command>`, you can run any command in the current context, just like `execute ... run ...`. |
| 120 | +- [Fabric](https://fabricmc.net/) - Mod loader for Minecraft |
| 121 | +- [VSCode Debug Adapter](https://code.visualstudio.com/api/extension-guides/debugger-extension) - VSCode debugging API |
| 122 | +- [Datapack Debugger](https://github.com/Alumopper/Datapack-Debugger/) by [Alumopper](https://github.com/Alumopper) - Original implementation of the debugger, without the DAP layer |
0 commit comments