From 2f464843cb57832b71ff617f39aa274a8493a8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20R=C3=BChle?= Date: Sun, 20 Apr 2025 20:48:48 +0200 Subject: [PATCH] Make it more convenient to customize node drops (#15872) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Provide tool and digger to get_node_drops This gives games/mods the ability to modify node drops depending on item and/or player metadata without overriding node_dig or other workarounds. * Copy wielded item to prevent modification in get_node_drops * Also pass node pos to get_node_drops Allowing properties of the node and its surroundings to affect node drops. * Copy pos to prevent modification in get_node_drops Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> * Don't pass empty item stack to get_node_drops if wielded is nil --------- Co-authored-by: sfan5 Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> --- builtin/game/item.lua | 3 ++- doc/lua_api.md | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 5dd5312aa..4d68f1136 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -513,7 +513,8 @@ function core.node_dig(pos, node, digger) .. node.name .. " at " .. core.pos_to_string(pos)) local wielded = digger and digger:get_wielded_item() - local drops = core.get_node_drops(node, wielded and wielded:get_name()) + local drops = core.get_node_drops(node, wielded and wielded:get_name(), + wielded and ItemStack(wielded), digger, vector.copy(pos)) if wielded then local wdef = wielded:get_definition() diff --git a/doc/lua_api.md b/doc/lua_api.md index d8e58fcde..e2a55b7e1 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -6910,11 +6910,16 @@ Item handling given `param2` value. * Returns `nil` if the given `paramtype2` does not contain color information. -* `core.get_node_drops(node, toolname)` - * Returns list of itemstrings that are dropped by `node` when dug - with the item `toolname` (not limited to tools). +* `core.get_node_drops(node, toolname[, tool, digger, pos])` + * Returns list of itemstrings that are dropped by `node` when dug with the + item `toolname` (not limited to tools). The default implementation doesn't + use `tool`, `digger`, and `pos`, but these are provided by `core.node_dig` + since 5.12.0 for games/mods implementing customized drops. * `node`: node as table or node name * `toolname`: name of the item used to dig (can be `nil`) + * `tool`: `ItemStack` used to dig (can be `nil`) + * `digger`: the ObjectRef that digs the node (can be `nil`) + * `pos`: the pos of the dug node (can be `nil`) * `core.get_craft_result(input)`: returns `output, decremented_input` * `input.method` = `"normal"` or `"cooking"` or `"fuel"` * `input.width` = for example `3`