forked from mtcontrib/locks
added support for pipeworks mod
This commit is contained in:
parent
1c4a406a93
commit
bfbc6712f9
@ -1 +1,2 @@
|
|||||||
default
|
default
|
||||||
|
pipeworks?
|
||||||
|
50
init.lua
50
init.lua
@ -21,9 +21,11 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
-- Version 1.16
|
-- Version 1.20
|
||||||
|
|
||||||
-- Changelog:
|
-- Changelog:
|
||||||
|
-- 10.01.2013 * Added command to toggle for pipeworks output
|
||||||
|
-- * Added pipeworks support for chests and furnace.
|
||||||
-- 17.12.2013 * aborting input with ESC is possible again
|
-- 17.12.2013 * aborting input with ESC is possible again
|
||||||
-- 01.09.2013 * fixed bug in input sanitization
|
-- 01.09.2013 * fixed bug in input sanitization
|
||||||
-- 31.08.2013 * changed receipe for key to avoid crafting conflickt with screwdriver
|
-- 31.08.2013 * changed receipe for key to avoid crafting conflickt with screwdriver
|
||||||
@ -37,6 +39,13 @@ locks = {};
|
|||||||
minetest.register_privilege("openlocks", { description = "allows to open/use all locked objects", give_to_singleplayer = false});
|
minetest.register_privilege("openlocks", { description = "allows to open/use all locked objects", give_to_singleplayer = false});
|
||||||
minetest.register_privilege("diglocks", { description = "allows to open/use and dig up all locked objects", give_to_singleplayer = false});
|
minetest.register_privilege("diglocks", { description = "allows to open/use and dig up all locked objects", give_to_singleplayer = false});
|
||||||
|
|
||||||
|
|
||||||
|
locks.pipeworks_enabled = false;
|
||||||
|
|
||||||
|
if( minetest.get_modpath("pipeworks") ~= nil ) then
|
||||||
|
locks.pipeworks_enabled = true;
|
||||||
|
end
|
||||||
|
|
||||||
-- initializes a lock (that is: prepare the metadata so that it can store data)
|
-- initializes a lock (that is: prepare the metadata so that it can store data)
|
||||||
-- default_formspec is the formspec that will be used on right click; the input field for the commands has to exist
|
-- default_formspec is the formspec that will be used on right click; the input field for the commands has to exist
|
||||||
-- Call this in on_construct in register_node. Excample:
|
-- Call this in on_construct in register_node. Excample:
|
||||||
@ -69,6 +78,8 @@ function locks:lock_init( pos, default_formspec )
|
|||||||
meta:set_string("pw_user","");
|
meta:set_string("pw_user","");
|
||||||
-- this formspec is presented on right-click for every user
|
-- this formspec is presented on right-click for every user
|
||||||
meta:set_string("formspec", default_formspec);
|
meta:set_string("formspec", default_formspec);
|
||||||
|
-- by default, do not send output to pipework tubes
|
||||||
|
meta:set_int( "allow_pipeworks", 0 );
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -199,6 +210,15 @@ function locks:lock_allow_use( pos, player )
|
|||||||
local name = player:get_player_name();
|
local name = player:get_player_name();
|
||||||
local meta = minetest.env:get_meta(pos);
|
local meta = minetest.env:get_meta(pos);
|
||||||
|
|
||||||
|
-- pipeworks sends a special username
|
||||||
|
if( name == ':pipeworks' ) then
|
||||||
|
if( meta:get_int( 'allow_pipeworks' ) == 1 ) then
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- the player has to have a key or a keychain to open his own shared locked objects
|
-- the player has to have a key or a keychain to open his own shared locked objects
|
||||||
if( name == meta:get_string("owner")) then
|
if( name == meta:get_string("owner")) then
|
||||||
|
|
||||||
@ -288,7 +308,7 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||||||
|
|
||||||
-- is this input the lock is supposed to handle?
|
-- is this input the lock is supposed to handle?
|
||||||
if( not( fields.locks_sent_lock_command )
|
if( not( fields.locks_sent_lock_command )
|
||||||
or (fields.quit and fields.quit==true)
|
or (fields.quit and (fields.quit==true or fields.quit=='true'))
|
||||||
-- or not( fields.locks_sent_input )
|
-- or not( fields.locks_sent_input )
|
||||||
or fields.locks_sent_lock_command == "" ) then
|
or fields.locks_sent_lock_command == "" ) then
|
||||||
return;
|
return;
|
||||||
@ -304,7 +324,8 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||||||
" /add <name> Player <name> can now unlock this object with any key.\n"..
|
" /add <name> Player <name> can now unlock this object with any key.\n"..
|
||||||
" /del <name> Player <name> can no longer use this object.\n"..
|
" /del <name> Player <name> can no longer use this object.\n"..
|
||||||
" /list Shows a list of players who can use this object.\n"..
|
" /list Shows a list of players who can use this object.\n"..
|
||||||
" /set <password> Sets a password. Everyone who types that in can use the object.");
|
" /set <password> Sets a password. Everyone who types that in can use the object.\n"..
|
||||||
|
" /pipeworks Toggles permission for pipeworks to take inventory out of the shared locked object.\n");
|
||||||
|
|
||||||
else if( locks:lock_allow_use( pos, player )) then
|
else if( locks:lock_allow_use( pos, player )) then
|
||||||
minetest.chat_send_player(name, "This locked object is owned by "..tostring( meta:get_string( "owner" ))..".\n"..
|
minetest.chat_send_player(name, "This locked object is owned by "..tostring( meta:get_string( "owner" ))..".\n"..
|
||||||
@ -383,10 +404,33 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||||||
txt = txt.."\nThe password for this lock is: \""..tostring( meta:get_string( "password" ).."\"");
|
txt = txt.."\nThe password for this lock is: \""..tostring( meta:get_string( "password" ).."\"");
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if( not( minetest.get_modpath("pipeworks") )) then
|
||||||
|
txt = txt.."\nThe pipeworks mod is not installed. Install it if you wish support for tubes.";
|
||||||
|
elseif( meta:get_int( "allow_pipeworks" ) == 1 ) then
|
||||||
|
txt = txt.."\nTubes from pipeworks may be used to extract items out of/add items to this shared locked object.";
|
||||||
|
else
|
||||||
|
txt = txt.."\nInput from tubes is accepted, but output to them is denied (default).";
|
||||||
|
end
|
||||||
|
|
||||||
minetest.chat_send_player(name, txt );
|
minetest.chat_send_player(name, txt );
|
||||||
return;
|
return;
|
||||||
end -- of /list
|
end -- of /list
|
||||||
|
|
||||||
|
|
||||||
|
-- toggle tube output on/off
|
||||||
|
if( fields.locks_sent_lock_command == "/pipeworks" ) then
|
||||||
|
|
||||||
|
if( meta:get_int('allow_pipeworks') == 1 ) then
|
||||||
|
meta:set_int('allow_pipeworks', 0 );
|
||||||
|
minetest.chat_send_player( name, 'Output to pipework tubes is now DISABLED (input is still acceped).');
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
meta:set_int('allow_pipeworks', 1 );
|
||||||
|
minetest.chat_send_player( name, 'Output to pipework tubes is now ENABLED. Connected tubes may insert and remove items.');
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- -- all other commands take exactly one parameter
|
-- -- all other commands take exactly one parameter
|
||||||
local help = fields.locks_sent_lock_command:split( " " );
|
local help = fields.locks_sent_lock_command:split( " " );
|
||||||
|
|
||||||
|
@ -1,10 +1,46 @@
|
|||||||
|
-- 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"};
|
||||||
|
locks.chest_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2};
|
||||||
|
locks.chest_add.tube = {};
|
||||||
|
|
||||||
|
-- additional/changed definitions for pipeworks;
|
||||||
|
-- taken from pipeworks/compat.lua
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
locks.chest_add.tiles = {
|
||||||
|
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
|
||||||
|
"default_chest_top.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_side.png^pipeworks_tube_connection_wooden.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 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 inv = meta:get_inventory()
|
||||||
|
return inv:room_for_item("main", stack)
|
||||||
|
end,
|
||||||
|
input_inventory = "main",
|
||||||
|
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||||
|
};
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("locks:shared_locked_chest", {
|
minetest.register_node("locks:shared_locked_chest", {
|
||||||
description = "Shared locked chest",
|
description = "Shared locked chest",
|
||||||
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
tiles = locks.chest_add.tiles,
|
||||||
"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
groups = locks.chest_add.groups,
|
||||||
|
tube = locks.chest_add.tube,
|
||||||
legacy_facedir_simple = true,
|
legacy_facedir_simple = true,
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
@ -26,6 +62,11 @@ minetest.register_node("locks:shared_locked_chest", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
|
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
pipeworks.scan_for_tube_objects( pos );
|
||||||
|
end
|
||||||
|
|
||||||
locks:lock_set_owner( pos, placer, "Shared locked chest" );
|
locks:lock_set_owner( pos, placer, "Shared locked chest" );
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -78,6 +119,11 @@ minetest.register_node("locks:shared_locked_chest", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
after_dig_node = function( pos )
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
@ -3,6 +3,66 @@
|
|||||||
-- containing only the furnace and adopted slightly for my locks mod
|
-- containing only the furnace and adopted slightly for my locks mod
|
||||||
|
|
||||||
|
|
||||||
|
-- 09.01.13 Added support for pipeworks.
|
||||||
|
|
||||||
|
|
||||||
|
locks.furnace_add = {};
|
||||||
|
locks.furnace_add_tiles_normal = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"};
|
||||||
|
locks.furnace_add.tiles_active = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front_active.png"};
|
||||||
|
locks.furnace_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2};
|
||||||
|
locks.furnace_add.tube = {};
|
||||||
|
|
||||||
|
-- additional/changed definitions for pipeworks;
|
||||||
|
-- taken from pipeworks/compat.lua
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
|
||||||
|
locks.furnace_add.tiles_normal = {
|
||||||
|
"default_furnace_top.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_bottom.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_front.png^pipeworks_tube_connection_stony.png" };
|
||||||
|
|
||||||
|
|
||||||
|
locks.furnace_add.tiles_active = {
|
||||||
|
"default_furnace_top.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_bottom.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||||
|
"default_furnace_front_active.png^pipeworks_tube_connection_stony.png" };
|
||||||
|
|
||||||
|
|
||||||
|
locks.furnace_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,
|
||||||
|
tubedevice = 1, tubedevice_receiver = 1 };
|
||||||
|
locks.furnace_add.tube = {
|
||||||
|
insert_object = function(pos, node, stack, direction)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
if direction.y == 1 then
|
||||||
|
return inv:add_item("fuel",stack)
|
||||||
|
else
|
||||||
|
return inv:add_item("src",stack)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
can_insert = function(pos, node, stack, direction)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
if direction.y == 1 then
|
||||||
|
return inv:room_for_item("fuel", stack)
|
||||||
|
else
|
||||||
|
return inv:room_for_item("src", stack)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
input_inventory = "dst",
|
||||||
|
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||||
|
};
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function locks.get_furnace_active_formspec(pos, percent)
|
function locks.get_furnace_active_formspec(pos, percent)
|
||||||
local formspec =
|
local formspec =
|
||||||
"size[8,9]"..
|
"size[8,9]"..
|
||||||
@ -30,11 +90,14 @@ locks.furnace_inactive_formspec =
|
|||||||
|
|
||||||
minetest.register_node("locks:shared_locked_furnace", {
|
minetest.register_node("locks:shared_locked_furnace", {
|
||||||
description = "Shared locked furnace",
|
description = "Shared locked furnace",
|
||||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
|
||||||
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"},
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
legacy_facedir_simple = true,
|
legacy_facedir_simple = true,
|
||||||
|
|
||||||
|
tiles = locks.furnace_add.tiles_normal,
|
||||||
|
groups = locks.furnace_add.groups,
|
||||||
|
tube = locks.furnace_add.tube,
|
||||||
|
|
||||||
-- sounds = default.node_sound_stone_defaults(),
|
-- sounds = default.node_sound_stone_defaults(),
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -45,9 +108,19 @@ minetest.register_node("locks:shared_locked_furnace", {
|
|||||||
inv:set_size("src", 1)
|
inv:set_size("src", 1)
|
||||||
inv:set_size("dst", 4)
|
inv:set_size("dst", 4)
|
||||||
end,
|
end,
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
locks:lock_set_owner( pos, placer, "Shared locked chest" );
|
after_place_node = function(pos, placer)
|
||||||
end,
|
if( locks.pipeworks_enabled ) then
|
||||||
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
end
|
||||||
|
locks:lock_set_owner( pos, placer, "Shared locked furnace" );
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos)
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
if( not(locks:lock_allow_dig( pos, player ))) then
|
if( not(locks:lock_allow_dig( pos, player ))) then
|
||||||
return false;
|
return false;
|
||||||
@ -119,13 +192,16 @@ minetest.register_node("locks:shared_locked_furnace", {
|
|||||||
|
|
||||||
minetest.register_node("locks:shared_locked_furnace_active", {
|
minetest.register_node("locks:shared_locked_furnace_active", {
|
||||||
description = "Furnace",
|
description = "Furnace",
|
||||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
|
||||||
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front_active.png"},
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
light_source = 8,
|
light_source = 8,
|
||||||
drop = "locks:shared_locked_furnace",
|
drop = "locks:shared_locked_furnace",
|
||||||
groups = {cracky=2, not_in_creative_inventory=1},
|
groups = {cracky=2, not_in_creative_inventory=1},
|
||||||
legacy_facedir_simple = true,
|
legacy_facedir_simple = true,
|
||||||
|
|
||||||
|
tiles = locks.furnace_add.tiles_active,
|
||||||
|
groups = locks.furnace_add.groups,
|
||||||
|
tube = locks.furnace_add.tube,
|
||||||
|
|
||||||
-- sounds = default.node_sound_stone_defaults(),
|
-- sounds = default.node_sound_stone_defaults(),
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -151,6 +227,19 @@ minetest.register_node("locks:shared_locked_furnace_active", {
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
after_place_node = function(pos, placer)
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
end
|
||||||
|
locks:lock_set_owner( pos, placer, "Shared locked furnace (active)" );
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos)
|
||||||
|
if( locks.pipeworks_enabled ) then
|
||||||
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
locks:lock_handle_input( pos, formname, fields, sender );
|
locks:lock_handle_input( pos, formname, fields, sender );
|
||||||
end,
|
end,
|
||||||
@ -321,3 +410,5 @@ minetest.register_craft({
|
|||||||
})
|
})
|
||||||
|
|
||||||
print( "[Mod] locks: loading locks:shared_locked_furnace");
|
print( "[Mod] locks: loading locks:shared_locked_furnace");
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user