-
Notifications
You must be signed in to change notification settings - Fork 0
Developer Guide
This guide provides technical information for developers who want to contribute to CraftDeck, understand its architecture, or extend its functionality.
- Architecture Overview
- Development Environment Setup
- Building the Project
- WebSocket Protocol Specification
- Extending CraftDeck
- Testing
- Contributing
- Release Process
CraftDeck consists of two main components that communicate via WebSocket protocol:
┌─────────────────┐ WebSocket ┌─────────────────┐
│ Minecraft Mod │◄──────────────►│StreamDeck Plugin│
│ (Kotlin) │ Port 8080 │ (C#) │
└─────────────────┘ └─────────────────┘
Technology Stack:
- Language: Kotlin
- Framework: Architectury (multi-platform mod development)
- WebSocket: Java-WebSocket 1.5.3
- Build Tool: Gradle
Module Structure:
craftdeck-mod/
├── common/ # Shared code across all platforms
│ ├── CraftDeckMod.kt # Main mod entry point
│ ├── WebSocketServer.kt # WebSocket server implementation
│ ├── GameDataCollector.kt # Player data collection
│ └── CommandHandler.kt # Command execution handling
├── fabric/ # Fabric-specific implementation
├── forge/ # Forge-specific implementation
└── quilt/ # Quilt-specific implementation
Key Components:
- CraftDeckMod: Main mod class that initializes the WebSocket server and registers commands
- CraftDeckWebSocketServer: WebSocket server that handles client connections and message routing
- GameDataCollector: Collects player data (health, position, level, etc.) from Minecraft
- CommandHandler: Executes Minecraft commands received from StreamDeck
Technology Stack:
- Language: C#
- Framework: .NET 6
- WebSocket: System.Net.WebSockets.Client
- StreamDeck: StreamDeckLib 0.5.2040
- JSON: Newtonsoft.Json
Project Structure:
craftdeck-plugin/
├── Actions/ # StreamDeck action implementations
│ ├── PlayerMonitorAction.cs # Player data monitoring
│ └── CommandAction.cs # Command execution
├── Services/ # Business logic services
│ ├── MinecraftWebSocketService.cs # WebSocket client
│ ├── SharedWebSocketManager.cs # Connection management
│ ├── DisplayFormatService.cs # Data formatting
│ └── LocalizationService.cs # Multi-language support
├── Models/ # Data models
│ └── GameDataModels.cs # WebSocket message models
└── property_inspector/ # Web-based configuration UI
For Minecraft Mod Development:
- Java Development Kit (JDK) 17+
- IntelliJ IDEA (recommended) or VS Code
- Git
For StreamDeck Plugin Development:
- .NET 6 SDK
- Visual Studio 2022 (recommended) or VS Code
- StreamDeck Software 6.0+
- StreamDeck device (for testing)
-
Clone the Repository
git clone https://github.com/[username]/craftdeck.git cd craftdeck -
Minecraft Mod Setup
cd craftdeck-mod ./gradlew build -
StreamDeck Plugin Setup
cd craftdeck-plugin dotnet restore dotnet build
IntelliJ IDEA (for Minecraft Mod):
- Open the
craftdeck-modfolder as a Gradle project - Wait for Gradle sync to complete
- Configure run configurations for each platform (Fabric, Forge, Quilt)
Visual Studio (for StreamDeck Plugin):
- Open
CraftDeckSolution.sln - Restore NuGet packages
- Set
CraftDeck.StreamDeckPluginas startup project
Build All Platforms:
cd craftdeck-mod
./gradlew buildPlatform-Specific Builds:
# Fabric only
./gradlew :fabric:build
# Forge only
./gradlew :forge:build
# Quilt only
./gradlew :quilt:buildDevelopment Testing:
# Run Fabric development client
./gradlew :fabric:runClient
# Run Forge development client
./gradlew :forge:runClientDebug Build:
cd craftdeck-plugin
dotnet buildRelease Build:
dotnet build -c ReleaseCreate StreamDeck Plugin Package:
dotnet publish -c Release --self-contained
# Manual packaging required for .streamDeckPlugin filePowerShell Scripts (Windows):
# Build everything
.\scripts\Build-All.ps1
# Build mod only
.\scripts\Build-MinecraftMod.ps1
# Build plugin only
.\scripts\Build-StreamDeckPlugin.ps1
# Prepare release packages
.\scripts\Prepare-Release.ps1- Protocol: WebSocket (ws://)
- Host: localhost (127.0.0.1)
- Port: 8080
- Message Format: JSON
Connection Established (Mod → Plugin)
{
"type": "connection",
"status": "connected",
"message": "Welcome to CraftDeck"
}Player Status Update (Mod → Plugin)
{
"type": "player_status",
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "PlayerName",
"health": 20.0,
"max_health": 20.0,
"food": 20,
"experience": 0.5,
"level": 30,
"gamemode": "survival",
"position": {
"x": 100.5,
"y": 64.0,
"z": 200.3
},
"dimension": "minecraft:overworld"
}Player Data Request (Plugin → Mod)
{
"type": "get_player_data"
}Player Data Response (Mod → Plugin)
{
"type": "player_data",
"players": [
{
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "PlayerName",
"health": 20.0,
"max_health": 20.0,
"food": 20,
"experience": 0.5,
"level": 30,
"gamemode": "survival",
"position": {
"x": 100.5,
"y": 64.0,
"z": 200.3
},
"dimension": "minecraft:overworld"
}
]
}Execute Command (Plugin → Mod)
{
"type": "execute_command",
"command": "time set day",
"player": "PlayerName"
}Command Result (Mod → Plugin)
{
"type": "command_result",
"success": true,
"message": "Set the time to 1000",
"result": 1
}Error Response (Mod → Plugin)
{
"type": "error",
"message": "Command execution failed: Permission denied"
}-
Connection Establishment
- StreamDeck plugin connects to Minecraft mod on port 8080
- Mod sends connection confirmation message
-
Data Synchronization
- Plugin requests initial player data
- Mod sends current player status
- Mod continuously sends updates when player data changes
-
Command Execution
- Plugin sends command execution request
- Mod executes command and sends result back
-
Error Handling
- Both sides handle connection drops gracefully
- Error messages provide debugging information
Step 1: Update GameDataCollector (Mod)
// Add new data collection method
fun getNewDataType(): NewDataType {
// Implementation
}
// Update player data structure
data class PlayerInfo(
// existing fields...
val newField: String
)Step 2: Update WebSocket Messages
// Mod side - update message building
private fun buildPlayerStatusMessage(info: PlayerInfo): String {
return buildString {
// existing fields...
append(""""new_field":"${info.newField}",""")
}
}// Plugin side - update data models
public class PlayerStatusMessage : WebSocketMessage
{
// existing properties...
[JsonProperty("new_field")]
public string NewField { get; set; }
}Step 3: Update StreamDeck Actions
// Create new action or update existing ones
[ActionUuid(Uuid = "com.craftdeck.plugin.action.newaction")]
public class NewDataAction : BaseStreamDeckActionWithSettingsModel<NewDataSettingsModel>
{
// Implementation
}Step 1: Update CommandHandler (Mod)
object CommandHandler {
fun executeCommand(command: String, playerName: String?): CommandResult {
// Add validation for new command types
// Add execution logic
}
}Step 2: Create New StreamDeck Action
[ActionUuid(Uuid = "com.craftdeck.plugin.action.newcommand")]
public class NewCommandAction : BaseStreamDeckActionWithSettingsModel<CommandSettingsModel>
{
public override async Task OnKeyDown(StreamDeckEventPayload args)
{
var webSocketService = SharedWebSocketManager.WebSocketService;
await webSocketService.SendCommandAsync(SettingsModel.Command);
}
}-
Create Action Class
- Inherit from
BaseStreamDeckActionWithSettingsModel<T> - Add
[ActionUuid]attribute with unique UUID
- Inherit from
-
Create Settings Model
- Define configuration properties
- Add JSON serialization attributes
-
Create Property Inspector
- Design HTML/CSS/JS configuration interface
- Handle settings validation and updates
-
Update Manifest
- Add action definition to
manifest.json - Include icons and localization
- Add action definition to
Minecraft Mod Testing:
// Example test structure
@Test
fun testWebSocketServerStartup() {
val server = CraftDeckWebSocketServer(8080)
server.start()
assertTrue(server.isStarted)
server.stop()
}StreamDeck Plugin Testing:
[Test]
public async Task TestWebSocketConnection()
{
var service = new MinecraftWebSocketService();
var connected = await service.ConnectAsync();
Assert.IsTrue(connected);
}-
Manual Testing Process
- Start Minecraft with mod in development environment
- Install plugin in StreamDeck Software
- Test all actions and data synchronization
- Verify error handling and reconnection
-
Automated Testing (Future Enhancement)
- Mock WebSocket server for plugin testing
- Automated UI testing for StreamDeck actions
- Protocol compliance testing
Minecraft Mod Debugging:
// Enable debug logging
CraftDeckMod.LOGGER.info("Debug message")StreamDeck Plugin Debugging:
// Use console output for debugging
Console.WriteLine($"Debug: {message}");
// Enable verbose WebSocket loggingKotlin (Minecraft Mod):
- Follow Kotlin coding conventions
- Use meaningful variable and function names
- Add KDoc comments for public APIs
- Prefer immutable data structures
C# (StreamDeck Plugin):
- Follow C# coding conventions
- Use PascalCase for public members
- Add XML documentation comments
- Use async/await for asynchronous operations
- Fork the Repository
-
Create Feature Branch
git checkout -b feature/my-new-feature
- Make Changes and Test
-
Commit with Descriptive Messages
git commit -m "Add new player monitoring feature" - Push and Create Pull Request
- Follow the PR template
- Include tests for new features
- Update documentation as needed
- Ensure all CI checks pass
- Request review from maintainers
- Follow Semantic Versioning (SemVer)
- Format: MAJOR.MINOR.PATCH
- Update all relevant files with new version
-
Pre-Release
- Update version numbers in all project files
- Update CHANGELOG.md with new features and fixes
- Run full test suite
- Build release artifacts for all platforms
-
Release
- Create Git tag with version number
- Build final release packages
- Create GitHub release with artifacts
- Update documentation
-
Post-Release
- Update package managers (if applicable)
- Announce release in community channels
- Monitor for issues and feedback
# Full release preparation
.\scripts\Prepare-Release.ps1 -Version "1.0.0"
# Create release packages
.\scripts\Release-CraftDeck.ps1For user documentation, see the User Guide.
For the latest development updates, visit the CraftDeck GitHub Repository.