0
0
Fork 0
This commit is contained in:
Wuzzy 2019-09-10 17:23:11 +02:00
commit e88e95d564
1 changed files with 41 additions and 26 deletions

View File

@ -123,21 +123,25 @@ function mcl_doors:register_door(name, def)
return itemstack return itemstack
end end
-- get left coordinate for checking if another door is there
local pt_left = {x=pt.x, y=pt.y, z=pt.z}
local p2 = minetest.dir_to_facedir(placer:get_look_dir()) local p2 = minetest.dir_to_facedir(placer:get_look_dir())
local pt3 = {x=pt.x, y=pt.y, z=pt.z}
if p2 == 0 then if p2 == 0 then
pt3.x = pt3.x-1 pt_left.x = pt_left.x-1
elseif p2 == 1 then elseif p2 == 1 then
pt3.z = pt3.z+1 pt_left.z = pt_left.z+1
elseif p2 == 2 then elseif p2 == 2 then
pt3.x = pt3.x+1 pt_left.x = pt_left.x+1
elseif p2 == 3 then elseif p2 == 3 then
pt3.z = pt3.z-1 pt_left.z = pt_left.z-1
end end
local left_node = minetest.get_node(pt_left)
-- Set door nodes -- Set door nodes
minetest.set_node(pt, {name=name.."_b_1", param2=p2}) minetest.set_node(pt, {name=name.."_b_1", param2=p2})
minetest.set_node(pt2, {name=name.."_t_1", param2=p2}) minetest.set_node(pt2, {name=name.."_t_1", param2=p2})
-- TODO: Mirror door when 2 doors are placed next to each other, to create double doors
if def.sounds and def.sounds.place then if def.sounds and def.sounds.place then
minetest.sound_play(def.sounds.place, {pos=pt}) minetest.sound_play(def.sounds.place, {pos=pt})
@ -150,12 +154,19 @@ function mcl_doors:register_door(name, def)
meta:set_string("doors_owner", "") meta:set_string("doors_owner", "")
end end
-- Save open state. 1 = open. 0 = closed local meta1 = minetest.get_meta(pt)
local meta = minetest.get_meta(pt) local meta2 = minetest.get_meta(pt2)
meta:set_int("is_open", 0) -- save mirror state for the correct door
meta = minetest.get_meta(pt2) if left_node.name:sub(1, #name) == name then
meta:set_int("is_open", 0) meta1:set_int("is_mirrored", 1)
meta2:set_int("is_mirrored", 1)
end
-- Save open state. 1 = open. 0 = closed
meta1:set_int("is_open", 0)
meta2:set_int("is_open", 0)
if not minetest.settings:get_bool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
@ -170,24 +181,28 @@ function mcl_doors:register_door(name, def)
local tt = def.tiles_top local tt = def.tiles_top
local tb = def.tiles_bottom local tb = def.tiles_bottom
local function on_open_close(pos, dir, check_name, replace, replace_dir, params) local function on_open_close(pos, dir, check_name, replace, replace_dir)
local meta1 = minetest.get_meta(pos) local meta1 = minetest.get_meta(pos)
pos.y = pos.y+dir pos.y = pos.y+dir
local meta2 = minetest.get_meta(pos) local meta2 = minetest.get_meta(pos)
if not minetest.get_node(pos).name == check_name then
-- if name of other door is not the same as check_name -> return
if not minetest.get_node(pos).name == check_name then
return return
end end
-- swap directions if mirrored
local params = {3,0,1,2}
if meta1:get_int("is_open") == 0 and meta2:get_int("is_mirrored") == 0 or meta1:get_int("is_open") == 1 and meta2:get_int("is_mirrored") == 1 then
params = {1,2,3,0}
end
local p2 = minetest.get_node(pos).param2 local p2 = minetest.get_node(pos).param2
local np2 = params[p2+1] local np2 = params[p2+1]
local metatable = minetest.get_meta(pos):to_table() minetest.swap_node(pos, {name=replace_dir, param2=np2})
minetest.set_node(pos, {name=replace_dir, param2=np2})
minetest.get_meta(pos):from_table(metatable)
pos.y = pos.y-dir pos.y = pos.y-dir
metatable = minetest.get_meta(pos):to_table() minetest.swap_node(pos, {name=replace, param2=np2})
minetest.set_node(pos, {name=replace, param2=np2})
minetest.get_meta(pos):from_table(metatable)
local door_switching_sound local door_switching_sound
if meta1:get_int("is_open") == 1 then if meta1:get_int("is_open") == 1 then
@ -203,11 +218,11 @@ function mcl_doors:register_door(name, def)
end end
local function on_mesecons_signal_open(pos, node) local function on_mesecons_signal_open(pos, node)
on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2")
end end
local function on_mesecons_signal_close(pos, node) local function on_mesecons_signal_close(pos, node)
if not mesecon.is_powered({x=pos.x,y=pos.y+1,z=pos.z}) then if not mesecon.is_powered({x=pos.x,y=pos.y+1,z=pos.z}) then
on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1")
end end
end end
local function on_mesecons_signal_open_top(pos, node) local function on_mesecons_signal_open_top(pos, node)
@ -233,7 +248,7 @@ function mcl_doors:register_door(name, def)
if not def.only_redstone_can_open then if not def.only_redstone_can_open then
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
if check_player_priv(pos, clicker) then if check_player_priv(pos, clicker) then
on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2")
end end
end end
end end
@ -282,7 +297,7 @@ function mcl_doors:register_door(name, def)
else else
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
if check_player_priv(pos, clicker) then if check_player_priv(pos, clicker) then
on_open_close(pos, -1, name.."_b_1", name.."_t_2", name.."_b_2", {1,2,3,0}) on_open_close(pos, -1, name.."_b_1", name.."_t_2", name.."_b_2")
end end
end end
end end
@ -331,7 +346,7 @@ function mcl_doors:register_door(name, def)
else else
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
if check_player_priv(pos, clicker) then if check_player_priv(pos, clicker) then
on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1")
end end
end end
end end
@ -380,7 +395,7 @@ function mcl_doors:register_door(name, def)
else else
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
if check_player_priv(pos, clicker) then if check_player_priv(pos, clicker) then
on_open_close(pos, -1, name.."_b_2", name.."_t_1", name.."_b_1", {3,0,1,2}) on_open_close(pos, -1, name.."_b_2", name.."_t_1", name.."_b_1")
end end
end end
end end