From 9fad09d4a1d11eab7de20bcf3ce507645851fc12 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 4 Jul 2025 12:48:23 +0200 Subject: [PATCH] PlayerHPChangeReason: Replace detail by 2 types --- builtin/game/chat.lua | 2 +- builtin/game/item.lua | 2 +- doc/lua_api.md | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index 277b20fcd5..c409b8957a 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -1346,7 +1346,7 @@ local function handle_kill_command(killer, victim) core.log("action", string.format("%s killed %s", killer, victim)) end -- Kill victim - victimref:set_hp(0, {type="set_hp", detail="__builtin:kill_command"}) + victimref:set_hp(0, {type="kill_command"}) return true, S("@1 has been killed.", victim) end diff --git a/builtin/game/item.lua b/builtin/game/item.lua index d3d0529015..71529adf6a 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -435,7 +435,7 @@ function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed core.add_item(pos, replace_with_item) end - user:set_hp(user:get_hp() + hp_change, {type="set_hp", detail="__builtin:item_eat"}) + user:set_hp(user:get_hp() + hp_change, {type="item_eat"}) return nil -- don't overwrite wield item a second time end diff --git a/doc/lua_api.md b/doc/lua_api.md index 38202c03dc..b537f0d9d0 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -11089,11 +11089,12 @@ The `PlayerHPChangeReason` table specifies a reason for player health changes. * `drown`: Drowning damage from a node with the `drowning` field set. `reason.node` and `reason.node_pos` are same as for `node_damage` * `respawn`: HP restored by respawning. -* The `detail` field may optionally be used to provide a more detailed reason - as a string. It's recommended to follow the `modname:detail` naming convention. - These detail names exist by default: - * `__builtin:item_eat`: HP change caused by `core.do_item_eat` - * `__builtin:kill_command`: `/kill` command + * `item_eat`: HP change caused by `core.do_item_eat` + * `kill_command`: `/kill` command + * A custom value. This may be used by mods to inform other mods + about a damage type when none of the above applies. It should + follow a `_:` naming convention. + Example: `_example:poison` for poison damage from a mod named `example` * The `from` field denotes the origin of the HP change: * `engine`: Engine * `mod`: Mod or builtin