Skip to content

Commit

Permalink
Lua API: Add function to deregister single biomes (#5445)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeuner authored and SmallJoker committed Aug 27, 2017
1 parent e09c7fc commit 1f207a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions builtin/game/register.lua
Expand Up @@ -505,6 +505,19 @@ local function make_registration_wrap(reg_fn_name, clear_fn_name)
return list
end

local function make_wrap_deregistration(reg_fn, clear_fn, list)
local unregister = function (unregistered_key)
local temporary_list = table.copy(list)
clear_fn()
for k,v in pairs(temporary_list) do
if unregistered_key ~= k then
reg_fn(v)
end
end
end
return unregister
end

core.registered_on_player_hpchanges = { modifiers = { }, loggers = { } }

function core.registered_on_player_hpchange(player, hp_change)
Expand Down Expand Up @@ -543,6 +556,8 @@ core.registered_biomes = make_registration_wrap("register_biome", "cle
core.registered_ores = make_registration_wrap("register_ore", "clear_registered_ores")
core.registered_decorations = make_registration_wrap("register_decoration", "clear_registered_decorations")

core.unregister_biome = make_wrap_deregistration(core.register_biome, core.clear_registered_biomes, core.registered_biomes)

core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
core.registered_globalsteps, core.register_globalstep = make_registration()
core.registered_playerevents, core.register_playerevent = make_registration()
Expand Down
4 changes: 4 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -715,6 +715,10 @@ the global `minetest.registered_*` tables.
* added to `minetest.registered_biome` with the key of `biome.name`
* if `biome.name` is nil, the key is the returned ID

* `minetest.unregister_biome(name)`
* Unregisters the biome name from engine, and deletes the entry with key
* `name` from `minetest.registered_biome`

* `minetest.register_ore(ore definition)`
* returns an integer uniquely identifying the registered ore
* added to `minetest.registered_ores` with the key of `ore.name`
Expand Down

0 comments on commit 1f207a3

Please sign in to comment.