可投掷物品
intermediate
TIP
本教程假设您已基本了解Molang语言、动画控制器和实体定义。
像喷溅药水或三叉戟这样的物品属于特殊可投掷物品。
物品配置
首先需要创建基础物品:
BP/items/throwable_item.item.json
json
{
"format_version": "1.21.70",
"minecraft:item": {
"description": {
"identifier": "wiki:throwable_item"
},
"components": {
"minecraft:max_stack_size": 16,
"minecraft:throwable": {
"do_swing_animation": true
},
"minecraft:projectile": {
"projectile_entity": "wiki:throwable_item_entity"
},
"minecraft:icon": "wiki:throwable_item"
}
}
}实体配置
该实体将作为实际投掷物,具有抛射体特性。
注意必须添加雪球运行时标识符才能使抛射体真正被投掷而非生成。您也可以尝试其他抛射体的运行时ID。
BP/entities/throwable_item_entity.se.json
json
{
"format_version": "1.16.0",
"minecraft:entity": {
"description": {
"identifier": "wiki:throwable_item_entity",
"is_spawnable": false,
"is_summonable": true,
"is_experimental": false,
"runtime_identifier": "minecraft:snowball"
},
"components": {
"minecraft:collision_box": {
"width": 0.25,
"height": 0.25
},
"minecraft:projectile": {
"on_hit": {
"grant_xp": {
"minXP": 3,
"maxXP": 5
},
"impact_damage": {
"damage": 16
},
"remove_on_hit": {}
},
"power": 0.7,
"gravity": 0.03,
"angle_offset": -20,
"hit_sound": "glass"
},
"minecraft:physics": {},
"minecraft:pushable": {
"is_pushable": true,
"is_pushable_by_piston": true
},
"minecraft:conditional_bandwidth_optimization": {
"default_values": {
"max_optimized_distance": 80,
"max_dropped_ticks": 10,
"use_motion_prediction_hints": true
}
}
}
}
}该实体基于原版喷溅药水实现。
您可以通过编辑minecraft:projectile组件来自定义行为,本例中投掷物命中时将给予经验值并对击中的实体造成伤害。
结语
完成可投掷物品创建后,您可以尝试调整其力度、特效、动画,或与范围效果云结合使用。唯一的限制就是您的想象力。







