这个轻量级模组为聊天添加了结构化、定时的消息:通过精确的每分钟字数(WPM)计时和逐行递送来创建独白!
ChatDiag 的对话可以由数据包、命令方块、玩家执行或模组集成提供。它们专为服务器事件中的故事讲述和地图制作而设计。
对话支持格式化代码,以及自定义声音、字体和命令。
执行对话
要开始渲染对话,请使用新的 /chatdiag 或 /cdiag 管理员命令。
语法
按命名空间执行已定义的对话
/chatdiag [players] id [dialog-id]
示例:
/chatdiag @s id example:example_dialog

按数据执行已定义的对话
/chatdiag [players] data [dialog-object]
示例:
/cdiag @a data {"prefix": "<ChatDiag> ", "lines": ["Hello!", "This dialog was not defined in any file."]}

开发
数据包
数据驱动的对话通过命名空间资源定义。这些定义必须位于 chatdiag/ 目录下(data/<namespace>/chatdiag/<file>.json,加载为 <namespace>:<file>),适用于模组资源或数据包。
/reload 会重新加载数据包中的对话。
模组集成
ChatDiag 为模组提供了 ChatDiag.api() 集成入口点。
对话可以保持相同的可完成未来状态跨链式对话,因此结果仅在整条链完成后才完成。
为了在您的模组中声明对 ChatDiag 的依赖,请将以下内容添加到您的 build.gradle 中:
repositories {
// ...
maven { url = "https://api.modrinth.com/maven" }
}
dependencies {
// ...
// chatdiag_version 示例,用于 1.0.0+1.21.11: 7GbCgI5k
modImplementation "maven.modrinth:chatdiag:${project.chatdiag_version}"
}
对话定义
对话
对话由一系列**行(Lines)**列表组成,以及可选的设置以添加自定义行为。这些行为包括:
- WPM。每分钟字数。控制每行的延迟。默认为 120,必须为正数。
- 前缀。在每行之前渲染。
- 后缀。在每行之后渲染。
- 声音。可以是单个条目或数组。为每行播放。
- 下一个对话。用于将对话链接在一起。必须是命名空间的对话标识符。在给定对话结束后,下一个对话将开始。
- 下一个命令。必须是有效的 Minecraft/模组命令。在当前对话结束时执行。通过对话运行的命令继承其源的权限。因此,如果从数据包执行,某人可能会使用它们运行一些恶作剧命令,所以请确保您了解正在执行的对话,不要盲目地运行共享对话。小心!
对话行可以是:
- 具有其对话行为的字符串,或者
- 具有自定义行为的 DialogLine 对象。定义的自定义行为能够覆盖或添加到其对话的设置中。
DialogLine 对象可以通过其 replace_prefix、replace_suffix 和 replace_sound 布尔标志替换其父对话的行为。
此外,DialogLines 可以使用其 command 属性执行命令。这与 Dialogs 的 next_command 不同,因为 command 在渲染时运行,而 next_command 在最后一条行的延迟过后运行。
Sound 对象包含一个命名空间声音 Id,以及以下可选属性:
- 音高。默认为 1。范围在
0.5 到 2.0 之间。
- 音量。默认为 1。必须为正数。
- 位置。默认为每个玩家的客户端。可以是列表或单个条目。每个条目定义为向量或描述实体选择器的字符串。这对于任意位置特别有用,因为可以使用标记实体。
如果玩家未安装 ChatDiag,则未指定位置的声音将在每个玩家的位置处播放。因此,如果玩家移动,声音将定位到声音开始播放时他们站立的位置(就像
/playsound 命令一样)。因此,建议同时在服务器和客户端上安装 ChatDiag,但并非必需。
对话定义示例
{
"wpm": "number",
"sound": {
"id": "string",
"pitch": "number"
},
"prefix": "string",
"suffix": "string",
"lines": [
"string",
{
"line": "string",
"replace_sound": "boolean",
"replace_prefix": "boolean",
"replace_suffix": "boolean",
"sound": [
{
"id": "string",
"pitch": "number",
"position": "string"
},
{
"id": "string",
position: [
["number", "number", "number"],
"string",
"string"
]
}
],
"prefix": "string",
"suffix": "string",
"delay": "number",
"command": "string"
}
],
"next_command": "string",
"next_dialog": "string",
}
开发技巧
- 在处理对话链和分支时,通常建议利用文件夹结构。例如,
example:entity/mission/success 和 example:entity/welcome/0 在拥有多个实体和任务对话的情况下,大多优于 example:entity_mission_success 和 example:entity_welcome_start。
- 不要在
next_command 属性中调用新对话。如果你希望在一个对话结束后立即开始另一个对话(无需等待最后一行的延迟),可以将最后一行转换为 DialogLine 对象,并指定 "delay": 0。
- 指定声音位置时,不建议使用数据包宏(datapack macros)。如果值不发生变化,最好将其放在向量位置;如果会变化,标记实体选择器往往更加灵活。
欢迎在你的整合包中使用此模组!
This lightweight mod adds structured, timed messages to chat: create monologues with precise WPM timing and line-by-line delivery!
ChatDiag's dialogs can be provided by datapacks, command blocks, player execution, or mod integration. They are specially designed for storytelling in server events and mapmaking.
Dialogs support formatting codes, as well as custom sounds, fonts, and commands.
Executing dialogs
To start rendering a dialog, use the new /chatdiag or /cdiag admin command.
Syntax
Executes a defined dialog by namespace
/chatdiag [players] id [dialog-id]
Example:
/chatdiag @s id example:example_dialog

Executes a defined dialog by data
/chatdiag [players] data [dialog-object]
Example:
/cdiag @a data {"prefix": "<ChatDiag> ", "lines": ["Hello!", "This dialog was not defined in any file."]}

Development
Data packs
Data-driven dialogs are defined via namespaced resources. These definitions must reside under the chatdiag/ directory (data/<namespace>/chatdiag/<file>.json, loads as <namespace>:<file>) for mod resources or datapacks.
/reload reloads data-pack dialogs.
Mod integration
ChatDiag provides the ChatDiag.api() integration entrypoint for mods.
Dialogs can be made to keep the same completable future across chained dialogs, so the result only completes once the entire chain is done.
In order to declare a dependency on ChatDiag from your mod, add the following to your build.gradle:
repositories {
// ...
maven { url = "https://api.modrinth.com/maven" }
}
dependencies {
// ...
// chatdiag_version example for 1.0.0+1.21.11: 7GbCgI5k
modImplementation "maven.modrinth:chatdiag:${project.chatdiag_version}"
}
Dialog definition
Dialogs
Dialogs consist of a list of Lines, and optional settings that add custom behaviors. These behaviors are:
- WPM. Words per minute. Controls delay for each line. Defaults to 120, must be positive.
- Prefix. Renders before each line.
- Suffix. Renders after each line.
- Sounds. Can be either a single entry or an array. Plays for each line.
- Next dialog. Used to chain dialogs together. Must be a namespaced dialog identifier. After the given dialog ends, the next one will start.
- Next command. Must be a valid Minecraft/mod command. Executes at the end of the current dialog. Commands that are run via dialogs inherit their source's permissions. Because of this, someone could run some mischievous commands with them if executing from a datapack, so please make sure you understand what dialogs you're executing and not running shared dialogs blindly. Beware!
Dialog lines can be either:
- A string with their dialog's behavior, or
- A DialogLine object with custom behavior. Defined custom behaviors are able to override or add to their dialog's settings.
A DialogLine object can replace its parent dialog's behaviors via its replace_prefix, replace_suffix, and replace_sound boolean flags.
Moreover, DialogLines can execute commands using their command attribute. This is different from Dialogs' next_command, as command runs when rendering, and next_command runs after the last line's delay has passed.
Sound objects contain a namespaced sound Id, and the following optional attributes:
- Pitch. Defaults to 1. Ranges between
0.5 and 2.0.
- Volume. Defaults to 1. Must be positive.
- Position. Defaults to every player's client. Can be a list or a single entry. Each entry is defined as a vector or a string describing an entity selector. This is specially useful for arbitrary positions, as one can use marker entities.
If a player does not have ChatDiag installed, sounds with an unspecified position will simply play at each player's position. Therefore, if a player moves, the sound will be localized to where they were standing when the sound started playing (just like with the
/playsound command). Because of this, having ChatDiag on both the server AND the client is recommended, but not needed.
Dialog definition example
{
"wpm": "number",
"sound": {
"id": "string",
"pitch": "number"
},
"prefix": "string",
"suffix": "string",
"lines": [
"string",
{
"line": "string",
"replace_sound": "boolean",
"replace_prefix": "boolean",
"replace_suffix": "boolean",
"sound": [
{
"id": "string",
"pitch": "number",
"position": "string"
},
{
"id": "string",
position: [
["number", "number", "number"],
"string",
"string"
]
}
],
"prefix": "string",
"suffix": "string",
"delay": "number",
"command": "string"
}
],
"next_command": "string",
"next_dialog": "string",
}
Dev Tips
- When dealing with dialog chains and branches, it's generally better to make use of folder structure. For instance,
example:entity/mission/success and example:entity/welcome/0 are superior to example:entity_mission_success and example:entity_welcome_start in most cases where you have multiple entity and mission dialogs.
- Don't invoke new dialogs in
next_command attributes. If you want to begin a dialog immediately after another without waiting for the last line's delay, you can instead turn the last line into a DialogLine object and specify "delay": 0.
- When specifying sound positions, it's advised not to use datapack macros. If a value does not change, it's better for it to be in a vector position. If it does, marker entity selectors tend to be more flexible.
Feel free to use this mod in your modpacks!
评论 0
登录后参与评分
还没有评论,来抢沙发吧