Created
June 27, 2022 16:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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