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.
- Set breakpoints in
.mcfunctionfiles - Connect to a running Minecraft instance
- Inspect game state during debugging
- Step through command execution
- Path mapping between Minecraft and local files
- Debug commands started with
#! - Assert command
- Log command (Much more powerful than
tellraworsay) - Hot reload datapack changes
- Minecraft with Fabric Loader
- Visual Studio Code
The mod can be configured through the in-game configuration screen, accessible via Mod Menu.
You can also configure the mod in the config/sniffer.json file.
The following options are available:
- Server Port: The port number for the debug server (default: 25599)
- Server path: The path to the debug server (default:
/dap)
- Open your datapack project in VSCode
- Create a
.vscode/launch.jsonfile with the following configuration:
{
"version": "0.2.0",
"configurations": [
{
"type": "sniffer",
"request": "attach",
"name": "Connect to Minecraft",
"address": "ws://localhost:25599/dap"
}
]
}In this case, after the game executes say 2, the game will be "frozen" because it meets the breakpoint.
When the game is "frozen", you can still move around, do whatever you want, just like execute the command tick freeze.
So you can check the game state, or do some debugging.
- Step
The debugger can be controlled directly from Minecraft using the following commands:
- Continue
When the game is "frozen", you can use the command /breakpoint move to unfreeze the game and continue running.
- Get Macro Arguments
Comment started with #! are recognized as debug commands. They will be executed as same as the normal commands in the game but without Sniffer, those debug commands will only be considered as comments.
Sniffer adds some useful commands for datapack developer. By using debug command, you can use those commands in your datapack without worrying about breaking your datapack in vanilla Minecraft.
For example, if you want to place a breakpoint in your function:
say 1
say 2
say 3
#The function will stop at the line with `#!breakpoint`
#!breakpoint
say 4
say 5Also you can execute normal commands in debug command line:
say 1
say 2
say 3
#!execute if score @s test matches 1..10 run breakpoint
say 4
say 5This breakpoint will only be triggerred when the score of the executor in test object is between 1 and 10.
Assert command is used to check if a condition is true. If the condition is false, the mod will print an error message to the game chat.
Syntax: assert <expr>
say 1
say 2
say 3
#!assert {(score @s test ) <= 10}
say 4
say 5This assert command will check if the score of the executor in test object is less than or equal to 10.
In sniffer command, you can use complex expression as command argument. Normally, an expression is surrounded by curly braces {}. Within an expression, you may obtain a value from an argument enclosed in parentheses and employ it in the expression’s evaluation.
Supported expression arguments:
score <score_holder> <objective>: The same asexecute if score. Returns an int value.data entity <entity>/storage <id>/block <pos> path: The same asexecute if data. Returns a nbt value.name <entity>: return a text components with all names of the entities.
Warning
Owing to inherent limitations in the command-parsing system, the closing parenthesis of an expression argument must be preceded by at least one space
Supported operators:
+,-,*,/,%: Arithmetic operators==,!=,<,<=,>,>=: Comparison operators&&,||,!: Logical operatorsis: Check if a value is a certain type. Returns a boolean value. Available types:nbt,text,string,number,byte,short,int,long,float,double,int_array,long_array,byte_array,list,compound, `
Note
No operator possesses intrinsic precedence; expressions are evaluated strictly from left to right. By nesting subexpressions, however, you can enforce prioritized evaluation
Log command is used to print a message to the game chat. The log message can contain expression arguments.
Syntax: log <log>
say 1
say 2
say 3
#!log The score of @s in test objective is {(score @s test )}
say 4
say 5This log command will print The score of @s in test objective is 10 to the game chat.
Sniffer can watch the changes of the datapack files (only *.mcfunction files currently) and reload them automatically. Hot reloading will not reload all resources, as it will only reload the function that is changed. It will not trigger functions with #minecraft:load tag too. In large-scale datapack projects, or if you installed kubejs mod, hot reloading can markedly mitigate unnecessary reload-induced pauses and stuttering.
Hot reloading will watch any changes, create or delete of the datapack files.
Hot reloading is not enabled by default. You must use the watch start command to start watching a datapack. Each time you re-enter the world, the watcher must be reestablished. After making any changes in the datapack, you can use the watch reload command to trigger hot reloading and apply changes in your datapack. A message will be sent to the game chat to tell you what changes have been actually applied.
If the command parser encounters any error while parsing a function, the changes in the function will not apply, and a message will be sent to the game chat to tell you the error.
Command Syntax:
watch start <Datapack Folder Name>: Start watching a datapack folder.watch stop <Datapack Folder Name>: Stop watching a datapack folder.watch reload: Trigger the hot loading to apply changes.watch auto [true|false]: Set whether auto reloading is enabled. Auto reloading will apply any change once the watcher detects it. Default isfalse. If value is not provided, it will tell you if the auto reloading is enabled.
say start
#breakpoint
After executing `function test:test_macro {"msg":"test"}`, we passed the value `test` to the macro argument `msg` and
then the game will pause before `$say $(msg)`. At this time, you can use `/breakpoint get msg` to get the value `test`.
* Get Function Stack
By using `/breakpoint stack`, you can get the function stack of the current game. For example, if we have following two
functions:
```mcfunction
#test:test1
say 1
function test:test2
say 2
#test: test2
say A
#breakpoint
say B
When the game pauses at the breakpoint, you can use /breakpoint stack and the function stack will be printed in the
chat screen:
test:test2
test:test
- Run command in current context
- Fabric - Mod loader for Minecraft
- VSCode Debug Adapter - VSCode debugging API
- Datapack Debugger by Alumopper - Original implementation of the debugger, without the DAP layer