|
@@ -1811,7 +1811,9 @@ minetest.register_node("default:lava_flowing", {
|
|
|
-- Tools / "Advanced" crafting / Non-"natural"
|
|
|
--
|
|
|
|
|
|
-function default.get_chest_formspec(pos)
|
|
|
+default.chest = {}
|
|
|
+
|
|
|
+function default.chest.get_chest_formspec(pos)
|
|
|
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
|
|
|
local formspec =
|
|
|
"size[8,9]" ..
|
|
@@ -1827,7 +1829,7 @@ function default.get_chest_formspec(pos)
|
|
|
return formspec
|
|
|
end
|
|
|
|
|
|
-local function chest_lid_obstructed(pos)
|
|
|
+function default.chest.chest_lid_obstructed(pos)
|
|
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
|
|
local def = minetest.registered_nodes[minetest.get_node(above).name]
|
|
|
-- allow ladders, signs, wallmounted things and torches to not obstruct
|
|
@@ -1841,15 +1843,14 @@ local function chest_lid_obstructed(pos)
|
|
|
return true
|
|
|
end
|
|
|
|
|
|
-local open_chests = {}
|
|
|
-
|
|
|
-local function chest_lid_close(pn)
|
|
|
- local pos = open_chests[pn].pos
|
|
|
- local sound = open_chests[pn].sound
|
|
|
- local swap = open_chests[pn].swap
|
|
|
+function default.chest.chest_lid_close(pn)
|
|
|
+ local chest_open_info = default.chest.open_chests[pn]
|
|
|
+ local pos = chest_open_info.pos
|
|
|
+ local sound = chest_open_info.sound
|
|
|
+ local swap = chest_open_info.swap
|
|
|
|
|
|
- open_chests[pn] = nil
|
|
|
- for k, v in pairs(open_chests) do
|
|
|
+ default.chest.open_chests[pn] = nil
|
|
|
+ for k, v in pairs(default.chest.open_chests) do
|
|
|
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then
|
|
|
return true
|
|
|
end
|
|
@@ -1861,6 +1862,8 @@ local function chest_lid_close(pn)
|
|
|
minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10})
|
|
|
end
|
|
|
|
|
|
+default.chest.open_chests = {}
|
|
|
+
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
if formname ~= "default:chest" then
|
|
|
return
|
|
@@ -1870,22 +1873,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
end
|
|
|
local pn = player:get_player_name()
|
|
|
|
|
|
- if not open_chests[pn] then
|
|
|
+ if not default.chest.open_chests[pn] then
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- chest_lid_close(pn)
|
|
|
+ default.chest.chest_lid_close(pn)
|
|
|
return true
|
|
|
end)
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
local pn = player:get_player_name()
|
|
|
- if open_chests[pn] then
|
|
|
- chest_lid_close(pn)
|
|
|
+ if default.chest.open_chests[pn] then
|
|
|
+ default.chest.chest_lid_close(pn)
|
|
|
end
|
|
|
end)
|
|
|
|
|
|
-function default.register_chest(name, d)
|
|
|
+function default.chest.register_chest(name, d)
|
|
|
local def = table.copy(d)
|
|
|
def.drawtype = "mesh"
|
|
|
def.visual = "mesh"
|
|
@@ -1940,15 +1943,15 @@ function default.register_chest(name, d)
|
|
|
|
|
|
minetest.sound_play(def.sound_open, {gain = 0.3,
|
|
|
pos = pos, max_hear_distance = 10})
|
|
|
- if not chest_lid_obstructed(pos) then
|
|
|
+ if not default.chest.chest_lid_obstructed(pos) then
|
|
|
minetest.swap_node(pos,
|
|
|
{ name = "default:" .. name .. "_open",
|
|
|
param2 = node.param2 })
|
|
|
end
|
|
|
minetest.after(0.2, minetest.show_formspec,
|
|
|
clicker:get_player_name(),
|
|
|
- "default:chest", default.get_chest_formspec(pos))
|
|
|
- open_chests[clicker:get_player_name()] = { pos = pos,
|
|
|
+ "default:chest", default.chest.get_chest_formspec(pos))
|
|
|
+ default.chest.open_chests[clicker:get_player_name()] = { pos = pos,
|
|
|
sound = def.sound_close, swap = name }
|
|
|
end
|
|
|
def.on_blast = function() end
|
|
@@ -1969,7 +1972,7 @@ function default.register_chest(name, d)
|
|
|
minetest.show_formspec(
|
|
|
player:get_player_name(),
|
|
|
"default:chest_locked",
|
|
|
- default.get_chest_formspec(pos)
|
|
|
+ default.chest.get_chest_formspec(pos)
|
|
|
)
|
|
|
end
|
|
|
def.on_skeleton_key_use = function(pos, player, newsecret)
|
|
@@ -2007,15 +2010,15 @@ function default.register_chest(name, d)
|
|
|
def.on_rightclick = function(pos, node, clicker)
|
|
|
minetest.sound_play(def.sound_open, {gain = 0.3, pos = pos,
|
|
|
max_hear_distance = 10})
|
|
|
- if not chest_lid_obstructed(pos) then
|
|
|
+ if not default.chest.chest_lid_obstructed(pos) then
|
|
|
minetest.swap_node(pos, {
|
|
|
name = "default:" .. name .. "_open",
|
|
|
param2 = node.param2 })
|
|
|
end
|
|
|
minetest.after(0.2, minetest.show_formspec,
|
|
|
clicker:get_player_name(),
|
|
|
- "default:chest", default.get_chest_formspec(pos))
|
|
|
- open_chests[clicker:get_player_name()] = { pos = pos,
|
|
|
+ "default:chest", default.chest.get_chest_formspec(pos))
|
|
|
+ default.chest.open_chests[clicker:get_player_name()] = { pos = pos,
|
|
|
sound = def.sound_close, swap = name }
|
|
|
end
|
|
|
def.on_blast = function(pos)
|
|
@@ -2093,8 +2096,7 @@ function default.register_chest(name, d)
|
|
|
})
|
|
|
end
|
|
|
|
|
|
-
|
|
|
-default.register_chest("chest", {
|
|
|
+default.chest.register_chest("chest", {
|
|
|
description = "Chest",
|
|
|
tiles = {
|
|
|
"default_chest_top.png",
|
|
@@ -2110,7 +2112,7 @@ default.register_chest("chest", {
|
|
|
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
|
|
})
|
|
|
|
|
|
-default.register_chest("chest_locked", {
|
|
|
+default.chest.register_chest("chest_locked", {
|
|
|
description = "Locked Chest",
|
|
|
tiles = {
|
|
|
"default_chest_top.png",
|