Fix -- Bamboo grow, bamboo place to be correct.

This commit is contained in:
Michieal 2023-01-11 07:16:12 -05:00
parent e7c238c17e
commit 00408b998c
2 changed files with 32 additions and 23 deletions

View File

@ -91,7 +91,7 @@ local bamboo_def = {
end end
local node = minetest.get_node(pointed_thing.under) local node = minetest.get_node(pointed_thing.under)
local pos = pointed_thing.under local pos = pointed_thing.under
local nodename = node.name local nodename = node.name -- intentional use of nodename.
mcl_bamboo.mcl_log("Node placement data:") mcl_bamboo.mcl_log("Node placement data:")
mcl_bamboo.mcl_log(dump(pointed_thing)) mcl_bamboo.mcl_log(dump(pointed_thing))
@ -106,13 +106,14 @@ local bamboo_def = {
-- Use pointed node's on_rightclick function first, if present -- Use pointed node's on_rightclick function first, if present
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 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_thing.under, node, placer, itemstack) or itemstack
end end
end end
if mcl_bamboo.is_bamboo(nodename) == false and nodename ~= BAMBOO_ENDCAP_NAME then if mcl_bamboo.is_bamboo(nodename) == false and nodename ~= BAMBOO_ENDCAP_NAME then
-- not bamboo... -- not bamboo...
mcl_bamboo.mcl_log("not bamboo...")
if nodename ~= "mcl_flowerpots:flower_pot" then if nodename ~= "mcl_flowerpots:flower_pot" then
if mcl_bamboo.is_dirt(nodename) == false then if mcl_bamboo.is_dirt(nodename) == false then
mcl_bamboo.mcl_log("bamboo dirt node not found; node name: " .. nodename) mcl_bamboo.mcl_log("bamboo dirt node not found; node name: " .. nodename)
@ -132,22 +133,20 @@ local bamboo_def = {
local place_item = ItemStack(itemstack) -- make a copy so that we don't indirectly mess with the original. local place_item = ItemStack(itemstack) -- make a copy so that we don't indirectly mess with the original.
local bamboo_node = mcl_bamboo.is_bamboo(nodename) local bamboo_node = mcl_bamboo.is_bamboo(nodename) or 0
mcl_bamboo.mcl_log("node name: " .. nodename .. "\nbamboo_node: " .. bamboo_node) mcl_bamboo.mcl_log("node name: " .. nodename .. "\nbamboo_node: " .. bamboo_node)
-- intentional use of nodename.
local rand_height local rand_height
local BAMBOO_MAX_HEIGHT = 16 -- maximum height of 16, per wiki. local BAMBOO_MAX_HEIGHT = 16 -- maximum height of 16, per wiki.
local first_shoot local first_shoot
local meta local meta
if bamboo_node ~= -1 then if bamboo_node and bamboo_node > 0 then
place_item = ItemStack(mcl_bamboo.bamboo_index[bamboo_node]) place_item = ItemStack(mcl_bamboo.bamboo_index[bamboo_node])
-- height check for placing bamboo nodes. because... lmfao bamboo stalk to the sky. -- height check for placing bamboo nodes. because... lmfao bamboo stalk to the sky.
-- variables used in more than one spot. -- variables used in more than one spot.
local chk_pos local chk_pos
local soil_pos
local node_name = "" local node_name = ""
local dist = 0 local dist = 0
local height = -1 local height = -1
@ -160,12 +159,11 @@ local bamboo_def = {
if mcl_bamboo.is_dirt(node_name) then if mcl_bamboo.is_dirt(node_name) then
first_shoot = vector.offset(chk_pos, 0, 1, 0) first_shoot = vector.offset(chk_pos, 0, 1, 0)
break break
else end
if mcl_bamboo.is_bamboo(node_name) == false then if mcl_bamboo.is_bamboo(node_name) == false then
break break
end end
end end
end
-- requires knowing where the soil node is. -- requires knowing where the soil node is.
if first_shoot == nil then if first_shoot == nil then
return return
@ -205,11 +203,14 @@ local bamboo_def = {
itemstack:take_item(1) itemstack:take_item(1)
end end
if rand_height and rand_height > 1 then if rand_height and rand_height > 1 then
if position then
mcl_bamboo.mcl_log("Setting Height Data...")
meta = minetest.get_meta(position) meta = minetest.get_meta(position)
if meta then if meta then
meta:set_int("height", rand_height) meta:set_int("height", rand_height)
end end
end end
end
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
end, end,
@ -243,7 +244,7 @@ bamboo_top.tiles = {"mcl_bamboo_endcap.png"}
bamboo_top.drawtype = "plantlike_rooted" --"plantlike" bamboo_top.drawtype = "plantlike_rooted" --"plantlike"
--bamboo_top.paramtype2 = "meshoptions" --bamboo_top.paramtype2 = "meshoptions"
--bamboo_top.param2 = 2 --bamboo_top.param2 = 2
bamboo_top.waving = 2 -- bamboo_top.waving = 2
bamboo_top.special_tiles = {{name = "mcl_bamboo_endcap.png"}} bamboo_top.special_tiles = {{name = "mcl_bamboo_endcap.png"}}
bamboo_top.nodebox = nil bamboo_top.nodebox = nil
bamboo_top.selection_box = nil bamboo_top.selection_box = nil

View File

@ -13,7 +13,6 @@ local BAMBOO_MAX_HEIGHT = 16 -- base height check.
local BAMBOO_SOIL_DIST = BAMBOO_MAX_HEIGHT * -1 local BAMBOO_SOIL_DIST = BAMBOO_MAX_HEIGHT * -1
local BAM_MAX_HEIGHT_STPCHK = BAMBOO_MAX_HEIGHT - 5 local BAM_MAX_HEIGHT_STPCHK = BAMBOO_MAX_HEIGHT - 5
local BAM_MAX_HEIGHT_TOP = BAMBOO_MAX_HEIGHT - 1 local BAM_MAX_HEIGHT_TOP = BAMBOO_MAX_HEIGHT - 1
local GROW_DOUBLE_CHANCE = 32 local GROW_DOUBLE_CHANCE = 32
--Bamboo can be planted on moss blocks, grass blocks, dirt, coarse dirt, rooted dirt, gravel, mycelium, podzol, sand, red sand, or mud --Bamboo can be planted on moss blocks, grass blocks, dirt, coarse dirt, rooted dirt, gravel, mycelium, podzol, sand, red sand, or mud
@ -31,7 +30,12 @@ mcl_bamboo.bamboo_dirt_nodes = {
} }
function mcl_bamboo.is_dirt(node_name) function mcl_bamboo.is_dirt(node_name)
return table.indexof(mcl_bamboo.bamboo_dirt_nodes, node_name) ~= -1 local index = table.indexof(mcl_bamboo.bamboo_dirt_nodes, node_name)
if index == -1 then
return false
else
return true
end
end end
mcl_bamboo.bamboo_index = { mcl_bamboo.bamboo_index = {
@ -42,7 +46,12 @@ mcl_bamboo.bamboo_index = {
} }
function mcl_bamboo.is_bamboo(node_name) function mcl_bamboo.is_bamboo(node_name)
return table.indexof(mcl_bamboo.bamboo_index, node_name) local index = table.indexof(mcl_bamboo.bamboo_index, node_name)
if index == -1 then
return false
else
return index
end
end end
--- pos: node position; placer: ObjectRef that is placing the item --- pos: node position; placer: ObjectRef that is placing the item
@ -62,7 +71,7 @@ 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)) 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) ~= false 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.
end end
if minetest.get_node_light(pos) < 8 then if minetest.get_node_light(pos) < 8 then
@ -79,19 +88,18 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
-- ------------------- -- -------------------
mcl_bamboo.mcl_log("Grow bamboo; checking for soil: ") mcl_bamboo.mcl_log("Grow bamboo; checking for soil: ")
-- the soil node below. -- the soil node below the bamboo.
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)
node_name = minetest.get_node(chk_pos).name node_name = minetest.get_node(chk_pos).name
if mcl_bamboo.is_dirt(node_name) then if mcl_bamboo.is_dirt(node_name) then
soil_pos = chk_pos soil_pos = chk_pos
break break
else end
if mcl_bamboo.is_bamboo(node_name) == false then if mcl_bamboo.is_bamboo(node_name) == false then
break break
end end
end end
end
-- requires knowing where the soil node is. -- requires knowing where the soil node is.
if soil_pos == nil then if soil_pos == nil then
return false -- returning false means don't use up the bonemeal. return false -- returning false means don't use up the bonemeal.