2021-09-18 00:36:33 +02:00
|
|
|
local string = string
|
|
|
|
|
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)
|
|
|
|
|
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,
|
2024-06-24 15:19:43 +02:00
|
|
|
action = mcl_chests.select_and_spawn_entity,
|
2021-01-03 18:16:12 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
})
|