Skip to content

Commit e2b9ffa

Browse files
authored
Merge pull request #7 from mcbookshelf/master
pr
2 parents 137c565 + 462581e commit e2b9ffa

File tree

79 files changed

+9649
-1866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+9649
-1866
lines changed

LICENSE

Lines changed: 373 additions & 674 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 91 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,122 @@
1-
# Datapack Breakpoint
1+
# Sniffer
22

3-
English | [简体中文](README_zh.md)
3+
## Overview
44

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.
66

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
98

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
1114

12-
* Set a breakpoint
15+
## Requirements
1316

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
1519

16-
```mcfunction
17-
#test:test
1820

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
2722
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
3024
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
3229
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
3631
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 -->
3836

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:
4041

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`)
4245

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
4547

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:
4850

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+
}
5363
```
5464

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
5768

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.
5970

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
6272

63-
```mcfunction
64-
#test:test1
73+
The debugger can be controlled directly from Minecraft using the following commands:
6574

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
6979

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
7589

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
7893

94+
### Building the Project
95+
96+
To build the Minecraft mod:
97+
98+
```bash
99+
./gradlew build
79100
```
80-
test:test2
81-
test:test
82101

102+
To build the VSCode extension:
103+
104+
```bash
105+
cd vscode
106+
npm install
107+
npm run build
83108
```
84109

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
86119

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

README_zh.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

build.gradle

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ repositories {
1616
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
1717
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
1818
// for more information about repositories.
19+
20+
// Added repositories for Cloth Config and ModMenu
21+
maven { url "https://maven.shedaniel.me/" }
22+
maven { url "https://maven.terraformersmc.com/releases/" }
1923
}
2024

2125
loom {
2226
splitEnvironmentSourceSets()
2327

2428
mods {
25-
"datapack-debugger" {
29+
"sniffer" {
2630
sourceSet sourceSets.main
2731
sourceSet sourceSets.client
2832
}
@@ -31,13 +35,26 @@ loom {
3135
}
3236

3337
dependencies {
38+
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0'
39+
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.24.0'
40+
implementation 'jakarta.websocket:jakarta.websocket-api:2.2.0'
41+
implementation 'org.glassfish.tyrus:tyrus-server:2.2.0'
42+
implementation 'org.glassfish.tyrus:tyrus-container-grizzly-server:2.2.0'
43+
3444
// To change the versions see the gradle.properties file
3545
minecraft "com.mojang:minecraft:${project.minecraft_version}"
3646
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
3747
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
3848

3949
// Fabric API. This is technically optional, but you probably want it anyway.
4050
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
51+
modImplementation "net.fabricmc.fabric-api:fabric-key-binding-api-v1:${project.fabric_version}"
52+
53+
// Added Cloth Config and ModMenu
54+
modApi("me.shedaniel.cloth:cloth-config-fabric:17.0.144") {
55+
exclude(group: "net.fabricmc.fabric-api")
56+
}
57+
modImplementation("com.terraformersmc:modmenu:13.0.2")
4158
}
4259

4360
processResources {
@@ -57,7 +74,6 @@ java {
5774
// if it is present.
5875
// If you remove this line, sources will not be generated.
5976
withSourcesJar()
60-
6177
sourceCompatibility = JavaVersion.VERSION_21
6278
targetCompatibility = JavaVersion.VERSION_21
6379
}
@@ -87,5 +103,5 @@ publishing {
87103
}
88104

89105
loom {
90-
accessWidenerPath = file("src/main/resources/datapack-debugger.accesswidener")
106+
accessWidenerPath = file("src/main/resources/sniffer.accesswidener")
91107
}

gradle.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21
8-
yarn_mappings=1.21+build.9
9-
loader_version=0.15.11
7+
minecraft_version=1.21.4
8+
yarn_mappings=1.21.4+build.8
9+
loader_version=0.16.10
1010

1111
# Mod Properties
12-
mod_version=1.1.2
13-
maven_group=top.mcfpp.mod.debugger
14-
archives_base_name=datapack-debugger
12+
mod_version=0.1.0
13+
maven_group=net.gunivers
14+
archives_base_name=sniffer
1515

1616
# Dependencies
17-
fabric_version=0.100.7+1.21
17+
fabric_version=0.118.0+1.21.4
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.gunivers.sniffer;
2+
3+
import net.fabricmc.api.ClientModInitializer;
4+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
5+
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
6+
import net.minecraft.client.option.KeyBinding;
7+
import net.minecraft.client.util.InputUtil;
8+
import org.lwjgl.glfw.GLFW;
9+
import net.gunivers.sniffer.command.BreakPointCommand;;
10+
11+
/**
12+
* @author Alumopper
13+
* @author theogiraudet
14+
*/
15+
public class DatapackBreakpointClient implements ClientModInitializer {
16+
17+
private static KeyBinding stepInto;
18+
19+
@Override
20+
public void onInitializeClient() {
21+
stepInto = KeyBindingHelper.registerKeyBinding(new KeyBinding(
22+
"sniffer.step", // The translation key of the keybinding's name
23+
InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse.
24+
GLFW.GLFW_KEY_F7, // The keycode of the key
25+
"sniffer.name" // The translation key of the keybinding's category.
26+
));
27+
28+
ClientTickEvents.END_CLIENT_TICK.register(client -> {
29+
while(stepInto.wasPressed()) {
30+
if(BreakPointCommand.debugMode) {
31+
BreakPointCommand.step(1, client.player.getCommandSource(client.getServer().getWorld(client.player.getWorld().getRegistryKey())));
32+
}
33+
}
34+
});
35+
}
36+
37+
}

0 commit comments

Comments
 (0)