1
0
Fork 0

Moved bamboo grow code to its own function, and made that function global so that it can be called outside of mcl_bamboo.

This commit is contained in:
Michieal 2022-12-28 14:34:14 -05:00
parent 6f05992c8b
commit 76669e1f3c
1 changed files with 46 additions and 43 deletions

View File

@ -772,7 +772,7 @@ register_craftings()
dofile(minetest.get_modpath(modname) .. "/bambootoo.lua")
local BAMBOO_SOIL_DIST = -16
local BAM_MAX_HEIGHT_STCHK = 11
local BAM_MAX_HEIGHT_STPCHK = 11
local BAM_MAX_HEIGHT_TOP = 15
--ABMs
@ -780,50 +780,53 @@ minetest.register_abm({
nodenames = {bamboo},
interval = 40,
chance = 40,
action = function(pos, _)
local soil_pos
if minetest.get_node_light(pos) < 8 then
return
end
local found_soil = false
for py = -1, BAMBOO_SOIL_DIST, -1 do
local chk_pos = vector.offset(pos, 0, py, 0)
local name = minetest.get_node(chk_pos).name
if minetest.get_item_group(name, "soil") ~= 0 then
found_soil = true
soil_pos = chk_pos
break
elseif name ~= "mcl_bamboo:bamboo" then
break
end
end
if not found_soil then
return
end
for py = 1, 15 do
local npos = vector.offset(pos, 0, py, 0)
local name = minetest.get_node(npos).name
local dist = vector.distance(soil_pos, npos)
if dist >= BAM_MAX_HEIGHT_STCHK then
-- stop growing check.
if name == "air" then
local height = math.random(BAM_MAX_HEIGHT_STCHK, BAM_MAX_HEIGHT_TOP)
if height == dist then
minetest.set_node(npos, {name = "mcl_bamboo:bamboo_endcap"})
end
end
break
end
if name == "air" then
minetest.set_node(npos, {name = "mcl_bamboo:bamboo"})
break
elseif name ~= bamboo then
break
end
end
end,
action = mcl_bamboo.grow_bamboo(pos,_),
})
function mcl_bamboo.grow_bamboo(pos, _, force)
local soil_pos
if minetest.get_node_light(pos) < 8 then
return
end
local found_soil = false
for py = -1, BAMBOO_SOIL_DIST, -1 do
local chk_pos = vector.offset(pos, 0, py, 0)
local name = minetest.get_node(chk_pos).name
if minetest.get_item_group(name, "soil") ~= 0 then
found_soil = true
soil_pos = chk_pos
break
elseif name ~= bamboo then
break
end
end
if not found_soil then
return
end
for py = 1, 15 do
local npos = vector.offset(pos, 0, py, 0)
local name = minetest.get_node(npos).name
local dist = vector.distance(soil_pos, npos)
if dist >= BAM_MAX_HEIGHT_STPCHK then
-- stop growing check.
if name == "air" then
local height = math.random(BAM_MAX_HEIGHT_STPCHK, BAM_MAX_HEIGHT_TOP)
if height == dist then
minetest.set_node(npos, {name = "mcl_bamboo:bamboo_endcap"})
end
end
break
end
if name == "air" then
minetest.set_node(npos, {name = bamboo})
break
elseif name ~= bamboo then
break
end
end
end
-- Base Aliases.
minetest.register_alias("bamboo_block", "mcl_bamboo:bamboo_block")
minetest.register_alias("bamboo_strippedblock", "mcl_bamboo:bamboo_block_stripped")