|
1 | | -# Sniffer |
| 1 | +> [!NOTE] |
| 2 | +> This project is now being developed by Bookshelf team and has been renamed to Sniffer. Bookshelf has added more features to Sniffer and developed a VSCode plugin! So head over to their repository to stay updated~ |
| 3 | +> |
| 4 | +> It's worth mentioning that the original author is still actively contributing to Sniffer's development~ |
| 5 | +> |
| 6 | +> Sniffer: <https://github.com/mcbookshelf/sniffer> |
2 | 7 |
|
3 | | -## Overview |
4 | 8 |
|
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. |
| 9 | +# Datapack Breakpoint |
6 | 10 |
|
7 | | -## Features |
| 11 | +English | [简体中文](README_zh.md) |
8 | 12 |
|
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 |
| 13 | +## Introduce |
14 | 14 |
|
15 | | -## Requirements |
| 15 | +This is a fabric mod for Minecraft 1.21, which allows you to set breakpoints in the game and "freeze" the game when |
| 16 | +the breakpoint is reached. |
16 | 17 |
|
17 | | -- Minecraft with Fabric Loader |
18 | | -- Visual Studio Code |
| 18 | +## Usage |
19 | 19 |
|
| 20 | +* Set a breakpoint |
20 | 21 |
|
21 | | -<!-- ## Installation |
| 22 | +In datapack, you can insert `#breakpoint` into .mcfunction file to set a breakpoint. For example: |
22 | 23 |
|
23 | | -### Minecraft Mod Installation |
| 24 | +```mcfunction |
| 25 | +#test:test |
24 | 26 |
|
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 |
29 | | -
|
30 | | -### VSCode Extension Installation |
31 | | -
|
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 --> |
36 | | - |
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: |
41 | | - |
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`) |
45 | | - |
46 | | -## Connecting to Minecraft |
47 | | - |
48 | | -1. Open your datapack project in VSCode |
49 | | -2. Create a `.vscode/launch.json` file with the following configuration: |
50 | | - |
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 | | -} |
| 27 | +say 1 |
| 28 | +say 2 |
| 29 | +#breakpoint |
| 30 | +say 3 |
| 31 | +say 4 |
63 | 32 | ``` |
64 | 33 |
|
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 |
| 34 | +In this case, after the game executes `say 2`, the game will be "frozen" because it meets the breakpoint. |
68 | 35 |
|
69 | | -You can now place breakpoints in your `.mcfunction` files and execute it from the game to step through the code. |
| 36 | +When the game is "frozen", you can still move around, do whatever you want, just like execute the command `tick freeze`. |
| 37 | +So you can check the game state, or do some debugging. |
70 | 38 |
|
71 | | -## Usage in Minecraft |
| 39 | +* Step |
72 | 40 |
|
73 | | -The debugger can be controlled directly from Minecraft using the following commands: |
| 41 | +When the game is "frozen", you can use the command `/breakpoint step` to execute the next command. In above example, |
| 42 | +after the game meets the breakpoint, you can use `/breakpoint step` to execute `say 3`, and then use `/breakpoint step` |
| 43 | +to execute `say 4`. When all commands are executed, the game will be unfrozen and continue running. |
74 | 44 |
|
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 |
| 45 | +* Continue |
79 | 46 |
|
80 | | -All commands require operator permissions (level 2) to use. |
| 47 | +When the game is "frozen", you can use the command `/breakpoint move` to unfreeze the game and continue running. |
81 | 48 |
|
82 | | -When execution is paused at a breakpoint, the gametick will be freezed. |
| 49 | +* Get Macro Arguments |
83 | 50 |
|
| 51 | +By using `/breakpoint get <key>`, you can get the value of the macro argument if the game is executing a macro function. |
| 52 | +For example: |
84 | 53 |
|
| 54 | +```mcfunction |
| 55 | +#test:test_macro |
85 | 56 |
|
86 | | -## Development |
87 | | - |
88 | | -### Project Structure |
| 57 | +say start |
| 58 | +#breakpoint |
| 59 | +$say $(msg) |
| 60 | +say end |
| 61 | +``` |
89 | 62 |
|
90 | | -- `src/main`: Main mod code for Minecraft |
91 | | -- `src/client`: Client-side mod code |
92 | | -- `vscode`: VSCode extension source code |
| 63 | +After executing `function test:test_macro {"msg":"test"}`, we passed the value `test` to the macro argument `msg` and |
| 64 | +then the game will pause before `$say $(msg)`. At this time, you can use `/breakpoint get msg` to get the value `test`. |
93 | 65 |
|
94 | | -### Building the Project |
| 66 | +* Get Function Stack |
95 | 67 |
|
96 | | -To build the Minecraft mod: |
| 68 | +By using `/breakpoint stack`, you can get the function stack of the current game. For example, if we have following two |
| 69 | +functions: |
97 | 70 |
|
98 | | -```bash |
99 | | -./gradlew build |
100 | | -``` |
| 71 | +```mcfunction |
| 72 | +#test:test1 |
101 | 73 |
|
102 | | -To build the VSCode extension: |
| 74 | +say 1 |
| 75 | +function test:test2 |
| 76 | +say 2 |
103 | 77 |
|
104 | | -```bash |
105 | | -cd vscode |
106 | | -npm install |
107 | | -npm run build |
| 78 | +#test: test2 |
| 79 | +say A |
| 80 | +#breakpoint |
| 81 | +say B |
108 | 82 | ``` |
109 | 83 |
|
110 | | -## License |
| 84 | +When the game pauses at the breakpoint, you can use `/breakpoint stack` and the function stack will be printed in the |
| 85 | +chat screen: |
111 | 86 |
|
112 | | -This project is licensed under the MPL-2.0 License - see the [LICENSE](LICENSE) file for details. |
113 | | - |
114 | | -## Contributing |
| 87 | +``` |
| 88 | +test:test2 |
| 89 | +test:test |
115 | 90 |
|
116 | | -Contributions are welcome! Please feel free to submit a Pull Request. |
| 91 | +``` |
117 | 92 |
|
118 | | -## Acknowledgements |
| 93 | +* Run command in current context |
119 | 94 |
|
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 |
| 95 | +By using `/breakpoint run <command>`, you can run any command in the current context, just like `execute ... run ...`. |
0 commit comments