diff --git a/mods/ITEMS/mcl_lush_caves/init.lua b/mods/ITEMS/mcl_lush_caves/init.lua index d74d5700e0..3e10bca0fb 100644 --- a/mods/ITEMS/mcl_lush_caves/init.lua +++ b/mods/ITEMS/mcl_lush_caves/init.lua @@ -9,6 +9,12 @@ local adjacents = { vector.new(0,0,-1), vector.new(0,-1,0) } +local plane_adjacents = { + vector.new(1,0,0), + vector.new(-1,0,0), + vector.new(0,0,1), + vector.new(0,0,-1) +} local function vector_distance_xz(a, b) return vector.distance( { x=a.x, y=0, z=a.z }, @@ -16,6 +22,35 @@ local function vector_distance_xz(a, b) ) end mcl_lush_caves = {} + +local function find_top(pos,node) + local p = pos + repeat + p = vector.offset(p,0,1,0) + until minetest.get_node(p).name ~= node.name + return p +end + +local function get_height(pos,node) + local p = pos + local i = 0 + repeat + i = i + 1 + p = vector.offset(p,0,-1,0) + until minetest.get_node(p).name ~= node.name + return i - 1 +end + +local function dripleaf_grow(pos, node) + local t = find_top(pos,node) + local h = get_height(t,node) + local target = vector.offset(t,0,1,0) + if minetest.get_node(target).name ~= "air" then return end + if h >= 5 then return end + minetest.set_node(t,node) + minetest.set_node(target,{name = "mcl_lush_caves:dripleaf_big"}) +end + function mcl_lush_caves.makelake(pos,pr) local p1 = vector.offset(pos,-5,-2,-5) local p2 = vector.offset(pos,5,1,5) @@ -24,10 +59,11 @@ function mcl_lush_caves.makelake(pos,pr) return vector_distance_xz(pos, a) < vector_distance_xz(pos, b) end) if not nn[1] then return end + local dripleaves = {} for i=1,pr:next(1,#nn) do minetest.set_node(nn[i],{name="mcl_core:water_source"}) - if pr:next(1,2) == 1 then - minetest.set_node(nn[i],{name="mcl_lush_caves:dripleaf_big_stem"}) + if pr:next(1,20) == 1 then + table.insert(dripleaves,nn[i]) end end local nnn = minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_core:water_source","group:water"}) @@ -43,6 +79,15 @@ function mcl_lush_caves.makelake(pos,pr) end end end + for _,d in pairs(dripleaves) do + if minetest.get_item_group(minetest.get_node(d).name,"water") > 0 then + minetest.set_node(vector.offset(d,0,-1,0),{name="mcl_lush_caves:dripleaf_big_waterroot"}) + minetest.registered_nodes["mcl_lush_caves:dripleaf_big_stem"].on_construct(d) + for ii = 1, pr:next(1,3) do + dripleaf_grow(d,{name = "mcl_lush_caves:dripleaf_big_stem"}) + end + end + end end function mcl_lush_caves.makeazaela(pos,pr) @@ -73,12 +118,6 @@ function mcl_lush_caves.makeazaela(pos,pr) return true end -minetest.register_chatcommand("makeazalea",{func=function(n,p) - local pl = minetest.get_player_by_name(n) - local pos = pl:get_pos() - mcl_lush_caves.makeazaela(pos) -end}) - minetest.register_node("mcl_lush_caves:lake_structblock", {drawtype="airlike",walkable = false,pointable=false,groups = {structblock=1,not_in_creative_inventory=1},}) minetest.register_node("mcl_lush_caves:azalea_structblock", {drawtype="airlike",walkable = false,pointable=false,groups = {structblock=1,not_in_creative_inventory=1},}) @@ -206,32 +245,6 @@ minetest.register_node("mcl_lush_caves:cave_vines_lit", { end, }) -local function find_top(pos,node) - local p = pos - repeat - p = vector.offset(p,0,1,0) - until minetest.get_node(p).name ~= node.name - return p -end - -local function get_height(pos,node) - local p = pos - local i = 0 - repeat - i = i + 1 - p = vector.offset(p,0,-1,0) - until minetest.get_node(p).name ~= node.name - return i - 1 -end - -local function dripleaf_grow(pos, node) - local t = find_top(pos,node) - local h = get_height(t,node) - if h >= 5 then return end - minetest.set_node(t,node) - minetest.set_node(vector.offset(t,0,1,0),{name = "mcl_lush_caves:dripleaf_big"}) -end - minetest.register_node("mcl_lush_caves:dripleaf_big_waterroot", { drawtype = "plantlike_rooted", paramtype = "light", @@ -253,7 +266,7 @@ minetest.register_node("mcl_lush_caves:dripleaf_big_waterroot", { } }, groups = { handy = 1, dig_immediate = 3, not_in_creative_inventory = 1 }, - drop = "mcl_lush_caves:dripleaf_big_stem", + drop = "", node_placement_prediction = "", _mcl_hardness = 0, _mcl_blast_resistance = 0, @@ -283,14 +296,21 @@ minetest.register_node("mcl_lush_caves:dripleaf_big_stem", { {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} }, }, - groups = { shearsy = 1, handy = 1, plant=1, supported_node=0, dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1 }, + drops = "", + groups = { shearsy = 1, handy = 1, plant=1, supported_node=0, destroy_by_lava_flow=1, dig_by_piston=1 }, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, _mcl_blast_hardness = 0, on_construct = function(pos) local p = pos local l = 0 - if minetest.get_item_group(minetest.get_node(pos).name,"water") <= 0 then return end + local in_water = false + for _,a in pairs(plane_adjacents) do + if minetest.get_item_group(minetest.get_node(vector.add(pos,a)).name,"water") > 0 then + in_water = true + end + end + if not in_water then return end repeat l = l + 1 p = vector.offset(p,0,1,0) @@ -334,6 +354,11 @@ local dripleaf = { sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, _mcl_blast_hardness = 0, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if itemstack:get_name() ~= "mcl_dye:white" then return itemstack end + itemstack:take_item(1) + dripleaf_grow(vector.offset(pos,0,-1,0),{name = "mcl_lush_caves:dripleaf_big_stem" }) + end } local dripleaf_tipped = table.copy(dripleaf) dripleaf_tipped.walkable = false