Fix broken grass and clam ABM

This commit is contained in:
Wuzzy 2019-09-06 13:26:54 +02:00
parent 109fcba8c2
commit c958af51d2
2 changed files with 79 additions and 38 deletions

View File

@ -1,3 +1,5 @@
local water_level = tonumber(minetest.get_mapgen_setting("water_level"))
--
-- Functions/ABMs
--
@ -288,46 +290,85 @@ minetest.register_abm( -- dirt with grass becomes dirt if covered
end
})
minetest.register_abm( -- grass expands
{
label = "Grass expansion",
nodenames = {"default:grass"},
interval = 20,
chance = 160,
action = function(pos, node)
local rx = math.random(0, 2) - 1
local rz = math.random(0, 2) - 1
minetest.register_abm({
label = "Grass expansion",
nodenames = {"group:grass"},
neighbors = {"group:grass_cover"},
interval = 20,
chance = 160,
action = function(pos, node)
pos.y = pos.y - 1
local under = minetest.get_node(pos)
pos.y = pos.y + 1
local edgepos = {x = pos.x+rx, y = pos.y, z = pos.z+rz}
local downpos = {x = pos.x+rx, y = pos.y-1, z = pos.z+rz}
local edgenode = minetest.get_node(edgepos)
local downnode = minetest.get_node(downpos)
local required_under
if minetest.get_item_group(node.name, "normal_grass") ~= 0 then
required_under = "default:dirt_with_grass"
elseif minetest.get_item_group(node.name, "dry_grass") ~= 0 then
required_under = "default:dirt_with_dry_grass"
elseif minetest.get_item_group(node.name, "swamp_grass") ~= 0 then
required_under = "default:dirt_with_swamp_grass"
else
return
end
if edgenode.name == "air" and downnode.name ~= "air" and downnode.buildable_to == false and walkable == true then
minetest.set_node(edgepos, {name = "default:grass"})
end
end
if under.name ~= required_under then
return
end
-- Lower chance to spread dry grass
if node.name == "default:dry_grass" and math.random(1,2) == 1 then
return
end
local pos0 = vector.subtract(pos, 4)
local pos1 = vector.add(pos, 4)
-- Testing shows that a threshold of 3 results in an appropriate maximum
-- density of approximately 7 nodes per 9x9 area.
if #minetest.find_nodes_in_area(pos0, pos1, {"group:grass", "default:fern"}) > 3 then
return
end
local soils = minetest.find_nodes_in_area_under_air( pos0, pos1, "group:grass_cover")
local num_soils = #soils
if num_soils >= 1 then
for si = 1, math.min(3, num_soils) do
local soil = soils[math.random(num_soils)]
local soil_above = {x = soil.x, y = soil.y + 1, z = soil.z}
minetest.set_node(soil_above, {name = node.name})
end
end
end
})
minetest.register_abm( -- clams grow
{
label = "Growing clams",
nodenames = {"default:clam"},
interval = 20,
chance = 160,
action = function(pos, node)
local rx = math.random(0, 2) - 1
local rz = math.random(0, 2) - 1
minetest.register_abm({
label = "Growing clams",
nodenames = {"default:sand", "default:gravel"},
neighbors = {"default:water_source"},
interval = 20,
chance = 160,
action = function(pos, node)
if pos.y ~= water_level then
return
end
local pos0 = vector.add(pos, {x=-5, y=0, z=-5})
local pos1 = vector.add(pos, {x=5, y=2, z=5})
if #minetest.find_nodes_in_area(pos0, pos1, "default:clam") >= 1 then
return
end
local edgepos = {x = pos.x+rx, y = pos.y, z = pos.z+rz}
local downpos = {x = pos.x+rx, y = pos.y-1, z = pos.z+rz}
local edgenode = minetest.get_node(edgepos)
local downnode = minetest.get_node(downpos)
if edgenode.name == "air" and downnode.name ~= "air" and downnode.buildable_to == false and walkable == true then
minetest.set_node(edgepos, {name = "default:clam"})
end
end
pos0 = vector.add(pos, {x=-2, y=0, z=-2})
pos1 = vector.add(pos, {x=2, y=0, z=2})
local soils = minetest.find_nodes_in_area_under_air( pos0, pos1, {"default:sand", "default:gravel"})
local num_soils = #soils
if num_soils >= 1 then
for si = 1, math.min(3, num_soils) do
local soil = soils[math.random(num_soils)]
local soil_above = {x = soil.x, y = soil.y + 1, z = soil.z}
minetest.set_node(soil_above, {name = "default:clam"})
end
end
end
})
minetest.register_abm( -- cactus grows

View File

@ -927,7 +927,7 @@ minetest.register_node(
walkable = false,
buildable_to = true,
floodable = true,
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, fern = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -974,7 +974,7 @@ minetest.register_node(
walkable = false,
buildable_to = true,
floodable = true,
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1, swamp_grass = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -995,7 +995,7 @@ minetest.register_node(
waving = 1,
walkable = false,
buildable_to = true,
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1},
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1, dry_grass = 1},
sounds = default.node_sound_leaves_defaults(),
})