替换玩家背包
玩家背包替换用于重做生存模式背包外观。它与箱子替换使用同一个 display.mode: container,但目标改为 player_inventory,并且不配置标题和行数。
创造模式背包属于专用界面,当前不会被这个页面接管。
完整示例
下面页面显示主手、副手和头盔,并让快捷栏第一格保留原版物品槽交互。保存为 pages/player_inventory_skin.yml 后,玩家打开生存背包时会自动匹配。
yaml
id: player_inventory_skin
version: 1
title: 玩家背包替换
size:
width: window.width
height: window.height
coordinateMode: absolute
display:
mode: container
container:
target: player_inventory
priority: 100
elements:
- id: panel
type: rect
visible: true
enabled: false
pointerEvents: block
opacity: 0.92
z: 0
layout:
x: window.width * 0.5 - 105
y: window.height * 0.5 - 72
width: 210
height: 144
rect:
color: '#171C26'
- id: title
type: text
visible: true
enabled: false
pointerEvents: pass
z: 1
layout:
x: window.width * 0.5 - 90
y: window.height * 0.5 - 60
width: 180
height: 12
text:
value: 我的背包
textSize: 1.0
textLineLength: 20
align: center
- id: hotbar_first
type: item_slot
visible: true
enabled: true
pointerEvents: auto
containerBinding: backpack_0
containerTooltip: true
z: 2
layout:
x: window.width * 0.5 - 74
y: window.height * 0.5 + 38
width: 18
height: 18
itemSlot:
bind: backpack_0
mode: mapped
allowPut: true
allowTake: true
- id: mainhand
type: item_display
visible: true
enabled: false
pointerEvents: pass
containerBinding: backpack_mainhand
z: 2
layout:
x: window.width * 0.5 - 28
y: window.height * 0.5 - 16
width: 18
height: 18
itemDisplay: {}
- id: offhand
type: item_display
visible: true
enabled: false
pointerEvents: pass
containerBinding: backpack_offhand
z: 2
layout:
x: window.width * 0.5 + 10
y: window.height * 0.5 - 16
width: 18
height: 18
itemDisplay: {}
- id: helmet
type: item_display
visible: true
enabled: false
pointerEvents: pass
containerBinding: backpack_helmet
z: 2
layout:
x: window.width * 0.5 - 9
y: window.height * 0.5 - 42
width: 18
height: 18
itemDisplay: {}可绑定区域
| 区域 | 语义 ID |
|---|---|
| 快捷栏与主背包 36 格 | backpack_0 至 backpack_35 |
| 当前主手 | backpack_mainhand |
| 副手 | backpack_offhand |
| 头盔、胸甲、护腿、靴子 | backpack_helmet、backpack_chestplate、backpack_leggings、backpack_boots |
| 2×2 合成输入 | crafting_0 至 crafting_3 |
| 合成结果 | crafting_result |
数字都从 0 开始。backpack_mainhand 会跟随玩家当前选中的快捷栏位置,它不是额外复制出来的物品。
多张背包页面
玩家背包不使用标题和行数,只按 priority 选择。若两个玩家背包页面的最高优先级相同,ChaUI 会判定冲突并保留原版背包。建议只保留一张启用中的背包替换页面,或给不同用途设置明确优先级。
item_slot 为什么同时写两个 bind
示例中的 containerBinding: backpack_0 决定当前替换页面实际连接的原版槽位;itemSlot.bind 与 mode 是物品槽组件本身的标准配置。容器替换运行时优先使用 containerBinding 并委托当前原版背包,所以 Shift、数字键、拖拽、拆分和双击仍按原版容器处理。将两个 bind 写成相同值最容易阅读和维护。
只想展示物品、不允许交互时使用 item_display。只想读取名称或 Lore 时,文本等非布局组件也可以绑定同一位置。
猹件开发组