Files
netease-bedrock-wiki/mcguide/20-玩法开发/15-自定义游戏内容/1-自定义物品/3-自定义盔甲.md
2025-08-25 18:36:29 +08:00

237 lines
8.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
front:
hard: 入门
time: 分钟
---
# 自定义盔甲
## 概述
自定义盔甲属于特殊的自定义物品,在支持自定义物品所有特性的基础上,还具有盔甲相关的功能。
## 注册
1. 与自定义基础物品的注册1-6步相同
2. custom_item_type需要为armor
3.`behavior/netease_items_beh`的json中添加[netease:armor](#json组件)组件
```json
{
"format_version": "1.10",
"minecraft:item": {
"description": {
"identifier": "customitems:modarmor1",
"custom_item_type": "armor"
},
"components": {
"netease:armor": {
"defense": 10,
"enchantment":4,
"armor_slot":0
}
}
}
}
```
4. 添加模型贴图到资源包的`textures\models`
与微软内置盔甲贴图一致,自定义盔甲也需要设置贴图。
5.`resource/netease_item_res`目录下创建新json中添加盔甲物品的贴图参数详见自定义物品注册中贴图的设置解释
```json
{
"format_version": "1.10",
"minecraft:item": {
"description": {
"identifier": "customitems:modarmor1",
"category": "Equipment"
},
"components": {
"minecraft:icon": "customitems:modarmor1"
}
}
}
```
6. 在resource目录下创建`attachables`目录创建新json描述文件其中可配置的参数详见[json组件](#json组件)
```json
{
"format_version": "1.8.0",
"minecraft:attachable": {
"description": {
"identifier": "customitems:modarmor1",
"materials": {
"default": "armor",
"enchanted": "armor_enchanted"
},
"textures": {
"default": "textures/models/diamond_1",
"enchanted": "textures/misc/enchanted_item_glint"
},
"geometry": {
"default": "geometry.customitems_modarmor1"
},
"scripts": {
"parent_setup": "variable.chest_layer_visible = 0.0;"
},
"render_controllers": [ "controller.render.armor" ]
}
}
}
```
7. 在`resource/models`目录下增加`entity`目录增加对应的geometry描述文件
可配置的参数主要为根节点描述符`geometry.modid_modarmor1`这个值与上一步中的geometry文件值对应。
```json
{
"geometry.customitems_modarmor1": {
"texturewidth": 64,
"textureheight": 32,
"visible_bounds_width": 2,
"visible_bounds_height": 2,
"visible_bounds_offset": [ 0, 1, 0 ],
"bones": [
{
"cubes": [
{
"origin": [ -4, 24, -4],
"uv": [ 0, 0 ],
"size": [ 8, 8, 8 ],
"inflate": 1.0
},
{
"origin": [ 4, 30, -1],
"size": [ 2, 2, 2],
"uv": [47, 0]
},
{
"origin": [-6, 30, -1],
"size": [2, 2, 2],
"uv": [47, 0]
},
{
"origin": [6, 31, -1],
"size": [2, 2, 2],
"uv": [42, 8]
},
{
"origin": [-8, 31, -1],
"size": [2, 2, 2],
"uv": [42, 8]
},
{
"origin": [8, 32, -1],
"size": [2, 4, 2],
"uv": [41, 0]
},
{
"origin": [-10, 32, -1],
"size": [2, 4, 2],
"uv": [41, 0]
},
{
"origin": [-8, 36, -1],
"size": [16, 2, 2],
"uv": [28, 28]
}
],
"name": "head",
"parent": null,
"pivot": [
0.0,
24.0,
0.0
]
}
]
}
}
```
## JSON组件
### netease\_item\_beh文件
**description**
| 键 | 类型 | 默认值 | 解释 |
| -------- | ---- | --------- | ----------------------------------------- |
| category | str | equipment | 与普通物品不同盔甲的默认分类是equipment |
**网易components**
* netease:armor行为包
| 键 | 类型 | 默认值 | 解释 |
| -------------------- | ----- | ------ | ------------------------------------------------------------ |
| defense | int | 0 | 盔甲的防御值 |
| enchantment | int | 0 | 盔甲的附魔能力。该值的解释见[官方wiki](https://zh.minecraft.wiki/w/%E9%99%84%E9%AD%94%EF%BC%88%E7%89%A9%E5%93%81%E4%BF%AE%E9%A5%B0%EF%BC%89) |
| armor_slot | int | | 盔甲槽位,详见<a href="../../../../mcdocs/1-ModAPI/枚举值/ArmorSlotType.html" rel="noopenner"> ArmorSlotType </a> |
| toughness | int | 0 | 盔甲韧性范围0~20详见[盔甲机制](https://zh.minecraft.wiki/w/%E7%9B%94%E7%94%B2%E6%9C%BA%E5%88%B6) |
| knockback_resistance | float | 0.0 | 击退抗性范围0~1详见[伤害-击退抗性](https://zh.minecraft.wiki/w/%E4%BC%A4%E5%AE%B3#%E5%87%BB%E9%80%80%E6%8A%97%E6%80%A7) |
### attachables文件
| 键 | 类型 | 描述 |
| -------------------- | ---- | ------------------------------------------------------ |
| identifier | str | 盔甲的唯一描述符,与之前注册流程中的物品描述符保持一致 |
| textures/default | str | 盔甲对应的贴图路径设置 |
| geometry/default | str | 盔甲对应的模型描述文件路径设置 |
| scripts/parent_setup | str | 盔甲对应部位影响玩家渲染的设置参数 |
**parent_setup**
为了避免皮肤外层和盔甲形成穿模现象游戏使用了以下4个变量来控制对应部位皮肤外层的显示
- variable.helmet_layer_visible 玩家头部层是否显示
- variable.chest_layer_visible 玩家上半身层是否显示
- variable.leg_layer_visible 玩家腿部层是否显示
- variable.boot_layer_visible 玩家脚部层是否显示
一般而言,当编写对应的部位的盔甲,需要在`scripts/parent_setup`设置对应的变量值为0
**geometry/default**
需要设置成盔甲对应位置的geometry例如`geometry.humanoid.armor.boots`。
| 键 | 说明 |
| ---------------------------------- | ---- |
| geometry.humanoid.armor.boots | 靴子 |
| geometry.humanoid.armor.chestplate | 胸甲 |
| geometry.humanoid.armor.helmet | 头盔 |
| geometry.humanoid.armor.leggings | 护腿 |
## 附属功能
除了支持自定义物品的所有功能外还支持盔甲的python事件及接口包括OnNewArmorExchangeServerEvent事件及armorslot组件
## demo解释
[CustomItemsMod](../../13-模组SDK编程/60-Demo示例.md#CustomItemsMod)中定义了一个自定义装备:
* customitems:modarmor1
头盔类型的自定义装备
## 自定义模型设置建议
* 盔甲模型的基础参考文件为:`data\resource_packs\vanilla\models`目录下的`mobs.json`文件中的**geometry.humanoid**。
* 模型制作工具推荐使用BlockBench导出的模型JSON文件格式与要求的格式相近。
* 使用BlockBench制作模型并导出为JSON文件后按照我们提供的装备物品Demo的JSON样式进行调整
需注意的是请尽量使用JSON范例中key的顺序避免出现比较奇怪的Bug。
* 如果Cube和已有的模型或者Cube之间有重叠的面重叠部分可能会无法显示或者闪烁可通过调整每个Cube的`inflate`可为负数来避免这种情况。inflate的作用是让Cube向各个方向膨胀一定数值同时不会影响贴图坐标。
* **注意**:对于溺尸,不能使用`SetArmorNew`(该接口已废弃)接口装备自定义盔甲,该行为会造成游戏闪退。