summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
Diffstat (limited to 'locks')
-rw-r--r--locks/init.lua211
-rw-r--r--locks/shared_locked_chest.lua39
-rw-r--r--locks/shared_locked_furnace.lua31
-rw-r--r--locks/shared_locked_sign_wall.lua27
-rw-r--r--locks/shared_locked_xdoors2.lua90
5 files changed, 302 insertions, 96 deletions
diff --git a/locks/init.lua b/locks/init.lua
index 0f2ba58..e8a1355 100644
--- a/locks/init.lua
+++ b/locks/init.lua
@@ -18,10 +18,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
--]]
--- Version 2.00
+-- Version 2.10
-- Changelog:
+-- 30.07.2018 * Merged PR from adrido from 25.02.2016: Added new Locks config Formspec.
+-- 30.07.2018 * Removed deprecated minetest.env usage.
-- 30.07.2018 * Front side of chest does not get pipeworks image anymore.
+-- Instead it always shows the locks texture as overlay.
-- 30.07.2018 * Fixed bug with pipeworks.
-- * Repaired password.
-- * Converted back to unix file format.
@@ -42,6 +45,108 @@ minetest.register_privilege("openlocks", { description = "allows to open/use all
minetest.register_privilege("diglocks", { description = "allows to open/use and dig up all locked objects", give_to_singleplayer = false});
+locks.config_button = [[
+ image_button[%d,%d;1,1;locks_lock16.png;locks_config;Config
+Locks]
+ tooltip[locks_config;Configure the players or set the password to grant access to other players.]
+]]
+
+function locks.get_config_button(x,y)
+ return locks.config_button:format((x or 0), (y or 0))
+end
+
+locks.authorize_button = [[
+ image_button[%d,%d;1,1;locks_key16.png;locks_authorize;Autho-
+rize]
+ tooltip[locks_authorize;Opens a password prompt to grant you access to this object.]
+]]
+function locks.get_authorize_button(x,y)
+ return locks.authorize_button:format((x or 1), (y or 0))
+end
+
+locks.password_prompt = [[
+ size[6,3;]
+ pwdfield[0.5,1;5.5,0;password;Enter password:]
+ tooltip[password;Opens a password prompt to grant you access to this object.]
+
+ box[0.1,1.5;5.5,0.05;#FFFFFF]
+ button[1.5,2;3,1;proceed;Proceed]
+]]
+function locks.prompt_password(playername, formname)
+ local fs = locks.password_prompt;
+ minetest.show_formspec(playername, formname, fs);
+end
+
+function locks.access_denied(playername, formname, ask_for_pw)
+ local fs = [[
+ size[6,3;]
+ label[0.5,1;Access denied]
+
+ box[0.1,1.5;5.5,0.05;#FFFFFF]
+ button_exit[4,2;2,1;cancel;Cancel]
+]];
+ if ask_for_pw == true then
+ fs = fs.."button[0,2;3.5,1;enter_password;Enter Password]";
+ end
+ minetest.show_formspec(playername, formname, fs);
+end
+
+locks.access_granted_formspec = [[
+ size[6,3;]
+ label[0.5,1;Access granted]
+
+ box[0.1,1.5;5.5,0.05;#FFFFFF]
+ button_exit[1.5,2;3,1;proceed;Proceed]
+]]
+function locks.access_granted(playername, formname)
+ minetest.show_formspec(playername, formname, locks.access_granted_formspec);
+end
+
+locks.config_formspec = [[
+ size[12,9;]
+
+ image[0,0;0.7,0.7;locks_lock32.png] label[0.7,0;Locks configuration panel]
+ box[0.1,0.6;11.5,0.05;#FFFFFF]
+
+ label[0.1,0.7;Owner: %q]
+
+ checkbox[0.1,1;pipeworks;Enable Pipeworks;%s]
+ tooltip[pipeworks;Tubes from pipeworks may be used to extract items out of/add items to this shared locked object.]
+
+ textarea[0.4,2;6.5,4;allowed_users;Allowed Players:;%s]
+ label[6.5,2;Insert the Playernames here,
+that should have access to this Object.
+One Player per line]
+ tooltip[allowed_users;Insert the Playernames here,
+that should have access to this Object.
+One Player per line]
+
+ field[0.4,6.5;4.5,0;password;Password:;%s] button[4.5,6.2;2,0;save_pw;Set PW]
+ tooltip[password;Every player with this password can access this object]
+ label[6.5,5.5;Specify a password here.
+Every Player with this password can access this object.
+Set an empty Password to remove the Password]
+
+ box[0.1,8.5;11.5,0.05;#FFFFFF]
+ button_exit[4,9;2,0;ok;OK] button_exit[6,9;2,0;cancel;Cancel]
+]]
+locks.uniform_background = "";
+
+if default and default.gui_bg then
+ locks.uniform_background = locks.uniform_background..default.gui_bg;
+end
+
+if default and default.gui_bg_img then
+ locks.uniform_background = locks.uniform_background..default.gui_bg_img;
+end
+
+if default and default.gui_slots then
+ locks.uniform_background = locks.uniform_background..default.gui_slots;
+end
+
+locks.config_formspec = locks.config_formspec..locks.uniform_background
+
+
locks.pipeworks_enabled = false;
if( minetest.get_modpath("pipeworks") ~= nil ) then
@@ -62,7 +167,7 @@ function locks:lock_init( pos, default_formspec )
return;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
if( meta == nil ) then
print( "Error: [locks] lock_init: unable to get meta data");
return;
@@ -79,7 +184,9 @@ function locks:lock_init( pos, default_formspec )
-- the last player who entered the right password (to save space this is not a list)
meta:set_string("pw_user","");
-- this formspec is presented on right-click for every user
- meta:set_string("formspec", default_formspec);
+ meta:set_string("formspec", default_formspec..
+ locks.get_authorize_button(6,0)..
+ locks.get_config_button(7,0));
-- by default, do not send output to pipework tubes
meta:set_int( "allow_pipeworks", 0 );
end
@@ -91,7 +198,7 @@ function locks:get_lockdata( pos )
return;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
if( meta == nil) then
return;
end
@@ -112,7 +219,7 @@ function locks:set_lockdata( pos, data )
return;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
if( meta == nil) then
return;
end
@@ -140,7 +247,7 @@ function locks:lock_set_owner( pos, player_or_name, description )
return false;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
if( meta == nil ) then
print( "Error: [locks] lock_set_owner: unable to get meta data");
return;
@@ -170,7 +277,7 @@ function locks:lock_allow_dig( pos, player )
return false;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
local lock_owner = meta:get_string("owner");
-- locks who lost their owner can be opened/digged by anyone
@@ -210,7 +317,7 @@ function locks:lock_allow_use( pos, player )
end
local name = player:get_player_name();
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
-- pipeworks sends a special username
if( player.is_fake_player) then
@@ -302,12 +409,49 @@ function locks:lock_handle_input( pos, formname, fields, player )
return false;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
if( meta == nil ) then
print( "Error: [locks] lock_handle_input: unable to get meta data");
return;
end
+ local name = player:get_player_name();
+ local owner = meta:get_string("owner");
+
+ --first check for locks_config_button
+ if fields.locks_config then
+ -- else the player could set a new pw and gain access anyway...
+ if( owner and owner ~= "" and owner ~= name ) then
+ minetest.chat_send_player(name, "Only the owner can change the configuration.");
+ return;
+ end
+ local allow_pipeworks = "false";
+ if meta:get_int( 'allow_pipeworks' ) == 1 then
+ allow_pipeworks = "true";
+ end
+ local data = locks:get_lockdata( pos );
+ local fs = locks.config_formspec:format(data.owner,
+ allow_pipeworks,
+ data.allowed_users:gsub(",","\n"),
+ meta:get_string("password"));
+ minetest.show_formspec(player:get_player_name(), "locks_config:"..minetest.pos_to_string(pos), fs);
+ return true; -- we could full handle the input. No need to continue. so we return true
+ elseif fields.locks_authorize then
+ local data = locks:get_lockdata( pos );
+
+ if name == data.owner then
+ minetest.chat_send_player(name, "You are the owner of this object. Its not required to enter a password.",false)
+ elseif minetest.string_to_privs(meta:get_string("allowed_users"))[name] then
+ minetest.chat_send_player(name, "You are already authorized in the whitelist. Its not required to enter a password.",false)
+ else
+
+ local fs = locks.password_prompt;
+ minetest.show_formspec(name, "locks_authorize:"..minetest.pos_to_string(pos), fs);
+ end
+ return true;
+ end
+
+
-- is this input the lock is supposed to handle?
if( ( not( fields.locks_sent_lock_command )
or fields.locks_sent_lock_command == "" )
@@ -316,8 +460,6 @@ function locks:lock_handle_input( pos, formname, fields, player )
return;
end
- name = player:get_player_name();
-
if( fields.locks_sent_lock_command == "/help" ) then
if( name == meta:get_string( "owner" )) then
@@ -559,6 +701,51 @@ function locks:lock_handle_input( pos, formname, fields, player )
end
+--this is required to handle the locks control panel
+minetest.register_on_player_receive_fields(function(player, formname, fields)
+ local playername = player:get_player_name();
+ if formname:find("locks_config:") then -- search if formname contains locks
+ --minetest.chat_send_player(playername,dump(fields));
+ local pos = minetest.string_to_pos(formname:gsub("locks_config:",""))
+ if fields.ok then
+ local data = locks:get_lockdata( pos )
+ data.allowed_users = fields.allowed_users:gsub("\n",",");
+ --data.password = fields.password;
+ locks:set_lockdata( pos, data )
+ --print("Player "..player:get_player_name().." submitted fields "..dump(fields))
+ elseif fields.save_pw then
+ local data = locks:get_lockdata( pos )
+ data.password = fields.password;
+ locks:set_lockdata( pos, data );
+ elseif fields.pipeworks then
+ local meta = minetest.get_meta(pos);
+ if fields.pipeworks == "true" then
+ meta:set_int( 'allow_pipeworks', 1 );
+ else
+ meta:set_int( 'allow_pipeworks', 0 );
+ end
+ end
+ return true; --everything handled good :)
+
+ elseif formname:find("locks_authorize:") then
+ if fields.password and fields.password ~="" then
+ local pos = minetest.string_to_pos(formname:gsub("locks_authorize:",""))
+ local meta = minetest.get_meta(pos);
+ if meta:get_string("password")==fields.password then
+ locks.access_granted(playername, formname);
+ meta:set_string("pw_user", playername)
+ else
+ locks.access_denied(playername, formname, true);
+
+ end
+ elseif fields.enter_password then --if the user clicks the "Enter Password" button in the "access denied" formspec
+ locks.prompt_password(playername, formname);
+ end
+
+ return true --evrything is great :)
+ end
+ return false;
+end)
-- craftitem; that can be used to craft shared locked objects
minetest.register_craftitem("locks:lock", {
@@ -611,5 +798,3 @@ dofile(minetest.get_modpath("locks").."/shared_locked_chest.lua");
dofile(minetest.get_modpath("locks").."/shared_locked_sign_wall.lua");
dofile(minetest.get_modpath("locks").."/shared_locked_xdoors2.lua");
dofile(minetest.get_modpath("locks").."/shared_locked_furnace.lua");
-
-
diff --git a/locks/shared_locked_chest.lua b/locks/shared_locked_chest.lua
index f40bde8..db4a7a0 100644
--- a/locks/shared_locked_chest.lua
+++ b/locks/shared_locked_chest.lua
@@ -1,9 +1,10 @@
+-- 25.02.16 Added new Locks config Buttons.
-- 09.01.13 Added support for pipeworks.
locks.chest_add = {};
locks.chest_add.tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
- "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"};
+ "default_chest_side.png", "default_chest_side.png", "default_chest_front.png^locks_lock16.png"};
locks.chest_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2};
locks.chest_add.tube = {};
@@ -16,17 +17,17 @@ if( locks.pipeworks_enabled ) then
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
- "default_chest_front.png"};
+ "default_chest_front.png^locks_lock16.png"};
locks.chest_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,
tubedevice = 1, tubedevice_receiver = 1 };
locks.chest_add.tube = {
insert_object = function(pos, node, stack, direction)
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("main", stack)
end,
can_insert = function(pos, node, stack, direction)
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("main", stack)
end,
@@ -45,20 +46,28 @@ minetest.register_node("locks:shared_locked_chest", {
legacy_facedir_simple = true,
on_construct = function(pos)
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
-- prepare the lock of the chest
locks:lock_init( pos,
"size[8,10]"..
--- "field[0.5,0.2;8,1.0;locks_sent_lock_command;Locked chest. Type password, command or /help for help:;]"..
--- "button_exit[3,0.8;2,1.0;locks_sent_input;Proceed]"..
- "list[current_name;main;0,0;8,4;]"..
- "list[current_player;main;0,5;8,4;]"..
- "field[0.3,9.6;6,0.7;locks_sent_lock_command;Locked chest. Type /help for help:;]"..
- "background[-0.5,-0.65;9,11.2;bg_shared_locked_chest.jpg]"..
- "button_exit[6.3,9.2;1.7,0.7;locks_sent_input;Proceed]" );
--- "size[8,9]"..
+---- "field[0.5,0.2;8,1.0;locks_sent_lock_command;Locked chest. Type password, command or /help for help:;]"..
+---- "button_exit[3,0.8;2,1.0;locks_sent_input;Proceed]"..
-- "list[current_name;main;0,0;8,4;]"..
--- "list[current_player;main;0,5;8,4;]");
+-- "list[current_player;main;0,5;8,4;]"..
+-- "field[0.3,9.6;6,0.7;locks_sent_lock_command;Locked chest. Type /help for help:;]"..
+-- "background[-0.5,-0.65;9,11.2;bg_shared_locked_chest.jpg]"..
+-- "button_exit[6.3,9.2;1.7,0.7;locks_sent_input;Proceed]" );
+---- "size[8,9]"..
+---- "list[current_name;main;0,0;8,4;]"..
+---- "list[current_player;main;0,5;8,4;]");
+ locks.uniform_background ..
+ "list[current_name;main;0,1;8,4;]"..
+ "list[current_player;main;0,5.85;8,1;]" ..
+ "list[current_player;main;0,7.08;8,3;8]" ..
+ "listring[current_name;main]" ..
+ "listring[current_player;main]" ..
+ default.get_hotbar_bg(0,5.85) );
+
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
@@ -78,7 +87,7 @@ minetest.register_node("locks:shared_locked_chest", {
if( not(locks:lock_allow_dig( pos, player ))) then
return false;
end
- local meta = minetest.env:get_meta(pos);
+ local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
diff --git a/locks/shared_locked_furnace.lua b/locks/shared_locked_furnace.lua
index 1543c7b..c18adf0 100644
--- a/locks/shared_locked_furnace.lua
+++ b/locks/shared_locked_furnace.lua
@@ -3,6 +3,7 @@
-- containing only the furnace and adopted slightly for my locks mod
+-- 25.02.16 Added new Locks config Buttons.
-- 09.01.13 Added support for pipeworks.
@@ -60,7 +61,7 @@ if( locks.pipeworks_enabled ) then
tubedevice = 1, tubedevice_receiver = 1 };
locks.furnace_add.tube = {
insert_object = function(pos, node, stack, direction)
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:add_item("fuel",stack)
@@ -69,7 +70,7 @@ if( locks.pipeworks_enabled ) then
end
end,
can_insert = function(pos, node, stack, direction)
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
@@ -86,29 +87,29 @@ end
function locks.get_furnace_active_formspec(pos, percent)
local formspec =
"size[8,9]"..
- "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
+ "image[2,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
(100-percent)..":default_furnace_fire_fg.png]"..
- "list[current_name;fuel;2,3;1,1;]"..
- "list[current_name;src;2,1;1,1;]"..
+ "list[current_name;fuel;2,2.5;1,1;]"..
+ "list[current_name;src;2,0.5;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"..
- "background[-0.5,-0.65;9,10.35;bg_shared_locked_furnace.jpg]"..
-
- "field[0.3,4.5;6,0.7;locks_sent_lock_command;Locked furnace. Type /help for help:;]"..
- "button_exit[6.3,4;1.7,0.7;locks_sent_input;Proceed]" ;
+ locks.uniform_background..
+ locks.get_authorize_button(6,0)..
+ locks.get_config_button(7,0)
+
return formspec
end
locks.furnace_inactive_formspec =
"size[8,9]"..
- "image[2,2;1,1;default_furnace_fire_bg.png]"..
- "list[current_name;fuel;2,3;1,1;]"..
- "list[current_name;src;2,1;1,1;]"..
+ "image[2,1.5;1,1;default_furnace_fire_bg.png]"..
+ "list[current_name;fuel;2,2.5;1,1;]"..
+ "list[current_name;src;2,0.5;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"..
- "background[-0.5,-0.65;9,10.35;bg_shared_locked_furnace.jpg]"..
- "field[0.3,4.5;6,0.7;locks_sent_lock_command;Locked furnace. Type /help for help:;]"..
- "button_exit[6.3,4;1.7,0.7;locks_sent_input;Proceed]" ;
+ locks.uniform_background..
+ locks.get_authorize_button(6,0)..
+ locks.get_config_button(7,0)
minetest.register_node("locks:shared_locked_furnace", {
description = "Shared locked furnace",
diff --git a/locks/shared_locked_sign_wall.lua b/locks/shared_locked_sign_wall.lua
index c04d33e..209c8ef 100644
--- a/locks/shared_locked_sign_wall.lua
+++ b/locks/shared_locked_sign_wall.lua
@@ -1,4 +1,5 @@
+-- 25.02.16 Added new Locks config Buttons.
-- allow aborting with ESC in newer Versions of MT again
-- a sign
@@ -23,14 +24,15 @@ minetest.register_node("locks:shared_locked_sign_wall", {
on_construct = function(pos)
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
-- prepare the lock of the sign
locks:lock_init( pos,
"size[8,4]"..
"field[0.3,0.6;6,0.7;text;Text:;${text}]"..
- "field[0.3,3.6;6,0.7;locks_sent_lock_command;Locked sign. Type /help for help:;]"..
- "button_exit[6.3,3.2;1.7,0.7;locks_sent_input;Proceed]");
+-- "field[0.3,3.6;6,0.7;locks_sent_lock_command;Locked sign. Type /help for help:;]"..
-- "background[-0.5,-0.5;9,5;bg_shared_locked_sign.jpg]" );
+ "button_exit[6.3,3.2;1.7,0.7;locks_sent_input;Proceed]"..
+ locks.uniform_background );
end,
after_place_node = function(pos, placer)
@@ -44,24 +46,23 @@ minetest.register_node("locks:shared_locked_sign_wall", {
on_receive_fields = function(pos, formname, fields, sender)
- -- if the user already has the right to use this and did input text
- if( fields.text
- and ( not(fields.locks_sent_lock_command)
- or fields.locks_sent_lock_command=="")
+ -- if locks can not handle the input
+ if not locks:lock_handle_input( pos, formname, fields, sender ) then
+ --then handle compatibility stuff or insert text
+ if( fields.text
+ and ( not(fields.locks_sent_lock_command) --compatibility
+ or fields.locks_sent_lock_command=="") --compatibility
and locks:lock_allow_use( pos, sender )) then
--print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields))
- local meta = minetest.env:get_meta(pos)
+ local meta = minetest.get_meta(pos)
fields.text = fields.text or "";
print((sender:get_player_name() or "").." wrote \""..fields.text..
"\" to sign at "..minetest.pos_to_string(pos));
meta:set_string("text", fields.text);
meta:set_string("infotext", '"'..fields.text..'"'.." ["..sender:get_player_name().."]");
-
- -- a command for the lock?
- else
- locks:lock_handle_input( pos, formname, fields, sender );
- end
+ end
+ end
end,
});
diff --git a/locks/shared_locked_xdoors2.lua b/locks/shared_locked_xdoors2.lua
index 1af36fc..eb96f5c 100644
--- a/locks/shared_locked_xdoors2.lua
+++ b/locks/shared_locked_xdoors2.lua
@@ -1,7 +1,8 @@
--- xDoors² mod by xyz
+-- xDoors² mod by xyz
-- modified by Sokomine to allow locked doors that can only be opened/closed/dig up by the player who placed them
-- a little bit modified by addi to allow someone with the priv "opendoors" to open/close/dig all locked doors.
-- Sokomine: modified again so that it uses the new locks-mod
+-- 25.02.16 Added new Locks config Buttons.
local door_bottom = {-0.5, -0.5, -0.5, 0.5, 0.5, -0.4}
local door_top = {
@@ -33,13 +34,15 @@ local xdoors2_transform = function(pos, node, puncher)
local p2 = 0
if t == 2 then
p2 = (node.param2 + 1) % 4
+ minetest.sound_play("doors_door_open", { pos = pos, gain = 0.3, max_hear_distance = 10})
else
p2 = (node.param2 + 3) % 4
+ minetest.sound_play("doors_door_close", { pos = pos, gain = 0.3, max_hear_distance = 10})
end
local olddata = locks:get_lockdata( pos );
- minetest.env:add_node(pos, {name = "locks:door_bottom_"..t, param2 = p2})
- minetest.env:add_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "locks:door_top_"..t, param2 = p2})
+ minetest.add_node(pos, {name = "locks:door_bottom_"..t, param2 = p2})
+ minetest.add_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "locks:door_top_"..t, param2 = p2})
-- remember who owns the door, what passwords are set etc.
locks:set_lockdata( pos, olddata );
@@ -51,8 +54,8 @@ local xdoors2_destruct = function(pos, oldnode)
if is_top(oldnode.name) then
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
end
- minetest.env:remove_node(pos)
- minetest.env:remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
+ minetest.remove_node(pos)
+ minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
end
for i = 1, 2 do
@@ -77,8 +80,8 @@ for i = 1, 2 do
on_construct = function(pos)
locks:lock_init( pos,
"size[8,2]"..
- "field[0.3,0.6;6,0.7;locks_sent_lock_command;Locked door. Type /help for help:;]"..
- "button_exit[6.3,1.2;1.7,0.7;locks_sent_input;Proceed]" );
+ locks.uniform_background..
+ "button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" );
end,
on_receive_fields = function(pos, formname, fields, sender)
@@ -110,8 +113,8 @@ for i = 1, 2 do
on_construct = function(pos)
locks:lock_init( pos,
"size[8,2]"..
- "field[0.3,0.6;6,0.7;locks_sent_lock_command;Locked door. Type /help for help:;]"..
- "button_exit[6.3,0.2;1.7,0.7;locks_sent_input;Proceed]" );
+ locks.uniform_background..
+ "button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" );
end,
on_receive_fields = function(pos, formname, fields, sender)
@@ -137,40 +140,47 @@ minetest.register_node("locks:door", {
inventory_image = 'locks_xdoors2_door.png',
wield_image = 'xdoors2_door.png',
stack_max = 1,
+ sunlight_propogates = true,
on_place = function(itemstack, placer, pointed_thing)
local above = pointed_thing.above
-
- -- there should be 2 empty nodes
- if minetest.env:get_node({x = above.x, y = above.y + 1, z = above.z}).name ~= "air" then
- return itemstack
- end
+ local above1 = {x = above.x, y = above.y + 1, z = above.z};
+ if (minetest.is_protected(above, placer:get_player_name())
+ or minetest.is_protected(above1, placer:get_player_name())) then
+ minetest.chat_send_player(placer:get_player_name(), "This area is protected!")
+ return itemstack
+ else
+ -- there should be 2 empty nodes
+ if minetest.get_node(above1).name ~= "air" then
+ return itemstack
+ end
- local fdir = 0
- local placer_pos = placer:getpos()
- if placer_pos then
- dir = {
- x = above.x - placer_pos.x,
- y = above.y - placer_pos.y,
- z = above.z - placer_pos.z
- }
- fdir = minetest.dir_to_facedir(dir)
- end
-
- local t = 1
- local another_door = minetest.env:get_node({x = above.x + delta[fdir + 1].x, y = above.y, z = above.z + delta[fdir + 1].z})
- if (another_door.name:sub(-1) == "1" and another_door.param2 == fdir)
- or (another_door.name:sub(-1) == "2" and another_door.param2 == (fdir + 1) % 4) then
- t = 2
- end
-
- minetest.env:add_node(above, {name = "locks:door_bottom_"..t, param2 = fdir})
- minetest.env:add_node({x = above.x, y = above.y + 1, z = above.z}, {name = "locks:door_top_"..t, param2 = fdir})
-
- -- store who owns the door; the other data can be default for now
- locks:lock_set_owner( above, placer:get_player_name() or "", "Shared locked door");
- locks:lock_set_owner( {x = above.x, y = above.y + 1, z = above.z}, placer:get_player_name() or "", "Shared locked door");
-
- return ItemStack("")
+ local fdir = 0
+ local placer_pos = placer:getpos()
+ if placer_pos then
+ dir = {
+ x = above.x - placer_pos.x,
+ y = above.y - placer_pos.y,
+ z = above.z - placer_pos.z
+ }
+ fdir = minetest.dir_to_facedir(dir)
+ end
+
+ local t = 1
+ local another_door = minetest.get_node({x = above.x + delta[fdir + 1].x, y = above.y, z = above.z + delta[fdir + 1].z})
+ if (another_door.name:sub(-1) == "1" and another_door.param2 == fdir)
+ or (another_door.name:sub(-1) == "2" and another_door.param2 == (fdir + 1) % 4) then
+ t = 2
+ end
+
+ minetest.add_node(above, {name = "locks:door_bottom_"..t, param2 = fdir})
+ minetest.add_node({x = above.x, y = above.y + 1, z = above.z}, {name = "locks:door_top_"..t, param2 = fdir})
+
+ -- store who owns the door; the other data can be default for now
+ locks:lock_set_owner( above, placer:get_player_name() or "", "Shared locked door");
+ locks:lock_set_owner( {x = above.x, y = above.y + 1, z = above.z}, placer:get_player_name() or "", "Shared locked door");
+
+ return ItemStack("")
+ end
end
})