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 -- Functions/ABMs
-- --
@ -288,44 +290,83 @@ minetest.register_abm( -- dirt with grass becomes dirt if covered
end end
}) })
minetest.register_abm( -- grass expands minetest.register_abm({
{
label = "Grass expansion", label = "Grass expansion",
nodenames = {"default:grass"}, nodenames = {"group:grass"},
neighbors = {"group:grass_cover"},
interval = 20, interval = 20,
chance = 160, chance = 160,
action = function(pos, node) action = function(pos, node)
local rx = math.random(0, 2) - 1 pos.y = pos.y - 1
local rz = math.random(0, 2) - 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 required_under
local downpos = {x = pos.x+rx, y = pos.y-1, z = pos.z+rz} if minetest.get_item_group(node.name, "normal_grass") ~= 0 then
local edgenode = minetest.get_node(edgepos) required_under = "default:dirt_with_grass"
local downnode = minetest.get_node(downpos) 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 if under.name ~= required_under then
minetest.set_node(edgepos, {name = "default:grass"}) 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
end end
}) })
minetest.register_abm( -- clams grow minetest.register_abm({
{
label = "Growing clams", label = "Growing clams",
nodenames = {"default:clam"}, nodenames = {"default:sand", "default:gravel"},
neighbors = {"default:water_source"},
interval = 20, interval = 20,
chance = 160, chance = 160,
action = function(pos, node) action = function(pos, node)
local rx = math.random(0, 2) - 1 if pos.y ~= water_level then
local rz = math.random(0, 2) - 1 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} pos0 = vector.add(pos, {x=-2, y=0, z=-2})
local downpos = {x = pos.x+rx, y = pos.y-1, z = pos.z+rz} pos1 = vector.add(pos, {x=2, y=0, z=2})
local edgenode = minetest.get_node(edgepos) local soils = minetest.find_nodes_in_area_under_air( pos0, pos1, {"default:sand", "default:gravel"})
local downnode = minetest.get_node(downpos) local num_soils = #soils
if num_soils >= 1 then
if edgenode.name == "air" and downnode.name ~= "air" and downnode.buildable_to == false and walkable == true then for si = 1, math.min(3, num_soils) do
minetest.set_node(edgepos, {name = "default:clam"}) 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
end end
}) })

View File

@ -927,7 +927,7 @@ minetest.register_node(
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
floodable = 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(), sounds = default.node_sound_leaves_defaults(),
}) })
@ -974,7 +974,7 @@ minetest.register_node(
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
floodable = 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(), sounds = default.node_sound_leaves_defaults(),
}) })
@ -995,7 +995,7 @@ minetest.register_node(
waving = 1, waving = 1,
walkable = false, walkable = false,
buildable_to = true, 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(), sounds = default.node_sound_leaves_defaults(),
}) })