forked from ThorfinnS/fun_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint.lua
104 lines (90 loc) · 2.61 KB
/
paint.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- Fun_tools paint.lua
-- Copyright Duane Robertson ([email protected]), 2019
-- Distributed under the LGPLv2.1 (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html)
local mod = fun_tools
local mod_name = 'fun_tools'
------------------------------------------------
-- Magic Paint... really!
------------------------------------------------
do
for _, i in pairs({ 'bucket:bucket_empty', 'wooden_bucket:bucket_wood_empty' }) do
local n = minetest.registered_items[i]
if n then
local groups = n.groups
local ct = 0
for k, v in pairs(groups) do
ct = ct + 1
end
if ct == 0 then
groups = {}
end
groups.buckets = 1
n.groups = groups
minetest.override_item(i, { groups = groups })
end
end
local descs = {
{ 'Stone', 'stone', 'elixirs_paint_gray', 'grey', {
['default:desert_stonebrick'] = 'default:stonebrick',
['default:sandstonebrick'] = 'default:stonebrick',
}, },
{ 'Desert Stone', 'desert_stone', 'elixirs_paint_red', 'red', {
['default:stonebrick'] = 'default:desert_stonebrick',
['default:sandstonebrick'] = 'default:desert_stonebrick',
}, },
{ 'Sandstone', 'sandstone', 'elixirs_paint_sand', 'white', {
['default:stonebrick'] = 'default:sandstonebrick',
['default:desert_stonebrick'] = 'default:sandstonebrick',
}, },
}
local convert = { }
for _, desc in pairs(descs) do
local name = desc[1]
local material = desc[2]
local image = desc[3]..'.png'
local dye = 'dye:'..desc[4]
convert[material] = desc[5]
minetest.register_craftitem(mod_name..':paint_'..material, {
description = 'Dr Robertson\'s Patented '..name..' Paint',
drawtype = 'plantlike',
paramtype = 'light',
tiles = { image },
inventory_image = image,
groups = { dig_immediate = 3, vessel = 1 },
--sounds = default.node_sound_glass_defaults(),
on_use = function(itemstack, user, pointed_thing)
if not (itemstack and user and pointed_thing and pointed_thing.under) then
return
end
--print(dump(pointed_thing))
local n = minetest.get_node_or_nil(pointed_thing.under)
if not n then
return
end
local dn = minetest.registered_items[n.name]
if not dn or not dn.groups then
return
end
local dto = convert[material][n.name]
if dto then
minetest.swap_node(pointed_thing.under, { name=dto, param2 = n.param2 })
else
--print(n.name)
return
end
itemstack:take_item()
return itemstack
end,
})
minetest.register_craft({
type = 'shapeless',
output = mod_name..':paint_'..material..' 20',
recipe = {
mod.magic_ingredient,
dye,
dye,
'group:buckets',
},
})
end
end