📦 SIRIUS Ui 维基
适用 Minecraft 26.1.1 | 数据驱动型界面框架(版本 0.3.1)
SIRIUS Ui 是一款模组,允许您通过简洁的 JSON 配置与纹理资源自定义 Minecraft 的标题画面、游戏选择画面、暂停屏幕以及死亡屏幕。无需编写 Java 代码,即可轻松添加图像、按钮、背景以及动态布局。
📌 目前支持四种屏幕:标题画面(title_screen)、游戏选择画面(game_selection_screen)、暂停屏幕(pause_screen) 与 死亡屏幕(death_screen)。模组名称为 SIRIUS Ui。
总览
SIRIUS Ui 将硬编码的界面替换为基于 JSON 的动态渲染系统。资源包可覆写下列文件:
assets/sirius_ui/screens/title_screen.json— 标题画面布局assets/sirius_ui/screens/game_selection_screen.json— 游戏选择画面布局assets/sirius_ui/screens/pause_screen.json— 暂停屏幕布局assets/sirius_ui/screens/death_screen.json— 死亡屏幕布局assets/sirius_ui/buttons/*.json— 按钮样式定义- 任意 PNG 纹理文件
资源包结构
您的资源包必须遵循下述精确的文件夹层次:
📦 您的资源包/
└── 📁 assets/
└── 📁 sirius_ui/
├── 📁 screens/
│ ├── 📄 title_screen.json
│ ├── 📄 game_selection_screen.json
│ ├── 📄 pause_screen.json
│ └── 📄 death_screen.json
├── 📁 buttons/
│ ├── singleplayer.json
│ ├── multiplayer.json
│ └── ...
└── 📁 textures/
└── 📁 gui/
├── custom_logo.png
├── btn_normal.png
└── ...
└── 📄 pack.mcmeta
pack.mcmeta 示例:
{
"pack": {
"pack_format": 26,
"description": "SIRIUS Ui 自定义界面资源包"
}
}
屏幕配置
每个屏幕 JSON 的根对象为 screen,其可包含以下字段:
panorama— 背景配置(对象或字符串)graphicsDraw— 背景图层数组(可选)elements— 界面元素数组(必填)copyright— 版权文本对象(仅标题画面使用,可选)
背景(panorama)
支持三种形式:
"panorama": "vanilla"— 原版动态全景背景"panorama": "none"— 纯黑背景"panorama": { "type": "image", "texture": "命名空间:路径/图片名" }— 自定义图像,会自动缩放并居中填充屏幕(保持宽高比,类似 CSS background-size: cover)。纹理路径示例:"sirius_ui:textures/gui/background.png"。
背景图层(graphicsDraw)
graphicsDraw 是一个数组,每个元素定义一个彩色矩形,绘制于背景与常规元素之间。可用于制作遮罩、装饰线、半透明层等。每个矩形对象包含:
| 字段 | 类型 | 说明 |
|---|---|---|
x | 字符串(表达式) | 矩形左上角 X 坐标 |
y | 字符串(表达式) | 矩形左上角 Y 坐标 |
width | 字符串(表达式) | 矩形宽度 |
height | 字符串(表达式) | 矩形高度 |
color | 字符串 | 颜色,格式支持 "#RRGGBB"、"0xRRGGBB"、"0xAARRGGBB"(带透明度) |
comment | 字符串 | 可选注释,不会被解析 |
元素(elements)
elements 数组可包含以下三种类型的对象,每个对象必须包含 "type" 字段来区分类型。
🖼️ Logo 元素(type: "logo")
用于显示静态图片(如 Mod 徽标、装饰图)。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
type | 字符串 | 是 | 固定为 "logo" |
texture | 字符串 | 是 | 纹理标识符,例如 "sirius_ui:textures/gui/logo.png" |
position | 对象 | 是 | 包含 x 和 y 字段(表达式字符串),定义图片左上角位置 |
size | 对象 | 是 | 包含 width 和 height 字段(整数),定义图片显示尺寸(像素) |
🔘 Button 元素(type: "button")
可交互按钮,支持不同状态纹理、文字、动作。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
type | 字符串 | 是 | 固定为 "button" |
style | 字符串 | 是 | 按钮样式文件的标识符,例如 "sirius_ui:buttons/default.json" |
position | 对象 | 是 | x 和 y 表达式,按钮左上角坐标 |
size | 对象 | 是 | width 和 height(整数),按钮尺寸 |
action | 对象 | 是 | 定义点击后的行为,详见 动作(action) 章节 |
text_key | 字符串 | 否 | 覆盖样式文件中定义的文本键,用于动态更改按钮文字 |
enabled | 布尔 | 否 | 默认为 true,设为 false 可禁用按钮(显示禁用纹理且不可点击) |
📝 Text 元素(type: "text")
显示文本,支持静态本地化键、动态游戏数据、缩放、阴影、颜色自定义。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
type | 字符串 | 是 | 固定为 "text" |
text_key | 字符串 | 条件 | 本地化键名(例如 "menu.paused")。如果未提供 dynamicType,则必须提供此项。 |
dynamicType | 字符串 | 条件 | 动态数据类型,可选值: • "score" — 玩家当前得分(纯数字)• "death_cause" — 死亡原因文本(仅死亡屏幕有效)• "player_name" — 玩家名字如果提供此项且未提供 text_key,则只显示动态值;若同时提供,则 text_key 被忽略。 |
position | 对象 | 是 | x 和 y 表达式,文本左上角坐标(注意文本的宽高由实际渲染内容决定,表达式中可使用 elementWidth/elementHeight) |
color | 字符串 | 否 | 颜色,格式同背景图层,默认 "#FFFFFF"(白色) |
shadow | 布尔 | 否 | 是否绘制文字阴影,默认为 true |
scale | 浮点数 | 否 | 文字缩放倍数,默认 1.0。例如 "scale": 1.5 放大 50%。 |
💡 提示:如果要显示原版风格的“分数:123”,建议使用两个文本元素:一个显示
"text_key": "deathScreen.score"(输出“分数:”),另一个使用 "dynamicType": "score"(输出数字),并通过 position 将它们并排。版权信息(copyright)
仅标题画面可使用,用于在屏幕底部显示版权文字。对象字段:
| 字段 | 类型 | 说明 |
|---|---|---|
textKey | 字符串 | 本地化键名 |
position | 对象 | x 和 y 表达式,定义文字左上角位置 |
color | 字符串 | 颜色,默认 "#808080" |
按钮样式(button style)
按钮样式文件(例如 buttons/default.json)必须包含顶层对象 button,其字段如下:
| 字段 | 类型 | 说明 |
|---|---|---|
text_key | 字符串 | 按钮默认显示的本地化文本键(可在按钮元素中用 text_key 覆盖) |
texture | 对象 | 包含 normal、hovered、disabled 三个字段,值为纹理标识符(不含 .png),纹理需放在 assets/命名空间/textures/gui/sprites/ 目录下。 |
text_color | 字符串或整数 | 普通状态文字颜色,推荐使用字符串如 "#FFFFFF" |
hover_text_color | 字符串或整数 | 悬停状态文字颜色 |
disabled_text_color | 字符串或整数 | 禁用状态文字颜色 |
text_offset_x | 字符串(表达式) | 文字相对于按钮左上角的 X 偏移,默认 "center"(水平居中) |
text_offset_y | 字符串(表达式) | 文字相对于按钮左上角的 Y 偏移,推荐使用 "(height - elementHeight)/2" 实现垂直居中 |
📌 注意:按钮纹理使用九宫格缩放(Nine-slice scaling),纹理文件中需要定义
gui 元数据(如 gui_metadata.json)或使用默认拉伸。通常原版按钮纹理已配置好九宫格。动作(action)
按钮的 action 字段是一个对象,包含 type 和特定参数。支持以下动作类型:
| type | 参数 | 说明 |
|---|---|---|
open_screen | screenId | 打开指定屏幕。预定义的 screenId 包括:singleplayer, multiplayer, options, realms, selectGame, language, accessibility, advancements, stats, share_to_lan, player_social 等。 |
quit_game | 无 | 退出游戏 |
close_screen | 无 | 关闭当前屏幕,返回父屏幕(如果存在) |
resume_game | 无 | 继续游戏,关闭暂停屏幕并释放鼠标(用于暂停屏幕) |
disconnect | 无 | 断开当前连接并返回标题屏幕 |
open_link | url | 打开外部链接,会先弹出确认对话框。示例:{ "type": "open_link", "url": "https://example.com" } |
respawn | 无 | 重生玩家(用于死亡屏幕) |
exit_to_title | 无 | 退出到标题屏幕(用于死亡屏幕) |
坐标系与表达式
原点
原点 (0,0) 位于屏幕左上角。X 轴向右递增,Y 轴向下递增。
▲ 原点位于左上角,X 向右,Y 向下。
元素锚点
position 字段定义的是元素的左上角,而非其中心。
⚠️ 常见误区:
"x": "width/2", "y": "height/2" 并不能将元素居中——它只是将元素的左上角置于屏幕中心。
正确的居中表达式:
"x": "(width - elementWidth)/2"
"y": "(height - elementHeight)/2"
表达式变量与运算
表达式支持以下变量:
width— 当前屏幕宽度(缩放后的像素)height— 当前屏幕高度elementWidth— 元素自身的宽度(对于按钮,来自size.width;对于文本,为渲染后的文本宽度,受scale影响)elementHeight— 元素自身的高度(同理)
支持运算符:+ - * / ( ),除法为整数截断。快捷写法:
"center"→"(width - elementWidth)/2"(仅用于 x 坐标)"bottom-20"→"height - elementHeight - 20"(仅用于 y 坐标)
常用对齐公式
| 效果 | X 表达式 | Y 表达式 |
|---|---|---|
| 水平居中 | "center" 或 "(width - elementWidth)/2" | 任意 |
| 垂直居中 | 任意 | "(height - elementHeight)/2" |
| 完全居中 | "center" | "(height - elementHeight)/2" |
| 左上角偏移 (20,20) | 20 | 20 |
| 右上角距右边缘 20px | "width - elementWidth - 20" | 20 |
| 左下角距底边缘 30px | 20 | "height - elementHeight - 30" 或 "bottom-30" |
| 右下角 | "width - elementWidth - 15" | "height - elementHeight - 15" |
配置范例
以下是一个完整的死亡屏幕配置,展示了上述所有特性:
{
"screen": {
"panorama": "vanilla",
"graphicsDraw": [
{ "x": "0", "y": "0", "width": "width", "height": "height", "color": "#88000000" },
{ "x": "width/2 - 140", "y": "height/2", "width": 280, "height": 1, "color": "#88FF0000" }
],
"elements": [
{
"type": "text",
"text_key": "deathScreen.title",
"position": { "x": "center", "y": "height/5" },
"color": "#FF0000",
"scale": 2.5,
"shadow": true
},
{
"type": "text",
"dynamicType": "death_cause",
"position": { "x": "width/2 - 140", "y": "height/2 - 30" },
"color": "#FFFFFF"
},
{
"type": "text",
"dynamicType": "score",
"position": { "x": "width/2 + 140", "y": "height/2 - 30" },
"color": "#FFFFAA"
},
{
"type": "button",
"text_key": "deathScreen.respawn",
"style": "sirius_ui:buttons/death/button_re.json",
"position": { "x": "width/2 - 130", "y": "height * 3 / 4" },
"size": { "width": 120, "height": 20 },
"action": { "type": "respawn" }
},
{
"type": "button",
"text_key": "deathScreen.titleScreen",
"style": "sirius_ui:buttons/death/button_quit.json",
"position": { "x": "width/2 + 10", "y": "height * 3 / 4" },
"size": { "width": 120, "height": 20 },
"action": { "type": "exit_to_title" }
}
],
"copyright": {
"textKey": "auui.copyright",
"position": { "x": "width - 10", "y": "height - 10" },
"color": "#666666"
}
}
}
疑难排解
| 问题 | 可能原因与解决方案 |
|---|---|
| 按钮无响应 | 检查 action 与 screenId 是否正确;确保按钮的 enabled 为 true(默认为 true)。 |
| 纹理显示粉黑棋盘格 | 路径错误或文件缺失;确认纹理文件位于正确的命名空间和路径,且 .png 扩展名不需要写在标识符中。 |
| 表达式错误“未知变量” | 仅允许使用 width, height, elementWidth, elementHeight,检查拼写。 |
| 背景图层未显示 | 检查颜色格式是否正确(例如 "#RRGGBB" 或 "0xAARRGGBB"),以及坐标/尺寸是否在屏幕范围内。 |
| 自定义全景图未显示 | 确认 panorama.type 为 "image",texture 路径包含正确的命名空间和文件,且图片文件存在。 |
| 文字颜色不显示或透明 | 确保颜色值为字符串,例如 "#FFFFFF";若使用 0xFFFFFF 格式,必须带引号且不能省略 0x。 |
| 动态文本(得分/死亡原因)不显示 | 确认 dynamicType 拼写正确,且当前屏幕支持该类型(例如 death_cause 仅在死亡屏幕有效)。 |
| 修改 JSON 后界面未变化 | 从版本 0.3.0 开始,重新打开屏幕即可生效,无需重启游戏。如果仍无效,按 F3+T 重载资源包。 |
| 按钮文字未居中 | 检查样式文件中的 text_offset_y 是否设置为 "(height - elementHeight)/2"。 |
🔧 按下 F3+T 可快速重载资源包 —— 调试布局时非常方便。
📢 版本 0.3.1 重要变更:颜色值必须使用带引号的字符串(例如
"color": "#FFFFFF"),不再支持纯数字。同时新增了暂停屏幕、死亡屏幕、动态文本、文字缩放等强大功能。详情请查阅随模组发布的更新日志。