ethereal/dirt.lua

399 lines
9.9 KiB
Lua
Raw Normal View History

2016-06-09 07:08:34 -07:00
local S = ethereal.intllib
2015-04-10 07:38:53 -07:00
-- override default dirt (to stop caves cutting away dirt)
minetest.override_item("default:dirt", {is_ground_content = ethereal.cavedirt})
2014-11-09 11:17:41 -08:00
minetest.register_alias("ethereal:green_dirt", "default:dirt_with_grass")
2014-11-09 11:17:41 -08:00
2015-04-10 07:38:53 -07:00
-- dry dirt
2014-11-09 11:17:41 -08:00
minetest.register_node("ethereal:dry_dirt", {
2016-06-09 07:08:34 -07:00
description = S("Dried Dirt"),
2014-11-09 11:17:41 -08:00
tiles = {"ethereal_dry_dirt.png"},
is_ground_content = ethereal.cavedirt,
2015-07-04 04:22:39 -07:00
groups = {crumbly = 3},
2016-12-13 12:04:58 -08:00
sounds = default.node_sound_dirt_defaults()
2014-11-09 11:17:41 -08:00
})
minetest.register_craft({
type = "cooking",
output = "ethereal:dry_dirt",
recipe = "default:dirt",
cooktime = 3,
})
local dirts = {
"Bamboo", "Jungle", "Grove", "Prairie", "Cold",
"Crystal", "Mushroom", "Fiery", "Gray"
2014-11-09 11:17:41 -08:00
}
for n = 1, #dirts do
2014-11-09 11:17:41 -08:00
local desc = dirts[n]
2014-11-09 11:17:41 -08:00
local name = desc:lower()
minetest.register_node("ethereal:"..name.."_dirt", {
2016-06-09 07:08:34 -07:00
description = S(desc.." Dirt"),
tiles = {
"ethereal_grass_"..name.."_top.png",
"default_dirt.png",
{name = "default_dirt.png^ethereal_grass_"..name.."_side.png",
tileable_vertical = false}
},
is_ground_content = ethereal.cavedirt,
2015-07-04 04:22:39 -07:00
groups = {crumbly = 3, soil = 1, ethereal_grass = 1},
soil = {
base = "ethereal:"..name.."_dirt",
dry = "farming:soil",
wet = "farming:soil_wet"
},
2014-11-09 11:17:41 -08:00
drop = "default:dirt",
sounds = default.node_sound_dirt_defaults({
footstep = {name = "default_grass_footstep", gain = 0.25},
}),
2014-11-09 11:17:41 -08:00
})
end
-- re-register dirt types for abm
dirts = {
"ethereal:bamboo_dirt", "ethereal:jungle_dirt", "ethereal:grove_dirt",
"ethereal:prairie_dirt", "ethereal:cold_dirt", "ethereal:crystal_dirt",
"ethereal:mushroom_dirt", "ethereal:fiery_dirt", "ethereal:gray_dirt",
"default:dirt_with_grass", "default:dirt_with_dry_grass",
2019-05-22 13:09:44 -07:00
"default:dirt_with_snow", "default:dirt_with_rainforest_litter"
}
2014-11-09 11:17:41 -08:00
-- check surrounding grass and change dirt to same colour
2016-08-19 09:22:09 -07:00
local grass_spread = function(pos, node)
2016-08-19 09:22:09 -07:00
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
-- not enough light
2016-08-19 09:22:09 -07:00
if (minetest.get_node_light(above) or 0) < 13 then
return
end
2016-08-19 09:22:09 -07:00
local name = minetest.get_node(above).name
local def = minetest.registered_nodes[name]
-- water above grass
2016-08-19 09:22:09 -07:00
if name == "ignore" or not def or def.liquidtype ~= "none" then
return
end
local curr_max, curr_type, num = 0, ""
-- find all default and ethereal grasses in area around dirt
local positions, grasses = minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 2, z = pos.z - 1},
{x = pos.x + 1, y = pos.y + 2, z = pos.z + 1}, dirts)
2016-08-19 09:22:09 -07:00
-- count new grass nodes
for n = 1, #dirts do
num = grasses[ dirts[n] ] or 0
if num > curr_max then
curr_max = num
curr_type = dirts[n]
end
2016-08-19 09:22:09 -07:00
end
2016-08-19 09:22:09 -07:00
-- no grass nearby, keep as dirt
if curr_type == "" then
return
end
2016-08-19 09:22:09 -07:00
minetest.swap_node(pos, {name = curr_type})
end
-- any grass with a block above will turn into dirt
local grass_devoid = 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
minetest.swap_node(pos, {name = "default:dirt"})
end
end
-- flower spread, also crystal and fire flower regeneration
local flower_spread = function(pos, node)
2016-10-04 13:05:06 -07:00
if (minetest.get_node_light(pos) or 0) < 13 then
2016-08-19 09:22:09 -07:00
return
end
local pos0 = {x = pos.x - 4, y = pos.y - 2, z = pos.z - 4}
local pos1 = {x = pos.x + 4, y = pos.y + 2, z = pos.z + 4}
2016-10-04 13:05:06 -07:00
local num = #minetest.find_nodes_in_area(pos0, pos1, "group:flora")
2016-08-19 09:22:09 -07:00
-- stop flowers spreading too much just below top of map block
if minetest.find_node_near(pos, 2, "ignore") then
return
end
2016-08-19 09:22:09 -07:00
if num > 3
and node.name == "ethereal:crystalgrass" then
local grass = minetest.find_nodes_in_area_under_air(
pos0, pos1, {"ethereal:crystalgrass"})
if #grass > 4
and not minetest.find_node_near(pos, 4, {"ethereal:crystal_spike"}) then
2016-10-04 13:05:06 -07:00
pos = grass[math.random(#grass)]
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
pos.y = pos.y - 1
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
if minetest.get_node(pos).name == "ethereal:crystal_dirt" then
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
pos.y = pos.y + 1
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
minetest.swap_node(pos, {name = "ethereal:crystal_spike"})
2016-08-19 09:22:09 -07:00
end
end
2016-08-19 09:22:09 -07:00
return
elseif num > 3
and node.name == "ethereal:dry_shrub" then
local grass = minetest.find_nodes_in_area_under_air(
pos0, pos1, {"ethereal:dry_shrub"})
if #grass > 8
and not minetest.find_node_near(pos, 4, {"ethereal:fire_flower"}) then
2016-10-04 13:05:06 -07:00
pos = grass[math.random(#grass)]
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
pos.y = pos.y - 1
2016-10-04 13:05:06 -07:00
if minetest.get_node(pos).name == "ethereal:fiery_dirt" then
2016-10-04 13:05:06 -07:00
pos.y = pos.y + 1
2016-10-04 13:05:06 -07:00
minetest.swap_node(pos, {name = "ethereal:fire_flower"})
2014-11-09 11:17:41 -08:00
end
end
2016-08-19 09:22:09 -07:00
return
elseif num > 3 then
return
2015-07-04 04:22:39 -07:00
end
2014-11-09 11:17:41 -08:00
2016-08-19 09:22:09 -07:00
local seedling = minetest.find_nodes_in_area_under_air(
pos0, pos1, {"group:soil"})
if #seedling > 0 then
2016-10-04 13:05:06 -07:00
pos = seedling[math.random(#seedling)]
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
-- default farming has desert sand as soil, so dont spread on this
if minetest.get_node(pos).name == "default:desert_sand" then
return
end
2016-08-19 09:22:09 -07:00
2016-10-04 13:05:06 -07:00
pos.y = pos.y + 1
if (minetest.get_node_light(pos) or 0) < 13 then
2016-08-19 09:22:09 -07:00
return
end
2016-10-04 13:05:06 -07:00
minetest.swap_node(pos, {name = node.name})
2016-08-19 09:22:09 -07:00
end
end
-- grow papyrus up to 4 high and bamboo up to 8 high
local grow_papyrus = function(pos, node)
local oripos = pos.y
local high = 4
pos.y = pos.y - 1
2016-08-19 09:22:09 -07:00
local nod = minetest.get_node_or_nil(pos)
2016-08-19 09:22:09 -07:00
if not nod
or minetest.get_item_group(nod.name, "soil") < 1
or minetest.find_node_near(pos, 3, {"group:water"}) == nil then
return
end
if node.name == "ethereal:bamboo" then
high = 8
end
2016-08-19 09:22:09 -07:00
pos.y = pos.y + 1
2016-08-19 09:22:09 -07:00
local height = 0
while height < high
and minetest.get_node(pos).name == node.name do
height = height + 1
pos.y = pos.y + 1
end
nod = minetest.get_node_or_nil(pos)
if nod
and nod.name == "air"
and height < high then
if node.name == "ethereal:bamboo"
and height == (high - 1) then
ethereal.grow_bamboo_tree({x = pos.x, y = oripos, z = pos.z})
else
minetest.swap_node(pos, {name = node.name})
2014-11-09 11:17:41 -08:00
end
end
2016-08-19 09:22:09 -07:00
end
-- loop through active abm's
for _, ab in pairs(minetest.registered_abms) do
local label = ab.label or ""
local node1 = ab.nodenames and ab.nodenames[1] or ""
local node2 = ab.nodenames and ab.nodenames[2] or ""
local neigh = ab.neighbors and ab.neighbors[1] or ""
-- find 'dirt to grass abm' and replace with spread function
2016-08-19 09:22:09 -07:00
if label == "Grass spread"
or (node1 == "default:dirt"
and neigh == "default:dirt_with_grass") then
--ab.interval = 2
--ab.chance = 1
ab.nodenames = {"default:dirt"}
2016-08-19 09:22:09 -07:00
ab.neighbors = {"air"}
ab.action = grass_spread
-- find 'grass devoid of light to dirt' abm and change to devoid function
2016-08-19 09:22:09 -07:00
elseif label == "Grass covered"
or (node1 == "default:dirt_with_grass"
and node2 == "default:dirt_with_dry_grass") then
--ab.interval = 2
--ab.chance = 1
ab.nodenames = {
"default:dirt_with_grass", "default:dirt_with_dry_grass",
"default:dirt_with_snow", "group:ethereal_grass"
}
ab.action = grass_devoid
-- find flower spread abm and change to spread function
elseif label == "Flower spread"
or node1 == "group:flora" then
2016-10-04 13:05:06 -07:00
--ab.interval = 1
2016-08-19 09:22:09 -07:00
--ab.chance = 1
ab.nodenames = {"group:flora"}
ab.neighbors = {"group:soil"}
ab.action = flower_spread
-- find grow papyrus abm and change to grow_papyrus function
elseif label == "Grow papyrus"
or node1 == "default:papyrus" then
--ab.interval = 2
--ab.chance = 1
ab.nodenames = {"default:papyrus", "ethereal:bamboo"}
ab.neighbors = {"group:soil"}
ab.action = grow_papyrus
end
end
2014-11-09 11:17:41 -08:00
-- If Baked Clay mod not active, make Red, Orange and Grey nodes
2014-11-09 11:17:41 -08:00
if not minetest.get_modpath("bakedclay") then
minetest.register_node(":bakedclay:red", {
2016-06-09 07:08:34 -07:00
description = S("Red Baked Clay"),
2014-11-09 11:17:41 -08:00
tiles = {"baked_clay_red.png"},
2015-07-04 04:22:39 -07:00
groups = {cracky = 3},
is_ground_content = ethereal.cavedirt,
2014-11-09 11:17:41 -08:00
sounds = default.node_sound_stone_defaults(),
})
2014-11-09 11:17:41 -08:00
minetest.register_node(":bakedclay:orange", {
2016-06-09 07:08:34 -07:00
description = S("Orange Baked Clay"),
2014-11-09 11:17:41 -08:00
tiles = {"baked_clay_orange.png"},
2015-07-04 04:22:39 -07:00
groups = {cracky = 3},
is_ground_content = ethereal.cavedirt,
2014-11-09 11:17:41 -08:00
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node(":bakedclay:grey", {
2016-06-09 07:08:34 -07:00
description = S("Grey Baked Clay"),
tiles = {"baked_clay_grey.png"},
groups = {cracky = 3},
is_ground_content = ethereal.cavedirt,
sounds = default.node_sound_stone_defaults(),
})
end
-- Quicksand (old style, sinking inside shows black instead of yellow effect,
-- works ok with noclip enabled though)
minetest.register_node("ethereal:quicksand", {
2016-06-09 07:08:34 -07:00
description = S("Quicksand"),
tiles = {"default_sand.png"},
drop = "default:sand",
liquid_viscosity = 15,
liquidtype = "source",
liquid_alternative_flowing = "ethereal:quicksand",
liquid_alternative_source = "ethereal:quicksand",
liquid_renewable = false,
liquid_range = 0,
drowning = 1,
walkable = false,
climbable = false,
post_effect_color = {r = 230, g = 210, b = 160, a = 245},
groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
sounds = default.node_sound_sand_defaults(),
})
-- Quicksand (new style, sinking inside shows yellow effect with or without noclip,
-- but old quicksand is shown as black until block placed nearby to update light)
minetest.register_node("ethereal:quicksand2", {
2016-06-09 07:08:34 -07:00
description = S("Quicksand"),
tiles = {"default_sand.png"},
drawtype = "glasslike",
paramtype = "light",
drop = "default:sand",
liquid_viscosity = 15,
liquidtype = "source",
liquid_alternative_flowing = "ethereal:quicksand2",
liquid_alternative_source = "ethereal:quicksand2",
liquid_renewable = false,
liquid_range = 0,
drowning = 1,
walkable = false,
climbable = false,
post_effect_color = {r = 230, g = 210, b = 160, a = 245},
groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
sounds = default.node_sound_sand_defaults(),
})
-- craft quicksand
minetest.register_craft({
output = "ethereal:quicksand2",
recipe = {
{"group:sand", "group:sand", "group:sand"},
2018-11-19 01:29:14 -08:00
{"group:sand", "bucket:bucket_water", "group:sand"},
{"group:sand", "group:sand", "group:sand"},
},
replacements = {
2018-11-19 01:29:14 -08:00
{"bucket:bucket_water", "bucket:bucket_empty"}
}
})