Files
netease-modsdk-wiki/docs/mcguide/20-玩法开发/15-自定义游戏内容/3-自定义生物/02-重写原版生物.md
2025-03-17 13:24:39 +08:00

133 lines
4.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: 分钟
---
# 重写原版生物
我们可以通过自定义与原版生物一样的identifier来重写原版生物的行为与外观。
请结合示例[CustomEntityMod](../../13-模组SDK编程/60-Demo示例.md#CustomEntityMod)来阅读该文档。
## 1. 重写生物行为
如示例[CustomEntityMod](../../13-模组SDK编程/60-Demo示例.md#CustomEntityMod)中在behavior_pack/entities下添加custom_pig.jsonidentifier依然为minecraft:pig然后加上了**苦力怕**的攻击组件minecraft:nearest_attackable_target和minecraft:target_nearby_sensor以及爆炸事件使得它会攻击玩家并且爆炸消失。
## 2. 重写生物外观
重写生物外观有两种方式:
* **重写客户端实体的定义resource_pack/entity下改方式为纯配置json的方式**
与重写生物行为一样我们可以通过重写资源包下的entity定义、贴图、动画、模型、渲染控制器等json文件来重写生物的外观如示例[CustomEntityMod](../../13-模组SDK编程/60-Demo示例.md#CustomEntityMod)中,猪穿上了屠夫的贴图。
```json
{
"format_version": "1.10.0",
"minecraft:client_entity": {
"description": {
"identifier": "minecraft:pig",
"materials": { "default": "custom_entity" },
"textures": {
"default": "textures/entity/custom_pig", # 修改此贴图
"saddled": "textures/entity/custom_pig_saddle" # 修改此贴图
},
"geometry": {
"default": "geometry.pig"
},
"animations": {
"setup": "animation.pig.setup.v1.0",
"walk": "animation.quadruped.walk",
"look_at_target": "animation.common.look_at_target",
"baby_transform": "animation.pig.baby_transform"
},
"scripts": {
"animate": [
"setup",
{ "walk": "query.modified_move_speed" },
"look_at_target",
{ "baby_transform": "query.is_baby" }
]
},
"render_controllers": [ "controller.render.custom_pig" ],
"spawn_egg": {
"texture": "spawn_egg",
"texture_index": 2
}
}
}
}
```
并在textures/entity目录下增加贴图custom_pig.png和custom_pig_saddle.png
## 3. 关于重写玩家的客户端实体定义
**对玩家客户端定义的修改,都应该基于`data\resource_packs\vanilla_netease\entity\player.entity.json`进行而非vanilla或其他的原版资源包。**
引擎支持玩家皮肤时会对player的render_controllers进行硬编码的修改
1. 根据玩家是否使用拥有自发光的会员皮肤移除controller.render.player.first_person_bloom及controller.render.player.third_person_bloom或者controller.render.player.first_person及controller.render.player.third_person。因为为了兼容自发光请同时保留以上4个render controller。
2. 若玩家使用了个性化搭配则会添加controller.render.persona_animated_face.third_person。
这会导致当开发者想完全重写player的外观时例如
```json
{
"format_version": "1.10.0",
"minecraft:client_entity": {
"description": {
"identifier": "minecraft:player",
"materials": {
"MC_default": "entity"
},
"textures": {
"MC_default": "textures/entity/penguin/penguin"
},
"geometry": {
"MC_default": "geometry.penguin"
},
"animations": {
...
},
"scripts": {
...
},
"render_controllers": [ "controller.render.penguin" ]
}
}
}
```
那么当玩家使用了个性化搭配时会多出一个render controller。
为了解决这种情况可以在description中添加netease_override_persona属性。当该属性为true时引擎不会对player的render_controllers作任何修改。例如
```json
{
"format_version": "1.10.0",
"minecraft:client_entity": {
"description": {
"identifier": "minecraft:player",
"netease_override_persona": true,
...
"render_controllers": [ "controller.render.penguin" ]
}
}
}
```