我的世界基岩版 UI 文档

修改

子控件属性修改

下面这种方法我们可以使用斜杠区分子控件,这样就不需要使用 controls 去修改某个子控件了。同时去除一些不必要修改的属性:

原文件
1
2
3
4
5
6
7
8
9
"test": {
"controls": [
{
"test": {
"controls": [{"test": {"type": "label","text": "hello world"}}]
}
}
]
}

接下来,我们只需要修改 text 属性的内容就可以这样做:

新文件
1
2
3
"test/test/test": {
"text": "test"
}

引用修改

一般修改引用只需要在控件名后方"@xxx.xxx"或"@xxx"。另外,如果没有修改引用的需要,可以去除引用。这样不会对原来的引用影响。

RP/ui/start_screen.json
1
"start_screen": {}

最值得注意的是,修改引用后并且没有任何属性的情况下,会对当前控件重置并仅使用引用控件的属性。

RP/ui/start_screen.json
1
2
// 这样就会闪退
"start_screen@common.empty_panel": {}

数组修改

我们总是需要对其他资源包的 controls 进行增加控件或者删除控件。但是为了修改,我们就需要使用到 modifications。这样我们就不需要引用其他资源包的代码进行大面积的修改,也不会破坏其他资源包的内容。

modifications 仅用于修改低于当前资源包排序的资源包,一般我们只对 vanilla 进行处理。
(资源包排序为:世界资源包 > 全局资源 > 游戏安装包资源包 > treatment,其中他们还可以细分为许多部分,游戏安装包资源包排序又能分为 vanilla版本包 > vanilla > vanilla_base。)

每个控件中 modifications 属性可以同时执行多个修改操作,不过,当目标不存在时、未知的修改操作会报错。

数组对象属性属性名描述
array_name数组键名字符串定义要修改的目标数组。
operation修改操作字符串:列举执行的修改操作。列举的值详见下方内容。
该属性是必要的!
where执行操作的对象对象执行操作的对象,可模糊(指使用目标对象中的某个属性。控件无法模糊,必须是完整控件)选中某个对象。
value执行操作后的值数组 或 对象执行操作后的值。
单个对象时使用对象,多个对象时使用数组。
target被操作的对象对象被操作的对象。

接下来我们将展示几种修改操作:

插入

insert_front 插入到数组的开始处。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [
// value 目标插入到数组开始处
{
"array_name": "controls",
"operation": "insert_front",
"value": {"test":{}}
},
{
"array_name": "bindings",
"operation": "insert_front",
"value": {"binding_name":"#is_insert"}
}
]
insert_back 插入到数组的结尾处。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [
// value 目标插入到数组结尾处
{
"array_name": "controls",
"operation": "insert_back",
"value": {"test":{}}
},
{
"array_name": "controls",
"operation": "insert_back",
"where": {"binding_name":"#is_insert"}
}
]
insert_before 插入到目标对象的前方。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [
// value 目标插入到 test2 控件前方
{
"control_name": "test2",
"operation": "insert_before",
"value": {"test":{}}
},
// value 目标插入到 where 目标前方
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "insert_before",
"value": {"binding_name":"#is_insert"}
}
]
insert_after 插入到目标对象的后方。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [
// value 目标插入到 test2 控件后方
{
"control_name": "test2",
"operation": "insert_after",
"value": {"test":{}}
},
// value 目标插入到 where 目标后方
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "insert_after",
"value": {"binding_name":"#is_insert"}
}
]

删除

remove 移除目标对象。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [
// 删除目标控件
{
"control_name": "test",
"operation": "remove"
},
// 删除目标绑定
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "remove"
}
]

替换

replace 替换目标对象。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [
// 控件替换为 value 目标
{
"control_name": "test",
"operation": "replace",
"value": {"replace":{}}
},
// where 目标替换为 value 目标
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "replace",
"value": {"binding_name":"#is_replace"}
}
]

交换

swap 交换目标对象。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [
// 控件与目标交换
{
"control_name": "test",
"operation": "swap",
"target": {"replace":{}}
},
// where 目标与目标交换
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "swap",
"target": {"binding_name":"#is_replace"}
}
]

移动

move_front 移动目标对象到数组开始处。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [
// value 目标移动到数组开始处
{
"array_name": "controls",
"operation": "move_front",
"value": {"replace":{}}
},
{
"array_name": "bindings",
"operation": "move_front",
"where": {"binding_name":"#is_move"}
}
]
move_back 移动目标对象到数组结尾处。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [
// value 目标移动到数组结尾处
{
"array_name": "controls",
"operation": "move_back",
"value": {"replace":{}}
},
{
"array_name": "bindings",
"operation": "move_back",
"where": {"binding_name":"#is_move"}
}
]
move_before 插入到目标对象的前方。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [
// value 目标移动到控件前方
{
"control_name": "test2",
"operation": "move_before",
"value": {"test":{}}
},
// value 目标移动到 where 目标前方
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "move_before",
"value": {"binding_name":"#is_move"}
}
]
move_after 插入到目标对象的后方。
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [
// value 目标移动到控件后方
{
"control_name": "test2",
"operation": "move_after",
"value": {"test":{}}
},
// value 目标移动到 where 目标后方
{
"array_name": "bindings",
"where": {"binding_name":"#test"},
"operation": "move_after",
"value": {"binding_name":"#is_move"}
}
]
版权声明- 除非另有说明,否则文档内容均采用CC BY-NC-SA 4.0许可协议
- 此网站与 Mojang Studios 以及微软无任何从属关系
- 转载需要作者同意,并且标明内容来自于本网站
 导航&目录