Skip to content

Instantly share code, notes, and snippets.

@appgurueu
Created June 27, 2022 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appgurueu/b70732bf7ea3a7e7b556d609e0b87a0b to your computer and use it in GitHub Desktop.
Save appgurueu/b70732bf7ea3a7e7b556d609e0b87a0b to your computer and use it in GitHub Desktop.
Small, hacky Minetest utility to get rid of "unknown entities" as they are activated
--[[
Small, hacky Minetest utility to get rid of "unknown entities" as they are activated. Licensed under CC0.
Caveat: `/spawnentity <name>` will fail with "<name> failed to spawn" rather than "Cannot spawn an unknown entity."
for unknown entities as the unknown entity will immediately be removed inside `on_activate`.
]]
setmetatable(minetest.registered_entities, {
__index = function(_, name)
-- Default entity def if `minetest.registered_entities[name]` would otherwise be `nil`
-- Necessarily leads to `minetest.registered_entities[name]` being truthy for unknown entities as well
local def = {
on_activate = function(self, staticdata)
minetest.log("warning",
("Removing entity %s at %s with staticdata %q")
:format(name, minetest.pos_to_string(self.object:get_pos(), 2), staticdata))
self.object:remove()
end
}
def.__index = def
return def
end
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment