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") dofile(minetest.get_modpath(modname) .. "/bambootoo.lua")
local BAMBOO_SOIL_DIST = -16 local BAMBOO_SOIL_DIST = -16
local BAM_MAX_HEIGHT_STCHK = 11 local BAM_MAX_HEIGHT_STPCHK = 11
local BAM_MAX_HEIGHT_TOP = 15 local BAM_MAX_HEIGHT_TOP = 15
--ABMs --ABMs
@ -780,7 +780,10 @@ minetest.register_abm({
nodenames = {bamboo}, nodenames = {bamboo},
interval = 40, interval = 40,
chance = 40, chance = 40,
action = function(pos, _) action = mcl_bamboo.grow_bamboo(pos,_),
})
function mcl_bamboo.grow_bamboo(pos, _, force)
local soil_pos local soil_pos
if minetest.get_node_light(pos) < 8 then if minetest.get_node_light(pos) < 8 then
return return
@ -793,7 +796,7 @@ minetest.register_abm({
found_soil = true found_soil = true
soil_pos = chk_pos soil_pos = chk_pos
break break
elseif name ~= "mcl_bamboo:bamboo" then elseif name ~= bamboo then
break break
end end
end end
@ -804,10 +807,10 @@ minetest.register_abm({
local npos = vector.offset(pos, 0, py, 0) local npos = vector.offset(pos, 0, py, 0)
local name = minetest.get_node(npos).name local name = minetest.get_node(npos).name
local dist = vector.distance(soil_pos, npos) local dist = vector.distance(soil_pos, npos)
if dist >= BAM_MAX_HEIGHT_STCHK then if dist >= BAM_MAX_HEIGHT_STPCHK then
-- stop growing check. -- stop growing check.
if name == "air" then if name == "air" then
local height = math.random(BAM_MAX_HEIGHT_STCHK, BAM_MAX_HEIGHT_TOP) local height = math.random(BAM_MAX_HEIGHT_STPCHK, BAM_MAX_HEIGHT_TOP)
if height == dist then if height == dist then
minetest.set_node(npos, {name = "mcl_bamboo:bamboo_endcap"}) minetest.set_node(npos, {name = "mcl_bamboo:bamboo_endcap"})
end end
@ -815,14 +818,14 @@ minetest.register_abm({
break break
end end
if name == "air" then if name == "air" then
minetest.set_node(npos, {name = "mcl_bamboo:bamboo"}) minetest.set_node(npos, {name = bamboo})
break break
elseif name ~= bamboo then elseif name ~= bamboo then
break break
end end
end end
end,
}) end
-- Base Aliases. -- Base Aliases.
minetest.register_alias("bamboo_block", "mcl_bamboo:bamboo_block") minetest.register_alias("bamboo_block", "mcl_bamboo:bamboo_block")