forked from mtcontrib/connected_chests
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
482de1c06b | |||
a158d5db4a | |||
ccac8fe4ca | |||
2702cf4ae8 |
1
LICENSE.txt
Normal file
1
LICENSE.txt
Normal file
@ -0,0 +1 @@
|
||||
WTFPL
|
19
README.md
Normal file
19
README.md
Normal file
@ -0,0 +1,19 @@
|
||||
[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)
|
||||
|
||||

|
||||
|
||||
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
|
@ -1,2 +0,0 @@
|
||||
TODO:
|
||||
— disallow rotating the chest with a screwdriver
|
159
init.lua
159
init.lua
@ -1,6 +1,7 @@
|
||||
local load_time_start = os.clock()
|
||||
local load_time_start = minetest.get_us_time()
|
||||
|
||||
local creative_enabled = minetest.setting_getbool("creative_mode")
|
||||
|
||||
local creative_enabled = minetest.setting_getbool"creative_mode"
|
||||
|
||||
local big_formspec = "size[13,9]"..
|
||||
"list[current_name;main;0,0;13,5;]"..
|
||||
@ -8,8 +9,57 @@ local big_formspec = "size[13,9]"..
|
||||
"listring[current_name;main]"..
|
||||
"listring[current_player;main]"
|
||||
|
||||
local function formspec_biggerinv(spec)
|
||||
return big_formspec
|
||||
end
|
||||
|
||||
local chests = {}
|
||||
|
||||
local chestdata = {}
|
||||
local function register_chest(fromname, data)
|
||||
chestdata[fromname] = data
|
||||
|
||||
local mod, name = fromname:split":"
|
||||
|
||||
-- executed when connecting the chest
|
||||
chests[fromname] = function(pu, pa, par, metatable)
|
||||
minetest.add_node(pu, {name=fromname .. "_connected_left", param2=par})
|
||||
minetest.add_node(pa, {name=fromname .. "_connected_right", param2=par})
|
||||
|
||||
metatable.fields.formspec = formspec_biggerinv(metatable.fields.formspec)
|
||||
metatable.fields.infotext = "Big " .. metatable.fields.infotext
|
||||
local inv = metatable.inventory
|
||||
inv:set_size("main", 65)
|
||||
local meta = minetest.get_meta(pu)
|
||||
meta:from_table(metatable)
|
||||
end
|
||||
|
||||
-- override the original node to support connecting
|
||||
local place_chest = minetest.registered_nodes[fromname].on_place
|
||||
minetest.override_item(fromname, {
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer then
|
||||
return
|
||||
end
|
||||
local pu, pa, par2 = get_pointed_info(pointed_thing, fromname)
|
||||
if not pu
|
||||
or not placer:get_player_control().sneak then
|
||||
return place_chest(itemstack, placer, pointed_thing)
|
||||
end
|
||||
if minetest.is_protected(pa, placer:get_player_name()) then
|
||||
return
|
||||
end
|
||||
connect_chests(pu, pa, par2, fromname)
|
||||
if not creative_enabled then
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local chests = {
|
||||
["default:chest"] = function(pu, pa, par, stuff)
|
||||
["default:chest"] = function(pu, pa, par, metatable, stuff)
|
||||
minetest.add_node(pu, {name="connected_chests:chest_left", param2=par})
|
||||
minetest.add_node(pa, {name="connected_chests:chest_right", param2=par})
|
||||
|
||||
@ -29,7 +79,7 @@ local chests = {
|
||||
meta:set_string("owner", owner)
|
||||
meta:set_string("formspec", big_formspec)
|
||||
meta:set_string("infotext", "Big Locked Chest (owned by "..
|
||||
meta:get_string("owner")..")")
|
||||
meta:get_string"owner"..")")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 65)
|
||||
inv:set_list("main", stuff)
|
||||
@ -37,12 +87,12 @@ local chests = {
|
||||
}
|
||||
|
||||
|
||||
local function get_pointed_info(pointed_thing, name)
|
||||
if not pointed_thing then
|
||||
local function get_pointed_info(pt, name)
|
||||
if not pt then
|
||||
return
|
||||
end
|
||||
local pu = minetest.get_pointed_thing_position(pointed_thing)
|
||||
local pa = minetest.get_pointed_thing_position(pointed_thing, true)
|
||||
local pu = minetest.get_pointed_thing_position(pt)
|
||||
local pa = minetest.get_pointed_thing_position(pt, true)
|
||||
if not pu
|
||||
or not pa
|
||||
or pu.y ~= pa.y then
|
||||
@ -64,15 +114,14 @@ local param_tab = {
|
||||
|
||||
local param_tab2 = {}
|
||||
for n,i in pairs(param_tab) do
|
||||
param_tab2[i] = n
|
||||
param_tab2[i] = n:split" "
|
||||
end
|
||||
|
||||
local pars = {[0]=2, 3, 0, 1}
|
||||
|
||||
local function connect_chests(pu, pa, old_param2, name)
|
||||
local oldmeta = minetest.get_meta(pu)
|
||||
local stuff = oldmeta:get_inventory():get_list("main")
|
||||
local owner = oldmeta:get_string("owner")
|
||||
local metatable = minetest.get_meta(pu):to_table()
|
||||
print(dump(metatable))
|
||||
|
||||
local par = param_tab[pu.x-pa.x.." "..pu.z-pa.z]
|
||||
local par_inverted = pars[par]
|
||||
@ -81,10 +130,11 @@ local function connect_chests(pu, pa, old_param2, name)
|
||||
par = par_inverted
|
||||
end
|
||||
|
||||
chests[name](pu, pa, par, stuff, name, owner)
|
||||
chests[name](pu, pa, par, metatable)
|
||||
end
|
||||
|
||||
for name,_ in pairs(chests) do
|
||||
--[[
|
||||
for name in pairs(chests) do
|
||||
local place_chest = minetest.registered_nodes[name].on_place
|
||||
minetest.override_item(name, {
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
@ -106,14 +156,14 @@ for name,_ in pairs(chests) do
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
end--]]
|
||||
|
||||
local function return_remove_next(allowed_name)
|
||||
local function remove_next(pos, oldnode)
|
||||
if oldnode.param2 > 3 then
|
||||
return
|
||||
end
|
||||
local x, z = unpack(string.split(param_tab2[oldnode.param2], " "))
|
||||
local x, z = unpack(param_tab2[oldnode.param2])
|
||||
pos.x = pos.x-x
|
||||
pos.z = pos.z-z
|
||||
if minetest.get_node(pos).name == allowed_name then
|
||||
@ -132,7 +182,7 @@ local function return_add_next(right_name)
|
||||
minetest.set_node(pos, node)
|
||||
return
|
||||
end
|
||||
local x, z = unpack(string.split(param_tab2[par], " "))
|
||||
local x, z = unpack(param_tab2[par])
|
||||
pos.x = pos.x-x
|
||||
pos.z = pos.z-z
|
||||
if minetest.get_node(pos).name == "air" then
|
||||
@ -154,7 +204,12 @@ 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 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 = table.copy(minetest.registered_nodes["default:chest"])
|
||||
local chest = {}
|
||||
local origdef = minetest.registered_nodes["default:chest"]
|
||||
for i in pairs(origdef) do
|
||||
chest[i] = rawget(origdef, i)
|
||||
end
|
||||
|
||||
chest.description = nil
|
||||
chest.legacy_facedir_simple = nil
|
||||
chest.after_place_node = nil
|
||||
@ -168,8 +223,8 @@ chest.selection_box = {
|
||||
{-0.5, -0.5, -0.5, 1.5, 0.5, 0.5},
|
||||
},
|
||||
}
|
||||
chest.on_construct = return_add_next("connected_chests:chest_right")
|
||||
chest.after_destruct = return_remove_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.on_metadata_inventory_move = function(pos, _, _, _, _, _, player)
|
||||
log_access(pos, player, "in a big chest")
|
||||
end
|
||||
@ -183,7 +238,12 @@ end
|
||||
minetest.register_node("connected_chests:chest_left", chest)
|
||||
|
||||
|
||||
local chest_locked = table.copy(minetest.registered_nodes["default:chest_locked"])
|
||||
local 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.legacy_facedir_simple = nil
|
||||
chest_locked.after_place_node = nil
|
||||
@ -198,8 +258,8 @@ chest_locked.selection_box = {
|
||||
{-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.after_destruct = return_remove_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.on_metadata_inventory_move = function(pos, _, _, _, _, _, player)
|
||||
log_access(pos, player, "in a big locked chest")
|
||||
end
|
||||
@ -211,9 +271,11 @@ chest_locked.on_metadata_inventory_take = function(pos, _, _, _, player)
|
||||
end
|
||||
chest_locked.on_rightclick = function(pos, _, clicker)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if clicker:get_player_name() == meta:get_string("owner") or clicker:get_player_name() == minetest.setting_get("name") then
|
||||
local pname = clicker:get_player_name()
|
||||
if pname == meta:get_string"owner"
|
||||
or pname == minetest.setting_get"name" then
|
||||
minetest.show_formspec(
|
||||
clicker:get_player_name(),
|
||||
pname,
|
||||
"connected_chests:chest_locked_left",
|
||||
"size[13,9]"..
|
||||
"list[nodemeta:".. pos.x .. "," .. pos.y .. "," ..pos.z .. ";main;0,0;13,5;]"..
|
||||
@ -226,15 +288,15 @@ minetest.register_node("connected_chests:chest_locked_left", chest_locked)
|
||||
|
||||
|
||||
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 = {
|
||||
insert_object = function(pos, node, stack)
|
||||
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)
|
||||
local x, z = unpack(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)
|
||||
end,
|
||||
can_insert = function(pos, node, stack)
|
||||
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)
|
||||
local x, z = unpack(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)
|
||||
end,
|
||||
connect_sides = {right = 1, back = 1, front = 1, bottom = 1, top = 1}
|
||||
}
|
||||
@ -263,8 +325,8 @@ minetest.register_node("connected_chests:chest_right", {
|
||||
minetest.set_node(pos, node)
|
||||
return
|
||||
end
|
||||
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 x, z = unpack(param_tab2[node.param2])
|
||||
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"
|
||||
or node_left.param2 ~= node.param2 then
|
||||
minetest.remove_node(pos)
|
||||
@ -276,8 +338,8 @@ minetest.register_node("connected_chests:chest_right", {
|
||||
if oldnode.param2 > 3 then
|
||||
return
|
||||
end
|
||||
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 x, z = unpack(param_tab2[oldnode.param2])
|
||||
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"
|
||||
and node_left.param2 == oldnode.param2
|
||||
and minetest.get_node(pos).name == "air" then
|
||||
@ -305,8 +367,8 @@ minetest.register_node("connected_chests:chest_locked_right", {
|
||||
minetest.set_node(pos, node)
|
||||
return
|
||||
end
|
||||
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 x, z = unpack(param_tab2[node.param2])
|
||||
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"
|
||||
or node_left.param2 ~= node.param2 then
|
||||
minetest.remove_node(pos)
|
||||
@ -318,8 +380,8 @@ minetest.register_node("connected_chests:chest_locked_right", {
|
||||
if oldnode.param2 > 3 then
|
||||
return
|
||||
end
|
||||
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 x, z = unpack(param_tab2[oldnode.param2])
|
||||
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"
|
||||
and node_left.param2 == oldnode.param2
|
||||
and minetest.get_node(pos).name == "air" then
|
||||
@ -333,8 +395,8 @@ minetest.register_node("connected_chests:chest_locked_right", {
|
||||
})
|
||||
|
||||
-- abms to fix half chests
|
||||
for _,i in pairs({"chest", "chest_locked"}) do
|
||||
minetest.register_abm ({
|
||||
for _,i in pairs{"chest", "chest_locked"} do
|
||||
minetest.register_abm{
|
||||
nodenames = {"connected_chests:"..i.."_right"},
|
||||
interval = 10,
|
||||
chance = 1,
|
||||
@ -344,25 +406,26 @@ for _,i in pairs({"chest", "chest_locked"}) do
|
||||
minetest.set_node(pos, node)
|
||||
return
|
||||
end
|
||||
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 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 ~= "connected_chests:"..i.."_left"
|
||||
or left_node.param2 ~= node.param2 then
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
minetest.register_abm ({
|
||||
}
|
||||
minetest.register_abm{
|
||||
nodenames = {"connected_chests:"..i.."_left"},
|
||||
interval = 3,
|
||||
chance = 1,
|
||||
action = return_add_next("connected_chests:"..i.."_right"),
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
|
||||
local msg = "[connected_chests] loaded after ca. "..time
|
||||
if time > 0.05 then
|
||||
|
||||
local time = (minetest.get_us_time() - load_time_start) / 1000000
|
||||
local msg = "[connected_chests] loaded after ca. " .. time .. " seconds."
|
||||
if time > 0.01 then
|
||||
print(msg)
|
||||
else
|
||||
minetest.log("info", msg)
|
||||
|
Reference in New Issue
Block a user