1
0
mirror of https://github.com/HybridDog/connected_chests.git synced 2025-06-29 23:00:36 +02:00

1 Commits

Author SHA1 Message Date
8fcf23c55c Version MFF. 2018-09-07 19:34:44 +02:00
11 changed files with 47 additions and 83 deletions

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
## Generic ignorable patterns and files
*~
.*.swp
debug.txt

View File

@ -1 +0,0 @@
WTFPL

View File

@ -1,19 +0,0 @@
[Mod] connected chests [connected_chests]
This mod allows making bigger default chests.
Just hold shift and place a chest onto another one's side.
This is not the first mod which adds big chests.
**Depends:** see [depends.txt](https://raw.githubusercontent.com/HybridDog/connected_chests/master/depends.txt)
**License:** see [LICENSE.txt](https://raw.githubusercontent.com/HybridDog/connected_chests/master/LICENSE.txt)
**Download:** [zip](https://github.com/HybridDog/connected_chests/archive/master.zip), [tar.gz](https://github.com/HybridDog/connected_chests/tarball/master)
![I'm a screenshot!](http://wiki.minetest.net/images/d/d1/Connected_chest.png)
If you got ideas or found bugs, please tell them to me.
[How to install a mod?](http://wiki.minetest.net/Installing_Mods)
TODO:
— disallow rotating the chest with a screwdriver

2
README.txt Executable file
View File

@ -0,0 +1,2 @@
TODO:
— disallow rotating the chest with a screwdriver

0
depends.txt Normal file → Executable file
View File

104
init.lua Normal file → Executable file
View File

@ -1,7 +1,6 @@
local load_time_start = minetest.get_us_time() local load_time_start = os.clock()
local creative_enabled = minetest.setting_getbool("creative_mode")
local creative_enabled = minetest.setting_getbool"creative_mode"
local big_formspec = "size[13,9]".. local big_formspec = "size[13,9]"..
"list[current_name;main;0,0;13,5;]".. "list[current_name;main;0,0;13,5;]"..
@ -30,7 +29,7 @@ local chests = {
meta:set_string("owner", owner) meta:set_string("owner", owner)
meta:set_string("formspec", big_formspec) meta:set_string("formspec", big_formspec)
meta:set_string("infotext", "Big Locked Chest (owned by ".. meta:set_string("infotext", "Big Locked Chest (owned by "..
meta:get_string"owner"..")") meta:get_string("owner")..")")
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 65) inv:set_size("main", 65)
inv:set_list("main", stuff) inv:set_list("main", stuff)
@ -38,12 +37,12 @@ local chests = {
} }
local function get_pointed_info(pt, name) local function get_pointed_info(pointed_thing, name)
if not pt then if not pointed_thing then
return return
end end
local pu = minetest.get_pointed_thing_position(pt) local pu = minetest.get_pointed_thing_position(pointed_thing)
local pa = minetest.get_pointed_thing_position(pt, true) local pa = minetest.get_pointed_thing_position(pointed_thing, true)
if not pu if not pu
or not pa or not pa
or pu.y ~= pa.y then or pu.y ~= pa.y then
@ -65,15 +64,15 @@ local param_tab = {
local param_tab2 = {} local param_tab2 = {}
for n,i in pairs(param_tab) do for n,i in pairs(param_tab) do
param_tab2[i] = n:split" " param_tab2[i] = n
end end
local pars = {[0]=2, 3, 0, 1} local pars = {[0]=2, 3, 0, 1}
local function connect_chests(pu, pa, old_param2, name) local function connect_chests(pu, pa, old_param2, name)
local oldmeta = minetest.get_meta(pu) local oldmeta = minetest.get_meta(pu)
local stuff = oldmeta:get_inventory():get_list"main" local stuff = oldmeta:get_inventory():get_list("main")
local owner = oldmeta:get_string"owner" local owner = oldmeta:get_string("owner")
local par = param_tab[pu.x-pa.x.." "..pu.z-pa.z] local par = param_tab[pu.x-pa.x.." "..pu.z-pa.z]
local par_inverted = pars[par] local par_inverted = pars[par]
@ -85,7 +84,7 @@ local function connect_chests(pu, pa, old_param2, name)
chests[name](pu, pa, par, stuff, name, owner) chests[name](pu, pa, par, stuff, name, owner)
end end
for name in pairs(chests) do for name,_ in pairs(chests) do
local place_chest = minetest.registered_nodes[name].on_place local place_chest = minetest.registered_nodes[name].on_place
minetest.override_item(name, { minetest.override_item(name, {
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
@ -114,7 +113,7 @@ local function return_remove_next(allowed_name)
if oldnode.param2 > 3 then if oldnode.param2 > 3 then
return return
end end
local x, z = unpack(param_tab2[oldnode.param2]) local x, z = unpack(string.split(param_tab2[oldnode.param2], " "))
pos.x = pos.x-x pos.x = pos.x-x
pos.z = pos.z-z pos.z = pos.z-z
if minetest.get_node(pos).name == allowed_name then if minetest.get_node(pos).name == allowed_name then
@ -133,7 +132,7 @@ local function return_add_next(right_name)
minetest.set_node(pos, node) minetest.set_node(pos, node)
return return
end end
local x, z = unpack(param_tab2[par]) local x, z = unpack(string.split(param_tab2[par], " "))
pos.x = pos.x-x pos.x = pos.x-x
pos.z = pos.z-z pos.z = pos.z-z
if minetest.get_node(pos).name == "air" then if minetest.get_node(pos).name == "air" then
@ -155,12 +154,7 @@ end
local top_texture = "connected_chests_top.png^default_chest_top.png^([combine:16x16:5,0=default_chest_top.png^connected_chests_frame.png^[makealpha:255,126,126)^connected_chests_top.png" local top_texture = "connected_chests_top.png^default_chest_top.png^([combine:16x16:5,0=default_chest_top.png^connected_chests_frame.png^[makealpha:255,126,126)^connected_chests_top.png"
local side_texture = "connected_chests_side.png^default_chest_side.png^([combine:16x16:5,0=default_chest_side.png^connected_chests_frame.png^[makealpha:255,126,126)^connected_chests_side.png" local side_texture = "connected_chests_side.png^default_chest_side.png^([combine:16x16:5,0=default_chest_side.png^connected_chests_frame.png^[makealpha:255,126,126)^connected_chests_side.png"
local chest = {} local chest = table.copy(minetest.registered_nodes["default:chest"])
local origdef = minetest.registered_nodes["default:chest"]
for i in pairs(origdef) do
chest[i] = rawget(origdef, i)
end
chest.description = nil chest.description = nil
chest.legacy_facedir_simple = nil chest.legacy_facedir_simple = nil
chest.after_place_node = nil chest.after_place_node = nil
@ -174,8 +168,8 @@ chest.selection_box = {
{-0.5, -0.5, -0.5, 1.5, 0.5, 0.5}, {-0.5, -0.5, -0.5, 1.5, 0.5, 0.5},
}, },
} }
chest.on_construct = return_add_next"connected_chests:chest_right" chest.on_construct = return_add_next("connected_chests:chest_right")
chest.after_destruct = return_remove_next"connected_chests:chest_right" chest.after_destruct = return_remove_next("connected_chests:chest_right")
chest.on_metadata_inventory_move = function(pos, _, _, _, _, _, player) chest.on_metadata_inventory_move = function(pos, _, _, _, _, _, player)
log_access(pos, player, "in a big chest") log_access(pos, player, "in a big chest")
end end
@ -189,12 +183,7 @@ end
minetest.register_node("connected_chests:chest_left", chest) minetest.register_node("connected_chests:chest_left", chest)
local chest_locked = {} local chest_locked = table.copy(minetest.registered_nodes["default:chest_locked"])
local origdef = minetest.registered_nodes["default:chest_locked"]
for i in pairs(origdef) do
chest_locked[i] = rawget(origdef, i)
end
chest_locked.description = nil chest_locked.description = nil
chest_locked.legacy_facedir_simple = nil chest_locked.legacy_facedir_simple = nil
chest_locked.after_place_node = nil chest_locked.after_place_node = nil
@ -209,8 +198,8 @@ chest_locked.selection_box = {
{-0.5, -0.5, -0.5, 1.5, 0.5, 0.5}, {-0.5, -0.5, -0.5, 1.5, 0.5, 0.5},
}, },
} }
chest_locked.on_construct = return_add_next"connected_chests:chest_locked_right" chest_locked.on_construct = return_add_next("connected_chests:chest_locked_right")
chest_locked.after_destruct = return_remove_next"connected_chests:chest_locked_right" chest_locked.after_destruct = return_remove_next("connected_chests:chest_locked_right")
chest_locked.on_metadata_inventory_move = function(pos, _, _, _, _, _, player) chest_locked.on_metadata_inventory_move = function(pos, _, _, _, _, _, player)
log_access(pos, player, "in a big locked chest") log_access(pos, player, "in a big locked chest")
end end
@ -222,11 +211,9 @@ chest_locked.on_metadata_inventory_take = function(pos, _, _, _, player)
end end
chest_locked.on_rightclick = function(pos, _, clicker) chest_locked.on_rightclick = function(pos, _, clicker)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local pname = clicker:get_player_name() if clicker:get_player_name() == meta:get_string("owner") or clicker:get_player_name() == minetest.setting_get("name") then
if pname == meta:get_string"owner"
or pname == minetest.setting_get"name" then
minetest.show_formspec( minetest.show_formspec(
pname, clicker:get_player_name(),
"connected_chests:chest_locked_left", "connected_chests:chest_locked_left",
"size[13,9]".. "size[13,9]"..
"list[nodemeta:".. pos.x .. "," .. pos.y .. "," ..pos.z .. ";main;0,0;13,5;]".. "list[nodemeta:".. pos.x .. "," .. pos.y .. "," ..pos.z .. ";main;0,0;13,5;]"..
@ -239,15 +226,15 @@ minetest.register_node("connected_chests:chest_locked_left", chest_locked)
local tube_to_left, tube_to_left_locked, tube_update, tube_groups local tube_to_left, tube_to_left_locked, tube_update, tube_groups
if minetest.global_exists"pipeworks" then if minetest.global_exists("pipeworks") then
tube_to_left_locked = { tube_to_left_locked = {
insert_object = function(pos, node, stack) insert_object = function(pos, node, stack)
local x, z = unpack(param_tab2[node.param2]) local x, z = unpack(string.split(param_tab2[node.param2], " "))
return minetest.get_meta{x=pos.x+x, y=pos.y, z=pos.z+z}:get_inventory():add_item("main", stack) return minetest.get_meta({x=pos.x+x, y=pos.y, z=pos.z+z}):get_inventory():add_item("main", stack)
end, end,
can_insert = function(pos, node, stack) can_insert = function(pos, node, stack)
local x, z = unpack(param_tab2[node.param2]) local x, z = unpack(string.split(param_tab2[node.param2], " "))
return minetest.get_meta{x=pos.x+x, y=pos.y, z=pos.z+z}:get_inventory():room_for_item("main", stack) return minetest.get_meta({x=pos.x+x, y=pos.y, z=pos.z+z}):get_inventory():room_for_item("main", stack)
end, end,
connect_sides = {right = 1, back = 1, front = 1, bottom = 1, top = 1} connect_sides = {right = 1, back = 1, front = 1, bottom = 1, top = 1}
} }
@ -276,8 +263,8 @@ minetest.register_node("connected_chests:chest_right", {
minetest.set_node(pos, node) minetest.set_node(pos, node)
return return
end end
local x, z = unpack(param_tab2[node.param2]) local x, z = unpack(string.split(param_tab2[node.param2], " "))
local node_left = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z} local node_left = minetest.get_node({x=pos.x+x, y=pos.y, z=pos.z+z})
if node_left.name ~= "connected_chests:chest_left" if node_left.name ~= "connected_chests:chest_left"
or node_left.param2 ~= node.param2 then or node_left.param2 ~= node.param2 then
minetest.remove_node(pos) minetest.remove_node(pos)
@ -289,8 +276,8 @@ minetest.register_node("connected_chests:chest_right", {
if oldnode.param2 > 3 then if oldnode.param2 > 3 then
return return
end end
local x, z = unpack(param_tab2[oldnode.param2]) local x, z = unpack(string.split(param_tab2[oldnode.param2], " "))
local node_left = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z} local node_left = minetest.get_node({x=pos.x+x, y=pos.y, z=pos.z+z})
if node_left.name == "connected_chests:chest_left" if node_left.name == "connected_chests:chest_left"
and node_left.param2 == oldnode.param2 and node_left.param2 == oldnode.param2
and minetest.get_node(pos).name == "air" then and minetest.get_node(pos).name == "air" then
@ -318,8 +305,8 @@ minetest.register_node("connected_chests:chest_locked_right", {
minetest.set_node(pos, node) minetest.set_node(pos, node)
return return
end end
local x, z = unpack(param_tab2[node.param2]) local x, z = unpack(string.split(param_tab2[node.param2], " "))
local node_left = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z} local node_left = minetest.get_node({x=pos.x+x, y=pos.y, z=pos.z+z})
if node_left.name ~= "connected_chests:chest_locked_left" if node_left.name ~= "connected_chests:chest_locked_left"
or node_left.param2 ~= node.param2 then or node_left.param2 ~= node.param2 then
minetest.remove_node(pos) minetest.remove_node(pos)
@ -331,8 +318,8 @@ minetest.register_node("connected_chests:chest_locked_right", {
if oldnode.param2 > 3 then if oldnode.param2 > 3 then
return return
end end
local x, z = unpack(param_tab2[oldnode.param2]) local x, z = unpack(string.split(param_tab2[oldnode.param2], " "))
local node_left = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z} local node_left = minetest.get_node({x=pos.x+x, y=pos.y, z=pos.z+z})
if node_left.name == "connected_chests:chest_locked_left" if node_left.name == "connected_chests:chest_locked_left"
and node_left.param2 == oldnode.param2 and node_left.param2 == oldnode.param2
and minetest.get_node(pos).name == "air" then and minetest.get_node(pos).name == "air" then
@ -346,37 +333,36 @@ minetest.register_node("connected_chests:chest_locked_right", {
}) })
-- abms to fix half chests -- abms to fix half chests
for _,i in pairs{"chest", "chest_locked"} do for _,i in pairs({"chest", "chest_locked"}) do
minetest.register_abm{ minetest.register_abm ({
nodenames = {"connected_chests:"..i.."_right"}, nodenames = {"connected_chests:"..i.."_right"},
interval = 10, interval = 10,
chance = 1, chance = 1,
action = function(pos, node) action = function (pos, node)
if node.param2 > 3 then if node.param2 > 3 then
node.param2 = node.param2%4 node.param2 = node.param2%4
minetest.set_node(pos, node) minetest.set_node(pos, node)
return return
end end
local x, z = unpack(param_tab2[node.param2]) local x, z = unpack(string.split(param_tab2[node.param2], " "))
local left_node = minetest.get_node{x=pos.x+x, y=pos.y, z=pos.z+z} local left_node = minetest.get_node({x=pos.x+x, y=pos.y, z=pos.z+z})
if left_node.name ~= "connected_chests:"..i.."_left" if left_node.name ~= "connected_chests:"..i.."_left"
or left_node.param2 ~= node.param2 then or left_node.param2 ~= node.param2 then
minetest.remove_node(pos) minetest.remove_node(pos)
end end
end, end,
} })
minetest.register_abm{ minetest.register_abm ({
nodenames = {"connected_chests:"..i.."_left"}, nodenames = {"connected_chests:"..i.."_left"},
interval = 3, interval = 3,
chance = 1, chance = 1,
action = return_add_next("connected_chests:"..i.."_right"), action = return_add_next("connected_chests:"..i.."_right"),
} })
end end
local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local time = (minetest.get_us_time() - load_time_start) / 1000000 local msg = "[connected_chests] loaded after ca. "..time
local msg = "[connected_chests] loaded after ca. " .. time .. " seconds." if time > 0.05 then
if time > 0.01 then
print(msg) print(msg)
else else
minetest.log("info", msg) minetest.log("info", msg)

0
textures/connected_chests_frame.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 88 B

BIN
textures/connected_chests_front.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 196 B

BIN
textures/connected_chests_lock.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 B

After

Width:  |  Height:  |  Size: 287 B

BIN
textures/connected_chests_side.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 B

After

Width:  |  Height:  |  Size: 331 B

BIN
textures/connected_chests_top.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 B

After

Width:  |  Height:  |  Size: 419 B