local chest_formspec = "size[8,9]" .. default.gui_bg .. default.gui_bg_img .. default.gui_slots .. "list[current_name;main;0,0.3;8,4;]" .. "list[current_player;main;0,4.85;8,1;]" .. "list[current_player;main;0,6.08;8,3;8]" .. "listring[current_name;main]" .. "listring[current_player;main]" .. default.get_hotbar_bg(0,4.85) local function get_locked_chest_formspec(pos) local spos = pos.x .. "," .. pos.y .. "," .. pos.z local formspec = "size[8,9]" .. default.gui_bg .. default.gui_bg_img .. default.gui_slots .. "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" .. "list[current_player;main;0,4.85;8,1;]" .. "list[current_player;main;0,6.08;8,3;8]" .. "listring[nodemeta:" .. spos .. ";main]" .. "listring[current_player;main]" .. default.get_hotbar_bg(0,4.85) return formspec end local function has_locked_chest_privilege(meta, player) local name = "" if player then if minetest.check_player_privs(player, "protection_bypass") then return true end name = player:get_player_name() end if name ~= meta:get_string("owner") then return false end return true end minetest.register_node("wood_plus:acacia_chest", { description = "Acacia Chest", tiles = {"wood_plus_acacia_chest_top.png", "wood_plus_acacia_chest_top.png", "wood_plus_acacia_chest_side.png", "wood_plus_acacia_chest_side.png", "wood_plus_acacia_chest_side.png", "wood_plus_acacia_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", chest_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") 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 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() .. " moves " .. stack:get_name() .. " to 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 " .. stack:get_name() .. " from chest at " .. minetest.pos_to_string(pos)) end, on_blast = function(pos) local drops = {} default.get_inventory_drops(pos, "main", drops) drops[#drops+1] = "wood_plus:acacia_chest" minetest.remove_node(pos) return drops end, }) minetest.register_node("wood_plus:acacia_chest_locked", { description = "Locked Acacia Chest", tiles = {"wood_plus_acacia_chest_top.png", "wood_plus_acacia_chest_top.png", "wood_plus_acacia_chest_side.png", "wood_plus_acacia_chest_side.png", "wood_plus_acacia_chest_side.png", "wood_plus_acacia_lock_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") meta:set_string("infotext", "Locked Chest (owned by " .. meta:get_string("owner") .. ")") end, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("owner", "") local inv = meta:get_inventory() inv:set_size("main", 8 * 4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") and has_locked_chest_privilege(meta, player) 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 has_locked_chest_privilege(meta, player) then return 0 end return count end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) if not has_locked_chest_privilege(meta, player) then 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 has_locked_chest_privilege(meta, player) then return 0 end return stack:get_count() end, on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " moves " .. stack:get_name() .. " to locked 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 " .. stack:get_name() .. " from locked chest at " .. minetest.pos_to_string(pos)) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) if has_locked_chest_privilege(meta, clicker) then minetest.show_formspec( clicker:get_player_name(), "wood_plus:acacia_chest_locked", get_locked_chest_formspec(pos) ) end return itemstack end, on_blast = function() end, }) minetest.register_node("wood_plus:aspen_chest", { description = "Aspen Chest", tiles = {"wood_plus_aspen_chest_top.png", "wood_plus_aspen_chest_top.png", "wood_plus_aspen_chest_side.png", "wood_plus_aspen_chest_side.png", "wood_plus_aspen_chest_side.png", "wood_plus_aspen_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", chest_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") 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 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() .. " moves " .. stack:get_name() .. " to 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 " .. stack:get_name() .. " from chest at " .. minetest.pos_to_string(pos)) end, on_blast = function(pos) local drops = {} default.get_inventory_drops(pos, "main", drops) drops[#drops+1] = "wood_plus:aspen_chest" minetest.remove_node(pos) return drops end, }) minetest.register_node("wood_plus:aspen_chest_locked", { description = "Locked Aspen Chest", tiles = {"wood_plus_aspen_chest_top.png", "wood_plus_aspen_chest_top.png", "wood_plus_aspen_chest_side.png", "wood_plus_aspen_chest_side.png", "wood_plus_aspen_chest_side.png", "wood_plus_aspen_lock_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") meta:set_string("infotext", "Locked Chest (owned by " .. meta:get_string("owner") .. ")") end, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("owner", "") local inv = meta:get_inventory() inv:set_size("main", 8 * 4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") and has_locked_chest_privilege(meta, player) 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 has_locked_chest_privilege(meta, player) then return 0 end return count end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) if not has_locked_chest_privilege(meta, player) then 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 has_locked_chest_privilege(meta, player) then return 0 end return stack:get_count() end, on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " moves " .. stack:get_name() .. " to locked 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 " .. stack:get_name() .. " from locked chest at " .. minetest.pos_to_string(pos)) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) if has_locked_chest_privilege(meta, clicker) then minetest.show_formspec( clicker:get_player_name(), "wood_plus:aspen_chest_locked", get_locked_chest_formspec(pos) ) end return itemstack end, on_blast = function() end, }) minetest.register_node("wood_plus:jungle_chest", { description = "Jungle Chest", tiles = {"wood_plus_jungle_chest_top.png", "wood_plus_jungle_chest_top.png", "wood_plus_jungle_chest_side.png", "wood_plus_jungle_chest_side.png", "wood_plus_jungle_chest_side.png", "wood_plus_jungle_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", chest_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") 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 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() .. " moves " .. stack:get_name() .. " to 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 " .. stack:get_name() .. " from chest at " .. minetest.pos_to_string(pos)) end, on_blast = function(pos) local drops = {} default.get_inventory_drops(pos, "main", drops) drops[#drops+1] = "wood_plus:jungle_chest" minetest.remove_node(pos) return drops end, }) minetest.register_node("wood_plus:jungle_chest_locked", { description = "Locked Jungle Chest", tiles = {"wood_plus_jungle_chest_top.png", "wood_plus_jungle_chest_top.png", "wood_plus_jungle_chest_side.png", "wood_plus_jungle_chest_side.png", "wood_plus_jungle_chest_side.png", "wood_plus_jungle_lock_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") meta:set_string("infotext", "Locked Chest (owned by " .. meta:get_string("owner") .. ")") end, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("owner", "") local inv = meta:get_inventory() inv:set_size("main", 8 * 4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") and has_locked_chest_privilege(meta, player) 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 has_locked_chest_privilege(meta, player) then return 0 end return count end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) if not has_locked_chest_privilege(meta, player) then 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 has_locked_chest_privilege(meta, player) then return 0 end return stack:get_count() end, on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " moves " .. stack:get_name() .. " to locked 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 " .. stack:get_name() .. " from locked chest at " .. minetest.pos_to_string(pos)) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) if has_locked_chest_privilege(meta, clicker) then minetest.show_formspec( clicker:get_player_name(), "wood_plus:jungle_chest_locked", get_locked_chest_formspec(pos) ) end return itemstack end, on_blast = function() end, }) minetest.register_node("wood_plus:pine_chest", { description = "Pine Chest", tiles = {"wood_plus_pine_chest_top.png", "wood_plus_pine_chest_top.png", "wood_plus_pine_chest_side.png", "wood_plus_pine_chest_side.png", "wood_plus_pine_chest_side.png", "wood_plus_pine_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", chest_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") 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 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() .. " moves " .. stack:get_name() .. " to 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 " .. stack:get_name() .. " from chest at " .. minetest.pos_to_string(pos)) end, on_blast = function(pos) local drops = {} default.get_inventory_drops(pos, "main", drops) drops[#drops+1] = "wood_plus:pine_chest" minetest.remove_node(pos) return drops end, }) minetest.register_node("wood_plus:pine_chest_locked", { description = "Locked Pine Chest", tiles = {"wood_plus_pine_chest_top.png", "wood_plus_pine_chest_top.png", "wood_plus_pine_chest_side.png", "wood_plus_pine_chest_side.png", "wood_plus_pine_chest_side.png", "wood_plus_pine_lock_chest_front.png"}, paramtype2 = "facedir", groups = {choppy = 2, oddly_breakable_by_hand = 2}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") meta:set_string("infotext", "Locked Chest (owned by " .. meta:get_string("owner") .. ")") end, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("owner", "") local inv = meta:get_inventory() inv:set_size("main", 8 * 4) end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() return inv:is_empty("main") and has_locked_chest_privilege(meta, player) 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 has_locked_chest_privilege(meta, player) then return 0 end return count end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) if not has_locked_chest_privilege(meta, player) then 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 has_locked_chest_privilege(meta, player) then return 0 end return stack:get_count() end, on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " moves " .. stack:get_name() .. " to locked 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 " .. stack:get_name() .. " from locked chest at " .. minetest.pos_to_string(pos)) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) if has_locked_chest_privilege(meta, clicker) then minetest.show_formspec( clicker:get_player_name(), "wood_plus:pine_chest_locked", get_locked_chest_formspec(pos) ) end return itemstack end, on_blast = function() end, })