From 109e6b1fdc79f3152fc78397cb25eb2e04c8e97d Mon Sep 17 00:00:00 2001 From: Louis <55180044+louisroyer@users.noreply.github.com> Date: Thu, 25 Feb 2021 18:03:57 +0100 Subject: [PATCH] Right inventory for wifi chests Fix #23 --- models/toolbox.lua | 2 +- models/wifi.lua | 45 +++++++++++++++++++-- utils/base.lua | 10 +++-- utils/formspec.lua | 13 +++++-- wifi.lua | 97 ---------------------------------------------- 5 files changed, 59 insertions(+), 108 deletions(-) delete mode 100644 wifi.lua diff --git a/models/toolbox.lua b/models/toolbox.lua index 3a0e6e6..0e287eb 100644 --- a/models/toolbox.lua +++ b/models/toolbox.lua @@ -15,7 +15,7 @@ local function register_toolbox(description, material, side_tile, craft_item) }) minetest.register_node("more_chests:toolbox_" .. material, def) minetest.register_craft({ - output = "morechests:toolbox_" .. material, + output = "more_chests:toolbox_" .. material, recipe = { {craft_item, craft_item, craft_item}, {craft_item, "group:pickaxe", craft_item}, diff --git a/models/wifi.lua b/models/wifi.lua index bfcef10..669fbf1 100644 --- a/models/wifi.lua +++ b/models/wifi.lua @@ -1,5 +1,6 @@ local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua") local S = minetest.get_translator("more_chests") +local pipeworks_enabled = minetest.global_exists("pipeworks") local wifi = gen_def({ description = S("Wifi Chest"), @@ -11,13 +12,51 @@ local wifi = gen_def({ front = {name="wifi_front_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}} }, - allow_metadata_inventory_move = false, - allow_metadata_inventory_put = false, - allow_metadata_inventory_take = false, + inventory_name = "more_chests:wifi", + pipeworks_enabled = pipeworks_enabled, -- this adds groups }) +-- wifi chests can always be removed because content is detached wifi.can_dig = function(pos, player) return true end +-- pipeworks support (we need to override what is created by gen_def because too generic) +wifi.tube = pipeworks_enabled and { + insert_object = function(pos, node, stack, direction, owner) + if not owner then + return stack + end + local player = minetest.get_player_by_name(owner) + if not player then + return stack + end + local inv = player:get_inventory() + return inv:add_item("more_chests:wifi", stack) + end, + can_insert = function(pos, node, stack, direction, owner) + if not owner then + return false + end + local player = minetest.get_player_by_name(owner) + if not player then + return false + end + local inv = player:get_inventory() + return inv:room_for_item("more_chests:wifi", stack) + end, + input_inventory = "more_chests:wifi", + return_input_invref = function(pos, node, direction, player_name) + if not player_name then + return false + end + local player = minetest.get_player_by_name(player_name) + if not player then + return false + end + return player:get_inventory() + end, + connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} +} or nil + minetest.register_node("more_chests:wifi", wifi) minetest.register_craft({ output = "more_chests:wifi", diff --git a/utils/base.lua b/utils/base.lua index 6d7947c..d6858aa 100644 --- a/utils/base.lua +++ b/utils/base.lua @@ -41,13 +41,15 @@ function generate_chest_def(def) end, on_construct = function(pos) local meta = minetest.get_meta(pos) - local formspec_str = def.formspec or generate_formspec_string(def.size) + local formspec_str = def.formspec or generate_formspec_string(def.size, def.inventory_name or nil) meta:set_string("formspec", formspec_str) meta:set_string("infotext", def.description) meta:set_string("owner", "") - local inv = meta:get_inventory() - local chest_size = def.size == "big" and 14*5 or 8*4 - inv:set_size("main", chest_size) + if def.inventory_name == nil or def.inventory_name == "main" then + local inv = meta:get_inventory() + local chest_size = def.size == "big" and 14*5 or 8*4 + inv:set_size("main", chest_size) + end end, can_dig = function(pos,player) local meta = minetest.get_meta(pos) diff --git a/utils/formspec.lua b/utils/formspec.lua index 073c49c..1452e61 100644 --- a/utils/formspec.lua +++ b/utils/formspec.lua @@ -1,5 +1,12 @@ -function generate(size) +function generate(size, inventory_name) local cfg + + -- chest inventory name + local inv_name = inventory_name + if inv_name == nil then + inv_name = "main" + end + if size == "small" then cfg = { window_width = 8, @@ -23,7 +30,7 @@ function generate(size) default.gui_bg .. default.gui_bg_img .. default.gui_slots .. - "list[current_name;main;0,0.3;" .. + "list["..((inv_name == "main") and "current_name" or "current_player")..";"..inv_name..";0,0.3;" .. cfg.chest_width .. "," .. cfg.chest_height .. ";]" .. "list[current_player;main;" .. player_inv_x_orig .. "," .. player_inv_y_orig .. @@ -31,7 +38,7 @@ function generate(size) "list[current_player;main;" .. player_inv_x_orig .. "," .. (player_inv_y_orig + 1.15) .. ";8,3;8]" .. - "listring[current_name;main]" .. + "listring["..(inv_name == "main" and "current_name" or "current_player")..";"..inv_name.."]" .. "listring[current_player;main]" .. default.get_hotbar_bg(player_inv_x_orig, player_inv_y_orig) end diff --git a/wifi.lua b/wifi.lua deleted file mode 100644 index 84534a9..0000000 --- a/wifi.lua +++ /dev/null @@ -1,97 +0,0 @@ --- Load support for translation. -local S = minetest.get_translator("more_chests") - -local pipeworks_enabled = minetest.global_exists("pipeworks") - -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", - {name="wifi_front_animated.png", animation={type="vertical_frames", - aspect_w=16, aspect_h=16, length=2.0}}}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1}, - -- Pipeworks - tube = pipeworks_enabled and { - insert_object = function(pos, node, stack, direction, owner) - if not owner then - return stack - end - local player = minetest.get_player_by_name(owner) - if not player then - return stack - end - local inv = player:get_inventory() - return inv:add_item("more_chests:wifi", stack) - end, - can_insert = function(pos, node, stack, direction, owner) - if not owner then - return false - end - local player = minetest.get_player_by_name(owner) - if not player then - return false - end - local inv = player:get_inventory() - return inv:room_for_item("more_chests:wifi", stack) - end, - input_inventory = "more_chests:wifi", - return_input_invref = function(pos, node, direction, player_name) - if not player_name then - return false - end - local player = minetest.get_player_by_name(player_name) - if not player then - return false - end - return player:get_inventory() - end, - connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} - } or nil, - after_place_node = pipeworks_enabled and pipeworks.after_place or nil, - after_dig_node = pipeworks_enabled and pipeworks.after_dig or nil, - 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)