From 5a5f472d610ae5c3d2bb66678a936256543dbfa9 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:31:44 -0600 Subject: [PATCH 1/7] Add translation support Edit by HybridDog: The description of the chest should be specfied in the second argument (the table) passed to `connected_chests.register_chest`. --- init.lua | 18 ++++++++++++++++-- locale/template.txt | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 locale/template.txt diff --git a/init.lua b/init.lua index 6aa60d6..0a63291 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,6 @@ +-- for translation +local S = minetest.get_translator("connected_chests") + -- param_tab maps the x and z offset to a param2 value local param_tab = { ["-1 0"] = 0, @@ -136,6 +139,8 @@ end connected_chests = {chestdata = chestdata} --[[ connected_chests.register_chest(, { + description = , -- The name of the connected chest as shown to the + -- player, i.e. the node metadata infotext get_formspec = function(metatable, pos) return end, @@ -156,6 +161,13 @@ function connected_chests.register_chest(fromname, data) data.left = name_left data.right = name_right + local description = data.description + if not description then + minetest.log("deprecated", + "Missing connected chest description for " .. fromname) + description = "Big " .. minetest.registered_nodes[fromname].description + end + -- executed when connecting the chest data.on_connect = function(pu, pa, par, metatable) minetest.add_node(pu, {name=name_left, param2=par}) @@ -164,7 +176,7 @@ function connected_chests.register_chest(fromname, data) if not data.add_open_chest then metatable.fields.formspec = data.get_formspec(metatable, pu) end - metatable.fields.infotext = "Big " .. metatable.fields.infotext + metatable.fields.infotext = description local meta = minetest.get_meta(pu) meta:from_table(metatable) local inv = meta:get_inventory() @@ -215,7 +227,7 @@ function connected_chests.register_chest(fromname, data) local inside_texture - chest.description = "Big " .. chest.description + chest.description = description chest.groups = table.copy(chest.groups) chest.groups.not_in_creative_inventory = 1 chest.legacy_facedir_simple = nil @@ -515,6 +527,7 @@ end) local chest_lid_obstructed = default.chest and default.chest.chest_lid_obstructed connected_chests.register_chest("default:chest", { + description = S("Big Chest"), add_open_chest = true, on_rightclick = function(pos, _, player) minetest.sound_play("default_chest_open", @@ -556,6 +569,7 @@ connected_chests.register_chest("default:chest", { }) connected_chests.register_chest("default:chest_locked", { + description = S("Big Locked Chest"), lock = true, add_open_chest = true, on_rightclick = function(pos, _, player) diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..2f94e47 --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,3 @@ +# textdomain: connected_chests +Big Chest= +Big Locked Chest= From afb999dbbd5e35f4adbc54e38b196a9fb7aee874 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:31:54 -0600 Subject: [PATCH 2/7] Add Esperanto translation --- locale/connected_chests.eo.tr | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 locale/connected_chests.eo.tr diff --git a/locale/connected_chests.eo.tr b/locale/connected_chests.eo.tr new file mode 100644 index 0000000..2195098 --- /dev/null +++ b/locale/connected_chests.eo.tr @@ -0,0 +1,3 @@ +# textdomain: connected_chests +Big Chest=Kestego +Big Locked Chest=Ŝlosita Kestego From 8a46cd10545a48d8efdef179a5bc8b924d9dbb0e Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 19 May 2024 19:46:32 -0500 Subject: [PATCH 3/7] Tweak Esperanto translation --- locale/connected_chests.eo.tr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/connected_chests.eo.tr b/locale/connected_chests.eo.tr index 2195098..9dab6a0 100644 --- a/locale/connected_chests.eo.tr +++ b/locale/connected_chests.eo.tr @@ -1,3 +1,3 @@ # textdomain: connected_chests Big Chest=Kestego -Big Locked Chest=Ŝlosita Kestego +Big Locked Chest=Ŝlosita kestego From 0e4ef74b52736d02fd77e208edf3d9d35e1f177e Mon Sep 17 00:00:00 2001 From: Ajrat Makhmutov Date: Tue, 21 May 2024 19:39:13 +0300 Subject: [PATCH 4/7] Add russian translation --- locale/connected_chests.ru.tr | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 locale/connected_chests.ru.tr diff --git a/locale/connected_chests.ru.tr b/locale/connected_chests.ru.tr new file mode 100644 index 0000000..5eb3b98 --- /dev/null +++ b/locale/connected_chests.ru.tr @@ -0,0 +1,3 @@ +# textdomain: connected_chests +Big Chest=Большой сундук +Big Locked Chest=Большой запертый сундук From 12b83258969ca611be712fb3764a293b454b785d Mon Sep 17 00:00:00 2001 From: Ajrat Makhmutov Date: Sun, 21 Jul 2024 04:14:30 +0300 Subject: [PATCH 5/7] Add hopper mod support --- init.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mod.conf | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 0a63291..8ed68aa 100644 --- a/init.lua +++ b/init.lua @@ -649,3 +649,59 @@ minetest.register_alias("connected_chests:chest_left_locked", "default:chest_loc minetest.register_alias("connected_chests:chest_right_locked", "default:chest_locked_connected_right") minetest.register_alias("connected_chests:chest_locked_left", "default:chest_locked_connected_left") minetest.register_alias("connected_chests:chest_locked_right", "default:chest_locked_connected_right") + +if minetest.get_modpath("hopper") then + local function get_inventory(chest_right_pos) + local node_right = minetest.get_node(chest_right_pos) + if node_right.param2 > 3 then + -- The right connected chest node has an invalid param2 value + -- Cannot determine the inventory + return + end + local x, z = unpack(param_tab2[node_right.param2]) + local chest_left_pos = {x=chest_right_pos.x+x, y=chest_right_pos.y, z=chest_right_pos.z+z} + local node_left = minetest.get_node(chest_left_pos) + if node_left.name ~= "default:chest_connected_left" and node_left.name ~= "default:chest_connected_left_open" then + minetest.log("error","The left chest is not a chest: " .. node_left.name .. " at " .. vector.to_string(chest_left_pos)) + return + end + if node_left.param2 ~= node_right.param2 then + minetest.log("error","The chests are pointing in different directions: node_left.param2:" + .. node_left.param2 .. ", node_right.param2:" .. node_right.param2) + return + end + return minetest.get_meta(chest_left_pos):get_inventory() + end + hopper:add_container({ + {"top", "default:chest_connected_left", "main"}, + {"bottom", "default:chest_connected_left", "main"}, + {"side", "default:chest_connected_left", "main"}, + {"top", "default:chest_connected_right", "main", get_inventory = get_inventory}, + {"bottom", "default:chest_connected_right", "main", get_inventory = get_inventory}, + {"side", "default:chest_connected_right", "main", get_inventory = get_inventory}, + {"top", "default:chest_connected_left_open", "main"}, + {"bottom", "default:chest_connected_left_open", "main"}, + {"side", "default:chest_connected_left_open", "main"}, + {"top", "default:chest_connected_right_open", "main", get_inventory = get_inventory}, + {"bottom", "default:chest_connected_right_open", "main", get_inventory = get_inventory}, + {"side", "default:chest_connected_right_open", "main", get_inventory = get_inventory}, + }) + local function set_hopper_param2(hopper_pos, chest_left_pos) + local param2_by_offset = { + [vector.new(-1, 0, 0):to_string()] = 0, + [vector.new( 0, 0, 1):to_string()] = 1, + [vector.new( 1, 0, 0):to_string()] = 2, + [vector.new( 0, 0,-1):to_string()] = 3, + } + local hopper_param2 = param2_by_offset[(chest_left_pos - hopper_pos):to_string()] + if hopper_param2 then + return hopper_param2 + end + local x, z = unpack(param_tab2[minetest.get_node(chest_left_pos).param2]) + local chest_right_pos = {x=chest_left_pos.x-x, y=chest_left_pos.y, z=chest_left_pos.z-z} + return param2_by_offset[(chest_right_pos - hopper_pos):to_string()] + end + hopper:set_extra_container_info({ + {"default:chest_connected_left", set_hopper_param2 = set_hopper_param2}, + }) +end diff --git a/mod.conf b/mod.conf index a874c1a..bad5138 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = connected_chests depends = default -optional_depends = pipeworks,technic +optional_depends = pipeworks,technic,hopper From 71a8a57ff1e834294ec39d5843149a7548a710d1 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sat, 17 Aug 2024 11:05:03 +0200 Subject: [PATCH 6/7] Fix luacheck linting luacheck currently fails because of missing globals and exceeding line length. To fix this, I add vector and hopper to the globals, add more line breaks in the code and remove outdated comments. --- .luacheckrc | 2 +- init.lua | 64 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index a31b01a..0c6c352 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,2 +1,2 @@ -read_globals = {"minetest", "table", "default", "pipeworks"} +read_globals = {"minetest", "table", "vector", "default", "hopper", "pipeworks"} globals = {"connected_chests"} diff --git a/init.lua b/init.lua index 8ed68aa..9b1af6b 100644 --- a/init.lua +++ b/init.lua @@ -377,14 +377,6 @@ function connected_chests.register_chest(fromname, data) end end - --~ def_opened.tiles[1] = "default_mese.png" -- top, passt - --~ def_opened.tiles[2] = "default_wood.png" -- bottom - --~ def_opened.tiles[3] = "default_stone.png" -- right and left side or so - --~ def_opened.tiles[4] = "default_obsidian.png" -- back side - - --~ def_opened.tiles[5] = "default_cobble.png" -- front side - --~ def_opened.tiles[6] = "default_leaves.png" -- inside - -- fix right side, somehow def_opened.tiles[4] = def_opened.tiles[3] def_opened.tiles[4].name = def_opened.tiles[4].name .. "^[transformFX" @@ -632,7 +624,8 @@ if not chest_lid_obstructed then (def.drawtype == "airlike" or def.drawtype == "signlike" or def.drawtype == "torchlike" or - (def.drawtype == "nodebox" and def.paramtype2 == "wallmounted")) then + (def.drawtype == "nodebox" + and def.paramtype2 == "wallmounted")) then return false end return true @@ -645,10 +638,14 @@ minetest.register_alias("connected_chests:chest_left", "default:chest_connected_left") minetest.register_alias("connected_chests:chest_right", "default:chest_connected_right") -minetest.register_alias("connected_chests:chest_left_locked", "default:chest_locked_connected_left") -minetest.register_alias("connected_chests:chest_right_locked", "default:chest_locked_connected_right") -minetest.register_alias("connected_chests:chest_locked_left", "default:chest_locked_connected_left") -minetest.register_alias("connected_chests:chest_locked_right", "default:chest_locked_connected_right") +minetest.register_alias("connected_chests:chest_left_locked", + "default:chest_locked_connected_left") +minetest.register_alias("connected_chests:chest_right_locked", + "default:chest_locked_connected_right") +minetest.register_alias("connected_chests:chest_locked_left", + "default:chest_locked_connected_left") +minetest.register_alias("connected_chests:chest_locked_right", + "default:chest_locked_connected_right") if minetest.get_modpath("hopper") then local function get_inventory(chest_right_pos) @@ -659,15 +656,19 @@ if minetest.get_modpath("hopper") then return end local x, z = unpack(param_tab2[node_right.param2]) - local chest_left_pos = {x=chest_right_pos.x+x, y=chest_right_pos.y, z=chest_right_pos.z+z} + local chest_left_pos = {x=chest_right_pos.x+x, y=chest_right_pos.y, + z=chest_right_pos.z+z} local node_left = minetest.get_node(chest_left_pos) - if node_left.name ~= "default:chest_connected_left" and node_left.name ~= "default:chest_connected_left_open" then - minetest.log("error","The left chest is not a chest: " .. node_left.name .. " at " .. vector.to_string(chest_left_pos)) + if node_left.name ~= "default:chest_connected_left" + and node_left.name ~= "default:chest_connected_left_open" then + minetest.log("error","The left chest is not a chest: " .. + node_left.name .. " at " .. vector.to_string(chest_left_pos)) return end if node_left.param2 ~= node_right.param2 then - minetest.log("error","The chests are pointing in different directions: node_left.param2:" - .. node_left.param2 .. ", node_right.param2:" .. node_right.param2) + minetest.log("error", "The chests are pointing in different " .. + "directions: node_left.param2:" .. node_left.param2 .. + ", node_right.param2:" .. node_right.param2) return end return minetest.get_meta(chest_left_pos):get_inventory() @@ -676,15 +677,21 @@ if minetest.get_modpath("hopper") then {"top", "default:chest_connected_left", "main"}, {"bottom", "default:chest_connected_left", "main"}, {"side", "default:chest_connected_left", "main"}, - {"top", "default:chest_connected_right", "main", get_inventory = get_inventory}, - {"bottom", "default:chest_connected_right", "main", get_inventory = get_inventory}, - {"side", "default:chest_connected_right", "main", get_inventory = get_inventory}, + {"top", "default:chest_connected_right", "main", + get_inventory = get_inventory}, + {"bottom", "default:chest_connected_right", "main", + get_inventory = get_inventory}, + {"side", "default:chest_connected_right", "main", + get_inventory = get_inventory}, {"top", "default:chest_connected_left_open", "main"}, {"bottom", "default:chest_connected_left_open", "main"}, {"side", "default:chest_connected_left_open", "main"}, - {"top", "default:chest_connected_right_open", "main", get_inventory = get_inventory}, - {"bottom", "default:chest_connected_right_open", "main", get_inventory = get_inventory}, - {"side", "default:chest_connected_right_open", "main", get_inventory = get_inventory}, + {"top", "default:chest_connected_right_open", "main", + get_inventory = get_inventory}, + {"bottom", "default:chest_connected_right_open", "main", + get_inventory = get_inventory}, + {"side", "default:chest_connected_right_open", "main", + get_inventory = get_inventory}, }) local function set_hopper_param2(hopper_pos, chest_left_pos) local param2_by_offset = { @@ -693,12 +700,15 @@ if minetest.get_modpath("hopper") then [vector.new( 1, 0, 0):to_string()] = 2, [vector.new( 0, 0,-1):to_string()] = 3, } - local hopper_param2 = param2_by_offset[(chest_left_pos - hopper_pos):to_string()] + local hopper_param2 = param2_by_offset[ + (chest_left_pos - hopper_pos):to_string()] if hopper_param2 then return hopper_param2 end - local x, z = unpack(param_tab2[minetest.get_node(chest_left_pos).param2]) - local chest_right_pos = {x=chest_left_pos.x-x, y=chest_left_pos.y, z=chest_left_pos.z-z} + local x, z = unpack( + param_tab2[minetest.get_node(chest_left_pos).param2]) + local chest_right_pos = {x=chest_left_pos.x-x, y=chest_left_pos.y, + z=chest_left_pos.z-z} return param2_by_offset[(chest_right_pos - hopper_pos):to_string()] end hopper:set_extra_container_info({ From 044a91fcd59ad4ab1dcd95351d2aaa9a17957760 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sun, 25 Aug 2024 09:48:03 +0200 Subject: [PATCH 7/7] Do not crash with tenplus1's hopper mod There are multiple hopper mods and not all of them support the set_extra_container_info function, so the mod crashes now if it is used together with an incompatible hopper mod. To prevent the crash, execute the code for hopper compatibility if hopper and hopper.set_extra_container_info exist and not if a mod named hopper is installed. --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 9b1af6b..98490b9 100644 --- a/init.lua +++ b/init.lua @@ -647,7 +647,7 @@ minetest.register_alias("connected_chests:chest_locked_left", minetest.register_alias("connected_chests:chest_locked_right", "default:chest_locked_connected_right") -if minetest.get_modpath("hopper") then +if minetest.global_exists("hopper") and hopper.set_extra_container_info then local function get_inventory(chest_right_pos) local node_right = minetest.get_node(chest_right_pos) if node_right.param2 > 3 then