From e3bec6564da3c17059fa0e0d289ef4207efd8f3e Mon Sep 17 00:00:00 2001 From: k Date: Sun, 3 May 2020 16:06:22 +0200 Subject: [PATCH] Rewritten models --- cobble.lua | 115 ------------------------------------- dropbox.lua | 113 ------------------------------------- init.lua | 10 ++-- models/cobble.lua | 26 +++++++++ models/dropbox.lua | 45 +++++++++++++++ models/secret.lua | 54 ++++++++++++++++++ models/shared.lua | 72 +++++++++++++++++++++++ models/wifi.lua | 34 +++++++++++ secret.lua | 132 ------------------------------------------- shared.lua | 138 --------------------------------------------- wifi.lua | 54 ------------------ 11 files changed, 236 insertions(+), 557 deletions(-) delete mode 100644 cobble.lua delete mode 100644 dropbox.lua create mode 100644 models/cobble.lua create mode 100644 models/dropbox.lua create mode 100644 models/secret.lua create mode 100644 models/shared.lua create mode 100644 models/wifi.lua delete mode 100644 secret.lua delete mode 100644 shared.lua delete mode 100644 wifi.lua diff --git a/cobble.lua b/cobble.lua deleted file mode 100644 index 6bb2c4c..0000000 --- a/cobble.lua +++ /dev/null @@ -1,115 +0,0 @@ --- Load support for translation. -local S = minetest.get_translator("more_chests") - -local function has_locked_chest_privilege(meta, player) - if player:get_player_name() ~= meta:get_string("owner") then - return false - end - return true -end - -minetest.register_node("more_chests:cobble", { - description = S("Cobble Chest"), - tiles = {"default_cobble.png", "default_cobble.png", "default_cobble.png", - "default_cobble.png", "default_cobble.png", "cobblechest_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1}, --- First attempt to add a way to connect to pipeworks. - tube = { - insert_object = function(pos, node, stack, direction) - 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.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} - }, - legacy_facedir_simple = true, - 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 "") - - end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("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)) - 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") - 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 - minetest.log("action", player:get_player_name().. - " tried to access a locked chest belonging to ".. - meta:get_string("owner").." 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 has_locked_chest_privilege(meta, player) then - minetest.log("action", player:get_player_name().. - " tried to access a locked chest belonging to ".. - meta:get_string("owner").." 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 has_locked_chest_privilege(meta, player) then - minetest.log("action", player:get_player_name().. - " tried to access a locked chest belonging to ".. - meta:get_string("owner").." 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 locked 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 stuff 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 stuff from locked chest at "..minetest.pos_to_string(pos)) - end, -}) - -minetest.register_craft({ - output = 'more_chests:cobble', - recipe = { - {'default:wood','default:cobble','default:wood'}, - {'default:cobble','default:steel_ingot','default:cobble'}, - {'default:wood','default:cobble','default:wood'} - } -}) diff --git a/dropbox.lua b/dropbox.lua deleted file mode 100644 index a8f16de..0000000 --- a/dropbox.lua +++ /dev/null @@ -1,113 +0,0 @@ --- Load support for translation. -local S = minetest.get_translator("more_chests") -local DS = minetest.get_translator("default") - -local function has_locked_chest_privilege(meta, player) - if player:get_player_name() ~= meta:get_string("owner") then - return false - end - return true -end - -minetest.register_node("more_chests:dropbox", { - description = S("Dropbox"), - tiles = {"dropbox_top.png", "dropbox_top.png", "dropbox_side.png", - "dropbox_side.png", "dropbox_side.png", "dropbox_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1}, --- Pipeworks - tube = { - insert_object = function(pos, node, stack, direction) - 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.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} - }, - legacy_facedir_simple = true, - 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", S("@1 (owned by @2)", - S("Dropbox"), - meta:get_string("owner"))) - end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("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)) - meta:set_string("infotext", DS("Chest")) - 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, - 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 - minetest.log("action", player:get_player_name().. - " tried to access a dropbox belonging to ".. - meta:get_string("owner").." at ".. - minetest.pos_to_string(pos)) - return 0 - end - return stack:get_count() - end, - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - local meta = minetest.get_meta(pos) - if has_locked_chest_privilege(meta, player) then - return stack:get_count() - end - local target = meta:get_inventory():get_list(listname)[index] - local target_name = target:get_name() - local stack_count = stack:get_count() - if target_name == stack:get_name() - and target:get_count() < stack_count then - return stack_count - end - if target_name ~= "" then - return 0 - end - return stack_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 dropbox 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 stuff to dropbox 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 dropbox at "..minetest.pos_to_string(pos)) - end, -}) - -minetest.register_craft({ - output = 'more_chests:dropbox', - recipe = { - {'default:wood','','default:wood'}, - {'default:wood','default:steel_ingot','default:wood'}, - {'default:wood','default:wood','default:wood'} - } -}) diff --git a/init.lua b/init.lua index 944b03a..26c7320 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,7 @@ -dofile(minetest.get_modpath("more_chests").."/cobble.lua") -dofile(minetest.get_modpath("more_chests").."/dropbox.lua") -dofile(minetest.get_modpath("more_chests").."/secret.lua") -dofile(minetest.get_modpath("more_chests").."/shared.lua") -dofile(minetest.get_modpath("more_chests").."/wifi.lua") +dofile(minetest.get_modpath("more_chests").."/models/cobble.lua") +dofile(minetest.get_modpath("more_chests").."/models/dropbox.lua") +dofile(minetest.get_modpath("more_chests").."/models/secret.lua") +dofile(minetest.get_modpath("more_chests").."/models/shared.lua") +dofile(minetest.get_modpath("more_chests").."/models/wifi.lua") dofile(minetest.get_modpath("more_chests").."/utils/aliases.lua") diff --git a/models/cobble.lua b/models/cobble.lua new file mode 100644 index 0000000..2a568fa --- /dev/null +++ b/models/cobble.lua @@ -0,0 +1,26 @@ +local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua") +local S = minetest.get_translator("more_chests") + +local cobble = gen_def({ + description = S("Cobble Chest"), + type = "chest", + size = "small", + tiles = { + top = "default_cobble.png", + side = "default_cobble.png", + front = "cobblechest_front.png" + }, + pipeworks_enabled = true, + recipe = { + {"group:wood", "default:cobble", "group:wood"}, + {"default:cobble", "default:steel_ingot", "default:cobble"}, + {"group:wood", "default:cobble", "group:wood"} + }, +}) + + +minetest.register_node("more_chests:cobble", cobble) +minetest.register_craft({ + output = "more_chests:cobble", + recipe = cobble.recipe, +}) diff --git a/models/dropbox.lua b/models/dropbox.lua new file mode 100644 index 0000000..94da127 --- /dev/null +++ b/models/dropbox.lua @@ -0,0 +1,45 @@ +local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua") +local actions = dofile(minetest.get_modpath("more_chests") .. "/utils/actions.lua") +local S = minetest.get_translator("more_chests") + +local dropbox = gen_def({ + description = S("Dropbox"), + type = "dropbox", + size = "small", + tiles = { + top = "dropbox_top.png", + side = "dropbox_side.png", + front = "dropbox_front.png" + }, + pipeworks_enabled = true, + recipe = { + {"group:wood", "", "group:wood"}, + {"group:wood", "default:steel_ingot", "group:wood"}, + {"group:wood", "group:wood", "group:wood"} + }, + allow_metadata_inventory_move = false, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if actions.has_locked_chest_privilege(meta, player) then + return stack:get_count() + end + local target = meta:get_inventory():get_list(listname)[index] + local target_name = target:get_name() + local stack_count = stack:get_count() + if target_name == stack:get_name() + and target:get_count() < stack_count then + return stack_count + end + if target_name ~= "" then + return 0 + end + return stack_count + end +}) + + +minetest.register_node("more_chests:dropbox", dropbox) +minetest.register_craft({ + output = "more_chests:dropbox", + recipe = dropbox.recipe, +}) diff --git a/models/secret.lua b/models/secret.lua new file mode 100644 index 0000000..2536694 --- /dev/null +++ b/models/secret.lua @@ -0,0 +1,54 @@ +local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua") +local actions = dofile(minetest.get_modpath("more_chests") .. "/utils/actions.lua") +local S = minetest.get_translator("more_chests") + +local open = "size[8,10]".. + 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]" .. + "button[3,9;2,1;open;close]" .. + default.get_hotbar_bg(0,4.85) + +local closed = "size[2,1]" .. + "button[0,0;2,1;open;open]" + +local secret = gen_def({ + description = S("Secret Chest"), + type = "secret chest", + size = "small", + tiles = { + top = "secret_top.png", + side = "secret_side.png", + front = "secret_front.png" + }, + formspec = open, + pipeworks_enabled = true, + recipe = { + {"group:wood", "default:cobble", "group:wood"}, + {"group:wood", "default:steel_ingot", "group:wood"}, + {"group:wood", "group:wood", "group:wood"} + }, +}) + +secret.on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + if actions.has_locked_chest_privilege(meta, sender) then + if fields.open == "open" then + meta:set_string("formspec", open) + else + meta:set_string("formspec", closed) + end + end +end + + +minetest.register_node("more_chests:secret", secret) +minetest.register_craft({ + output = "more_chests:secret", + recipe = secret.recipe, +}) diff --git a/models/shared.lua b/models/shared.lua new file mode 100644 index 0000000..b4272fa --- /dev/null +++ b/models/shared.lua @@ -0,0 +1,72 @@ +local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua") +local actions = dofile(minetest.get_modpath("more_chests") .. "/utils/actions.lua") +local S = minetest.get_translator("more_chests") + +local function get_formspec(string) + return "size[8,10]" .. + 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;8,3;8]" .. + "field[.25,9.5;8,1;shared;" .. + S("Shared with (separate names with spaces)") .. + ":;" .. string .. "]" .. + "button[6,9.2;2,1;submit;" .. + S("submit") .. "]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,4.85) +end + +local function check_privs(meta, player) + local name = player:get_player_name() + local shared = " " .. meta:get_string("shared") .. " " + if name == meta:get_string("owner") then + return true + elseif shared:find(" " .. name .. " ") then + return true + else + return false + end +end + +local shared = gen_def({ + description = S("Shared Chest"), + type = "shared chest", + size = "small", + tiles = { + top = "shared_top.png", + side = "shared_side.png", + front = "shared_front.png" + }, + formspec = get_formspec(""), + pipeworks_enabled = true, + sounds = default.node_sound_wood_defaults(), + recipe = { + {"group:wood", "default:leaves", "group:wood"}, + {"group:wood", "default:steel_ingot", "group:wood"}, + {"group:wood", "group:wood", "group:wood"} + }, + allow_metadata_inventory_move = actions.get_allow_metadata_inventory_move{"shared chest", check_privs=check_privs}, + allow_metadata_inventory_put = actions.get_allow_metadata_inventory_put{"shared chest", check_privs=check_privs}, + allow_metadata_inventory_take = actions.get_allow_metadata_inventory_take{"shared chest", check_privs=check_privs}, +}) + +shared.on_receive_fields = function(pos, formspec, fields, sender) + local meta = minetest.get_meta(pos); + if fields.shared then + if meta:get_string("owner") == sender:get_player_name() then + meta:set_string("shared", fields.shared) + meta:set_string("formspec", get_formspec(fields.shared)) + end + end +end + + +minetest.register_node("more_chests:shared", shared) +minetest.register_craft({ + output = "more_chests:shared", + recipe = shared.recipe, +}) diff --git a/models/wifi.lua b/models/wifi.lua new file mode 100644 index 0000000..f40d491 --- /dev/null +++ b/models/wifi.lua @@ -0,0 +1,34 @@ +local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua") +local S = minetest.get_translator("more_chests") + +local wifi = gen_def({ + description = S("Wifi Chest"), + type = "wifi chest", + size = "small", + tiles = { + top = "wifi_top.png", + side = "wifi_side.png", + front = "wifi_front.png" + }, + recipe = { + {"group:wood", "default:mese", "group:wood"}, + {"group:wood", "default:steel_ingot", "group:wood"}, + {"group:wood", "group:wood", "group:wood"} + }, + allow_metadata_inventory_move = false, + allow_metadata_inventory_put = false, + allow_metadata_inventory_take = false, +}) + +wifi.can_dig = function(pos, player) return true end + +minetest.register_node("more_chests:wifi", wifi) +minetest.register_craft({ + output = "more_chests:wifi", + recipe = wifi.recipe, +}) + +minetest.register_on_joinplayer(function(player) + local inv = player:get_inventory() + inv:set_size("more_chests:wifi", 8*4) +end) diff --git a/secret.lua b/secret.lua deleted file mode 100644 index 71fe742..0000000 --- a/secret.lua +++ /dev/null @@ -1,132 +0,0 @@ --- Load support for translation. -local S = minetest.get_translator("more_chests") - -local function has_locked_chest_privilege(meta, player) - if player:get_player_name() ~= meta:get_string("owner") then - return false - end - return true -end - -local open = "size[8,10]".. - 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]" .. - "button[3,9;2,1;open;close]" .. - default.get_hotbar_bg(0,4.85) -local closed = "size[2,1]".. - "button[0,0;2,1;open;open]" - -minetest.register_node("more_chests:secret", { - description = S("Secret Chest"), - tiles = {"secret_top.png", "secret_top.png", "secret_side.png", - "secret_side.png", "secret_side.png", "secret_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1}, --- Pipeworks - tube = { - insert_object = function(pos, node, stack, direction) - 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.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} - }, - legacy_facedir_simple = true, - 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", S("@1 (owned by @2)", - S("Secret Chest"), - meta:get_string("owner"))) - end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", open) - meta:set_string("infotext", S("Secret Chest")) - 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") - 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 - minetest.log("action", player:get_player_name().. - " tried to access a secret chest belonging to ".. - meta:get_string("owner").." 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 has_locked_chest_privilege(meta, player) then - minetest.log("action", player:get_player_name().. - " tried to access a secret chest belonging to ".. - meta:get_string("owner").." 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 has_locked_chest_privilege(meta, player) then - minetest.log("action", player:get_player_name().. - " tried to access a secret chest belonging to ".. - meta:get_string("owner").." 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 secret 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 stuff to secret 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 secret chest at "..minetest.pos_to_string(pos)) - end, - on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.get_meta(pos) - if has_locked_chest_privilege(meta, sender) then - if fields.open == "open" then - meta:set_string("formspec", open) - else - meta:set_string("formspec", closed) - end - end - end, -}) - -minetest.register_craft({ - output = 'more_chests:secret', - recipe = { - {'default:wood','default:cobble','default:wood'}, - {'default:wood','default:steel_ingot','default:wood'}, - {'default:wood','default:wood','default:wood'} - } -}) diff --git a/shared.lua b/shared.lua deleted file mode 100644 index e100a93..0000000 --- a/shared.lua +++ /dev/null @@ -1,138 +0,0 @@ --- Load support for translation. -local S = minetest.get_translator("more_chests") - -local function has_locked_chest_privilege(meta, player) - local name = player:get_player_name() - local shared = " "..meta:get_string("shared").." " - if name == meta:get_string("owner") then - return true - elseif shared:find(" "..name.." ") then - - return true - else - return false - end -end - -local function get_formspec(string) - return "size[8,10]".. - 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;8,3;8]" .. - "field[.25,9.5;8,1;shared;"..S("Shared with (separate names with spaces)")..":;"..string.."]".. - "button[6,9.2;2,1;submit;"..S("submit").."]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) -end - -minetest.register_node("more_chests:shared", { - description = S("Shared Chest"), - tiles = {"shared_top.png", "shared_top.png", "shared_side.png", - "shared_side.png", "shared_side.png", "shared_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1}, --- Pipeworks - tube = { - insert_object = function(pos, node, stack, direction) - 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.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} - }, - legacy_facedir_simple = true, - 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", S("@1 (owned by @2)", - S("Shared Chest"), - meta:get_string("owner"))) - end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", get_formspec("")) - meta:set_string("infotext", S("Shared Chest")) - 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") - 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 - minetest.log("action", player:get_player_name().. - " tried to access a shared chest belonging to ".. - meta:get_string("owner").." 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 has_locked_chest_privilege(meta, player) then - minetest.log("action", player:get_player_name().. - " tried to access a shared chest belonging to ".. - meta:get_string("owner").." 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 has_locked_chest_privilege(meta, player) then - minetest.log("action", player:get_player_name().. - " tried to access a shared chest belonging to ".. - meta:get_string("owner").." 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().. - " moves stuff to 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, - on_receive_fields = function(pos, formspec, fields, sender) - local meta = minetest.get_meta(pos); - if fields.shared then - if meta:get_string("owner") == sender:get_player_name() then - meta:set_string("shared", fields.shared); - meta:set_string("formspec", get_formspec(fields.shared)) - end - end - end, -}) - -minetest.register_craft({ - output = 'more_chests:shared', - recipe = { - {'default:wood','default:leaves','default:wood'}, - {'default:wood','default:steel_ingot','default:wood'}, - {'default:wood','default:wood','default:wood'} - } -}) diff --git a/wifi.lua b/wifi.lua deleted file mode 100644 index 8345ef7..0000000 --- a/wifi.lua +++ /dev/null @@ -1,54 +0,0 @@ --- Load support for translation. -local S = minetest.get_translator("more_chests") - -minetest.register_node("more_chests:wifi", { - description = S("Wifi Chest"), - tiles = {"wifi_top.png", "wifi_top.png", "wifi_side.png", - "wifi_side.png", "wifi_side.png", "wifi_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9]".. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_player;more_chests:wifi;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_player;more_chests:wifi]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85)) - - meta:set_string("infotext", S("Wifi Chest")) - 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 wifi 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 stuff to wifi 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 wifi chest at "..minetest.pos_to_string(pos)) - end, -}) - -minetest.register_craft({ - output = 'more_chests:wifi', - recipe = { - {'default:wood','default:mese','default:wood'}, - {'default:wood','default:steel_ingot','default:wood'}, - {'default:wood','default:wood','default:wood'} - } -}) - -minetest.register_on_joinplayer(function(player) - local inv = player:get_inventory() - inv:set_size("more_chests:wifi", 8*4) -end)