hades_revisited/mods/hades_core/functions.lua

511 lines
13 KiB
Lua
Raw Permalink Normal View History

2020-03-28 19:09:51 -07:00
-- This file registers ABMs
2015-11-09 10:49:35 -08:00
--
2020-03-26 08:41:24 -07:00
-- Lava cooling
2015-11-09 10:49:35 -08:00
--
2020-03-28 19:09:51 -07:00
local cool_lava_source = function(pos)
if minetest.find_node_near(pos, 5, {"hades_core:water_flowing"}) == nil then
2020-04-05 15:38:42 -07:00
minetest.sound_play({name="fire_extinguish_flame", gain = 0.2}, {pos=pos, max_hear_distance = 16}, true)
minetest.set_node(pos, {name="hades_core:tuff"})
2017-12-19 11:58:10 -08:00
else
if minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
2020-04-05 15:38:42 -07:00
minetest.sound_play({name="fire_extinguish_flame", gain = 0.05}, {pos=pos, max_hear_distance = 6}, true)
2017-12-19 11:58:10 -08:00
end
minetest.set_node(pos, {name="hades_core:water_source"})
2015-11-09 10:49:35 -08:00
end
end
2020-03-28 19:09:51 -07:00
local cool_lava_flowing = function(pos)
2020-04-05 15:38:42 -07:00
minetest.sound_play({name="fire_extinguish_flame", gain = 0.2}, {pos=pos, max_hear_distance = 16}, true)
minetest.set_node(pos, {name="hades_core:gravel_volcanic"})
2015-11-09 10:49:35 -08:00
end
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Cool flowing lava",
nodenames = {"hades_core:lava_flowing"},
2015-11-09 10:49:35 -08:00
neighbors = {"group:water"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
2020-03-28 19:09:51 -07:00
cool_lava_flowing(pos, node, active_object_count, active_object_count_wider)
2015-11-09 10:49:35 -08:00
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Cool lava source",
nodenames = {"hades_core:lava_source"},
2015-11-09 10:49:35 -08:00
neighbors = {"group:water"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
2020-03-28 19:09:51 -07:00
cool_lava_source(pos, node, active_object_count, active_object_count_wider)
2015-11-09 10:49:35 -08:00
end,
})
--
2020-03-26 08:41:24 -07:00
-- Stone transformation
2015-11-09 10:49:35 -08:00
--
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Burn stone",
nodenames = {"hades_core:stone", "hades_core:mossystone"},
2017-12-17 21:15:46 -08:00
neighbors = {"group:lava"},
2015-11-09 10:49:35 -08:00
interval = 25,
chance = 15,
action = function(pos, node)
2017-12-17 21:15:46 -08:00
local nn
if node.name == "hades_core:mossystone" then
nn = "hades_core:stone"
2017-12-17 21:15:46 -08:00
else
nn = "hades_core:stone_baked"
2017-12-17 21:15:46 -08:00
end
minetest.set_node(pos, {name=nn})
2015-11-09 10:49:35 -08:00
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Create mossy stone",
nodenames = {"hades_core:stone"},
2015-11-09 10:49:35 -08:00
interval = 600,
chance = 65,
action = function(pos, node)
if minetest.find_node_near(pos, 2, {"group:water"}) == nil then
return
else
minetest.set_node(pos, {name="hades_core:mossystone"})
2015-11-09 10:49:35 -08:00
end
end,
})
--
2020-03-26 08:41:24 -07:00
-- Tuff transformation
2015-11-09 10:49:35 -08:00
--
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Burn tuff",
nodenames = {"hades_core:tuff", "hades_core:mossytuff"},
2017-12-17 21:15:46 -08:00
neighbors = {"group:lava"},
2015-11-09 10:49:35 -08:00
interval = 25,
chance = 15,
action = function(pos, node)
local nn = "hades_core:tuff_baked"
if node.name == "hades_core:mossytuff" then
minetest.set_node(pos, {name="hades_core:tuff"})
2017-12-17 21:15:46 -08:00
else
minetest.set_node(pos, {name="hades_core:tuff_baked"})
2017-12-17 21:15:46 -08:00
end
2015-11-09 10:49:35 -08:00
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow moss on tuff",
nodenames = {"hades_core:tuff"},
2015-11-09 10:49:35 -08:00
interval = 600,
chance = 65,
action = function(pos, node)
if minetest.find_node_near(pos, 2, {"group:water"}) == nil then
return
else
minetest.set_node(pos, {name="hades_core:mossytuff"})
2015-11-09 10:49:35 -08:00
end
end,
})
--
2020-03-26 08:41:24 -07:00
-- Create marble
-- Requirements: chondrite at Y <= -500 next to water and lava is within reach of 4 nodes
2015-11-09 10:49:35 -08:00
--
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Create marble",
nodenames = {"hades_core:chondrite"},
2015-11-09 10:49:35 -08:00
neighbors = {"group:water"},
2020-10-29 03:37:19 -07:00
interval = 171,
2015-11-09 10:49:35 -08:00
chance = 55,
action = function(pos, node)
if minetest.find_node_near(pos, 4, {"group:lava"}) == nil or pos.y > -500 then
return
else
minetest.set_node(pos, {name="hades_core:marble"})
2015-11-09 10:49:35 -08:00
end
end,
})
--
2020-03-26 08:41:24 -07:00
-- Create obsidian
-- Requirements: Volcanic gravel at Y <= -1000 next to lava and water is within reach of 4 nodes
2015-11-09 10:49:35 -08:00
--
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Create obsidian",
nodenames = {"hades_core:gravel_volcanic"},
2015-11-09 10:49:35 -08:00
neighbors = {"group:lava"},
2020-10-29 03:37:19 -07:00
interval = 180,
2015-11-09 10:49:35 -08:00
chance = 65,
action = function(pos, node)
if minetest.find_node_near(pos, 4, {"group:water"}) == nil or pos.y > -1000 then
return
else
minetest.set_node(pos, {name="hades_core:obsidian"})
2015-11-09 10:49:35 -08:00
end
end,
})
--
2020-03-26 08:41:24 -07:00
-- Cobble transformation
2015-11-09 10:49:35 -08:00
--
2020-03-26 08:41:24 -07:00
2015-11-09 10:49:35 -08:00
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow moss on cobblestone (neighboring water)",
nodenames = {"hades_core:cobble"},
2017-12-17 21:15:46 -08:00
neighbors = {"group:water"},
2015-11-09 10:49:35 -08:00
interval = 500,
chance = 35,
action = function(pos, node)
minetest.set_node(pos, {name="hades_core:mossycobble"})
2015-11-09 10:49:35 -08:00
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow moss on cobblestone (extended water check)",
nodenames = {"hades_core:cobble"},
2015-11-09 10:49:35 -08:00
interval = 500,
chance = 55,
action = function(pos, node)
if minetest.find_node_near(pos, 2, {"group:water"}) == nil then
return
else
minetest.set_node(pos, {name="hades_core:mossycobble"})
2015-11-09 10:49:35 -08:00
end
end,
})
2021-07-19 04:11:09 -07:00
-- Takes a node name and if it's capable of being covered by grass,
-- returns the node name of the next level of "grassiness",
-- otherwise it returns nil
2021-07-20 01:36:07 -07:00
function hades_core.get_next_grass_cover_level(nodename)
2021-07-19 04:11:09 -07:00
if nodename == "hades_core:dirt" then
return "hades_core:dirt_with_grass_l1"
elseif nodename == "hades_core:dirt_with_grass_l1" then
return "hades_core:dirt_with_grass_l2"
elseif nodename == "hades_core:dirt_with_grass_l2" then
return "hades_core:dirt_with_grass_l3"
elseif nodename == "hades_core:dirt_with_grass_l3" then
return "hades_core:dirt_with_grass"
end
end
2021-07-20 01:36:07 -07:00
-- Dirt-with-Grass ABMs
2020-03-26 08:41:24 -07:00
minetest.register_abm({
2021-07-20 01:36:07 -07:00
label = "Increase Dirt-with-Grass grass level on Dirt-with-Grass under bright light",
nodenames = {"group:dirt_with_grass"},
2020-03-26 08:41:24 -07:00
interval = 2,
chance = 200,
action = function(pos, node)
local above = {x=pos.x, y=pos.y+1, z=pos.z}
local name = minetest.get_node(above).name
local nodedef = minetest.registered_nodes[name]
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light")
and nodedef.liquidtype == "none"
and (minetest.get_node_light(above) or 0) >= 13 then
2021-07-20 01:36:07 -07:00
local nextnode = hades_core.get_next_grass_cover_level(node.name)
2021-07-19 04:11:09 -07:00
if nextnode then
minetest.set_node(pos, {name = nextnode, param2 = node.param2})
end
2020-03-26 08:41:24 -07:00
end
end
})
2021-07-19 04:11:09 -07:00
minetest.register_abm({
2021-07-20 01:36:07 -07:00
label = "Increase Dirt-with-Grass level on Dirt-with-Grass under air in faint light",
nodenames = {"group:dirt_with_grass"},
2021-07-19 04:11:09 -07:00
interval = 50,
chance = 20,
action = function(pos, node)
local name = minetest.get_node(pos).name
local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
if node.name == "air" and (minetest.get_node_light(pos) or 0) >= 8 then
2021-07-20 01:36:07 -07:00
local nextnode = hades_core.get_next_grass_cover_level(node.name)
2021-07-19 04:11:09 -07:00
if nextnode then
minetest.set_node(pos, {name = nextnode, param2 = node.param2})
end
end
end,
})
2021-07-19 13:34:59 -07:00
-- Returns the param2 the grass node should currently (for seaons)
-- use, this determins the grass color.
-- * old_param2: Optional parameter for current param2 of grass
-- node, used for intermedite colors
function hades_core.get_seasonal_grass_color_param2(old_param2)
-- There are 6 grass colors:
-- 3 for the 3 seasons
-- and 3 for brief transition periods on season change
local new_param2 = old_param2
2021-07-19 13:34:59 -07:00
local season = hades_seasons.get_season()
if season == hades_seasons.SEASON_SPRING then
if old_param2 == 4 then
new_param2 = 5
else
new_param2 = 0
end
elseif season == hades_seasons.SEASON_SUMMER then
if old_param2 == 0 then
new_param2 = 1
else
new_param2 = 2
end
elseif season == hades_seasons.SEASON_FALL then
if old_param2 == 2 then
new_param2 = 3
else
new_param2 = 4
end
end
return new_param2
end
2020-03-26 08:41:24 -07:00
minetest.register_abm({
2021-07-19 13:34:59 -07:00
label = "Turn covered 'dirt with grass' back to dirt, update seasonal grass color",
2021-07-19 04:11:09 -07:00
nodenames = {"group:dirt_with_grass"},
2020-03-26 08:41:24 -07:00
interval = 2,
chance = 20,
action = function(pos, node)
local above = {x=pos.x, y=pos.y+1, z=pos.z}
local name = minetest.get_node(above).name
local nodedef = minetest.registered_nodes[name]
if name ~= "ignore" and nodedef
and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
and nodedef.liquidtype == "none") then
2021-07-19 04:11:09 -07:00
minetest.set_node(pos, {name = "hades_core:dirt", param2 = node.param2})
2021-07-19 13:34:59 -07:00
else
local old_param2 = node.param2
local new_param2 = hades_core.get_seasonal_grass_color_param2(old_param2)
if new_param2 ~= old_param2 then
minetest.set_node(pos, {name = node.name, param2 = new_param2})
end
2020-03-26 08:41:24 -07:00
end
end
})
2017-12-21 16:31:12 -08:00
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow moss on cobblestone wall",
2022-04-25 18:39:58 -07:00
nodenames = {"hades_walls:cobble"},
2017-12-21 16:31:12 -08:00
neighbors = {"group:water"},
interval = 500,
chance = 35,
action = function(pos, node)
2022-04-25 18:39:58 -07:00
minetest.set_node(pos, {name="hades_walls:mossycobble"})
2017-12-21 16:31:12 -08:00
end,
})
2017-12-17 21:15:46 -08:00
minetest.register_abm({
2020-03-28 19:09:51 -07:00
label = "Burn cobblestone",
nodenames = {"hades_core:cobble", "hades_core:mossycobble"},
2017-12-17 21:15:46 -08:00
neighbors = {"group:lava"},
interval = 45,
chance = 15,
action = function(pos, node)
local nn
if node.name == "hades_core:mossycobble" then
nn = "hades_core:cobble"
2017-12-17 21:15:46 -08:00
else
nn = "hades_core:cobble_baked"
2017-12-17 21:15:46 -08:00
end
minetest.set_node(pos, {name=nn})
end,
})
2015-11-09 10:49:35 -08:00
minetest.register_abm({
2020-03-28 19:09:51 -07:00
label = "Create gravel near water",
nodenames = {"hades_core:mossycobble"},
neighbors = {"hades_core:water_flowing"},
2015-11-09 10:49:35 -08:00
interval = 500,
chance = 75,
action = function(pos, node)
minetest.set_node(pos, {name="hades_core:gravel"})
2015-11-09 10:49:35 -08:00
end,
})
--
2020-03-26 08:41:24 -07:00
-- Ash transformation
2015-11-09 10:49:35 -08:00
--
minetest.register_abm({
2021-07-05 19:57:14 -07:00
label = "Create volcanic and fertile sand",
2020-10-29 11:10:58 -07:00
nodenames = {"group:ash_fertilizer"}, -- used by most leaves
interval = 60,
chance = 130,
2015-11-09 10:49:35 -08:00
action = function(pos, node)
2020-10-29 11:10:58 -07:00
local d = minetest.get_item_group(node.name, "ash_fertilizer")
local pos1 = vector.add(pos, {x=d ,y=-1, z=d})
local pos2 = vector.add(pos, {x=-d, y=-d*2, z=-d})
-- Turn ash to fertile sand
2021-07-05 19:57:14 -07:00
local ashes = minetest.find_nodes_in_area(pos1, pos2, {"hades_core:ash", "hades_core:volcanic_sand"})
2020-10-29 11:10:58 -07:00
if #ashes == 0 then
return
end
local ash = ashes[math.random(1, #ashes)]
local aname = minetest.get_node({x=ash.x,y=ash.y+1,z=ash.z}).name
local def = minetest.registered_nodes[aname]
if def and def.walkable then
2015-11-09 10:49:35 -08:00
return
end
2021-07-05 19:57:14 -07:00
aname = minetest.get_node(ash).name
if aname == "hades_core:ash" then
minetest.set_node(ash, {name="hades_core:volcanic_sand"})
else
minetest.set_node(ash, {name="hades_core:fertile_sand"})
end
2015-11-09 10:49:35 -08:00
end,
})
--
2020-03-26 08:41:24 -07:00
-- Fertile sand transformation
2015-11-09 10:49:35 -08:00
--
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Create dirt (direct neighboring water)",
nodenames = {"hades_core:fertile_sand"},
2020-03-26 08:41:24 -07:00
neighbors = {"group:water"},
2015-11-09 10:49:35 -08:00
interval = 25,
chance = 5,
action = function(pos, node)
2021-07-05 19:57:14 -07:00
minetest.set_node(pos, {name="hades_core:dirt"})
2015-11-09 10:49:35 -08:00
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Create dirt (extended water check)",
nodenames = {"hades_core:fertile_sand"},
2021-07-19 04:11:09 -07:00
neighbors = {"group:dirt"},
2015-11-09 10:49:35 -08:00
interval = 50,
chance = 5,
action = function(pos, node)
2021-07-19 04:11:09 -07:00
if minetest.find_node_near(pos, 10, {"group:water"}) == nil then
return
else
minetest.set_node(pos, {name="hades_core:dirt"})
end
2015-11-09 10:49:35 -08:00
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Create clay",
2021-07-05 19:57:14 -07:00
nodenames = {"hades_core:ash","hades_core:volcanic_sand"},
2020-03-26 08:41:24 -07:00
neighbors = {"group:water"},
2015-11-09 10:49:35 -08:00
interval = 700,
chance = 75,
action = function(pos, node)
minetest.set_node(pos, {name="hades_core:clay"})
2015-11-09 10:49:35 -08:00
end,
})
2020-03-26 08:41:24 -07:00
--
-- Sugarcane growing
--
2015-11-09 10:49:35 -08:00
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow sugarcane",
nodenames = {"hades_core:sugarcane"},
2021-07-19 04:11:09 -07:00
neighbors = {"group:dirt"},
2015-11-09 10:49:35 -08:00
interval = 55,
chance = 35,
action = function(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
2021-07-19 04:11:09 -07:00
if minetest.get_item_group(name, "dirt") > 0 then
2015-11-09 10:49:35 -08:00
pos.y = pos.y+1
local height = 0
while minetest.get_node(pos).name == "hades_core:sugarcane" and height < 3 do
2015-11-09 10:49:35 -08:00
height = height+1
pos.y = pos.y+1
end
if height < 3 then
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="hades_core:sugarcane"})
2015-11-09 10:49:35 -08:00
end
end
end
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Spread sugarcane",
nodenames = {"hades_core:dirt_with_grass"},
neighbors = {"hades_core:papyrus"},
2015-11-09 10:49:35 -08:00
interval = 500,
chance = 25,
action = function(pos, node)
2021-07-19 04:11:09 -07:00
if minetest.find_node_near(pos, 10, {"hades_core:sugarcane"}) == nil then
pos.y = pos.y+1
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="hades_core:sugarcane"})
end
end
2015-11-09 10:49:35 -08:00
end,
})
2020-03-26 08:41:24 -07:00
2015-11-09 10:49:35 -08:00
--
-- Papyrus and cactus growing
--
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow cactus",
nodenames = {"hades_core:cactus"},
2020-03-26 09:34:48 -07:00
neighbors = {"group:sand", "group:ash"},
2015-11-09 10:49:35 -08:00
interval = 50,
chance = 20,
action = function(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
2020-03-26 09:34:48 -07:00
if minetest.get_item_group(name, "sand") ~= 0 or minetest.get_item_group(name, "ash" ~= 0) then
2015-11-09 10:49:35 -08:00
pos.y = pos.y+1
local height = 0
while minetest.get_node(pos).name == "hades_core:cactus" and height < 4 do
2015-11-09 10:49:35 -08:00
height = height+1
pos.y = pos.y+1
end
if height < 3 then
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="hades_core:cactus"})
2015-11-09 10:49:35 -08:00
end
end
end
end,
})
minetest.register_abm({
2020-03-26 08:41:24 -07:00
label = "Grow papyrus",
nodenames = {"hades_core:papyrus"},
2021-07-19 04:11:09 -07:00
neighbors = {"group:dirt"},
2015-11-09 10:49:35 -08:00
interval = 50,
chance = 20,
action = function(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
2021-07-19 04:11:09 -07:00
if minetest.get_item_group(name, "dirt") > 0 then
2015-11-09 10:49:35 -08:00
if minetest.find_node_near(pos, 3, {"group:water"}) == nil then
return
end
pos.y = pos.y+1
local height = 0
while minetest.get_node(pos).name == "hades_core:papyrus" and height < 4 do
2015-11-09 10:49:35 -08:00
height = height+1
pos.y = pos.y+1
end
if height < 4 then
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="hades_core:papyrus"})
2015-11-09 10:49:35 -08:00
end
end
end
end,
})