-
Notifications
You must be signed in to change notification settings - Fork 0
/
lights.lua
186 lines (147 loc) · 3.49 KB
/
lights.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
local function swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
local loffs = {
{x=0, y=4, z=4},
{x=0, y=4, z=-4},
{x=4, y=4, z=0},
{x=-4, y=4, z=0},
{x=7, y=8, z=7},
{x=7, y=8, z=-7},
{x=-7, y=8, z=7},
{x=-7, y=8, z=-7},
{x=9, y=8, z=0},
{x=-9, y=8, z=0},
{x=0, y=8, z=-9},
{x=0, y=8, z=-9},
{x=0, y=16, z=0},
}
local function destruct_light(pos)
for _,v in ipairs(loffs) do
local p = vector.add(pos, v)
local n = minetest.get_node(p)
if n.name == "bitumen:magic_light" then
minetest.set_node(p, {name="air"})
end
end
end
local function try_turn_on(pos)
local bpos = {x=pos.x, y=pos.y - 1, z=pos.z}
local bnode = minetest.get_node(bpos)
local bmeta = minetest.env:get_meta(bpos)
if not bmeta or bnode.name ~= "bitumen:oil_drum" then
swap_node(pos, "bitumen:kerosene_light")
destruct_light(pos)
return
end
local fluid = bmeta:get_string("fluid")
local fill = bmeta:get_int("fill")
local max_fill = bmeta:get_int("maxfill")
if not fill or fill == 0 then
swap_node(pos, "bitumen:kerosene_light")
destruct_light(pos)
return
end
local taken = 1
-- turn on
for _,v in ipairs(loffs) do
local p = vector.add(pos, v)
local n = minetest.get_node(p)
if n.name == "air" then
minetest.set_node(p, {name="bitumen:magic_light"})
-- else
end
end
bmeta:set_float("fill", math.max(fill - taken, 0))
bmeta:set_string("infotext", fluid .." (".. math.floor(((fill-taken)*100/max_fill)+0.5) .."%)")
end
minetest.register_node("bitumen:kerosene_light", {
description = "Kerosene Light",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -.1, -.4, -.1, .1, .5, .1},
{ -.4, -.5, -.4, .4, -.3, .4},
{ -.4, .5, -.4, .41, .51, .41},
},
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
},
},
paramtype = "light",
is_ground_content = false,
tiles = { "default_wood.png" },
walkable = true,
groups = { cracky = 3, petroleum_fixture = 1 },
light_source = 1,
on_punch = function(pos)
swap_node(pos, "bitumen:kerosene_light_on")
try_turn_on(pos)
end,
on_destruct = destruct_light,
})
minetest.register_node("bitumen:kerosene_light_on", {
description = "Kerosene Light",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -.1, -.4, -.1, .1, .5, .1},
{ -.4, -.5, -.4, .4, -.3, .4},
},
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
},
},
paramtype = "light",
is_ground_content = false,
tiles = { "default_meselamp.png" },
walkable = true,
groups = { cracky = 3, petroleum_fixture = 1 },
light_source = default.LIGHT_MAX,
on_punch = function(pos)
swap_node(pos, "bitumen:kerosene_light")
destruct_light(pos)
end,
on_destruct = destruct_light,
})
minetest.register_node("bitumen:magic_light", {
description = "Hidden Magic Light",
drawtype = "airlike",
-- tiles = {"default_mese.png"},
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
light_source = default.LIGHT_MAX,
})
minetest.register_abm({
nodenames = {"bitumen:kerosene_light_on"},
-- neighbors = {"bitumen:oil_drum"},
interval = 60,
chance = 1,
action = function(pos, node)
try_turn_on(pos)
end,
})
--[[ cleanup failsafe
minetest.register_abm({
nodenames = {"bitumen:magic_light"},
interval = 30,
chance = 1,
action = function(pos, node)
minetest.set_node(pos, {name="air"})
end,
})
]]