❤️ 生命(Health)#
#bs.health:help
高效管理实体的生命周期和生命值。
“知生命之意者,可承生命之重。”
—弗里德里希·尼采(Friedrich Nietzsche)
关于 NBT
使用此模块时,不要依赖 NBT 来获取生命值信息。请使用 get_health 获取玩家的生命值,使用 get_max_health_total 获取最大生命值,而不是使用 attribute @s minecraft:max_health get。NBT 可能并不总是反映实际值,选择这种方法是为了绕过某些限制。
效果不兼容
此系统通过 instant_health 效果来治疗玩家并强制更新其生命值。若效果等级大于 28 可能会导致问题。此外,当前刻内任何待处理的治疗命令会优先于该效果,可能会覆盖它。
🔧 函数#
你可以在下方找到此模块中的所有可用函数。
增加/移除#
- #bs.health:add_health {points:<value>}
增加或移除玩家的生命值点数。
- 输入:
执行
as <玩家>:要更改生命值的玩家。函数宏:
参数
points: 要给玩家增加的生命值。
- 输出:
状态:生命值在计划刻更新。
示例:治疗自己 5 点生命值:
# Once (execute on you)
function #bs.health:add_health {points:5.0}
如何移除?
你可以使用负数来移除玩家的生命值点数。
- #bs.health:add_max_health {points:<value>}
增加或移除玩家的基础最大生命值点数。
- 输入:
执行
as <玩家>:要更改最大生命值的玩家。函数宏:
参数
points: 要给玩家增加的最大生命值。
- 输出:
状态:最大生命值在计划刻更新。
示例:将自己的最大生命值增加 5 点:
# Add 5 maximum health points to the executing player
function #bs.health:add_max_health {points:5.0}
如何移除?
你可以使用负数来移除玩家的最大生命值。
制作人员:Aksiome
获取#
- #bs.health:get_health {scale:<scaling>}
获取玩家的生命值点数。
- 输入:
执行
as <玩家>:你想要获取生命值点数的玩家。函数宏:
参数
scale: 函数返回值的缩放值。
- 输出:
返回值 | 命令存储
bs:out health.get_health: 玩家的生命值点数。
示例:获取自己当前的生命值(放大 1000 倍):
# Get and display the current health of the executing player
function #bs.health:get_health {scale:1000}
- #bs.health:get_max_health {scale:<scaling>}
获取玩家的基础最大生命值点数。
- 输入:
执行
as <玩家>:你想要获取最大生命值点数的玩家。函数宏:
参数
scale: 函数返回值的缩放值。
- 输出:
返回值 | 命令存储
bs:out health.get_max_health: 玩家的最大生命值点数。
示例:获取自己的最大生命值(放大 1000 倍):
# See the returned value (execute on you)
function #bs.health:get_max_health {scale:1000}
制作人员:Aksiome
设置#
- #bs.health:set_health {points:<value>}
设置玩家的生命值点数。
- 输入:
执行
as <玩家>:要更改生命值的玩家。函数宏:
参数
points: 生命值。
- 输出:
状态:生命值在计划刻更新。
示例:将自己的生命值设置为 10:
# Once (execute on you)
function #bs.health:set_health {points:5.0}
- #bs.health:set_max_health {points:<value>}
设置玩家的基础最大生命值点数。
- 输入:
执行
as <玩家>:要更改最大生命值的玩家。函数宏:
参数
points: 最大生命值。
- 输出:
状态:最大生命值在计划刻更新。
示例:将自己的最大生命值设置为 10:
# Once (execute on you)
function #bs.health:set_max_health {points:5.0}
制作人员:Aksiome
存活时间#
- #bs.health:time_to_live {with:{}}
设置实体的存活时间。
- 输入:
执行
as <实体>:要添加存活时间的实体。函数宏:
参数
with: 存活时间数据。
time: 存活时间,如果没有指定单位(unit)则单位默认为游戏刻时间。
unit: 时间单位(tick, second, minute, hour, t, s, m, h)。
on_death: 实体死亡时对其运行的函数。
- 输出:
状态:实体现在具有有限的存活时间。
示例:给爬行者设置 10 秒的存活时间:
# Set a 10-second lifetime for all creepers
execute as @e[type=minecraft:creeper] run function #bs.health:time_to_live {with:{time:10,unit:"s"}}
示例:在爬行者生命结束时给予爆炸效果:
# Set a lifetime with explosion effect for all creepers
execute as @e[type=minecraft:creeper] run function #bs.health:time_to_live {with:{time:10,on_death:"execute at @s run particle minecraft:explosion_emitter ~ ~ ~"}}
示例:在任意时间更新死亡回调:
# Set initial lifetime with explosion effect
execute as @e[type=minecraft:creeper] run function #bs.health:time_to_live {with:{time:100,on_death:"execute at @s run particle minecraft:explosion_emitter ~ ~ ~"}}
# At any time before the entity's death
execute as @e[type=minecraft:creeper,limit=1] run function #bs.health:time_to_live {with:{on_death:"say GOTCHA"}}
制作人员:Aksiome、Leirof
💬 这对你有帮助吗?
欢迎在下方留下你的问题和反馈!