From 7ad4c806fed4e1068d9966ecd4ea956f406f804e Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 7 Oct 2013 17:04:31 +0200 Subject: add a shared chest, that instead of being locked to a certain user, can be accessed by the current owner of a property as well as the users being shared access with it --- chest.lua | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 chest.lua (limited to 'chest.lua') diff --git a/chest.lua b/chest.lua new file mode 100644 index 0000000..00cd616 --- /dev/null +++ b/chest.lua @@ -0,0 +1,76 @@ +-- add a special chest that is shared among the land-possesors + +minetest.register_node("landrush:shared_chest", { + description = "Land Rush Shared Chest", + tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("main") + end, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec",default.chest_formspec) + meta:set_string("infotext", "Shared Chest") + local inv = meta:get_inventory() + inv:set_size("main", 8*4) + end, + + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + if not landrush.can_interact(player:get_player_name(),pos) then + minetest.log("action", player:get_player_name() .. " tried to access a shared chest at ".. minetest.pos_to_string(pos)) + return 0 + end + return count + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if not landrush.can_interact(player:get_player_name(),pos) then + minetest.log("action", player:get_player_name() .. " tried to access a shared chest at ".. minetest.pos_to_string(pos)) + return 0 + end + return stack:get_count() + end, + + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if not landrush.can_interact(player:get_player_name(),pos) then + minetest.log("action", player:get_player_name().. + " tried to access a shared chest at ".. + minetest.pos_to_string(pos)) + return 0 + end + return stack:get_count() + end, + + on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + minetest.log("action", player:get_player_name().. + " moves stuff in shared chest at "..minetest.pos_to_string(pos)) + end, + + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name().. + " puts stuff into shared chest at "..minetest.pos_to_string(pos)) + end, + + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name().. + " takes stuff from shared chest at "..minetest.pos_to_string(pos)) + end +}) + +minetest.register_craft({ + output = 'landrush:shared_chest', + recipe = { + {'default:wood','default:wood','default:wood'}, + {'default:wood','landrush:landclaim','default:wood'}, + {'default:wood','default:wood','default:wood'} + } +}) \ No newline at end of file -- cgit v1.2.3 From a938a10c6648ef1c81acafcb325770f75ecdee4b Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 7 Oct 2013 17:10:02 +0200 Subject: add compatibility between shared chest and pipeworks mod --- chest.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'chest.lua') diff --git a/chest.lua b/chest.lua index 00cd616..a328f6b 100644 --- a/chest.lua +++ b/chest.lua @@ -3,7 +3,7 @@ minetest.register_node("landrush:shared_chest", { description = "Land Rush Shared Chest", tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1}, legacy_facedir_simple = true, sounds = default.node_sound_wood_defaults(), @@ -63,7 +63,23 @@ minetest.register_node("landrush:shared_chest", { on_metadata_inventory_take = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name().. " takes stuff from shared chest at "..minetest.pos_to_string(pos)) - end + end, + + tube = { + insert_object = function(pos, node, stack, direction) + local meta = minetest.env:get_meta(pos) + local inventory = meta:get_inventory() + return inventory:add_item("main",stack) + end, + + can_insert = function(pos, node, stack, direction) + local meta=minetest.env:get_meta(pos) + local inventory = meta:get_inventory() + return inventory:room_for_item("main",stack) + end, + input_inventory="main", + connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, + } }) minetest.register_craft({ -- cgit v1.2.3