Added in Bamboo_Plank variable.

Dinked with the random number generator some.

Moved Bamboo Mosaic from base to items.

condensed some of the code duplication (WIP).

started to add in checks to prevent bamboo from being placed against itself horizontally.

Fixed a couple of naming issues.
This commit is contained in:
Michieal 2023-01-02 22:36:09 -05:00
parent 388632cd46
commit 5ef7d9f7a0
4 changed files with 185 additions and 186 deletions

View File

@ -139,37 +139,33 @@ local bamboo_def = {
if DEBUG then if DEBUG then
minetest.log("mcl_bamboo::placing bamboo directly.") minetest.log("mcl_bamboo::placing bamboo directly.")
end end
local dir = vector.subtract(pointed_thing.under, pointed_thing.above)
local wdir = minetest.dir_to_wallmounted(dir)
local fdir = minetest.dir_to_facedir(dir)
if wdir ~= 1 then
return
end
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.
itemstack:set_count(itemstack:get_count() - 1)
if nodename == bamboo then if nodename == bamboo then
-- 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, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
elseif nodename == bamboo_one then elseif nodename == bamboo_one then
place_item:set_name(bamboo_one) place_item:set_name(bamboo_one)
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 nodename == bamboo_two then elseif nodename == bamboo_two then
place_item:set_name(bamboo_two) place_item:set_name(bamboo_two)
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 nodename == bamboo_three then elseif nodename == bamboo_three then
place_item:set_name(bamboo_three) place_item:set_name(bamboo_three)
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
itemstack:set_count(itemstack:get_count() - 1)
local placed_type = pr:next(0, 3) -- randomly choose which one to place. local placed_type = pr:next(0, 3) -- randomly choose which one to place.
if DEBUG then if DEBUG then
minetest.log("MCL_BAMBOO::Place_Bamboo_Shoot--Type: " .. placed_type) minetest.log("MCL_BAMBOO::Place_Bamboo_Shoot--Type: " .. placed_type)
@ -182,21 +178,21 @@ local bamboo_def = {
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)))
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
elseif placed_type == 1 then elseif placed_type == 1 then
place_item=ItemStack(bamboo .. "_1") place_item=ItemStack(bamboo_one)
if DEBUG then if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table())) minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end end
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)))
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
elseif placed_type == 2 then elseif placed_type == 2 then
place_item=ItemStack(bamboo .. "_2") place_item=ItemStack(bamboo_two)
if DEBUG then if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table())) minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end end
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)))
return itemstack, pointed_thing.under return itemstack, pointed_thing.under
elseif placed_type == 3 then elseif placed_type == 3 then
place_item=ItemStack(bamboo .. "_3") place_item=ItemStack(bamboo_three)
if DEBUG then if DEBUG then
minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table())) minetest.log("Bamboo place_item definition (current):\n" .. dump(place_item:to_table()))
end end
@ -240,7 +236,7 @@ minetest.register_node(bamboo, bamboo_def)
local bamboo_top = table.copy(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.groups = {not_in_creative_inventory = 1, handy = 1, axey = 1, choppy = 1, flammable = 3}
bamboo_top.tiles = {"mcl_bamboo_endcap.png"} bamboo_top.tiles = {"mcl_bamboo_flower_pot.png"}
bamboo_top.drawtype = "plantlike" bamboo_top.drawtype = "plantlike"
bamboo_top.paramtype2 = "meshoptions" bamboo_top.paramtype2 = "meshoptions"
bamboo_top.param2 = 34 bamboo_top.param2 = 34
@ -374,12 +370,3 @@ bamboo_three_def.selection_box = {
} }
} }
minetest.register_node(bamboo_three, bamboo_three_def) minetest.register_node(bamboo_three, bamboo_three_def)
-- Bamboo Mosaic
local bamboo_mosaic = 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)

View File

@ -22,6 +22,17 @@ local DEBUG = false
local node_sound = mcl_sounds.node_sound_wood_defaults() 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 -- specific bamboo nodes (Items)... Pt. 1
if minetest.get_modpath("mcl_flowerpots") then if minetest.get_modpath("mcl_flowerpots") then
if DEBUG then if DEBUG then

View File

@ -12,6 +12,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 rand = math.random
math.randomseed((os.time() + 31) * 31415) -- try to make a valid seed
--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
mcl_bamboo.bamboo_dirt_nodes = { mcl_bamboo.bamboo_dirt_nodes = {
@ -113,18 +114,18 @@ function mcl_bamboo.grow_bamboo(pos, _)
end end
-- Add Groups function, courtesy of Warr1024. -- Add Groups function, courtesy of Warr1024.
function mcl_bamboo.addgroups(name, ...) function mcl_bamboo.add_groups(name, ...)
local def = minetest.registered_items[name] or error(name .. " not found") local def = minetest.registered_items[name] or error(name .. " not found")
local groups = {} local groups = {}
for k, v in pairs(def.groups) do for k, v in pairs(def.groups) do
groups[k] = v groups[k] = v
end end
local function addall(x, ...) local function add_all(x, ...)
if not x then if not x then
return return
end end
groups[x] = 1 groups[x] = 1
return addall(...) return add_all(...)
end end
addall(...) addall(...)
return minetest.override_item(name, {groups = groups}) return minetest.override_item(name, {groups = groups})

View File

@ -5,179 +5,179 @@
--- These are all of the fuel recipes and all of the crafting recipes, consolidated into one place. --- These are all of the fuel recipes and all of the crafting recipes, consolidated into one place.
local bamboo = "mcl_bamboo:bamboo" local bamboo = "mcl_bamboo:bamboo"
local bamboo_plank = bamboo .. "_plank"
-- Craftings
-- Basic Bamboo craftings
minetest.register_craft({
output = "mcl_core:stick",
recipe = {
{bamboo},
{bamboo},
}
})
-- Craftings minetest.register_craft({
-- Basic Bamboo craftings output = bamboo .. "_block",
minetest.register_craft({ recipe = {
output = "mcl_core:stick", {bamboo, bamboo, bamboo},
recipe = { {bamboo, bamboo, bamboo},
{bamboo}, {bamboo, bamboo, bamboo},
{bamboo}, }
} })
})
minetest.register_craft({ minetest.register_craft({
output = bamboo .. "_block", output = bamboo_plank .. " 2",
recipe = { recipe = {
{bamboo, bamboo, bamboo}, {bamboo .. "_block"},
{bamboo, bamboo, bamboo}, }
{bamboo, bamboo, bamboo}, })
}
})
minetest.register_craft({ minetest.register_craft({
output = bamboo .. "_plank 2", output = bamboo_plank .. " 2",
recipe = { recipe = {
{bamboo .. "_block"}, {bamboo .. "_block_stripped"},
} }
}) })
minetest.register_craft({ minetest.register_craft({
output = bamboo .. "_plank 2", output = bamboo .. "_mosaic",
recipe = { recipe = {
{bamboo .. "_block_stripped"}, {"mcl_stair:slab_bamboo_plank"},
} {"mcl_stair:slab_bamboo_plank"},
}) }
})
minetest.register_craft({ -- Bamboo specific items
output = bamboo .. "_mosaic",
recipe = {
{"mcl_stair:slab_bamboo_plank"},
{"mcl_stair:slab_bamboo_plank"},
}
})
-- Bamboo specific items if minetest.get_modpath("mcl_doors") then
if mcl_doors then
if minetest.get_modpath("mcl_doors") then minetest.register_craft({
if mcl_doors then output = "mcl_bamboo:bamboo_door 3",
minetest.register_craft({ recipe = {
output = "mcl_bamboo:bamboo_door 3", {bamboo_plank, bamboo_plank},
recipe = { {bamboo_plank, bamboo_plank},
{bamboo .. "_plank", bamboo .. "_plank"}, {bamboo_plank, bamboo_plank}
{bamboo .. "_plank", bamboo .. "_plank"}, }
{bamboo .. "_plank", bamboo .. "_plank"} })
} minetest.register_craft({
}) output = "mcl_bamboo:bamboo_trapdoor 2",
minetest.register_craft({ recipe = {
output = "mcl_bamboo:bamboo_trapdoor 2", {bamboo_plank, bamboo_plank, bamboo_plank},
recipe = { {bamboo_plank, bamboo_plank, bamboo_plank},
{bamboo .. "_plank", bamboo .. "_plank", bamboo .. "_plank"}, }
{bamboo .. "_plank", bamboo .. "_plank", bamboo .. "_plank"}, })
}
})
end
end end
end
minetest.register_craft({ minetest.register_craft({
output = "mcl_bamboo:scaffolding 6", output = "mcl_bamboo:scaffolding 6",
recipe = {{bamboo, "mcl_mobitems:string", bamboo}, recipe = {{bamboo, "mcl_mobitems:string", bamboo},
{bamboo, "", bamboo}, {bamboo, "", bamboo},
{bamboo, "", bamboo}} {bamboo, "", bamboo}}
}) })
-- Fuels -- Fuels
-- Basic Bamboo nodes -- Basic Bamboo nodes
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = bamboo, recipe = bamboo,
burntime = 2.5, -- supposed to be 1/2 that of a stick, per minecraft wiki as of JE 1.19.3 burntime = 2.5, -- supposed to be 1/2 that of a stick, per minecraft wiki as of JE 1.19.3
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = bamboo .. "_block", recipe = bamboo .. "_block",
burntime = 15, burntime = 15,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = bamboo .. "_block_stripped", recipe = bamboo .. "_block_stripped",
burntime = 15, burntime = 15,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = bamboo .. "_plank", recipe = bamboo_plank,
burntime = 7.5, burntime = 7.5,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = bamboo .. "_mosaic", recipe = bamboo .. "_mosaic",
burntime = 7.5, burntime = 7.5,
}) })
-- Bamboo Items -- Bamboo Items
if minetest.get_modpath("mcl_doors") then if minetest.get_modpath("mcl_doors") then
if mcl_doors then if mcl_doors then
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_bamboo:bamboo_door", recipe = "mcl_bamboo:bamboo_door",
burntime = 10, burntime = 10,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_bamboo:bamboo_trapdoor", recipe = "mcl_bamboo:bamboo_trapdoor",
burntime = 15, burntime = 15,
}) })
end
end end
end
if minetest.get_modpath("mcl_stairs") then if minetest.get_modpath("mcl_stairs") then
if mcl_stairs ~= nil then if mcl_stairs ~= nil then
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:slab_bamboo_plank", recipe = "mcl_stairs:slab_bamboo_plank",
burntime = 7.5, burntime = 7.5,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:slab_bamboo_block", recipe = "mcl_stairs:slab_bamboo_block",
burntime = 7.5, burntime = 7.5,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:slab_bamboo_stripped", recipe = "mcl_stairs:slab_bamboo_stripped",
burntime = 7.5, burntime = 7.5,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:stair_bamboo_plank", recipe = "mcl_stairs:stair_bamboo_plank",
burntime = 15, burntime = 15,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:stair_bamboo_block", recipe = "mcl_stairs:stair_bamboo_block",
burntime = 15, burntime = 15,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:stair_bamboo_stripped", recipe = "mcl_stairs:stair_bamboo_stripped",
burntime = 15, burntime = 15,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:slab_bamboo_mosaic", recipe = "mcl_stairs:slab_bamboo_mosaic",
burntime = 7.5, burntime = 7.5,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_stairs:stair_bamboo_mosaic", recipe = "mcl_stairs:stair_bamboo_mosaic",
burntime = 15, burntime = 15,
}) })
end
end end
end
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mesecons_button:button_bamboo_off", recipe = "mesecons_button:button_bamboo_off",
burntime = 5, burntime = 5,
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_bamboo:scaffolding", recipe = "mcl_bamboo:scaffolding",
burntime = 20 burntime = 20
}) })