From ee1f2b68df3fd15b4d489d4c236abf5dfe4cd9ff Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 13 Jan 2025 12:09:45 +0100 Subject: [PATCH] Add safety checks before overriding builtin item entity (#3177) --- mods/default/item_entity.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mods/default/item_entity.lua b/mods/default/item_entity.lua index 3e6cc9db..50b4cd03 100644 --- a/mods/default/item_entity.lua +++ b/mods/default/item_entity.lua @@ -2,9 +2,16 @@ local builtin_item = minetest.registered_entities["__builtin:item"] +-- strictly speaking none of this is part of the API, so do some checks +-- and if it looks wrong skip the modifications +if not builtin_item or type(builtin_item.set_item) ~= "function" or type(builtin_item.on_step) ~= "function" then + minetest.log("warning", "Builtin item entity does not look as expected, skipping overrides.") + return +end + local item = { - set_item = function(self, itemstring) - builtin_item.set_item(self, itemstring) + set_item = function(self, itemstring, ...) + builtin_item.set_item(self, itemstring, ...) local stack = ItemStack(itemstring) local itemdef = minetest.registered_items[stack:get_name()]