Files
netease-modsdk-wiki/docs/mcguide/20-玩法开发/15-自定义游戏内容/1-自定义物品/5-自定义蓄力物品.md
2025-03-18 14:46:12 +08:00

118 lines
3.2 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: 分钟
---
# 自定义蓄力物品
## 概述
属于特殊的自定义物品,在支持自定义物品所有特性的基础上,还具有右键按下开始蓄力过程,右键抬起触发释放事件。
与弓minecraft:bow、弩minecraft:crossbow类似在物品使用过程支持蓄力操作支持序列帧动画。
详细的物品定义以及物品使用详见示例mod [CustomRangedWeaponMod](../../13-模组SDK编程/60-Demo示例.md#CustomRangedWeaponMod)。
## 注册
1. 与自定义物品的注册1-6步相同
2. 在behavior创建的json文件
```json
{
"format_version": "1.10",
"minecraft:item": {
"description": {
"identifier": "customitems:ranged_weapon",
"custom_item_type": "ranged_weapon"
},
"components": {
"minecraft:use_duration": 72000
}
}
}
```
*注意use_duration的大小应该与序列帧帧数相匹配*
3. 自定义序列帧
3.1 将物品的序列帧贴图放到`textures\items`中,如:
![avatar](./picture/customitem/custom_ranged_weapon01.png)
3.2 在textures/item_texture.json中增加序列帧图片的定义
```json
"customitems:ranged_weapon_frame": {
"textures": [
"textures/items/customitems_ranged_weapon_0",
"textures/items/customitems_ranged_weapon_1",
"textures/items/customitems_ranged_weapon_2"
]
}
```
3.3 在netease_items_res中增加json文件
```json
{
"format_version": "1.10",
"minecraft:item": {
"description": {
"identifier": "customitems:ranged_weapon",
"category": "Equipment"
},
"components": {
"minecraft:icon": "customitems:ranged_weapon",
"netease:frame_animation": {
"frame_count": 3,
"texture_name": "customitems:ranged_weapon_frame",
"animate_in_toolbar": true
}
}
}
}
```
## 网易components
* netease:frame_animation
| 键 | 类型 | 默认值 | 解释 |
| ------------------ | ---- | ------ | ----------------------------------- |
| frame_count | int | 1 | 序列帧帧数 |
| texture_name | str | | item_texture.json中定义的序列帧数组 |
| animate_in_toolbar | bool | true | 在物品栏中是否支持动画 |
* netease:render_offsets
手中物品渲染配置
右手坐标系x是拇指方向y是食指方向z是中指方向
| 键 | 类型 | 默认值 | 解释 |
| -------------------------- | ----- | ------------- | ------------ |
| controller_position_adjust | array | [0.0,0.0,0.0] | 物品位置调整 |
| controller_rotation_adjust | array | [0.0,0.0,0.0] | 物品旋转调整 |
| controller_scale | float | 1.0 | 物品大小调整 |
## 物品耐久
自定义蓄力物品可以通过minecraft:max_damage组件设置其耐久值
然后在在物品使用事件ItemReleaseUsingServerEvent中获取/设置耐久值
```python
slotIndex = 0
comp = serverApi.CreateComponent(playerId,'Minecraft','item')
val = comp.GetInvItemDurability(slotIndex)
if val == 0:
# 销毁物品
comp.SetInvItemNum(slotIndex, 0)
else:
comp.SetInvItemDurability(slotIndex, val - 1)
```