Compare commits

..

21 Commits

Author SHA1 Message Date
462fe3bbe3 Merge remote-tracking branch 'upstream/master' 2024-09-15 08:46:38 +02:00
HybridDog
044a91fcd5 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.
2024-08-25 09:48:03 +02:00
HybridDog
71a8a57ff1 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.
2024-08-17 11:05:08 +02:00
Ajrat Makhmutov
12b8325896 Add hopper mod support 2024-08-17 10:22:35 +02:00
Ajrat Makhmutov
0e4ef74b52 Add russian translation 2024-05-22 20:13:25 +02:00
Jaidyn Ann
8a46cd1054 Tweak Esperanto translation 2024-05-20 11:04:50 +02:00
Jaidyn Ann
afb999dbbd Add Esperanto translation 2023-12-16 12:28:11 +01:00
Jaidyn Ann
5a5f472d61 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`.
2023-12-16 12:25:14 +01:00
e13bb490d1 Merge remote-tracking branch 'upstream/master' 2023-11-22 23:27:18 +01:00
HybridDog
01da3bf0b1 Change License 2023-07-15 12:45:37 +02:00
HybridDog
e575714eba Old code removal
Logging the loading time is not needed since Minetest writes it to the info log now.
2023-07-15 12:45:20 +02:00
HybridDog
c12542270b Add .luacheckrc for code linting 2023-07-15 12:44:00 +02:00
HybridDog
35da02ed5f Sound changes: Use a lower pitch for the big chest
I haven't changed the pitch for default_chest_locked since the sound seems to emanate from the lock and is thus unrelated to the chest size.
Additional, hardly-noticeable changes: Enable ephemeral as recommended and reduce the default_chest_close gain.
2023-07-15 12:13:55 +02:00
00eac777d7 Merge remote-tracking branch 'upstream/master' 2021-03-12 12:16:00 +01:00
HybridDog
02f3589c7a Replace the depends.txt with a mod.conf 2021-03-11 13:58:45 +01:00
1ec3601f7f Merge remote-tracking branch 'upstream/master' 2020-10-18 12:24:49 +02:00
HybridDog
f34f3b7724 Localise "node" 2020-10-18 00:00:25 +02:00
53d2009680 Merge branch 'master' into nalc-1.2 2019-05-06 01:11:32 +02:00
HybridDog
baefd45248 Update README 2019-03-08 17:46:58 +01:00
HybridDog
dd0c645899 Use LBM instead of ABM to fix rare half chests 2019-03-08 17:41:20 +01:00
HybridDog
04c7f21624 Fix README 2019-03-08 17:20:44 +01:00
9 changed files with 156 additions and 79 deletions

2
.luacheckrc Normal file
View File

@ -0,0 +1,2 @@
read_globals = {"minetest", "table", "vector", "default", "hopper", "pipeworks"}
globals = {"connected_chests"}

View File

@ -1,2 +1,2 @@
connected_chest_open from default connected_chest_open from default
rest WTFPL Content which is not copied from minetest_game is licensed under MIT.

View File

@ -1,12 +1,12 @@
[Mod] connected chests [connected_chests] [Mod] Connected Chests [connected_chests]
This mod allows making bigger default chests. This mod allows making bigger default chests.<br/>
Just hold shift and place a chest onto another one's side. Hold shift and place a chest onto another one's side to get a big chest.<br/>
This is not the first mod which adds big chests. This is not the first mod which adds big chests.
**Depends:** see [depends.txt](https://raw.githubusercontent.com/HybridDog/connected_chests/master/depends.txt) **Depends:** see [depends.txt](https://raw.githubusercontent.com/HybridDog/connected_chests/master/depends.txt)<br/>
**License:** see [LICENSE.txt](https://raw.githubusercontent.com/HybridDog/connected_chests/master/LICENSE.txt) **License:** see [LICENSE.txt](https://raw.githubusercontent.com/HybridDog/connected_chests/master/LICENSE.txt)<br/>
**Download:** [zip](https://github.com/HybridDog/connected_chests/archive/master.zip), [tar.gz](https://github.com/HybridDog/connected_chests/tarball/master) **Download:** [zip](https://github.com/HybridDog/connected_chests/archive/master.zip), [tar.gz](https://github.com/HybridDog/connected_chests/archive/master.tar.gz)
![I'm a screenshot!](http://wiki.minetest.net/images/d/d1/Connected_chest.png) ![I'm a screenshot!](http://wiki.minetest.net/images/d/d1/Connected_chest.png)
@ -16,5 +16,5 @@ If you got ideas or found bugs, please tell them to me.
TODO: TODO:
* add abms when registering the chest instead of using chestdata * Fix open big chest back side texture: The current .obj mesh model uses a side
* fix open big chest back side texture texture for the back side, so the model needs change.

View File

@ -1,3 +0,0 @@
default
pipeworks?
technic?

200
init.lua
View File

@ -1,5 +1,5 @@
local load_time_start = minetest.get_us_time() -- for translation
local S = minetest.get_translator("connected_chests")
-- param_tab maps the x and z offset to a param2 value -- param_tab maps the x and z offset to a param2 value
local param_tab = { local param_tab = {
@ -47,6 +47,9 @@ local function return_add_next(right_name)
-- if the left node is set with an unexpected rotation, put the chest -- if the left node is set with an unexpected rotation, put the chest
-- with default rotation -- with default rotation
if par > 3 then if par > 3 then
minetest.log("action",
node.name .. " with invalid param2 found, pos: " ..
minetest.pos_to_string(pos) .. ", param2: " .. par)
node.param2 = 0 node.param2 = 0
minetest.set_node(pos, node) minetest.set_node(pos, node)
return return
@ -92,7 +95,7 @@ local chestdata = {}
-- executed when connecting the chests -- executed when connecting the chests
local function connect_chests(pu, pa, old_param2, name) local function connect_chests(pu, pa, old_param2, data)
local metatable = minetest.get_meta(pu):to_table() local metatable = minetest.get_meta(pu):to_table()
local par = param_tab[pu.x-pa.x.." "..pu.z-pa.z] local par = param_tab[pu.x-pa.x.." "..pu.z-pa.z]
@ -102,7 +105,7 @@ local function connect_chests(pu, pa, old_param2, name)
par = par_inverted par = par_inverted
end end
chestdata[name].on_connect(pu, pa, par, metatable) data.on_connect(pu, pa, par, metatable)
end end
@ -136,6 +139,8 @@ end
connected_chests = {chestdata = chestdata} connected_chests = {chestdata = chestdata}
--[[ --[[
connected_chests.register_chest(<original_node>, { connected_chests.register_chest(<original_node>, {
description = <string>, -- The name of the connected chest as shown to the
-- player, i.e. the node metadata infotext
get_formspec = function(metatable, pos) get_formspec = function(metatable, pos)
return <formspec_of_big> return <formspec_of_big>
end, end,
@ -156,6 +161,13 @@ function connected_chests.register_chest(fromname, data)
data.left = name_left data.left = name_left
data.right = name_right 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 -- executed when connecting the chest
data.on_connect = function(pu, pa, par, metatable) data.on_connect = function(pu, pa, par, metatable)
minetest.add_node(pu, {name=name_left, param2=par}) 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 if not data.add_open_chest then
metatable.fields.formspec = data.get_formspec(metatable, pu) metatable.fields.formspec = data.get_formspec(metatable, pu)
end end
metatable.fields.infotext = "Big " .. metatable.fields.infotext metatable.fields.infotext = description
local meta = minetest.get_meta(pu) local meta = minetest.get_meta(pu)
meta:from_table(metatable) meta:from_table(metatable)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -188,7 +200,7 @@ function connected_chests.register_chest(fromname, data)
if minetest.is_protected(pa, placer:get_player_name()) then if minetest.is_protected(pa, placer:get_player_name()) then
return return
end end
connect_chests(pu, pa, par2, fromname) connect_chests(pu, pa, par2, data)
if not creative_mode then if not creative_mode then
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
@ -215,7 +227,7 @@ function connected_chests.register_chest(fromname, data)
local inside_texture local inside_texture
chest.description = "Big " .. chest.description chest.description = description
chest.groups = table.copy(chest.groups) chest.groups = table.copy(chest.groups)
chest.groups.not_in_creative_inventory = 1 chest.groups.not_in_creative_inventory = 1
chest.legacy_facedir_simple = nil chest.legacy_facedir_simple = nil
@ -276,7 +288,7 @@ function connected_chests.register_chest(fromname, data)
} }
def_opened.diggable = false def_opened.diggable = false
def_opened.on_blast = function() end def_opened.on_blast = function() end
inside_texture = "default_chest_inside.png^([combine:16x32:5,0=" .. inside_texture = "default_chest_inside.png^([combine:16x32:5,0=" ..
"default_chest_inside.png^connected_chests_inside_frame.png^[" .. "default_chest_inside.png^connected_chests_inside_frame.png^[" ..
"makealpha:255,126,126)" "makealpha:255,126,126)"
-- TODO, see right chest -- TODO, see right chest
@ -365,14 +377,6 @@ inside_texture = "default_chest_inside.png^([combine:16x32:5,0=" ..
end end
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 -- fix right side, somehow
def_opened.tiles[4] = def_opened.tiles[3] def_opened.tiles[4] = def_opened.tiles[3]
def_opened.tiles[4].name = def_opened.tiles[4].name .. "^[transformFX" def_opened.tiles[4].name = def_opened.tiles[4].name .. "^[transformFX"
@ -389,6 +393,35 @@ inside_texture = "default_chest_inside.png^([combine:16x32:5,0=" ..
end end
minetest.register_node(":" .. name_right, right_def) minetest.register_node(":" .. name_right, right_def)
-- LBMs to fix half chests if they occur for some reason
minetest.register_lbm{
label = "Connected Chest fixer " .. name_right,
name = ":" .. name_right .. "_reconnect_lbm",
nodenames = {name_right},
run_at_every_load = true,
action = function(pos, node)
if node.param2 > 3 then
node.param2 = node.param2%4
minetest.set_node(pos, node)
return
end
local x, z = unpack(param_tab2[node.param2])
local left_node = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z}
if left_node.name ~= name_left
or left_node.param2 ~= node.param2 then
minetest.remove_node(pos)
end
end,
}
minetest.register_lbm{
label = "Connected Chest fixer " .. name_left,
name = ":" .. name_left .. "_reconnect_lbm",
nodenames = {name_left},
run_at_every_load = true,
action = return_add_next(name_right),
}
end end
@ -443,7 +476,7 @@ local function close_chest(vi)
pos.x = pos.x + x * 0.5 pos.x = pos.x + x * 0.5
pos.z = pos.z + z * 0.5 pos.z = pos.z + z * 0.5
minetest.sound_play("default_chest_close", minetest.sound_play("default_chest_close",
{gain = 10.3, pos = pos, max_hear_distance = 10}) {gain = 0.3, pos = pos, max_hear_distance = 10, pitch = 0.7}, true)
end end
-- close all remaining open chest on shutdown -- close all remaining open chest on shutdown
@ -486,10 +519,11 @@ end)
local chest_lid_obstructed = default.chest local chest_lid_obstructed = default.chest
and default.chest.chest_lid_obstructed and default.chest.chest_lid_obstructed
connected_chests.register_chest("default:chest", { connected_chests.register_chest("default:chest", {
description = S("Big Chest"),
add_open_chest = true, add_open_chest = true,
on_rightclick = function(pos, _, player) on_rightclick = function(pos, _, player)
minetest.sound_play("default_chest_open", minetest.sound_play("default_chest_open",
{gain = 0.3, pos = pos, max_hear_distance = 10}) {gain = 0.3, pos = pos, max_hear_distance = 10, pitch = 0.7}, true)
local vi = minetest.hash_node_position(pos) local vi = minetest.hash_node_position(pos)
if not open_chests[vi] if not open_chests[vi]
@ -527,16 +561,17 @@ connected_chests.register_chest("default:chest", {
}) })
connected_chests.register_chest("default:chest_locked", { connected_chests.register_chest("default:chest_locked", {
description = S("Big Locked Chest"),
lock = true, lock = true,
add_open_chest = true, add_open_chest = true,
on_rightclick = function(pos, _, player) on_rightclick = function(pos, _, player)
if not default.can_interact_with_node(player, pos) then if not default.can_interact_with_node(player, pos) then
minetest.sound_play("default_chest_locked", {pos = pos}) minetest.sound_play("default_chest_locked", {pos = pos}, true)
return return
end end
minetest.sound_play("default_chest_open", minetest.sound_play("default_chest_open",
{gain = 0.32, pos = pos, max_hear_distance = 10}) {gain = 0.32, pos = pos, max_hear_distance = 10, pitch = 0.7}, true)
local vi = minetest.hash_node_position(pos) local vi = minetest.hash_node_position(pos)
-- TODO: somehow avoid using the chest node names here -- TODO: somehow avoid using the chest node names here
@ -547,7 +582,7 @@ connected_chests.register_chest("default:chest_locked", {
-- TODO: test for invalid param2 values -- TODO: test for invalid param2 values
local x, z = unpack(param_tab2[left_param2]) local x, z = unpack(param_tab2[left_param2])
local pos_right = {x=pos.x-x, y=pos.y, z=pos.z-z} local pos_right = {x=pos.x-x, y=pos.y, z=pos.z-z}
node = minetest.get_node(pos_right) local node = minetest.get_node(pos_right)
if node.name == "default:chest_locked_connected_right" if node.name == "default:chest_locked_connected_right"
and not chest_lid_obstructed(pos_right) then and not chest_lid_obstructed(pos_right) then
minetest.swap_node(pos_right, { minetest.swap_node(pos_right, {
@ -575,35 +610,6 @@ connected_chests.register_chest("default:chest_locked", {
}) })
-- abms to fix half chests
for _,i in pairs(chestdata) do
minetest.register_abm{
nodenames = {i.right},
interval = 10,
chance = 1,
action = function(pos, node)
if node.param2 > 3 then
node.param2 = node.param2%4
minetest.set_node(pos, node)
return
end
local x, z = unpack(param_tab2[node.param2])
local left_node = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z}
if left_node.name ~= i.left
or left_node.param2 ~= node.param2 then
minetest.remove_node(pos)
end
end,
}
minetest.register_abm{
nodenames = {i.left},
interval = 3,
chance = 1,
action = return_add_next(i.right),
}
end
-- legacy -- legacy
@ -618,7 +624,8 @@ if not chest_lid_obstructed then
(def.drawtype == "airlike" or (def.drawtype == "airlike" or
def.drawtype == "signlike" or def.drawtype == "signlike" or
def.drawtype == "torchlike" or def.drawtype == "torchlike" or
(def.drawtype == "nodebox" and def.paramtype2 == "wallmounted")) then (def.drawtype == "nodebox"
and def.paramtype2 == "wallmounted")) then
return false return false
end end
return true return true
@ -631,21 +638,80 @@ minetest.register_alias("connected_chests:chest_left",
"default:chest_connected_left") "default:chest_connected_left")
minetest.register_alias("connected_chests:chest_right", minetest.register_alias("connected_chests:chest_right",
"default:chest_connected_right") "default:chest_connected_right")
minetest.register_alias("connected_chests:chest_left_locked", "default:chest_locked_connected_left") minetest.register_alias("connected_chests:chest_left_locked",
minetest.register_alias("connected_chests:chest_right_locked", "default:chest_locked_connected_right") "default:chest_locked_connected_left")
minetest.register_alias("connected_chests:chest_locked_left", "default:chest_locked_connected_left") minetest.register_alias("connected_chests:chest_right_locked",
minetest.register_alias("connected_chests:chest_locked_right", "default:chest_locked_connected_right") "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")
--~ local function log_access(pos, player, text) if minetest.global_exists("hopper") and hopper.set_extra_container_info then
--~ minetest.log("action", player:get_player_name().. local function get_inventory(chest_right_pos)
--~ " moves stuff "..text.." at "..minetest.pos_to_string(pos)) local node_right = minetest.get_node(chest_right_pos)
--~ end if node_right.param2 > 3 then
-- The right connected chest node has an invalid param2 value
-- Cannot determine the inventory
local time = (minetest.get_us_time() - load_time_start) / 1000000 return
local msg = "[connected_chests] loaded after ca. " .. time .. " seconds." end
if time > 0.01 then local x, z = unpack(param_tab2[node_right.param2])
print(msg) local chest_left_pos = {x=chest_right_pos.x+x, y=chest_right_pos.y,
else z=chest_right_pos.z+z}
minetest.log("info", msg) 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 end

View File

@ -0,0 +1,3 @@
# textdomain: connected_chests
Big Chest=Kestego
Big Locked Chest=Ŝlosita kestego

View File

@ -0,0 +1,3 @@
# textdomain: connected_chests
Big Chest=Большой сундук
Big Locked Chest=Большой запертый сундук

3
locale/template.txt Normal file
View File

@ -0,0 +1,3 @@
# textdomain: connected_chests
Big Chest=
Big Locked Chest=

3
mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = connected_chests
depends = default
optional_depends = pipeworks,technic,hopper