VoxeLibre/mods/ITEMS/mcl_chests/init.lua

92 lines
2.5 KiB
Lua
Raw Permalink Normal View History

2021-09-18 00:36:33 +02:00
local string = string
local sm = string.match
2021-09-18 00:36:33 +02:00
mcl_chests = {}
-- Christmas chest setup
2023-12-24 05:48:41 +01:00
local it_is_christmas = mcl_util.is_it_christmas()
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" },
}
local tiles_postfix = ".png"
local tiles_postfix_double = ".png"
if it_is_christmas then
tiles_postfix = "_present.png^mcl_chests_noise.png"
tiles_postfix_double = "_present.png^mcl_chests_noise_double.png"
end
-- 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
end
mcl_chests.tiles = tiles
local modpath = minetest.get_modpath("mcl_chests")
dofile(modpath .. "/api.lua")
dofile(modpath .. "/chests.lua")
dofile(modpath .. "/ender.lua")
dofile(modpath .. "/shulkers.lua")
--dofile(modpath .. "/example.lua")
2021-01-03 14:21:35 +01:00
-- Disable chest when it has been closed
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
if fields.quit then
mcl_chests.player_chest_close(player)
end
end
end)
minetest.register_on_leaveplayer(function(player)
mcl_chests.player_chest_close(player)
end)
2021-01-03 14:21:35 +01:00
minetest.register_lbm({
label = "Spawn Chest entities",
name = "mcl_chests:spawn_chest_entities",
nodenames = { "group:chest_entity" },
2021-01-03 14:21:35 +01:00
run_at_every_load = true,
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",
nodenames = {
"mcl_chests:chest",
"mcl_chests:trapped_chest",
"mcl_chests:trapped_chest_on",
"mcl_chests:ender_chest",
"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
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
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
})