2021-09-18 00:36:33 +02:00
|
|
|
local string = string
|
|
|
|
local table = table
|
|
|
|
local math = math
|
|
|
|
|
2024-06-21 09:29:21 +02:00
|
|
|
local sm = string.match
|
2021-09-18 00:36:33 +02:00
|
|
|
|
2023-10-27 00:15:57 +02:00
|
|
|
mcl_chests = {}
|
|
|
|
|
2021-12-11 17:16:10 +01:00
|
|
|
-- Christmas chest setup
|
2023-12-24 05:48:41 +01:00
|
|
|
local it_is_christmas = mcl_util.is_it_christmas()
|
2021-12-11 17:16:10 +01:00
|
|
|
|
2024-06-21 09:29:21 +02:00
|
|
|
local tiles = { -- extensions will be added later
|
|
|
|
chest_normal_small = { "mcl_chests_normal" },
|
|
|
|
chest_normal_double = { "mcl_chests_normal_double" },
|
|
|
|
chest_trapped_small = { "mcl_chests_trapped" },
|
|
|
|
chest_trapped_double = { "mcl_chests_trapped_double" },
|
|
|
|
chest_ender_small = { "mcl_chests_ender" },
|
|
|
|
ender_chest_texture = { "mcl_chests_ender" },
|
|
|
|
}
|
2021-12-11 17:16:10 +01:00
|
|
|
|
2024-06-21 09:29:21 +02:00
|
|
|
local tiles_postfix = ".png"
|
|
|
|
local tiles_postfix_double = ".png"
|
2021-12-11 17:16:10 +01:00
|
|
|
if it_is_christmas then
|
2024-06-21 09:29:21 +02:00
|
|
|
tiles_postfix = "_present.png^mcl_chests_noise.png"
|
|
|
|
tiles_postfix_double = "_present.png^mcl_chests_noise_double.png"
|
2021-12-11 17:16:10 +01:00
|
|
|
end
|
|
|
|
|
2024-06-21 09:29:21 +02:00
|
|
|
-- Append the postfixes for each entry
|
|
|
|
for k,v in pairs(tiles) do
|
|
|
|
if not sm(k, "double") then
|
|
|
|
tiles[k] = {v[1] .. tiles_postfix}
|
|
|
|
else
|
|
|
|
tiles[k] = {v[1] .. tiles_postfix_double}
|
|
|
|
end
|
2021-12-11 17:16:10 +01:00
|
|
|
end
|
|
|
|
|
2024-06-21 11:15:39 +02:00
|
|
|
mcl_chests.tiles = tiles
|
2024-06-20 15:02:48 +02:00
|
|
|
|
2024-06-21 11:15:39 +02:00
|
|
|
local modpath = minetest.get_modpath("mcl_chests")
|
|
|
|
dofile(modpath .. "/api.lua")
|
|
|
|
dofile(modpath .. "/chests.lua")
|
|
|
|
dofile(modpath .. "/ender.lua")
|
|
|
|
dofile(modpath .. "/shulkers.lua")
|
2024-06-22 16:37:32 +02:00
|
|
|
--dofile(modpath .. "/example.lua")
|
2024-06-21 09:29:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-03 14:21:35 +01:00
|
|
|
-- Disable chest when it has been closed
|
2017-03-16 04:16:37 +01:00
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
2021-01-03 14:21:35 +01:00
|
|
|
if formname:find("mcl_chests:") == 1 then
|
2017-03-16 04:16:37 +01:00
|
|
|
if fields.quit then
|
2024-06-21 11:15:39 +02:00
|
|
|
mcl_chests.player_chest_close(player)
|
2017-03-16 04:16:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2018-01-27 00:34:37 +01:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
2024-06-21 11:15:39 +02:00
|
|
|
mcl_chests.player_chest_close(player)
|
2018-01-27 00:34:37 +01:00
|
|
|
end)
|
|
|
|
|
2024-06-21 09:29:21 +02:00
|
|
|
|
|
|
|
|
2021-01-03 18:16:12 +01:00
|
|
|
local function select_and_spawn_entity(pos, node)
|
|
|
|
local node_name = node.name
|
|
|
|
local node_def = minetest.registered_nodes[node_name]
|
|
|
|
local double_chest = minetest.get_item_group(node_name, "double_chest") > 0
|
2024-06-21 11:15:39 +02:00
|
|
|
mcl_chests.find_or_create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest,
|
2022-09-09 20:42:28 +02:00
|
|
|
node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type)
|
2021-01-03 18:16:12 +01:00
|
|
|
end
|
|
|
|
|
2021-01-03 14:21:35 +01:00
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Spawn Chest entities",
|
|
|
|
name = "mcl_chests:spawn_chest_entities",
|
2022-09-09 20:42:28 +02:00
|
|
|
nodenames = { "group:chest_entity" },
|
2021-01-03 14:21:35 +01:00
|
|
|
run_at_every_load = true,
|
2021-01-03 18:16:12 +01:00
|
|
|
action = select_and_spawn_entity,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Replace old chest nodes",
|
|
|
|
name = "mcl_chests:replace_old",
|
2024-06-22 11:35:52 +02:00
|
|
|
nodenames = {
|
|
|
|
"mcl_chests:chest",
|
|
|
|
"mcl_chests:trapped_chest",
|
|
|
|
"mcl_chests:trapped_chest_on",
|
2022-09-09 20:42:28 +02:00
|
|
|
"mcl_chests:ender_chest",
|
2024-06-22 11:35:52 +02:00
|
|
|
"group:old_shulker_box_node"
|
|
|
|
},
|
2021-01-04 17:10:07 +01:00
|
|
|
run_at_every_load = true,
|
2021-01-03 14:21:35 +01:00
|
|
|
action = function(pos, node)
|
2021-01-03 18:52:24 +01:00
|
|
|
local node_name = node.name
|
|
|
|
node.name = node_name .. "_small"
|
2021-01-03 19:05:07 +01:00
|
|
|
minetest.swap_node(pos, node)
|
2021-01-03 18:16:12 +01:00
|
|
|
select_and_spawn_entity(pos, node)
|
2021-01-03 18:52:24 +01:00
|
|
|
if node_name == "mcl_chests:trapped_chest_on" then
|
2022-09-09 20:42:28 +02:00
|
|
|
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
|
2024-06-21 11:15:39 +02:00
|
|
|
mcl_chests.chest_update_after_close(pos)
|
2021-01-04 11:26:07 +01:00
|
|
|
elseif node_name == "mcl_chests:ender_chest" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", formspec_ender_chest)
|
2021-01-03 18:52:24 +01:00
|
|
|
end
|
2021-01-03 14:21:35 +01:00
|
|
|
end
|
|
|
|
})
|
2020-01-18 04:46:41 +01:00
|
|
|
|
2024-06-20 15:02:48 +02:00
|
|
|
-- Disable active/open trapped chests when loaded because nobody could have them open at loading time.
|
|
|
|
-- Fixes redstone weirdness.
|
2019-03-09 07:59:07 +01:00
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Disable active trapped chests",
|
|
|
|
name = "mcl_chests:reset_trapped_chests",
|
2024-06-22 11:35:52 +02:00
|
|
|
nodenames = {
|
|
|
|
"mcl_chests:trapped_chest_on_small",
|
|
|
|
"mcl_chests:trapped_chest_on_left",
|
|
|
|
"mcl_chests:trapped_chest_on_right"
|
|
|
|
},
|
2019-03-09 07:59:07 +01:00
|
|
|
run_at_every_load = true,
|
|
|
|
action = function(pos, node)
|
2022-09-09 20:42:28 +02:00
|
|
|
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
|
2024-06-21 11:15:39 +02:00
|
|
|
mcl_chests.chest_update_after_close(pos)
|
2020-03-29 14:35:01 +02:00
|
|
|
end,
|
|
|
|
})
|
2021-04-18 11:50:02 +02:00
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Upgrade old ender chest formspec",
|
2021-05-29 16:12:33 +02:00
|
|
|
name = "mcl_chests:replace_old_ender_form",
|
2022-09-09 20:42:28 +02:00
|
|
|
nodenames = { "mcl_chests:ender_chest_small" },
|
2021-05-29 16:12:33 +02:00
|
|
|
run_at_every_load = false,
|
|
|
|
action = function(pos, node)
|
2021-04-18 11:50:02 +02:00
|
|
|
minetest.get_meta(pos):set_string("formspec", "")
|
2021-05-29 16:12:33 +02:00
|
|
|
end,
|
2021-04-18 11:50:02 +02:00
|
|
|
})
|