Any way to override registered decoration?

Post Reply
Termos
Member
Posts: 417
Joined: Sun Dec 16, 2018 12:50

Any way to override registered decoration?

by Termos » Post

Can't find any in the docs.
Tried registering under same name, but deco registration doesn't follow the colon convention, so exactly same name doesn't work because it's already taken, and using colon prefix it just registers a new decoration with the name beginning with a colon leaving the old definition intact.

Termos
Member
Posts: 417
Joined: Sun Dec 16, 2018 12:50

Re: Any way to override registered decoration?

by Termos » Post

Nevermind, looks like there's no dedicated api for that, but the workaround is simple enough not to bother.

Code: Select all

local exclude = {"default:apple_tree"}
local decpy = table.copy(minetest.registered_decorations)
minetest.clear_registered_decorations()
for k,v in pairs(decpy) do
	if not isin(v.name,exclude) then minetest.register_decoration(v) end
end

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Any way to override registered decoration?

by sirrobzeroone » Post

Lua dosen't appear to have builtin "isin" function. I found a function (thanks stackoverflow) that does a check and works so just adding this for others in the future:

Code: Select all

local function has_value (tab, val)
    for index, value in pairs(tab) do
        if value == val then
            return true
        end
    end
    return false
end

local exclude = {"default:apple_tree"}
local decpy = table.copy(minetest.registered_decorations)
minetest.clear_registered_decorations()
for k,v in pairs(decpy) do
	if not has_value(exclude,v.name) then minetest.register_decoration(v) end
end

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests