Datapack TCP 是一款将 Minecraft 与外部程序连接的模组。它开启了一个 TCP 套接字,向外流式传输记分板、聊天消息等游戏信息,并向内传输指令,从而实现内部数据包(datapack)与外部程序的协同工作。
用法
该模组会随你的 Minecraft 服务器一起运行一个 TCP 服务器(默认地址为本地主机:127.0.0.1,默认端口:25566)。
通信通过 JSON Lines 处理。发送到或来自服务器的每个载荷都必须是单行的有效 JSON 对象,并以换行符(\n)结尾。任意数量的客户端(例如 Python 脚本)都可以连接以接收/发送载荷。
客户端 -> 服务端协议
command
以服务器控制台的身份执行一条 Minecraft 指令。
type (String): "command"。
command (String): 要运行的 Minecraft 指令(无需前导斜杠)。
id (String, 可选): 唯一标识符(如 UUID),用于追踪此特定指令的结果。
tick (Long, 可选): 执行指令的目标刻数。如果缺失或该刻数已过,则立即执行指令。
示例:
{"type": "command", "command": "summon zombie ~ ~ ~", "id": "spawn_zombie_1", "tick": 2333}
服务端 -> 客户端协议
command_result
当客户端发送指令时,服务端执行该指令并将结果返回给请求的客户端。
type (String): "command_result"
command (String): 已执行的指令。
success (Boolean): 指令是否成功执行。
result (Int, 可选): 指令执行后的返回值(如果执行了的话)。
error (String, 可选): 指令无法执行时的语法错误信息。
id (String, 可选): 如果存在,则该指令的唯一标识符。
tick (Long): 执行指令时的服务器刻数。
示例(成功):
{"type": "command_result", "command": "summon zombie ~ ~ ~", "success": true, "result": 1, "id": "spawn_zombie_1", "tick": 2333}
示例(失败):
{"type": "command_result", "command": "summon zombi ~ ~ ~", "success": false, "error": "Can't find element 'minecraft:zombi' of type 'minecraft:entity_type' at position 12: ...mmon zombi<--[HERE]", "id": "spawn_zombie_1", "tick": 2333}
scoreboard
在客户端首次连接时发送,提供所有记分板的当前状态。
type (String): "scoreboard"
tick (Long): 记分板状态的服务器刻数。
scoreboard (Json): 目标名称到玩家分数的键值映射。
示例:
{"type": "scoreboard", "tick": 24000, "scoreboard": {"kills": {"Player1": 5,"Player2": 12}, "round": {"#current": 3}}}
scoreboard_change
当一个或多个分数发生变化时发送,且仅包含这些变化。
type (String): "scoreboard_change"
tick (Long): 记分板发生变化的服务器刻数。
scoreboard (Json): 目标名称到玩家分数的键值映射。
示例(Player1 获得一次击杀后):
{"type": "scoreboard_change", "tick": 24025, "scoreboard": {"kills": {"Player1": 6}}}
chat_message
当玩家发送普通聊天消息时发送。
type (String): "chat_message"
tick (Long): 消息发生时的服务器刻数。
sender (String): 玩家的用户名。
message (String): 消息的原始文本。
示例:
{"type": "chat_message", "tick": 24050, "sender": "Player1", "message": "Hello world!"}
command_message
当指令向聊天广播消息时发送(例如 /me、/say)。
type (String): "command_message"
tick (Long): 消息发生时的服务器刻数。
source (String): 执行指令的实体、方块或控制台。
message (String): 消息的原始文本。
示例:
{"type": "command_message", "tick": 24055, "source": "Server", "message": "Server restarting in 5 minutes"}
game_message
当游戏发布消息时发送,例如玩家加入/离开事件或死亡消息。
type (String): "game_message"
tick (Long): 消息发生时的服务器刻数。
overlay (Boolean): 如果消息显示为覆盖层则为 true,如果在聊天栏中则为 false。
message (String): 消息的原始文本。
示例:
{"type": "game_message", "tick": 24060, "overlay": false, "message": "Player2 fell from a high place"}
配置
| 选项 |
默认值 |
描述 |
port |
25566 |
使用的 TCP 端口。 |
host |
"127.0.0.1" |
使用的 IP 地址。默认为本地主机。 |
streamScoreboard |
true |
启用发送记分板数据。 |
scoreboardChanges |
true |
启用仅发送记分板的变化部分。否则每刻都会发送完整的记分板。 |
streamChatMessages |
true |
启用发送玩家聊天消息。 |
streamCommandMessages |
true |
启用发送指令消息事件(例如 /me、/say)。 |
streamGameMessages |
true |
启用发送游戏消息事件(例如 加入/离开、死亡消息)。 |
acceptCommands |
true |
允许客户端发送指令供服务器执行。 |
returnCommandResults |
true |
启用将指令结果发送回客户端。 |
Datapack TCP is a mod that connects Minecraft to external programs. It opens a TCP socket that streams game information such as scoreboards and chat messages outwards and commands inwards, allowing internal datapacks and external programs to work together.
Usage
The mod runs a TCP server alongside your Minecraft server (default is localhost: 127.0.0.1, default port: 25566).
Communication is handled via JSON Lines. Every payload sent to or from the server must be a single-line, valid JSON object, terminated by a newline character (\n). Any number of clients (such as Python scripts) can connect to receive/send payloads.
Client -> Server Protocol
command
Executes a Minecraft command as the server console.
type (String): "command".
command (String): The Minecraft command to run (no leading slash required).
id (String, Optional): A unique identifier (like a UUID) to track the result of this specific command.
tick (Long, Optional): The target tick to execute the command on. If absent or tick has already occured, command executes immediately.
Example:
{"type": "command", "command": "summon zombie ~ ~ ~", "id": "spawn_zombie_1", "tick": 2333}
Server -> Client Protocol
command_result
When a client sends a command, the server executes it and sends the result back to the client that requested it.
type (String): "command_result"
command (String): The command that was run.
success (Boolean): Whether the command could be run.
result (Int, Optional): The return value of the command if it was run.
error (String, Optional): The syntax error of the command if it could not be run.
id (String, Optional): The unique identifier of this command if present.
tick (Long): The server tick when the command was run.
Example (success):
{"type": "command_result", "command": "summon zombie ~ ~ ~", "success": true, "result": 1, "id": "spawn_zombie_1", "tick": 2333}
Example (failure):
{"type": "command_result", "command": "summon zombi ~ ~ ~", "success": false, "error": "Can't find element 'minecraft:zombi' of type 'minecraft:entity_type' at position 12: ...mmon zombi<--[HERE]", "id": "spawn_zombie_1", "tick": 2333}
scoreboard
Sent when a client first connects, providing the current state of all scoreboards.
type (String): "scoreboard"
tick (Long): The server tick of the scoreboard state.
scoreboard (Json): The key-value map of objective to player scores.
Example:
{"type": "scoreboard", "tick": 24000, "scoreboard": {"kills": {"Player1": 5,"Player2": 12}, "round": {"#current": 3}}}
scoreboard_change
Sent when one or more scores are changed, and contains only those changes.
type (String): "scoreboard_change"
tick (Long): The server tick that the scoreboard changed.
scoreboard (Json): The key-value map of objective to player scores.
Example (after Player1 gets a kill):
{"type": "scoreboard_change", "tick": 24025, "scoreboard": {"kills": {"Player1": 6}}}
chat_message
Sent when a player sends a normal chat message.
type (String): "chat_message"
tick (Long): The server tick when the message occurred.
sender (String): The username of the player.
message (String): The raw text of the message.
Example:
{"type": "chat_message", "tick": 24050, "sender": "Player1", "message": "Hello world!"}
command_message
Sent when a command broadcasts a message to chat (e.g., /me, /say).
type (String): "command_message"
tick (Long): The server tick when the message occurred.
source (String): The entity, block, or console that ran the command.
message (String): The raw text of the message.
Example:
{"type": "command_message", "tick": 24055, "source": "Server", "message": "Server restarting in 5 minutes"}
game_message
Sent when the game posts a message, such as player join/leave events or death messages.
type (String): "game_message"
tick (Long): The server tick when the message occurred.
overlay (Boolean): true if the message appeared as an overlay, false if in the chat.
message (String): The raw text of the message.
Example:
{"type": "game_message", "tick": 24060, "overlay": false, "message": "Player2 fell from a high place"}
Configuration
| Option |
Default |
Description |
port |
25566 |
The TCP port to use. |
host |
"127.0.0.1" |
The IP address to use. Default is localhost. |
streamScoreboard |
true |
Enables sending the scoreboard. |
scoreboardChanges |
true |
Enables sending only scoreboard changes. Otherwise send full scoreboard every tick. |
streamChatMessages |
true |
Enables sending player chat messages. |
streamCommandMessages |
true |
Enables sending command message events (e.g., /me, /say). |
streamGameMessages |
true |
Enables sending game message events (e.g., join/leave, death messages). |
acceptCommands |
true |
Allows clients to send commands for the server to run. |
returnCommandResults |
true |
Enables sending command results back to clients. |
评论 0
登录后参与评分
还没有评论,来抢沙发吧