Skip to content

Commit

Permalink
Add safety checks before overriding builtin item entity (#3177)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 authored Jan 13, 2025
1 parent 6da5e94 commit ee1f2b6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mods/default/item_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down

0 comments on commit ee1f2b6

Please sign in to comment.