Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safety checks before overriding builtin item entity #3177

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading