Adjusted growth interval.

tested and fixed bamboo growth function.

Add debug code across growth function and scaffold place.

disabled debug for commit. removed finished todos.
This commit is contained in:
Michieal 2023-01-06 00:41:26 -05:00
parent ed64e7f733
commit e1cd16c971
3 changed files with 26 additions and 8 deletions

@ -310,6 +310,8 @@ minetest.register_node(scaffold_name, {
local cnb = node -- Current Base Node. local cnb = node -- Current Base Node.
local bn = minetest.get_node(vector.offset(pos, 0, -1, 0)) -- current node below the cnb. local bn = minetest.get_node(vector.offset(pos, 0, -1, 0)) -- current node below the cnb.
mcl_bamboo.mcl_log("Below Node: " .. bn.name)
-- check protected placement. -- check protected placement.
if mcl_bamboo.is_protected(pos, placer) then if mcl_bamboo.is_protected(pos, placer) then
return return
@ -324,7 +326,7 @@ minetest.register_node(scaffold_name, {
if placer and not placer:get_player_control().sneak then if placer and not placer:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
mcl_bamboo.mcl_log("attempting placement of bamboo via targeted node's on_rightclick.") mcl_bamboo.mcl_log("attempting placement of bamboo via targeted node's on_rightclick.")
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack return minetest.registered_nodes[node.name].on_rightclick(pointed.under, node, placer, itemstack) or itemstack
end end
end end
-- -------- -- --------

@ -4,7 +4,7 @@
--- DateTime: 12/29/22 12:34 PM -- Restructure Date --- DateTime: 12/29/22 12:34 PM -- Restructure Date
--- ---
local DEBUG = true local DEBUG = false
local rand = math.random local rand = math.random
math.randomseed((os.time() + 31) * 31415) -- try to make a valid seed math.randomseed((os.time() + 31) * 31415) -- try to make a valid seed
@ -58,6 +58,7 @@ end
function mcl_bamboo.grow_bamboo(pos, bonemeal_applied) function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
local node_above = minetest.get_node(vector.offset(pos, 0, 1, 0)) local node_above = minetest.get_node(vector.offset(pos, 0, 1, 0))
mcl_bamboo.mcl_log("Grow bamboo called; bonemeal: " .. tostring(bonemeal_applied))
if not bonemeal_applied and mcl_bamboo.is_bamboo(node_above.name) == true then if not bonemeal_applied and mcl_bamboo.is_bamboo(node_above.name) == true then
return false -- short circuit this function if we're trying to grow (std) the bamboo and it's not the top shoot. return false -- short circuit this function if we're trying to grow (std) the bamboo and it's not the top shoot.
@ -75,6 +76,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
local node_below local node_below
-- ------------------- -- -------------------
mcl_bamboo.mcl_log("Grow bamboo; checking for soil: ")
-- the soil node below. -- the soil node below.
for py = -1, BAMBOO_SOIL_DIST, -1 do for py = -1, BAMBOO_SOIL_DIST, -1 do
chk_pos = vector.offset(pos, 0, py, 0) chk_pos = vector.offset(pos, 0, py, 0)
@ -93,11 +95,13 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
return false -- returning false means don't use up the bonemeal. return false -- returning false means don't use up the bonemeal.
end end
mcl_bamboo.mcl_log("Grow bamboo; soil found: ")
local grow_amount = rand(1, GROW_DOUBLE_CHANCE) local grow_amount = rand(1, GROW_DOUBLE_CHANCE)
grow_amount = rand(1, GROW_DOUBLE_CHANCE) grow_amount = rand(1, GROW_DOUBLE_CHANCE)
grow_amount = rand(1, GROW_DOUBLE_CHANCE) -- because yeah, not truly random, or even a good prng. grow_amount = rand(1, GROW_DOUBLE_CHANCE) -- because yeah, not truly random, or even a good prng.
grow_amount = rand(1, GROW_DOUBLE_CHANCE) grow_amount = rand(1, GROW_DOUBLE_CHANCE)
local init_height = rand(BAM_MAX_HEIGHT_STPCHK, BAM_MAX_HEIGHT_TOP) local init_height = rand(BAM_MAX_HEIGHT_STPCHK + 1, BAM_MAX_HEIGHT_TOP + 1)
mcl_bamboo.mcl_log("Grow bamboo; random height: " .. init_height)
node_name = "" node_name = ""
@ -106,16 +110,21 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
local meta = minetest.get_meta(first_shoot) local meta = minetest.get_meta(first_shoot)
node_below = minetest.get_node(first_shoot).name node_below = minetest.get_node(first_shoot).name
mcl_bamboo.mcl_log("Grow bamboo; checking height meta ")
-- check the meta data for the first node, to see how high to make the stalk. -- check the meta data for the first node, to see how high to make the stalk.
if not meta then if not meta then
-- if no metadata, set the metadata!!! -- if no metadata, set the metadata!!!
meta:get_int("height", init_height) meta:set_int("height", init_height)
end end
local height = meta:get_int("height", -1) local height = meta:get_int("height", -1)
if height == -1 then mcl_bamboo.mcl_log("Grow bamboo; meta-height: " .. height)
if height <= 10 then
height = init_height height = init_height
meta:set_int("height", init_height)
end end
mcl_bamboo.mcl_log("Grow bamboo; height: " .. height)
-- Bonemeal: Grows the bamboo by 1-2 stems. (per the minecraft wiki.) -- Bonemeal: Grows the bamboo by 1-2 stems. (per the minecraft wiki.)
if bonemeal_applied then if bonemeal_applied then
-- handle applying bonemeal. -- handle applying bonemeal.
@ -129,6 +138,8 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
end end
end end
mcl_bamboo.mcl_log("Grow bamboo; dist: " .. dist)
if node_name == "mcl_bamboo:bamboo_endcap" then if node_name == "mcl_bamboo:bamboo_endcap" then
-- prevent overgrowth -- prevent overgrowth
return false return false
@ -139,6 +150,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
if dist == height - 1 then if dist == height - 1 then
-- equals top of the stalk before the cap -- equals top of the stalk before the cap
if node_name == "air" then if node_name == "air" then
mcl_bamboo.mcl_log("Grow bamboo; Placing endcap")
minetest.set_node(vector.offset(chk_pos, 0, 1, 0), {name = "mcl_bamboo:bamboo_endcap"}) minetest.set_node(vector.offset(chk_pos, 0, 1, 0), {name = "mcl_bamboo:bamboo_endcap"})
return true -- returning true means use up the bonemeal. return true -- returning true means use up the bonemeal.
else else
@ -155,11 +167,13 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
if dist <= height - 2 then if dist <= height - 2 then
if node_name == "air" then if node_name == "air" then
-- here we can check to see if we can do up to 2 bamboo shoots onto the stalk -- here we can check to see if we can do up to 2 bamboo shoots onto the stalk
mcl_bamboo.mcl_log("Grow bamboo; Placing bamboo.")
minetest.set_node(chk_pos, {name = node_below}) minetest.set_node(chk_pos, {name = node_below})
-- handle growing a second node. -- handle growing a second node.
if grow_amount == 2 then if grow_amount == 2 then
chk_pos = vector.offset(chk_pos, 0, 1, 0) chk_pos = vector.offset(chk_pos, 0, 1, 0)
if minetest.get_node(chk_pos).name == "air" then if minetest.get_node(chk_pos).name == "air" then
mcl_bamboo.mcl_log("Grow bamboo; OOOH! It's twofer day!")
minetest.set_node(chk_pos, {name = node_below}) minetest.set_node(chk_pos, {name = node_below})
end end
end end
@ -180,6 +194,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
if dist >= height - 1 then if dist >= height - 1 then
if node_name == "air" then if node_name == "air" then
if height - 1 == dist then if height - 1 == dist then
mcl_bamboo.mcl_log("Grow bamboo; Placing endcap")
minetest.set_node(chk_pos, {name = "mcl_bamboo:bamboo_endcap"}) minetest.set_node(chk_pos, {name = "mcl_bamboo:bamboo_endcap"})
end end
end end
@ -190,11 +205,14 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
-- find the air node above the top shoot. place a node. And then, if short enough, -- find the air node above the top shoot. place a node. And then, if short enough,
-- check for second node placement. -- check for second node placement.
if node_name == "air" then if node_name == "air" then
mcl_bamboo.mcl_log("Grow bamboo; dist: " .. dist)
mcl_bamboo.mcl_log("Grow bamboo; Placing bamboo.")
minetest.set_node(chk_pos, {name = node_below}) minetest.set_node(chk_pos, {name = node_below})
-- handle growing a second node. (1 in 32 chance.) -- handle growing a second node. (1 in 32 chance.)
if grow_amount == 2 and dist <= height - 2 then if grow_amount == 2 and dist <= height - 2 then
chk_pos = vector.offset(chk_pos, 0, 1, 0) chk_pos = vector.offset(chk_pos, 0, 1, 0)
if minetest.get_node(chk_pos).name == "air" then if minetest.get_node(chk_pos).name == "air" then
mcl_bamboo.mcl_log("Grow bamboo; OOOH! It's twofer day!")
minetest.set_node(chk_pos, {name = node_below}) minetest.set_node(chk_pos, {name = node_below})
end end
end end

@ -25,7 +25,7 @@ dofile(minetest.get_modpath(modname) .. "/recipes.lua")
--ABMs --ABMs
minetest.register_abm({ minetest.register_abm({
nodenames = {bamboo, bamboo .. "_1", bamboo .. "_2", bamboo .. "_3"}, nodenames = {bamboo, bamboo .. "_1", bamboo .. "_2", bamboo .. "_3"},
interval = 40, interval = 31.5,
chance = 40, chance = 40,
action = function(pos, _) action = function(pos, _)
mcl_bamboo.grow_bamboo(pos, false) mcl_bamboo.grow_bamboo(pos, false)
@ -48,8 +48,6 @@ minetest.register_alias("mcl_scaffolding:scaffolding_horizontal", "mcl_bamboo:sc
--[[ --[[
todo -- make scaffolds do side scaffold blocks, so that they jut out. todo -- make scaffolds do side scaffold blocks, so that they jut out.
todo -- Also, make those blocks collapse (break) when a nearby connected scaffold breaks. todo -- Also, make those blocks collapse (break) when a nearby connected scaffold breaks.
todo -- fix the random height for bamboo. Use metadata for storing the height, on_place.
todo -- fix scaffolding placing, instead of using on_rightclick first.
waiting on specific things: waiting on specific things:
todo -- Raft -- need model todo -- Raft -- need model