Cleaned up the code. Fixed side placement of bamboo against bamboo.

Dinked with the random number generator some more.

Condensed some more of the code duplication (WIP).

Added in MCL_Log function.

Finally settled on a decent looking Bamboo top.
This commit is contained in:
Michieal 2023-01-03 01:38:12 -05:00
parent 5ef7d9f7a0
commit ef7fb0d2e3
5 changed files with 86 additions and 104 deletions

View File

@ -8,18 +8,17 @@
local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local bamboo = "mcl_bamboo:bamboo"
local bamboo_one = bamboo .."_1"
local bamboo_two = bamboo.."_2"
local bamboo_three = bamboo.."_3"
local bamboo_one = bamboo .. "_1"
local bamboo_two = bamboo .. "_2"
local bamboo_three = bamboo .. "_3"
local node_sound = mcl_sounds.node_sound_wood_defaults()
-- CONSTS
local DOUBLE_DROP_CHANCE = 8
local DEBUG = false
local strlen = string.len
local substr = string.sub
local pr = PseudoRandom(os.time() * 12 + 15766) -- switched from math.random() to PseudoRandom because the random wasn't very random.
local pr = PseudoRandom((os.time() + 15766) * 12) -- switched from math.random() to PseudoRandom because the random wasn't very random.
local on_rotate
if minetest.get_modpath("screwdriver") then
@ -93,34 +92,29 @@ local bamboo_def = {
local node = minetest.get_node(pointed_thing.under)
local pos = pointed_thing.under
local nodename = node.name
-- check the nodename to see if it is one of the bamboo's
local bamboo_node = substr(nodename, 1, strlen(bamboo))
if DEBUG then
minetest.log("mcl_bamboo::Node placement data:")
minetest.log(dump(pointed_thing))
minetest.log(node.name)
end
mcl_bamboo.mcl_log("Node placement data:")
mcl_bamboo.mcl_log(dump(pointed_thing))
mcl_bamboo.mcl_log(node.name)
if DEBUG then
minetest.log("mcl_bamboo::Checking for protected placement of bamboo.")
end
mcl_bamboo.mcl_log("Checking for protected placement of bamboo.")
if mcl_bamboo.is_protected(pos, placer) then
return
end
if DEBUG then
minetest.log("mcl_bamboo::placement of bamboo is not protected.")
end
mcl_bamboo.mcl_log("placement of bamboo is not protected.")
-- Use pointed node's on_rightclick function first, if present
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 DEBUG then
minetest.log("mcl_bamboo::attempting placement of bamboo via targeted node's on_rightclick.")
end
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
end
end
if nodename ~= bamboo and nodename ~= bamboo_one and nodename ~= bamboo_two and nodename ~= bamboo_three then
if bamboo_node ~= bamboo and nodename ~= "mcl_bamboo:bamboo_endcap" then
-- not bamboo...
if nodename ~= "mcl_flowerpots:flower_pot" then
local found = false
@ -131,14 +125,13 @@ local bamboo_def = {
end
end
if not found then
return itemstack
return
end
end
end
if DEBUG then
minetest.log("mcl_bamboo::placing bamboo directly.")
end
mcl_bamboo.mcl_log("placing bamboo directly.")
local dir = vector.subtract(pointed_thing.under, pointed_thing.above)
local wdir = minetest.dir_to_wallmounted(dir)
local fdir = minetest.dir_to_facedir(dir)
@ -152,54 +145,33 @@ local bamboo_def = {
-- return the missing item, so that we can lower the code
-- complexity and duplication.
itemstack:set_count(itemstack:get_count() + 1)
return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
return minetest.item_place(itemstack, placer, pointed_thing, fdir)
elseif nodename == bamboo_one then
place_item:set_name(bamboo_one)
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
elseif nodename == bamboo_two then
place_item:set_name(bamboo_two)
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
elseif nodename == bamboo_three then
place_item:set_name(bamboo_three)
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
else
local placed_type = pr:next(0, 3) -- randomly choose which one to place.
if DEBUG then
minetest.log("MCL_BAMBOO::Place_Bamboo_Shoot--Type: " .. placed_type)
end
mcl_bamboo.mcl_log("Place_Bamboo_Shoot--Type: " .. placed_type)
if placed_type == 0 then
place_item=ItemStack(bamboo)
if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
return itemstack, pointed_thing.under
place_item = ItemStack(bamboo)
elseif placed_type == 1 then
place_item=ItemStack(bamboo_one)
if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
return itemstack, pointed_thing.under
place_item = ItemStack(bamboo_one)
elseif placed_type == 2 then
place_item=ItemStack(bamboo_two)
if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
return itemstack, pointed_thing.under
place_item = ItemStack(bamboo_two)
elseif placed_type == 3 then
place_item=ItemStack(bamboo_three)
if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
return itemstack, pointed_thing.under
place_item = ItemStack(bamboo_three)
end
return false
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
end
end,
@ -207,7 +179,7 @@ local bamboo_def = {
-- Node destructor; called before removing node.
local new_pos = vector.offset(pos, 0, 1, 0)
local node_above = minetest.get_node(new_pos)
local mboo = substr(node_above.name, strlen(node_above.name) - 3, strlen(node_above.name))
local bamboo_node = substr(node_above.name, 1, strlen(bamboo))
local istack = ItemStack(bamboo)
local sound_params = {
pos = new_pos,
@ -215,7 +187,7 @@ local bamboo_def = {
max_hear_distance = 10, -- default, uses a Euclidean metric
}
if node_above and (mboo == "mboo" or mboo == "oo_1" or mboo == "oo_2" or mboo == "oo_3") then
if node_above and (bamboo_node == bamboo and node_above.name ~= "mcl_bamboo:bamboo_endcap") then
minetest.remove_node(new_pos)
minetest.sound_play(node_sound.dug, sound_params, true)
if pr:next(1, DOUBLE_DROP_CHANCE) == 1 then
@ -236,11 +208,25 @@ minetest.register_node(bamboo, bamboo_def)
local bamboo_top = table.copy(bamboo_def)
bamboo_top.groups = {not_in_creative_inventory = 1, handy = 1, axey = 1, choppy = 1, flammable = 3}
bamboo_top.tiles = {"mcl_bamboo_flower_pot.png"}
bamboo_top.drawtype = "plantlike"
bamboo_top.paramtype2 = "meshoptions"
bamboo_top.param2 = 34
bamboo_top.tiles = {"mcl_bamboo_endcap.png"}
bamboo_top.drawtype = "plantlike_rooted" --"plantlike"
--bamboo_top.paramtype2 = "meshoptions"
--bamboo_top.param2 = 2
bamboo_top.special_tiles = {{name = "mcl_bamboo_endcap.png"}}
bamboo_top.nodebox = nil
bamboo_top.selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.05, 0.5, 0.5},
}
}
bamboo_top.collision_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.05, 0.5, 0.5},
}
}
bamboo_top.on_place = function(itemstack, _, _)
-- Should never occur... but, if it does, then nix it.
@ -286,7 +272,8 @@ minetest.register_node("mcl_bamboo:bamboo_block", bamboo_block_def)
local bamboo_stripped_block = table.copy(bamboo_block_def)
bamboo_stripped_block.on_rightclick = nil
bamboo_stripped_block.description = S("Stripped Bamboo Block")
bamboo_stripped_block.tiles = {"mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_block_stripped.png"}
bamboo_stripped_block.tiles = {"mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_bottom.png",
"mcl_bamboo_bamboo_block_stripped.png"}
minetest.register_node("mcl_bamboo:bamboo_block_stripped", bamboo_stripped_block)
minetest.register_node("mcl_bamboo:bamboo_plank", {
description = S("Bamboo Plank"),
@ -301,10 +288,19 @@ minetest.register_node("mcl_bamboo:bamboo_plank", {
_mcl_hardness = 2,
})
-- Bamboo Part 2 Base nodes.
-- Bamboo alternative node types. Note that the table.copy's are very important! if you use a common node def and
-- make changes, even after registering them, the changes overwrite the previous node definitions, and in this case,
-- you will end up with 4 nodes all being type 3.
-- Bamboo Part 2 Base nodes.
-- Bamboo Mosaic
local bamboo_mosaic = table.copy(minetest.registered_nodes[bamboo .. "_plank"])
bamboo_mosaic.tiles = {"mcl_bamboo_bamboo_plank.png"}
bamboo_mosaic.groups = {handy = 1, axey = 1, flammable = 3, fire_encouragement = 5, fire_flammability = 20}
bamboo_mosaic.description = S("Bamboo Mosaic Plank")
bamboo_mosaic._doc_items_longdesc = S("Bamboo Mosaic Plank")
minetest.register_node("mcl_bamboo:bamboo_mosaic", bamboo_mosaic)
--[[ Bamboo alternative node types. Note that the table.copy's are very important! if you use a common node def and
make changes, even after registering them, the changes overwrite the previous node definitions, and in this case,
you will end up with 4 nodes all being type 3. --]]
local bamboo_one_def = table.copy(bamboo_def)
bamboo_one_def.node_box = {
type = "fixed",

View File

@ -18,26 +18,12 @@ local adj_nodes = {
-- Due to door fix #2736, doors are displayed backwards. When this is fixed, set this variable to false.
local BROKEN_DOORS = true
local SIDE_SCAFFOLDING = false
local DEBUG = false
local node_sound = mcl_sounds.node_sound_wood_defaults()
-- Bamboo Mosaic
local bamboo_mosaic = table.copy(minetest.registered_nodes[bamboo .. "_plank"])
bamboo_mosaic.tiles = {"mcl_bamboo_bamboo_plank.png"}
bamboo_mosaic.groups = {handy = 1, axey = 1, flammable = 3, fire_encouragement = 5, fire_flammability = 20}
bamboo_mosaic.description = S("Bamboo Mosaic Plank")
bamboo_mosaic._doc_items_longdesc = S("Bamboo Mosaic Plank")
minetest.register_node("mcl_bamboo:bamboo_mosaic", bamboo_mosaic)
-- specific bamboo nodes (Items)... Pt. 1
if minetest.get_modpath("mcl_flowerpots") then
if DEBUG then
minetest.log("mcl_bamboo::FlowerPot Section Entrance. Modpath exists.")
end
mcl_bamboo.mcl_log("FlowerPot Section Entrance. Modpath exists.")
if mcl_flowerpots ~= nil then
-- Flower-potted Bamboo...
local flwr_name = "mcl_bamboo:bamboo"
@ -195,9 +181,7 @@ if minetest.get_modpath("mesecons_pressureplates") then
end
if minetest.get_modpath("mcl_signs") then
if DEBUG then
minetest.log("mcl_bamboo::Signs Section Entrance. Modpath exists.")
end
mcl_bamboo.mcl_log("Signs Section Entrance. Modpath exists.")
if mcl_signs ~= nil then
-- Bamboo Signs...
mcl_signs.register_sign_custom("mcl_bamboo", "_bamboo", "mcl_signs_sign_greyscale.png",
@ -209,9 +193,8 @@ if minetest.get_modpath("mcl_signs") then
end
if minetest.get_modpath("mcl_fences") then
if DEBUG then
minetest.log("mcl_bamboo::Fences Section Entrance. Modpath exists.")
end
mcl_bamboo.mcl_log("Fences Section Entrance. Modpath exists.")
local id = "bamboo_fence"
local id_gate = "bamboo_fence_gate"
local wood_groups = {handy = 1, axey = 1, flammable = 2, fence_wood = 1, fire_encouragement = 5, fire_flammability = 20}
@ -222,10 +205,8 @@ if minetest.get_modpath("mcl_fences") then
local gate_id = mcl_fences.register_fence_gate(id, S("Bamboo Fence Gate"), "mcl_bamboo_fence_gate_bamboo.png",
wood_groups, 2, 15, node_sound) -- note: about missing params.. will use defaults.
if DEBUG then
minetest.log(dump(fence_id))
minetest.log(dump(gate_id))
end
mcl_bamboo.mcl_log(dump(fence_id))
mcl_bamboo.mcl_log(dump(gate_id))
local craft_wood = "mcl_bamboo:bamboo_plank"
minetest.register_craft({
@ -329,18 +310,13 @@ minetest.register_node("mcl_bamboo:scaffolding", {
return itemstack
end
end
if DEBUG then
minetest.log("mcl_bamboo::Checking for protected placement of scaffolding.")
end
mcl_bamboo.mcl_log("Checking for protected placement of scaffolding.")
local node = minetest.get_node(ptd.under)
local pos = ptd.under
if mcl_bamboo.is_protected(pos, placer) then
return
end
if DEBUG then
minetest.log("mcl_bamboo::placement of scaffolding is not protected.")
end
mcl_bamboo.mcl_log("placement of scaffolding is not protected.")
--place on solid nodes
if itemstack:get_name() ~= node.name then
minetest.set_node(ptd.above, {name = scaff_node_name, param2 = 0})

View File

@ -13,6 +13,11 @@ local strlen = string.len
local substr = string.sub
local rand = math.random
math.randomseed((os.time() + 31) * 31415) -- try to make a valid seed
local BAMBOO_MAX_HEIGHT = 16 -- base height check.
local BAMBOO_SOIL_DIST = BAMBOO_MAX_HEIGHT * -1
local BAM_MAX_HEIGHT_STPCHK = BAMBOO_MAX_HEIGHT - 5
local BAM_MAX_HEIGHT_TOP = BAMBOO_MAX_HEIGHT - 1
--Bamboo can be planted on moss blocks, grass blocks, dirt, coarse dirt, rooted dirt, gravel, mycelium, podzol, sand, red sand, or mud
mcl_bamboo.bamboo_dirt_nodes = {
@ -40,9 +45,6 @@ function mcl_bamboo.is_protected(pos, placer)
end
function mcl_bamboo.grow_bamboo(pos, _)
local BAMBOO_SOIL_DIST = -16
local BAM_MAX_HEIGHT_STPCHK = 11
local BAM_MAX_HEIGHT_TOP = 15
local chk_pos
local soil_pos
@ -130,3 +132,12 @@ function mcl_bamboo.add_groups(name, ...)
addall(...)
return minetest.override_item(name, {groups = groups})
end
function mcl_bamboo.mcl_log(m, l)
if DEBUG then
if not l then
minetest.log("[mcl_bamboo]: " .. m)
end
minetest.log(l, "[mcl_bamboo]: " .. m)
end
end

View File

@ -47,8 +47,7 @@ minetest.register_alias("mcl_scaffolding:scaffolding_horizontal", "mcl_bamboo:sc
--[[
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 -- Add Flourish to the endcap node for bamboo. Fix the flourish to not look odd or plain.
todo -- mash all of that together so that it drops as one item.
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:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 941 B

After

Width:  |  Height:  |  Size: 257 B