dfcaverns/features/snareweed.lua

49 lines
1.7 KiB
Lua
Raw Normal View History

-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
minetest.register_node("dfcaverns:snareweed", {
description = S("Snareweed"),
_doc_items_longdesc = dfcaverns.doc.snareweed_desc,
_doc_items_usagehelp = dfcaverns.doc.snareweed_usage,
tiles = {"default_dirt.png^dfcaverns_snareweed_roots.png", "default_dirt.png"},
drawtype="plantlike_rooted",
-- paramtype = "light",
paramtype2 = "leveled",
special_tiles = {{name = "dfcaverns_snareweed.png", tileable_vertical = true}},
is_ground_content = true,
drop = 'default:dirt',
light_source = 6,
groups = {crumbly = 3, soil = 1},
sounds = default.node_sound_dirt_defaults(),
})
local c_water = minetest.get_content_id("default:water_source")
local c_dirt = minetest.get_content_id("default:dirt")
local c_snareweed = minetest.get_content_id("dfcaverns:snareweed")
dfcaverns.place_snareweed = function(area, data, bi, param2_data)
local max_height = 0
local index = bi + area.ystride
while area:containsi(index) and data[index] == c_water and max_height <= 8*16 do
index = index + area.ystride
max_height = max_height + 16
end
if max_height > 0 then
data[bi] = c_snareweed
param2_data[bi] = math.min(math.random(3*16, 8*16), max_height)
else
data[bi] = c_dirt
end
end
dfcaverns.place_snareweed_patch = function(area, data, bi, param2_data, radius)
local pos = area:position(bi)
for li in area:iterp(vector.add(pos, -radius), vector.add(pos, radius)) do
local adjacent = li + area.ystride
local node_type = data[li]
if math.random() < 0.1 and (node_type == c_stone or node_type == c_dirt) and data[adjacent] == c_water then
dfcaverns.place_snareweed(area, data, li, param2_data)
end
end
end