restrict tree fern growth (#32)

This commit is contained in:
fluxionary 2022-10-30 14:57:12 -07:00 committed by GitHub
parent 6e842d9b0d
commit e159b843d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -13,6 +13,25 @@ assert(abstract_ferns.config.enable_giant_treefern == true)
local S = minetest.get_translator("ferns") local S = minetest.get_translator("ferns")
-- lot of code, lot to load -- lot of code, lot to load
function abstract_ferns.can_grow_giant_tree_fern(pos)
local node_name = minetest.get_node(pos).name
if node_name ~= "air" and node_name ~= "ferns:sapling_giant_tree_fern" and node_name ~= "default:junglegrass" then
return false
end
local below_name = minetest.get_node(vector.new(pos.x, pos.y - 1, pos.z)).name
if minetest.get_item_group(below_name, "soil") == 0 and minetest.get_item_group(below_name, "sand") == 0 then
return false
end
local light = minetest.get_node_light(pos, 0.5)
if light <= 8 then
return false
end
return true
end
abstract_ferns.grow_giant_tree_fern = function(pos) abstract_ferns.grow_giant_tree_fern = function(pos)
local pos_aux = {x = pos.x, y = pos.y + 1, z = pos.z} local pos_aux = {x = pos.x, y = pos.y + 1, z = pos.z}
local name = minetest.get_node(pos_aux).name local name = minetest.get_node(pos_aux).name
@ -293,8 +312,10 @@ minetest.register_abm({
interval = 1000, interval = 1000,
chance = 4, chance = 4,
action = function(pos, node, _, _) action = function(pos, node, _, _)
if abstract_ferns.can_grow_giant_tree_fern(pos) then
abstract_ferns.grow_giant_tree_fern({x = pos.x, y = pos.y-1, z = pos.z}) abstract_ferns.grow_giant_tree_fern({x = pos.x, y = pos.y-1, z = pos.z})
end end
end
}) })
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------

View File

@ -11,6 +11,25 @@ local S = minetest.get_translator("ferns")
assert(abstract_ferns.config.enable_treefern == true) assert(abstract_ferns.config.enable_treefern == true)
function abstract_ferns.can_grow_tree_fern(pos)
local node_name = minetest.get_node(pos).name
if node_name ~= "air" and node_name ~= "ferns:sapling_tree_fern" and node_name ~= "default:junglegrass" then
return false
end
local below_name = minetest.get_node(vector.new(pos.x, pos.y - 1, pos.z)).name
if minetest.get_item_group(below_name, "soil") == 0 and minetest.get_item_group(below_name, "sand") == 0 then
return false
end
local light = minetest.get_node_light(pos, 0.5)
if light <= 8 then
return false
end
return true
end
abstract_ferns.grow_tree_fern = function(pos) abstract_ferns.grow_tree_fern = function(pos)
local pos_aux = {x = pos.x, y = pos.y + 1, z = pos.z} local pos_aux = {x = pos.x, y = pos.y + 1, z = pos.z}
@ -171,8 +190,10 @@ minetest.register_abm({
interval = 1000, interval = 1000,
chance = 4, chance = 4,
action = function(pos, node, _, _) action = function(pos, node, _, _)
if abstract_ferns.can_grow_tree_fern(pos) then
abstract_ferns.grow_tree_fern({x = pos.x, y = pos.y-1, z = pos.z}) abstract_ferns.grow_tree_fern({x = pos.x, y = pos.y-1, z = pos.z})
end end
end
}) })
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------