Add Cloth Config plugin management screen
This commit is contained in:
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
mkdir -p "$script_dir/dist"
|
||||
|
||||
case "$(go env GOOS)" in
|
||||
windows) output="$script_dir/dist/hello_native.dll" ;;
|
||||
darwin) output="$script_dir/dist/libhello_native.dylib" ;;
|
||||
*) output="$script_dir/dist/libhello_native.so" ;;
|
||||
esac
|
||||
|
||||
(cd "$script_dir" && go build -buildmode=c-shared -o "$output" .)
|
||||
echo "$output"
|
||||
@@ -0,0 +1,7 @@
|
||||
module github.com/yawaflua/GoMinecraftBridge/examples/hello-native
|
||||
|
||||
go 1.24.0
|
||||
|
||||
require github.com/yawaflua/GoMinecraftBridge/sdk v0.0.0
|
||||
|
||||
replace github.com/yawaflua/GoMinecraftBridge/sdk => ../../sdk
|
||||
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/yawaflua/GoMinecraftBridge/sdk"
|
||||
)
|
||||
|
||||
type helloPlugin struct{}
|
||||
|
||||
func (helloPlugin) Metadata() sdk.Metadata {
|
||||
return sdk.Metadata{
|
||||
ID: "hello_native",
|
||||
Name: "Hello Native",
|
||||
Version: "0.1.0",
|
||||
Description: "Native Go plugin example for Go Minecraft Bridge",
|
||||
Authors: []string{"yawaflua"},
|
||||
ConfigSchema: map[string]any{
|
||||
"type": "object",
|
||||
"properties": map[string]any{
|
||||
"greeting": map[string]any{
|
||||
"type": "string",
|
||||
"default": "Hello from Go!",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (helloPlugin) Init(context *sdk.Context, event sdk.InitEvent) error {
|
||||
fmt.Printf("initialized for Minecraft %s; data=%s\n", event.MinecraftVersion, event.DataDirectory)
|
||||
context.SubscribeSnapshot(true, sdk.BlockReference{
|
||||
Dimension: "minecraft:overworld",
|
||||
X: 0,
|
||||
Y: 64,
|
||||
Z: 0,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (helloPlugin) Tick(context *sdk.Context, snapshot sdk.ServerSnapshot) error {
|
||||
if snapshot.Tick%200 == 0 {
|
||||
fmt.Printf("tick=%d entities=%d watched_blocks=%d\n", snapshot.Tick, len(snapshot.Entities), len(snapshot.Blocks))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (helloPlugin) Chat(context *sdk.Context, event sdk.ChatEvent) error {
|
||||
if event.Message != "!go" {
|
||||
return nil
|
||||
}
|
||||
|
||||
context.SendMessage(event.PlayerUUID, "Hello from a native Go plugin!")
|
||||
context.SystemCall("minecraft:server.info", map[string]any{})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (helloPlugin) Death(context *sdk.Context, event sdk.DeathEvent) error {
|
||||
context.Broadcast(fmt.Sprintf("[Go] %s died (%s)", event.Entity.Name, event.DamageType))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (helloPlugin) SystemCallResult(context *sdk.Context, result sdk.SystemCallResult) error {
|
||||
if !result.Success {
|
||||
return fmt.Errorf("system call %s failed: %s", result.Name, result.Error)
|
||||
}
|
||||
|
||||
var value any
|
||||
if err := json.Unmarshal(result.Data, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("system call %s result: %v\n", result.Name, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (helloPlugin) Deinit(context *sdk.Context, event sdk.DeinitEvent) error {
|
||||
// Intentionally omit the newline: the SDK flush barrier still assigns this
|
||||
// partial stdout line to the deinit response.
|
||||
fmt.Printf("deinit: %s", event.Reason)
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
sdk.Register(helloPlugin{})
|
||||
}
|
||||
|
||||
func main() {}
|
||||
Reference in New Issue
Block a user