Skip to content

Commit 81259e9

Browse files
committedMay 12, 2015
De-duplicate code in doors mod in make_on_blast
1 parent 4bd1094 commit 81259e9

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed
 

Diff for: ‎mods/doors/init.lua

+9-17
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,14 @@ function doors.register_door(name, def)
115115
end
116116
end
117117

118-
local function make_on_blast(base_name, door_type, other_door_type)
118+
local function make_on_blast(base_name, dir, door_type, other_door_type)
119119
if def.only_placer_can_open then
120120
return function() end
121121
else
122-
if door_type == "_b_1" or door_type == "_b_2" then
123-
return function(pos, intensity)
124-
check_and_blast(pos, base_name .. door_type)
125-
pos.y = pos.y + 1
126-
check_and_blast(pos, base_name .. other_door_type)
127-
end
128-
elseif door_type == "_t_1" or door_type == "_t_2" then
129-
return function(pos, intensity)
130-
check_and_blast(pos, base_name .. door_type)
131-
pos.y = pos.y - 1
132-
check_and_blast(pos, base_name .. other_door_type)
133-
end
122+
return function(pos, intensity)
123+
check_and_blast(pos, base_name .. door_type)
124+
pos.y = pos.y + dir
125+
check_and_blast(pos, base_name .. other_door_type)
134126
end
135127
end
136128
end
@@ -201,7 +193,7 @@ function doors.register_door(name, def)
201193
can_dig = check_player_priv,
202194
sounds = def.sounds,
203195
sunlight_propagates = def.sunlight,
204-
on_blast = make_on_blast(name, "_b_1", "_t_1")
196+
on_blast = make_on_blast(name, 1, "_b_1", "_t_1")
205197
})
206198

207199
minetest.register_node(name.."_t_1", {
@@ -234,7 +226,7 @@ function doors.register_door(name, def)
234226
can_dig = check_player_priv,
235227
sounds = def.sounds,
236228
sunlight_propagates = def.sunlight,
237-
on_blast = make_on_blast(name, "_t_1", "_b_1")
229+
on_blast = make_on_blast(name, -1, "_t_1", "_b_1")
238230
})
239231

240232
minetest.register_node(name.."_b_2", {
@@ -267,7 +259,7 @@ function doors.register_door(name, def)
267259
can_dig = check_player_priv,
268260
sounds = def.sounds,
269261
sunlight_propagates = def.sunlight,
270-
on_blast = make_on_blast(name, "_b_2", "_t_2")
262+
on_blast = make_on_blast(name, 1, "_b_2", "_t_2")
271263
})
272264

273265
minetest.register_node(name.."_t_2", {
@@ -300,7 +292,7 @@ function doors.register_door(name, def)
300292
can_dig = check_player_priv,
301293
sounds = def.sounds,
302294
sunlight_propagates = def.sunlight,
303-
on_blast = make_on_blast(name, "_t_2", "_b_2")
295+
on_blast = make_on_blast(name, -1, "_t_2", "_b_2")
304296
})
305297

306298
end

0 commit comments

Comments
 (0)