Add dripleaf functionality

This commit is contained in:
cora 2022-06-08 03:03:03 +02:00
parent 4aa9bdce68
commit db52b4a918
4 changed files with 206 additions and 8 deletions

View File

@ -26,6 +26,9 @@ function mcl_lush_caves.makelake(pos,pr)
if not nn[1] then return end if not nn[1] then return end
for i=1,pr:next(1,#nn) do for i=1,pr:next(1,#nn) do
minetest.set_node(nn[i],{name="mcl_core:water_source"}) 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"})
end
end end
local nnn = minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_core:water_source","group:water"}) local nnn = minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_core:water_source","group:water"})
for k,v in pairs(nnn) do for k,v in pairs(nnn) do
@ -202,6 +205,65 @@ minetest.register_node("mcl_lush_caves:cave_vines_lit", {
minetest.set_node(pos,{name="mcl_lush_caves:cave_vines"}) minetest.set_node(pos,{name="mcl_lush_caves:cave_vines"})
end, 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",
paramtype2 = "leveled",
place_param2 = 16,
tiles = { "default_clay.png" },
special_tiles = {
{ name = "mcl_lush_caves_big_dripleaf_stem.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0},
tileable_vertical = true,
}
},
inventory_image = "mcl_lush_caves_big_dripleaf_stem.png",
selection_box = {
type = "fixed",
fixed = {
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
{ -0.5, 0.5, -0.5, 0.5, 1.0, 0.5 },
}
},
groups = { handy = 1, dig_immediate = 3, not_in_creative_inventory = 1 },
drop = "mcl_lush_caves:dripleaf_big_stem",
node_placement_prediction = "",
_mcl_hardness = 0,
_mcl_blast_resistance = 0,
_mcl_silk_touch_drop = true,
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(pos,node)
end
})
minetest.register_node("mcl_lush_caves:dripleaf_big_stem", { minetest.register_node("mcl_lush_caves:dripleaf_big_stem", {
description = S("Dripleaf stem"), description = S("Dripleaf stem"),
_doc_items_create_entry = S("Dripleaf stem"), _doc_items_create_entry = S("Dripleaf stem"),
@ -225,15 +287,30 @@ minetest.register_node("mcl_lush_caves:dripleaf_big_stem", {
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_blast_hardness = 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
repeat
l = l + 1
p = vector.offset(p,0,1,0)
until minetest.get_item_group(minetest.get_node(p).name,"water") <= 0
minetest.set_node(p,{name = "mcl_lush_caves:dripleaf_big"})
minetest.set_node(vector.offset(pos,0,-1,0),{ name = "mcl_lush_caves:dripleaf_big_waterroot", param2 = l * 16})
end,
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(pos,node)
end
}) })
local dripleaf = {
minetest.register_node("mcl_lush_caves:dripleaf_big", {
description = S("Dripleaf"), description = S("Dripleaf"),
_doc_items_create_entry = S("Dripleaf"), _doc_items_create_entry = S("Dripleaf"),
_doc_items_entry_name = S("Dripleaf"), _doc_items_entry_name = S("Dripleaf"),
_doc_items_longdesc = S("Dripleaf"), _doc_items_longdesc = S("Dripleaf"),
paramtype = "light", paramtype = "light",
place_param2 = 3, place_param2 = 0,
sunlight_propagates = true, sunlight_propagates = true,
walkable = true, walkable = true,
drawtype = "nodebox", drawtype = "nodebox",
@ -257,8 +334,29 @@ minetest.register_node("mcl_lush_caves:dripleaf_big", {
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_blast_hardness = 0, _mcl_blast_hardness = 0,
--drop = "mcl_lush_caves:glow_berry", }
}) local dripleaf_tipped = table.copy(dripleaf)
dripleaf_tipped.walkable = false
dripleaf_tipped.tiles = {"mcl_lush_caves_big_dripleaf_tip.png"}
dripleaf_tipped.on_timer = function(p,e)
minetest.swap_node(p,{name="mcl_lush_caves:dripleaf_big"})
end
dripleaf.mesecons = {effector = {
action_on = function(pos, node)
node.param2 = 1
minetest.swap_node(pos, node)
end,
action_off = function(pos, node)
node.param2 = 0
minetest.swap_node(pos, node)
end,
rules = mesecon.rules.alldirs,
}}
minetest.register_node("mcl_lush_caves:dripleaf_big",dripleaf)
minetest.register_node("mcl_lush_caves:dripleaf_big_tipped",dripleaf_tipped)
minetest.register_node("mcl_lush_caves:dripleaf_small_stem", { minetest.register_node("mcl_lush_caves:dripleaf_small_stem", {
description = S("Small dripleaf stem"), description = S("Small dripleaf stem"),
@ -406,6 +504,87 @@ minetest.register_node("mcl_lush_caves:azalea_leaves_flowering", {
--_mcl_fortune_drop = { get_drops(1), get_drops(2), get_drops(3), get_drops(4) }, --_mcl_fortune_drop = { get_drops(1), get_drops(2), get_drops(3), get_drops(4) },
}) })
minetest.register_node("mcl_lush_caves:azalea", {
description = S("Azalea"),
inventory_image = "mcl_lush_caves_azalea_plant.png",
drawtype = "allfaces_optional",
-- drawtype = "nodebox",
-- node_box = {
-- type = "fixed",
-- fixed = {
-- { -16/16, -0/16, -16/16, 16/16, 16/16, 16/16 },
-- { -2/16, -16/16, -2/16, 2/16, 0/16, 2/16 },
-- }
-- },
--tiles = { "blank.png" },
tiles = {
"mcl_lush_caves_azalea_top.png",
"mcl_lush_caves_azalea_top.png",
"mcl_lush_caves_azalea_side.png",
"mcl_lush_caves_azalea_side.png",
"mcl_lush_caves_azalea_side.png",
"mcl_lush_caves_azalea_side.png",
},
is_ground_content = false,
groups = { handy=1 },
sounds = mcl_sounds.node_sound_dirt_defaults(),
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
use_texture_alpha = "clip",
})
minetest.register_node("mcl_lush_caves:azalea_flowering", {
description = S("Flowering azalea"),
inventory_image = "mcl_lush_caves_azalea_flowering_top.png",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -16/16, -4/16, -16/16, 16/16, 16/16, 16/16 },
{ -2/16, -16/16, -2/16, 2/16, -4/16, 2/16 },
}
},
--tiles = { "blank.png" },
tiles = {
"mcl_lush_caves_azalea_flowering_top.png",
"mcl_lush_caves_azalea_flowering_top.png",
"mcl_lush_caves_azalea_flowering_side.png",
"mcl_lush_caves_azalea_flowering_side.png",
"mcl_lush_caves_azalea_flowering_side.png",
"mcl_lush_caves_azalea_flowering_side.png",
},
is_ground_content = false,
groups = { handy=1 },
sounds = mcl_sounds.node_sound_dirt_defaults(),
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
use_texture_alpha = "clip",
})
--]]
minetest.register_node("mcl_lush_caves:azalea_leaves_flowering", {
description = description,
_doc_items_longdesc = longdesc,
_doc_items_hidden = false,
drawtype = "allfaces_optional",
waving = 2,
place_param2 = 1, -- Prevent leafdecay for placed nodes
tiles = { "mcl_lush_caves_azalea_leaves_flowering.png" },
paramtype = "light",
stack_max = 64,
groups = {
handy = 1, hoey = 1, shearsy = 1, swordy = 1, dig_by_piston = 1,
leaves = 1, leafdecay = leafdecay_distance, deco_block = 1,
flammable = 2, fire_encouragement = 30, fire_flammability = 60,
compostability = 30
},
_mcl_shears_drop = true,
sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0.2,
_mcl_hardness = 0.2,
_mcl_silk_touch_drop = true,
})
minetest.register_abm({ minetest.register_abm({
@ -427,9 +606,27 @@ minetest.register_abm({
node.name="mcl_lush_caves:cave_vines_lit" node.name="mcl_lush_caves:cave_vines_lit"
end end
if minetest.get_node(pd).name == "air" and pd2 == "air" then if minetest.get_node(pd).name == "air" and pd2 == "air" then
minetest.set_node(pd,node) minetest.swap_node(pd,node)
else else
minetest.set_node(pos,{name="mcl_lush_caves:cave_vines_lit"}) minetest.swap_node(pos,{name="mcl_lush_caves:cave_vines_lit"})
end end
end end
}) })
local player_dripleaf = {}
minetest.register_globalstep(function(dtime)
for _,p in pairs(minetest.get_connected_players()) do
local pos = p:get_pos()
local n = minetest.get_node(pos)
if n.name == "mcl_lush_caves:dripleaf_big" and n.param2 == 0 then
if not player_dripleaf[p] then player_dripleaf[p] = 0 end
player_dripleaf[p] = player_dripleaf[p] + dtime
if player_dripleaf[p] > 1 then
minetest.swap_node(pos,{name = "mcl_lush_caves:dripleaf_big_tipped"})
player_dripleaf[p] = nil
local t = minetest.get_node_timer(pos)
t:start(3)
end
end
end
end)

View File

@ -1,2 +1,3 @@
name = mcl_lush_caves name = mcl_lush_caves
depends = mcl_sounds author = cora
depends = mcl_sounds, mesecons

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB