|
|
@ -1,5 +1,5 @@
|
|
|
|
-- for translation
|
|
|
|
local load_time_start = minetest.get_us_time()
|
|
|
|
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 = {
|
|
|
@ -139,8 +139,6 @@ 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,
|
|
|
@ -161,13 +159,6 @@ 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})
|
|
|
@ -176,7 +167,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 = description
|
|
|
|
metatable.fields.infotext = "Big " .. metatable.fields.infotext
|
|
|
|
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()
|
|
|
@ -227,7 +218,7 @@ function connected_chests.register_chest(fromname, data)
|
|
|
|
local inside_texture
|
|
|
|
local inside_texture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chest.description = description
|
|
|
|
chest.description = "Big " .. chest.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
|
|
|
@ -377,6 +368,14 @@ function connected_chests.register_chest(fromname, data)
|
|
|
|
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"
|
|
|
@ -476,7 +475,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 = 0.3, pos = pos, max_hear_distance = 10, pitch = 0.7}, true)
|
|
|
|
{gain = 10.3, pos = pos, max_hear_distance = 10})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- close all remaining open chest on shutdown
|
|
|
|
-- close all remaining open chest on shutdown
|
|
|
@ -519,11 +518,10 @@ 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, pitch = 0.7}, true)
|
|
|
|
{gain = 0.3, pos = pos, max_hear_distance = 10})
|
|
|
|
|
|
|
|
|
|
|
|
local vi = minetest.hash_node_position(pos)
|
|
|
|
local vi = minetest.hash_node_position(pos)
|
|
|
|
if not open_chests[vi]
|
|
|
|
if not open_chests[vi]
|
|
|
@ -561,17 +559,16 @@ 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}, true)
|
|
|
|
minetest.sound_play("default_chest_locked", {pos = pos})
|
|
|
|
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, pitch = 0.7}, true)
|
|
|
|
{gain = 0.32, pos = pos, max_hear_distance = 10})
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
@ -582,7 +579,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}
|
|
|
|
local node = minetest.get_node(pos_right)
|
|
|
|
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, {
|
|
|
@ -624,8 +621,7 @@ 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"
|
|
|
|
(def.drawtype == "nodebox" and def.paramtype2 == "wallmounted")) then
|
|
|
|
and def.paramtype2 == "wallmounted")) then
|
|
|
|
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
return true
|
|
|
@ -638,80 +634,21 @@ 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",
|
|
|
|
minetest.register_alias("connected_chests:chest_left_locked", "default:chest_locked_connected_left")
|
|
|
|
"default:chest_locked_connected_left")
|
|
|
|
minetest.register_alias("connected_chests:chest_right_locked", "default:chest_locked_connected_right")
|
|
|
|
minetest.register_alias("connected_chests:chest_right_locked",
|
|
|
|
minetest.register_alias("connected_chests:chest_locked_left", "default:chest_locked_connected_left")
|
|
|
|
"default:chest_locked_connected_right")
|
|
|
|
minetest.register_alias("connected_chests:chest_locked_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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if minetest.get_modpath("hopper") then
|
|
|
|
--~ local function log_access(pos, player, text)
|
|
|
|
local function get_inventory(chest_right_pos)
|
|
|
|
--~ minetest.log("action", player:get_player_name()..
|
|
|
|
local node_right = minetest.get_node(chest_right_pos)
|
|
|
|
--~ " moves stuff "..text.." at "..minetest.pos_to_string(pos))
|
|
|
|
if node_right.param2 > 3 then
|
|
|
|
--~ end
|
|
|
|
-- The right connected chest node has an invalid param2 value
|
|
|
|
|
|
|
|
-- Cannot determine the inventory
|
|
|
|
|
|
|
|
return
|
|
|
|
local time = (minetest.get_us_time() - load_time_start) / 1000000
|
|
|
|
end
|
|
|
|
local msg = "[connected_chests] loaded after ca. " .. time .. " seconds."
|
|
|
|
local x, z = unpack(param_tab2[node_right.param2])
|
|
|
|
if time > 0.01 then
|
|
|
|
local chest_left_pos = {x=chest_right_pos.x+x, y=chest_right_pos.y,
|
|
|
|
print(msg)
|
|
|
|
z=chest_right_pos.z+z}
|
|
|
|
else
|
|
|
|
local node_left = minetest.get_node(chest_left_pos)
|
|
|
|
minetest.log("info", msg)
|
|
|
|
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
|
|
|
|