自定义死亡动画
死亡动画指的是实体死亡时的旋转效果。该效果会伴随红色着色,随后实体几何形状消失并出现死亡粒子。
取消死亡动画
本部分将说明如何完全移除死亡动画效果。
传送实体
一种常见的移除实体且不触发死亡效果的方法是将实体传送至虚空。可以通过动画控制器使用 !q.is_alive 条件实现: /teleport @s ~ ~-1000 ~
请注意,这将移除所有死亡效果,包括音效、粒子、战利品以及实体的视觉死亡表现。
minecraft:instant_despawn
若想让实体直接消失,可以添加包含 "minecraft:instant_despawn":{} 的组件组,并通过事件触发该组件组。
请注意,这将移除所有死亡效果,包括音效、粒子、战利品以及实体的视觉死亡表现。
转换为其他实体
与传送类似,实体在死亡时会触发实体转换。在动画控制器中使用 !q.is_alive 条件发送事件,添加包含 "minecraft:transformation" 组件的组件组。通过该组件,实体将转换为另一个实体:
"minecraft:transformation": {
"into": "wiki:death_animation_entity",
"transformation_sound" : "converted_to_zombified",
"keep_level": true,
"drop_inventory": true,
"preserve_equipment": false,
"drop_equipment": true,
"delay": {
"block_assist_chance": 0.0,
"block_radius": 0,
"block_max": 0,
"value": 10
}
}取消旋转动画
我们还可以取消实体的旋转值,使实体以更常规的方式死亡(保留粒子、红色着色、战利品),而不会出现90度旋转。
如需了解如何通过实体死亡触发动画的更多信息,请参阅关于死亡效果的此文档。
旋转需要应用于所有骨骼的父骨骼,枢轴点为[0,0,0],且动画仅在 !q.is_alive 时启动。
动画:
"rotation" : [ 0, 0, "Math.min(Math.sqrt(Math.max(0, q.anim_time * 20 - 0.5) / 20 * 1.6), 1) * -90" ]动画控制器:
(q.all_animations_finished 仅适用于可重生的实体,如玩家)
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.player.cancel_death_animaton": {
"initial_state": "default",
"states": {
"default": {
"transitions": [
{
"cancel_animation": "!q.is_alive"
}
]
},
"cancel_animation": {
"animations": ["my.animation"],
"transitions": [
{
"default": "q.is_alive && q.all_animations_finished"
}
]
}
}
}
}
}注意:你需要在资源包的 .entity.json 文件中附加动画和动画控制器。
自定义死亡动画
本部分将说明如何自定义死亡动画。
修改伤害着色叠加
你可以移除或自定义实体的伤害着色叠加效果。
开始前,请确保已掌握渲染控制器的基础知识,可参考渲染控制器教程。
要移除实体受伤时的伤害叠加颜色,我们将使用 is_hurt_color;若需移除实体受到熔岩或火焰伤害时的火焰叠加颜色,则使用 on_fire_color。首先,需要将RGBA值设为0。以下是移除伤害和火焰叠加颜色的示例:
{
"format_version": "1.8.0",
"render_controllers": {
"controller.render.sample": {
"geometry": "Geometry.default",
"materials": [{ "*": "Material.default" }],
"textures": ["Texture.default"],
"is_hurt_color": {},
"on_fire_color": {}
}
}
}上述代码将移除红色的伤害叠加颜色。
你也可以通过修改RGBA值将伤害叠加颜色改为其他颜色。可通过各类网站查询颜色的RGBA值。以下是将伤害叠加颜色改为粉色的示例:
{
"format_version": "1.8.0",
"render_controllers": {
"controller.render.kbg": {
"geometry": "Geometry.default",
"materials": [{ "*": "Material.default" }],
"textures": ["Texture.default"],
"is_hurt_color": {
"r": "1.0",
"g": "0.4",
"b": "0.7",
"a": "0.5"
},
"on_fire_color": {
"r": "1.0",
"g": "0.4",
"b": "0.7",
"a": "0.5"
}
}
}
}使用伤害传感器触发即时消失和单物品掉落
你可以使用 damage_sensor 组件在受到致命伤害时触发事件;该事件会添加一个特定的消失组件组,包含 spawn_entity 和 instant_despawn 组件。spawn_entity 的等待时间为0时,会在实体消失前掉落一个物品。对于只需掉落单一物品的简单实体(如家具),这非常方便。
当实体受到致命伤害时,会触发事件添加一个虚拟组件。随后,我们可以利用该虚拟组件播放动画,并通过 minecraft:timer 设置实体消失时间。
请注意,对于有物品栏的实体,你需要另寻解决方案。同时,需确保实体生成时不会通过 entity_spawned 事件添加消失组件组。若实体有其他行为(如移动和攻击),你可能还需要移除这些组件。
以下是行为包中的示例文件:
{
"format_version": "1.14.0",
"min_engine_version": "1.16.100",
"minecraft:entity": {
"description": {
"identifier": "wiki:entity",
"is_spawnable": true,
"is_summonable": true,
"is_experimental": true
},
"component_groups": {
"wiki:death": {
"minecraft:spawn_entity": {
"max_wait_time": 0,
"min_wait_time": 0,
"spawn_item": "egg",
"single_use": true
},
"minecraft:is_sheared": {},
"minecraft:timer": {
"looping": true,
"time": [2.56, 2.56], // 调整此值以匹配动画时间
"time_down_event": {
"event": "wiki:despawn"
}
}
},
"wiki:despawn": {
"minecraft:instant_despawn": {}
}
},
"components": {
"minecraft:type_family": {
"family": ["cart", "inanimate"]
},
"minecraft:collision_box": {
"width": 0.8,
"height": 0.5
},
"minecraft:health": {
"value": 8,
"max": 8
},
"minecraft:physics": {},
"minecraft:pushable": {
"is_pushable": true,
"is_pushable_by_piston": true
},
"minecraft:damage_sensor": {
"triggers": {
"on_damage": {
"filters": {
"all_of": [
{
"test": "has_damage",
"value": "fatal"
}
]
},
"target": "self",
"event": "wiki:death",
"deals_damage": false,
"cause": "fatal"
}
}
}
},
"events": {
"wiki:death": {
"add": {
"component_groups": ["wiki:death"]
},
"wiki:despawn": {
"add": {
"component_groups": ["wiki:despawn"]
}
}
}
}
}
}以下是动画控制器的示例文件:
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.entity": {
"states": {
"default": {
"blend_transition": 0.2,
"transitions": [
{
"dead": "q.is_sheared"
}
]
},
"death": {
"blend_transition": 0.2,
"animations": ["death"]
}
}
}
}
}注意:你也可以通过 minecraft:spawn_entity 组件生成自定义刷怪蛋物品,将 "spawn_item" 设置为你的实体ID并添加 spawn_egg 后缀,示例如下:
{
"minecraft:spawn_entity": [
{
"min_wait_time": 0,
"max_wait_time": 0,
"spawn_item": "wiki:custom_zombie_spawn_egg",
"single_use": true
}
]
}若想掉落战利品表,可以触发如下事件,并生成另一个包含该组件的实体:
{
"minecraft:behavior.drop_item_for": {
"seconds_before_pickup": 0.0,
"cooldown": 5,
"drop_item_chance": 1,
"offering_distance": 0.0,
"minimum_teleport_distance": 1024.0,
"target_range": [64.0, 64.0, 64.0],
"teleport_offset": [0.0, 1.0, 0.0],
"speed_multiplier": 1.0,
"search_range": 64,
"search_height": 64,
"search_count": 0,
"goal_radius": 64.0,
"entity_types": [
{
"filters": {
"test": "is_family",
"subject": "other",
"value": "player"
},
"max_dist": 64
}
],
"priority": 1,
"loot_table": "loot_tables/entities/example.loot_table.json",
"time_of_day_range": [0.0, 1.0]
},
"minecraft:timer": {
"time": 2,
"time_down_event": {
"event": "wiki:my_despawn_event"
}
}
}然后通过 wiki:my_despawn_event 事件添加包含 instant_despawn 的组件组来使其消失。








