1
0
Fork 0

Many bug fixes, Adjusted randomizing code.

And, Now with Lime-Cherry Kool-aid!! Yum!
This commit is contained in:
Michieal 2023-01-02 02:19:33 -05:00
parent 23b62c296a
commit a7a0c4791a
1 changed files with 98 additions and 29 deletions

View File

@ -16,7 +16,7 @@ local DEBUG = false
local strlen = string.len local strlen = string.len
local substr = string.sub local substr = string.sub
local rand = math.random local pr = PseudoRandom(os.time() * 12 + 15766) -- switched from math.random() to PseudoRandom because the random wasn't very random.
-- basic bamboo nodes. -- basic bamboo nodes.
local bamboo_def = { local bamboo_def = {
@ -63,6 +63,18 @@ local bamboo_def = {
{-0.175, -0.5, -0.195, 0.05, 0.5, 0.030}, {-0.175, -0.5, -0.195, 0.05, 0.5, 0.030},
} }
}, },
collision_box = {
type = "fixed",
fixed = {
{-0.175, -0.5, -0.195, 0.05, 0.5, 0.030},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.175, -0.5, -0.195, 0.05, 0.5, 0.030},
}
},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
@ -73,7 +85,7 @@ local bamboo_def = {
if DEBUG then if DEBUG then
minetest.log("mcl_bamboo::Node placement data:") minetest.log("mcl_bamboo::Node placement data:")
minetest.log(dump(pointed_thing)) minetest.log(dump(pointed_thing))
minetest.log(dump(node)) minetest.log(node.name)
end end
if DEBUG then if DEBUG then
@ -118,38 +130,57 @@ local bamboo_def = {
minetest.log("mcl_bamboo::placing bamboo directly.") minetest.log("mcl_bamboo::placing bamboo directly.")
end end
local place_item = table.copy(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.
node = minetest.get_node(pointed_thing.under)
mboo = substr(node.name, strlen(node.name) - 3, strlen(node.name))
if DEBUG then
minetest.log("mboo:\n" .. mboo)
end
if mboo == "mboo" then if mboo == "mboo" then
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, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
elseif mboo ~= "oo_1" then elseif mboo == "oo_1" then
place_item:set_name(bamboo .. "_1") place_item:set_name(bamboo .. "_1")
itemstack:set_count(itemstack:get_count() - 1) itemstack:set_count(itemstack:get_count() - 1)
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, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
if DEBUG then
minetest.log("Bamboo placeitem definition (current):\n" .. dump(place_item:to_table()))
end
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
elseif mboo ~= "oo_2" then elseif mboo == "oo_2" then
place_item:set_name(bamboo .. "_2") place_item:set_name(bamboo .. "_2")
itemstack:set_count(itemstack:get_count() - 1) itemstack:set_count(itemstack:get_count() - 1)
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, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
if DEBUG then
minetest.log("Bamboo placeitem definition (current):\n" .. dump(place_item:to_table()))
end
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
elseif mboo ~= "oo_3" then elseif mboo == "oo_3" then
place_item:set_name(bamboo .. "_3") place_item:set_name(bamboo .. "_3")
itemstack:set_count(itemstack:get_count() - 1) itemstack:set_count(itemstack:get_count() - 1)
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, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
if DEBUG then
minetest.log("Bamboo placeitem definition (current):\n" .. dump(place_item:to_table()))
end
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
else else
local placed_type = rand(0, 3) -- randomly choose which one to place. local placed_type = pr:next(0, 3) -- randomly choose which one to place.
placed_type = rand(0, 3) placed_type = pr:next(0, 3) -- Get the lua juices flowing. (Really, this is just to get it to give a real random number.)
placed_type = rand(0, 3) if DEBUG then
placed_type = rand(0, 3) -- Get the lua juices flowing. (Really, this is just to get it to give a real random number.) minetest.log("MCL_BAMBOO::Place_Bamboo_Shoot--Type: " .. placed_type)
if placed_type == 1 then
place_item:set_name(bamboo .. "_1")
end end
if placed_type == 2 then if placed_type == 0 then
place_item:set_name(bamboo .. "_2") place_item=ItemStack(bamboo)
elseif placed_type == 1 then
place_item=ItemStack(bamboo .. "_1")
elseif placed_type == 2 then
place_item=ItemStack(bamboo .. "_2")
elseif placed_type == 3 then
place_item=ItemStack(bamboo .. "_3")
end end
if placed_type == 3 then if DEBUG then
place_item:set_name(bamboo .. "_3") minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end end
itemstack:set_count(itemstack:get_count() - 1) itemstack:set_count(itemstack:get_count() - 1)
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, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
@ -162,26 +193,25 @@ local bamboo_def = {
local new_pos = vector.offset(pos, 0, 1, 0) local new_pos = vector.offset(pos, 0, 1, 0)
local node_above = minetest.get_node(new_pos) local node_above = minetest.get_node(new_pos)
local mboo = substr(node_above.name, strlen(node_above.name) - 3, strlen(node_above.name)) local mboo = substr(node_above.name, strlen(node_above.name) - 3, strlen(node_above.name))
local istack = ItemStack(bamboo)
local sound_params = {
pos = new_pos,
gain = 1.0, -- default
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 (mboo == "mboo" or mboo == "oo_1" or mboo == "oo_2" or mboo == "oo_3") then
local sound_params = {
pos = new_pos,
gain = 1.0, -- default
max_hear_distance = 10, -- default, uses a Euclidean metric
}
minetest.remove_node(new_pos) minetest.remove_node(new_pos)
minetest.sound_play(node_sound.dug, sound_params, true) minetest.sound_play(node_sound.dug, sound_params, true)
local istack = ItemStack(bamboo) if pr:next(1, DOUBLE_DROP_CHANCE) == 1 then
if rand(1, DOUBLE_DROP_CHANCE) == 1 then
minetest.add_item(new_pos, istack) minetest.add_item(new_pos, istack)
end end
minetest.add_item(new_pos, istack) minetest.add_item(new_pos, istack)
elseif node_above and node_above.name == "mcl_bamboo:bamboo_endcap" then elseif node_above and node_above.name == "mcl_bamboo:bamboo_endcap" then
minetest.remove_node(new_pos) minetest.remove_node(new_pos)
minetest.sound_play(node_sound.dug, sound_params, true) minetest.sound_play(node_sound.dug, sound_params, true)
local istack = ItemStack(bamboo)
minetest.add_item(new_pos, istack) minetest.add_item(new_pos, istack)
if rand(1, DOUBLE_DROP_CHANCE) == 1 then if pr:next(1, DOUBLE_DROP_CHANCE) == 1 then
minetest.add_item(new_pos, istack) minetest.add_item(new_pos, istack)
end end
end end
@ -258,14 +288,27 @@ minetest.register_node("mcl_bamboo:bamboo_plank", {
-- Bamboo Part 2 Base nodes. -- Bamboo Part 2 Base nodes.
-- Bamboo alternative node types. -- Bamboo alternative node types.
local def = minetest.registered_nodes [bamboo] local def = table.copy(bamboo_def)
def.node_box = { def.node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-0.05, -0.5, 0.285, -0.275, 0.5, 0.06}, {-0.05, -0.5, 0.285, -0.275, 0.5, 0.06},
} }
} }
minetest.register_node(bamboo.."_1", def) def.collision_box = {
-- see [Node boxes] for possibilities
type = "fixed",
fixed = {
{-0.05, -0.5, 0.285, -0.275, 0.5, 0.06},
}
}
def.selection_box = {
type = "fixed",
fixed = {
{-0.05, -0.5, 0.285, -0.275, 0.5, 0.06},
}
}
minetest.register_node(bamboo .. "_1", def)
def.node_box = { def.node_box = {
type = "fixed", type = "fixed",
@ -273,7 +316,20 @@ def.node_box = {
{0.25, -0.5, 0.325, 0.025, 0.5, 0.100}, {0.25, -0.5, 0.325, 0.025, 0.5, 0.100},
} }
} }
minetest.register_node(bamboo.."_2", def) def.collision_box = {
-- see [Node boxes] for possibilities
type = "fixed",
fixed = {
{0.25, -0.5, 0.325, 0.025, 0.5, 0.100},
}
}
def.selection_box = {
type = "fixed",
fixed = {
{0.25, -0.5, 0.325, 0.025, 0.5, 0.100},
}
}
minetest.register_node(bamboo .. "_2", def)
def.node_box = { def.node_box = {
type = "fixed", type = "fixed",
@ -281,7 +337,20 @@ def.node_box = {
{-0.125, -0.5, 0.125, -0.3125, 0.5, 0.3125}, {-0.125, -0.5, 0.125, -0.3125, 0.5, 0.3125},
} }
} }
minetest.register_node(bamboo.."_3", def) def.collision_box = {
-- see [Node boxes] for possibilities
type = "fixed",
fixed = {
{-0.125, -0.5, 0.125, -0.3125, 0.5, 0.3125},
}
}
def.selection_box = {
type = "fixed",
fixed = {
{-0.125, -0.5, 0.125, -0.3125, 0.5, 0.3125},
}
}
minetest.register_node(bamboo .. "_3", def)
-- Bamboo Mosaic -- Bamboo Mosaic
local bamboo_mosaic = minetest.registered_nodes[bamboo .. "_plank"] local bamboo_mosaic = minetest.registered_nodes[bamboo .. "_plank"]