-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.lua
82 lines (73 loc) · 2.51 KB
/
util.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function any_color.is_paintable(node)
if node == nil then return
elseif node.name == nil then return
elseif minetest.registered_nodes[node.name] == nil then return
else return minetest.registered_nodes[node.name].palette ~= nil
end
end
function any_color.dump(o)
--[[ Debug function for making tables printable.
Shame- and careless copy&paste from Stackoverflow --]]
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. any_color.dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function any_color.add_default_palette(nodename, override)
-- sets up nodename with a fitting default palette if possible
-- Returns false on error
local meta = minetest.registered_nodes[nodename]
if (meta == nil) or (meta.palette ~= nil) then return false end
if any_color.blacklist[nodename] then return false end
-- use given override otherwise choose own param
local or_param2 = (override.paramtype2 == nil)
local or_palette = (override.palette == nil)
if meta.paramtype2 == "none" then
if or_param2 then
override.paramtype2 = "color"
end
if or_palette then
override.palette = any_color.config.default_palette_256
end
elseif meta.paramtype2 == "wallmounted" then
if or_param2 then
override.paramtype2 = "colorwallmounted"
end
if or_palette then
override.palette = any_color.config.default_palette_32
end
elseif meta.paramtype2 == "facedir" then
if or_param2 then
override.paramtype2 = "colorfacedir"
end
if or_palette then
override.palette = any_color.config.default_palette_8
end
else
minetest.log('warning', "[any_color] Invalid param2type: "..meta.paramtype.." could not set pallete for "..nodename)
return false
end
-- Make param2 disappear on pickup so items stack
if not any_color.config.keep_color then
if not meta['drop'] then
override['drop'] = nodename
end
end
minetest.log("verbose","[any_color] Setting default_palette for "..nodename)
return minetest.override_item(nodename, override)
end
-- build blacklist of nodes that must not be colored according to config
any_color.blacklist = {}
for k, pattern in pairs(any_color.config.blacklist) do
for nodename, meta in pairs(minetest.registered_nodes) do
if not any_color.blacklist[nodename] and string.find(nodename, pattern) then
any_color.blacklist[nodename] = true
end
end
end