178 lines
4.5 KiB
Lua
178 lines
4.5 KiB
Lua
fun_caves = {}
|
|
fun_caves.version = "1.0"
|
|
fun_caves.time_factor = 10 -- affects growth abms
|
|
fun_caves.light_max = 8 -- light intensity for mushroom growth
|
|
fun_caves.path = minetest.get_modpath(minetest.get_current_modname())
|
|
fun_caves.world = minetest.get_worldpath()
|
|
|
|
fun_caves.elixir_armor = minetest.setting_getbool('fun_caves_use_armor_elixirs')
|
|
if fun_caves.elixir_armor == nil then
|
|
fun_caves.elixir_armor = true
|
|
end
|
|
|
|
fun_caves.expire_elixir_on_death = minetest.setting_getbool('fun_caves_expire_elixir_on_death')
|
|
if fun_caves.expire_elixir_on_death == nil then
|
|
fun_caves.expire_elixir_on_death = true
|
|
end
|
|
|
|
fun_caves.exploding_fungi = minetest.setting_getbool('fun_caves_exploding_fungi')
|
|
if fun_caves.exploding_fungi == nil then
|
|
fun_caves.exploding_fungi = true
|
|
end
|
|
|
|
fun_caves.breakable_wood = minetest.setting_getbool('fun_caves_breakable_wood')
|
|
if fun_caves.breakable_wood == nil then
|
|
fun_caves.breakable_wood = false
|
|
end
|
|
|
|
fun_caves.DEBUG = false -- for maintenance only
|
|
|
|
|
|
|
|
local inp = io.open(fun_caves.world..'/fun_caves_data.txt','r')
|
|
if inp then
|
|
local d = inp:read('*a')
|
|
fun_caves.db = minetest.deserialize(d)
|
|
inp.close()
|
|
end
|
|
if not fun_caves.db then
|
|
fun_caves.db = {}
|
|
end
|
|
for _, i in pairs({'teleport_data', 'hunger', 'spawn'}) do
|
|
if not fun_caves.db[i] then
|
|
fun_caves.db[i] = {}
|
|
end
|
|
end
|
|
|
|
|
|
-- whether to use biomes and heightmap
|
|
fun_caves.use_bi_hi = false
|
|
local mg_params = minetest.get_mapgen_params()
|
|
if mg_params and mg_params.mgname ~= "v6" and mg_params.mgname ~= "v5" then
|
|
fun_caves.use_bi_hi = true
|
|
end
|
|
|
|
|
|
minetest.register_on_mapgen_init(function(mgparams)
|
|
minetest.set_mapgen_params({flags="nocaves,nodungeons"})
|
|
end)
|
|
|
|
|
|
-- Check if the table contains an element.
|
|
function table.contains(table, element)
|
|
for key, value in pairs(table) do
|
|
if value == element then
|
|
if key then
|
|
return key
|
|
else
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- Modify a node to add a group
|
|
function minetest.add_group(node, groups)
|
|
local def = minetest.registered_items[node]
|
|
if not def then
|
|
return false
|
|
end
|
|
local def_groups = def.groups or {}
|
|
for group, value in pairs(groups) do
|
|
if value ~= 0 then
|
|
def_groups[group] = value
|
|
else
|
|
def_groups[group] = nil
|
|
end
|
|
end
|
|
minetest.override_item(node, {groups = def_groups})
|
|
return true
|
|
end
|
|
|
|
function fun_caves.clone_node(name)
|
|
local node = minetest.registered_nodes[name]
|
|
local node2 = table.copy(node)
|
|
return node2
|
|
end
|
|
|
|
|
|
--dofile(fun_caves.path .. "/recipe_list.lua")
|
|
|
|
dofile(fun_caves.path .. "/abms.lua")
|
|
dofile(fun_caves.path .. "/nodes.lua")
|
|
dofile(fun_caves.path .. "/deco.lua")
|
|
dofile(fun_caves.path .. "/fungal_tree.lua")
|
|
dofile(fun_caves.path .. "/elixir.lua")
|
|
dofile(fun_caves.path .. "/wallhammer.lua")
|
|
dofile(fun_caves.path .. "/mapgen.lua")
|
|
dofile(fun_caves.path .. "/chat.lua")
|
|
|
|
if mobs and mobs.mod == "redo" then
|
|
dofile(fun_caves.path .. "/mobs.lua")
|
|
end
|
|
|
|
--fun_caves.print_recipes()
|
|
|
|
|
|
local hunger_mod = minetest.get_modpath("hunger")
|
|
fun_caves.hunger_id = {}
|
|
|
|
function fun_caves.hunger_change(player, change)
|
|
local name = player:get_player_name()
|
|
if hunger_mod then
|
|
if change < 0 then
|
|
hunger.update_hunger(player, hunger.players[name].lvl + change * 4)
|
|
end
|
|
return
|
|
end
|
|
|
|
local hp = player:get_hp()
|
|
if change < 0 or hp >= 16 then
|
|
fun_caves.db.hunger[name] = math.min(20, math.max(0, fun_caves.db.hunger[name] + change))
|
|
player:hud_change(fun_caves.hunger_id[name], 'number', fun_caves.db.hunger[name])
|
|
if fun_caves.db.hunger[name] == 0 then
|
|
player:set_hp(player:get_hp() - 1)
|
|
end
|
|
end
|
|
end
|
|
|
|
if not hunger_mod then
|
|
minetest.register_on_joinplayer(function(player)
|
|
local name = player:get_player_name()
|
|
|
|
if not fun_caves.db.hunger[name] then
|
|
fun_caves.db.hunger[name] = 20
|
|
end
|
|
|
|
local hunger_bar = {
|
|
hud_elem_type = 'statbar',
|
|
position = {x=0.52, y=0.883},
|
|
name = "hunger",
|
|
text = "farming_bread.png",
|
|
number = fun_caves.db.hunger[name],
|
|
direction = 0,
|
|
size = { x=24, y=24 },
|
|
}
|
|
|
|
fun_caves.hunger_id[name] = player:hud_add(hunger_bar)
|
|
end)
|
|
|
|
minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
|
if hp_change > 0 then
|
|
fun_caves.hunger_change(user, hp_change)
|
|
end
|
|
end)
|
|
|
|
minetest.register_on_dieplayer(function(player)
|
|
local name = player:get_player_name()
|
|
local pos = vector.round(player:getpos())
|
|
|
|
if not hunger_mod then
|
|
fun_caves.db.hunger[name] = 20
|
|
player:hud_change(fun_caves.hunger_id[name], 'number', 20)
|
|
end
|
|
|
|
minetest.chat_send_player(name, 'Your bones will lie at ('..pos.x..','..pos.y..','..pos.z..'), in ignominy, unless you collect them.')
|
|
end)
|
|
end
|