diff --git a/lua/api.lua b/lua/api.lua index a9940aa..d73f6e8 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -45,7 +45,8 @@ else x_offset = 0.5 end -drawers.drawer_formspec = "size[9,7]" .. +local drawers_formspec_data = {} +local drawer_formspec = "size[9,7]" .. "list[context;upgrades;2,0.5;5,1;]" .. "list[current_player;main;" .. x_offset .. ",3;" .. formspec_size .. ";]" .. @@ -56,6 +57,18 @@ drawers.drawer_formspec = "size[9,7]" .. drawers.gui_slots .. drawers.get_upgrade_slots_bg(2, 0.5) +drawers.get_drawer_formspec = function(pos) + local shared + if minetest.get_meta(pos):get_string("shared") == "true" then + shared = "true" + else + shared = "false" + end + + return drawer_formspec .. + "checkbox[3.5,2;shared;" .. S("Shared") .. ";" .. shared .. "]" +end + -- construct drawer function drawers.drawer_on_construct(pos) local node = core.get_node(pos) @@ -90,9 +103,18 @@ function drawers.drawer_on_construct(pos) -- create drawer upgrade inventory meta:get_inventory():set_size("upgrades", 5) +end - -- set the formspec - meta:set_string("formspec", drawers.drawer_formspec) +-- show formspec on right click +drawers.drawer_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if not clicker:is_player() then + return + end + local pname = clicker:get_player_name() + if not minetest.is_protected(pos, pname) then + drawers_formspec_data[pname] = pos + minetest.show_formspec(pname, "drawers:drawer", drawers.get_drawer_formspec(pos)) + end end -- destruct drawer @@ -303,6 +325,7 @@ function drawers.register_drawer(name, def) -- events def.on_construct = drawers.drawer_on_construct + def.on_rightclick = drawers.drawer_on_rightclick def.on_destruct = drawers.drawer_on_destruct def.on_dig = drawers.drawer_on_dig def.allow_metadata_inventory_put = drawers.drawer_allow_metadata_inventory_put @@ -436,3 +459,13 @@ function drawers.register_drawer_upgrade(name, def) end end +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "drawers:drawer" then return end + local pname = player:get_player_name() + local pos = drawers_formspec_data[pname] + if pos and fields.shared then + local meta = minetest.get_meta(pos) + meta:set_string("shared", fields.shared) + end + drawers_formspec_data[pname] = nil +end) diff --git a/lua/visual.lua b/lua/visual.lua index a07446c..a848364 100755 --- a/lua/visual.lua +++ b/lua/visual.lua @@ -151,7 +151,8 @@ core.register_entity("drawers:visual", { end, on_rightclick = function(self, clicker) - if core.is_protected(self.drawer_pos, clicker:get_player_name()) then + if core.is_protected(self.drawer_pos, clicker:get_player_name()) and + minetest.get_meta(self.drawer_pos):get_string("shared") ~= "true" then core.record_protection_violation(self.drawer_pos, clicker:get_player_name()) return end @@ -214,7 +215,8 @@ core.register_entity("drawers:visual", { return end local add_stack = not puncher:get_player_control().sneak - if core.is_protected(self.drawer_pos, puncher:get_player_name()) then + if core.is_protected(self.drawer_pos, puncher:get_player_name()) and + minetest.get_meta(self.drawer_pos):get_string("shared") ~= "true" then core.record_protection_violation(self.drawer_pos, puncher:get_player_name()) return end @@ -437,7 +439,7 @@ core.register_lbm({ -- create drawer upgrade inventory meta:get_inventory():set_size("upgrades", 5) -- set the formspec - meta:set_string("formspec", drawers.drawer_formspec) + meta:set_string("formspec", "") -- count the drawer visuals local drawerType = core.registered_nodes[node.name].groups.drawer