From 2b11b5c17a5ca3743127ae46667827c3e350c74b Mon Sep 17 00:00:00 2001 From: Michieal Date: Wed, 21 Dec 2022 22:22:51 -0500 Subject: [PATCH] Added full node names for bamboo on_place. Added in bamboo top destruct. Removed mapgen.lua. --- mods/ITEMS/mcl_bamboo/init.lua | 68 +++++++++++++++++++++----------- mods/ITEMS/mcl_bamboo/mapgen.lua | 60 ---------------------------- 2 files changed, 46 insertions(+), 82 deletions(-) delete mode 100644 mods/ITEMS/mcl_bamboo/mapgen.lua diff --git a/mods/ITEMS/mcl_bamboo/init.lua b/mods/ITEMS/mcl_bamboo/init.lua index a5aa36d1a..b147e69bb 100644 --- a/mods/ITEMS/mcl_bamboo/init.lua +++ b/mods/ITEMS/mcl_bamboo/init.lua @@ -8,12 +8,7 @@ local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) local bamboo = "mcl_bamboo:bamboo" -local adj_nodes = { - vector.new(0, 0, 1), - vector.new(0, 0, -1), - vector.new(1, 0, 0), - vector.new(-1, 0, 0), -} + local node_sound = mcl_sounds.node_sound_wood_defaults() -- CONSTS @@ -27,13 +22,13 @@ local bamboo_dirt_nodes = { "mcl_core:redsand", "mcl_core:sand", "mcl_core:dirt", -"mcl_core:coarse_dirt", -"mcl_core:dirt_with_grass", -"mcl_core:podzol", -"mcl_core:mycelium", -"mcl_lush_caves:rooted_dirt", -"mcl_lush_caves:moss", -"mcl_mud:mud", + "mcl_core:coarse_dirt", + "mcl_core:dirt_with_grass", + "mcl_core:podzol", + "mcl_core:mycelium", + "mcl_lush_caves:rooted_dirt", + "mcl_lush_caves:moss", + "mcl_mud:mud", } -- Due to door fix #2736, doors are displayed backwards. When this is fixed, set this variable to false. @@ -126,7 +121,14 @@ local function create_nodes() if node.name ~= "mcl_bamboo:bamboo" then if node.name ~= "mcl_flowerpots:flower_pot" then - if minetest.get_item_group(node.name, "dirt") == 0 then + local found = false + for i = 1, #bamboo_dirt_nodes do + if node.name == bamboo_dirt_nodes[i] then + found = true + break + end + end + if not found then return itemstack end end @@ -143,13 +145,18 @@ local function create_nodes() -- Node destructor; called before removing node. local new_pos = vector.offset(pos, 0, 1, 0) local node_above = minetest.get_node(new_pos) - if node_above and node_above.name == "mcl_bamboo:bamboo" then + if node_above and node_above.name == bamboo 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.sound_play(node_sound.dug, sound_params, true) + local istack = ItemStack("mcl_bamboo:bamboo") + minetest.add_item(new_pos, istack) + elseif node_above and node_above.name == "mcl_bamboo:bamboo_endcap" then minetest.remove_node(new_pos) minetest.sound_play(node_sound.dug, sound_params, true) local istack = ItemStack("mcl_bamboo:bamboo") @@ -157,9 +164,10 @@ local function create_nodes() end end, } - minetest.register_node("mcl_bamboo:bamboo", bamboo_def) + 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.drops = bamboo bamboo_top.on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then @@ -200,7 +208,26 @@ local function create_nodes() minetest.log("mcl_bamboo::placing bamboo directly.") end return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) - end, + end + --[[ + bamboo_top.on_destruct = function(pos) + -- Node destructor; called before removing node. + local node = minetest.get_node(pos) + if node and node.name == "mcl_bamboo:bamboo_endcap" then + local sound_params = { + pos = pos, + gain = 1.0, -- default + max_hear_distance = 10, -- default, uses a Euclidean metric + } + + minetest.remove_node(pos) + minetest.sound_play(node_sound.dug, sound_params, true) + local istack = ItemStack("mcl_bamboo:bamboo") + minetest.add_item(pos, istack) + end + + end + ]] minetest.register_node("mcl_bamboo:bamboo_endcap", bamboo_top) @@ -732,9 +759,6 @@ end create_nodes() register_craftings() --- MAPGEN -dofile(minetest.get_modpath(modname) .. "/mapgen.lua") - -- BAMBOO_TOO (Bamboo two) dofile(minetest.get_modpath(modname) .. "/bambootoo.lua") @@ -745,8 +769,8 @@ minetest.register_abm({ nodenames = {"mcl_bamboo:bamboo"}, interval = 40, chance = 40, - action = function(pos, node) - local soil_pos = nil + action = function(pos, _) + local soil_pos if minetest.get_node_light(pos) < 8 then return end diff --git a/mods/ITEMS/mcl_bamboo/mapgen.lua b/mods/ITEMS/mcl_bamboo/mapgen.lua deleted file mode 100644 index 8fa61ca54..000000000 --- a/mods/ITEMS/mcl_bamboo/mapgen.lua +++ /dev/null @@ -1,60 +0,0 @@ -local item_water, item_dirt, item_grass - -item_water = "mcl_core:water_source" -item_dirt = "mcl_core:dirt" -item_grass = "mcl_core:dirt_with_grass" -local function make_bamboo(pos, size) - for y = 0, size - 1 do - local p = {x = pos.x, y = pos.y + y, z = pos.z} - if minetest.get_node(p).name ~= "air" then - return - end - minetest.set_node(p, {name = "mcl_bamboo:bamboo"}) - end -end - -minetest.register_on_generated(function(minp, maxp, seed) - if maxp.y < 2 and minp.y > 0 then - return - end - - local c_grass = minetest.get_content_id(item_grass) - local n_bamboo = minetest.get_perlin(8234, 3, 0.6, 100) - - local vm = minetest.get_voxel_manip() - local emin, emax = vm:read_from_map(minp, maxp) - local area = VoxelArea:new {MinEdge = emin, MaxEdge = emax} - local data = vm:get_data() - - local rand = PseudoRandom(seed % 8000) - for z = minp.z + 2, maxp.z - 2, 4 do - for x = minp.x + 2, maxp.x - 2, 4 do - local bamboo_amount = math.floor(n_bamboo:get_2d({x = x, y = z}) * 7 - 3) - for i = 1, bamboo_amount do - local p_pos = { - x = rand:next(x - 2, x + 2), - y = 0, - z = rand:next(z - 2, z + 2) - } - - local found = false - local node = -1 - for y = 4, 0, -1 do - p_pos.y = y - node = data[area:index(p_pos.x, p_pos.y, p_pos.z)] - if node == c_grass then - found = true - break - end - end - - if found and - minetest.find_node_near(p_pos, 5, {"group:water", item_water}) then - p_pos.y = p_pos.y + 1 - make_bamboo(p_pos, rand:next(4, 12)) - end - end - end - end -end -)