diff --git a/black_cap.lua b/black_cap.lua index 731e2cf..fe7ecdd 100644 --- a/black_cap.lua +++ b/black_cap.lua @@ -72,15 +72,15 @@ minetest.register_node("dfcaverns:black_cap_sapling", { end, }) +local c_stem = minetest.get_content_id("dfcaverns:black_cap_stem") +local c_cap = minetest.get_content_id("dfcaverns:black_cap") +local c_gills = minetest.get_content_id("dfcaverns:black_cap_gills") + dfcaverns.spawn_black_cap = function(pos) local x, y, z = pos.x, pos.y, pos.z local stem_height = math.random(1,5) local cap_radius = math.random(2,3) local maxy = y + stem_height + 3 - - local c_stem = minetest.get_content_id("dfcaverns:black_cap_stem") - local c_cap = minetest.get_content_id("dfcaverns:black_cap") - local c_gills = minetest.get_content_id("dfcaverns:black_cap_gills") local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( @@ -95,4 +95,12 @@ dfcaverns.spawn_black_cap = function(pos) vm:set_data(data) vm:write_to_map() vm:update_map() -end \ No newline at end of file +end + +dfcaverns.spawn_black_cap_vm = function(vi, area, data) + local stem_height = math.random(1,5) + local cap_radius = math.random(2,3) + + subterrane:giant_shroom(vi, area, data, c_stem, c_cap, c_gills, stem_height, cap_radius) +end + diff --git a/fungiwood.lua b/fungiwood.lua index 73144f3..b5acf4f 100644 --- a/fungiwood.lua +++ b/fungiwood.lua @@ -77,29 +77,45 @@ minetest.register_node("dfcaverns:fungiwood_sapling", { end, }) +local c_air = minetest.get_content_id("air") +local c_ignore = minetest.get_content_id("ignore") +local c_fungiwood = minetest.get_content_id("dfcaverns:fungiwood") +local c_fungiwood_shelf = minetest.get_content_id("dfcaverns:fungiwood_shelf") + function dfcaverns.spawn_fungiwood(pos) local x, y, z = pos.x, pos.y, pos.z - local maxy = y + math.random(6, 10) -- Trunk top - - local c_air = minetest.get_content_id("air") - local c_ignore = minetest.get_content_id("ignore") - local c_fungiwood = minetest.get_content_id("dfcaverns:fungiwood") - local c_fungiwood_shelf = minetest.get_content_id("dfcaverns:fungiwood_shelf") + local height = math.random(6, 10) + local maxy = y + height -- Trunk top local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( {x = x - 3, y = y, z = z - 3}, {x = x + 3, y = maxy + 3, z = z + 3} ) - local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) + local area = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) local data = vm:get_data() + dfcaverns.spawn_fungiwood_vm(area:indexp(pos), area, data, height) + + vm:set_data(data) + vm:write_to_map() + vm:update_map() +end + +dfcaverns.spawn_fungiwood_vm = function(vi, area, data, height) + if height == nil then height = math.random(6, 10) end + local pos = area:position(vi) + local x = pos.x + local y = pos.y + local z = pos.z + local maxy = y + height -- Trunk top + -- Upper branches layer local dev = 3 for yy = maxy - 2, maxy do for zz = z - dev, z + dev do - local vi = a:index(x - dev, yy, zz) - local via = a:index(x - dev, yy + 1, zz) + local vi = area:index(x - dev, yy, zz) + local via = area:index(x - dev, yy + 1, zz) for xx = x - dev, x + dev do if math.random() < 0.95 - dev * 0.05 then local node_id = data[vi] @@ -124,8 +140,8 @@ function dfcaverns.spawn_fungiwood(pos) my = yy end for zz = zi, zi+1 do - local vi = a:index(xi, yy, zz) - local via = a:index(xi, yy + 1, zz) + local vi = area:index(xi, yy, zz) + local via = area:index(xi, yy + 1, zz) for xx = xi, xi + 1 do local node_id = data[vi] if node_id == c_air or node_id == c_ignore then @@ -140,8 +156,8 @@ function dfcaverns.spawn_fungiwood(pos) dev = 2 for yy = my + 1, my + 2 do for zz = z - dev, z + dev do - local vi = a:index(x - dev, yy, zz) - local via = a:index(x - dev, yy + 1, zz) + local vi = area:index(x - dev, yy, zz) + local via = area:index(x - dev, yy + 1, zz) for xx = x - dev, x + dev do if math.random() < 0.95 - dev * 0.05 then local node_id = data[vi] @@ -158,16 +174,11 @@ function dfcaverns.spawn_fungiwood(pos) -- Trunk for yy = y, maxy do - local vi = a:index(x, yy, z) + local vi = area:index(x, yy, z) local node_id = data[vi] if node_id == c_air or node_id == c_ignore or node_id == c_fungiwood_shelf then data[vi] = c_fungiwood end end - - vm:set_data(data) - vm:write_to_map() - vm:update_map() end - diff --git a/goblin_cap.lua b/goblin_cap.lua index 1c30522..46aa811 100644 --- a/goblin_cap.lua +++ b/goblin_cap.lua @@ -72,16 +72,16 @@ minetest.register_node("dfcaverns:goblin_cap_sapling", { end, }) +local c_stem = minetest.get_content_id("dfcaverns:goblin_cap_stem") +local c_cap = minetest.get_content_id("dfcaverns:goblin_cap") +local c_gills = minetest.get_content_id("dfcaverns:goblin_cap_gills") + dfcaverns.spawn_goblin_cap = function(pos) local x, y, z = pos.x, pos.y, pos.z local stem_height = math.random(1,3) local cap_radius = math.random(3,6) local maxy = y + stem_height + 3 - local c_stem = minetest.get_content_id("dfcaverns:goblin_cap_stem") - local c_cap = minetest.get_content_id("dfcaverns:goblin_cap") - local c_gills = minetest.get_content_id("dfcaverns:goblin_cap_gills") - local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( {x = x - cap_radius, y = y, z = z - cap_radius}, @@ -95,4 +95,10 @@ dfcaverns.spawn_goblin_cap = function(pos) vm:set_data(data) vm:write_to_map() vm:update_map() +end + +dfcaverns.spawn_goblin_cap_vm = function(vi, area, data) + local stem_height = math.random(1,3) + local cap_radius = math.random(3,6) + subterrane:giant_shroom(vi, area, data, c_stem, c_cap, c_gills, stem_height, cap_radius) end \ No newline at end of file diff --git a/nether_cap.lua b/nether_cap.lua index 06abc31..663ec3c 100644 --- a/nether_cap.lua +++ b/nether_cap.lua @@ -72,16 +72,16 @@ minetest.register_node("dfcaverns:nether_cap_sapling", { end, }) +local c_stem = minetest.get_content_id("dfcaverns:nether_cap_stem") +local c_cap = minetest.get_content_id("dfcaverns:nether_cap") +local c_gills = minetest.get_content_id("dfcaverns:nether_cap_gills") + dfcaverns.spawn_nether_cap = function(pos) local x, y, z = pos.x, pos.y, pos.z local stem_height = math.random(1,3) local cap_radius = math.random(2,3) local maxy = y + stem_height + 3 - local c_stem = minetest.get_content_id("dfcaverns:nether_cap_stem") - local c_cap = minetest.get_content_id("dfcaverns:nether_cap") - local c_gills = minetest.get_content_id("dfcaverns:nether_cap_gills") - local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( {x = x - cap_radius, y = y, z = z - cap_radius}, @@ -97,6 +97,12 @@ dfcaverns.spawn_nether_cap = function(pos) vm:update_map() end +dfcaverns.spawn_nether_cap_vm = function(vi, area, data) + local stem_height = math.random(1,3) + local cap_radius = math.random(2,3) + subterrane:giant_shroom(vi, area, data, c_stem, c_cap, c_gills, stem_height, cap_radius) +end + minetest.register_abm{ label = "nether cap water freezing", nodenames = {"default:water_source", "default:river_water_source",}, diff --git a/spore_tree.lua b/spore_tree.lua index f4d69bf..5550d82 100644 --- a/spore_tree.lua +++ b/spore_tree.lua @@ -114,29 +114,111 @@ minetest.register_node("dfcaverns:spore_tree_sapling", { on_timer = function(pos) minetest.set_node(pos, {name="air"}) - minetest.spawn_tree(pos, dfcaverns.spore_tree_def) + dfcaverns.spawn_spore_tree(pos) end, }) -dfcaverns.spore_tree_def={ - axiom="TTdddA", - rules_a="[&&&Tdd&&FF][&&&++++Tdd&&FF][&&&----Tdd&&FF]", - rules_d="T", - trunk="dfcaverns:spore_tree", - leaves="dfcaverns:spore_tree_frond", - leaves2="dfcaverns:spore_tree_pod", - leaves2_chance=30, - angle=30, - iterations=2, - random_level=0, - trunk_type="single", - thin_branches=true, -} +--fcaverns.spore_tree_def={ +-- axiom="TTdddA", +-- rules_a="[&&&Tdd&&FF][&&&++++Tdd&&FF][&&&----Tdd&&FF]", +-- rules_d="T", +-- trunk="dfcaverns:spore_tree", +-- leaves="dfcaverns:spore_tree_frond", +-- leaves2="dfcaverns:spore_tree_pod", +-- leaves2_chance=30, +-- angle=30, +-- iterations=2, +-- random_level=0, +-- trunk_type="single", +-- thin_branches=true, +--} + +dfcaverns.spawn_spore_tree_vm = function(vi, data, area, height, size, iters, has_fruiting_bodies) + if height == nil then height = math.random(3,6) end + if size == nil then size = 2 end + if iters == nil then iters = 10 end + if has_fruiting_bodies == nil then has_fruiting_bodies = math.random() < 0.5 end + + local pos = area:position(vi) + local x, y, z = pos.x, pos.y, pos.z + local c_air = minetest.get_content_id("air") + local c_ignore = minetest.get_content_id("ignore") + local c_spore_pod = minetest.get_content_id("dfcaverns:spore_tree_pod") + local c_tree = minetest.get_content_id("dfcaverns:spore_tree") + local c_spore_frond = minetest.get_content_id("dfcaverns:spore_tree_frond") + + local has_fruiting_bodies = true + + -- Trunk + data[area:index(x, y, z)] = c_tree -- Force-place lowest trunk node to replace sapling + for yy = y + 1, y + height - 1 do + local vi = area:index(x, yy, z) + local node_id = data[vi] + if node_id == c_air or node_id == c_ignore or node_id == c_spore_frond then + data[vi] = c_tree + end + end + + -- Force leaves near the trunk + for z_dist = -1, 1 do + for y_dist = -size, 1 do + local vi = area:index(x - 1, y + height + y_dist, z + z_dist) + for x_dist = -1, 1 do + if data[vi] == c_air or data[vi] == c_ignore then + if has_fruiting_bodies and math.random() < 0.3 then + data[vi] = c_spore_pod + else + data[vi] = c_spore_frond + end + end + vi = vi + 1 + end + end + end + + -- Randomly add fronds in 2x2x2 clusters. + for i = 1, iters do + local clust_x = x + math.random(-size, size - 1) + local clust_y = y + height + math.random(-size, 0) + local clust_z = z + math.random(-size, size - 1) + + for xi = 0, 1 do + for yi = 0, 1 do + for zi = 0, 1 do + local vi = area:index(clust_x + xi, clust_y + yi, clust_z + zi) + if data[vi] == c_air or data[vi] == c_ignore then + if has_fruiting_bodies and math.random() < 0.3 then + data[vi] = c_spore_pod + else + data[vi] = c_spore_frond + end + end + end + end + end + end +end dfcaverns.spawn_spore_tree = function(pos) - minetest.spawn_tree(pos, dfcaverns.spore_tree_def) + local x, y, z = pos.x, pos.y, pos.z + local height = math.random(4, 5) + + local vm = minetest.get_voxel_manip() + local minp, maxp = vm:read_from_map( + {x = x - 2, y = y, z = z - 2}, + {x = x + 2, y = y + height + 1, z = z + 2} + ) + local area = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) + local data = vm:get_data() + + dfcaverns.spawn_spore_tree_vm(area:indexp(pos), data, area) + + vm:set_data(data) + vm:write_to_map() + vm:update_map() end + minetest.register_abm{ label = "spore tree raining spores", nodenames = {"dfcaverns:spore_tree_pod"}, diff --git a/tower_cap.lua b/tower_cap.lua index 2ac228b..bb2eef4 100644 --- a/tower_cap.lua +++ b/tower_cap.lua @@ -72,16 +72,16 @@ minetest.register_node("dfcaverns:tower_cap_sapling", { end, }) +local c_stem = minetest.get_content_id("dfcaverns:tower_cap_stem") +local c_cap = minetest.get_content_id("dfcaverns:tower_cap") +local c_gills = minetest.get_content_id("dfcaverns:tower_cap_gills") + dfcaverns.spawn_tower_cap = function(pos) local x, y, z = pos.x, pos.y, pos.z local stem_height = math.random(4,10) local cap_radius = math.random(4,6) local maxy = y + stem_height + 3 - local c_stem = minetest.get_content_id("dfcaverns:tower_cap_stem") - local c_cap = minetest.get_content_id("dfcaverns:tower_cap") - local c_gills = minetest.get_content_id("dfcaverns:tower_cap_gills") - local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( {x = x - cap_radius, y = y, z = z - cap_radius}, @@ -95,4 +95,10 @@ dfcaverns.spawn_tower_cap = function(pos) vm:set_data(data) vm:write_to_map() vm:update_map() +end + +dfcaverns.spawn_tower_cap_vm = function(vi, area, data) + local stem_height = math.random(4,10) + local cap_radius = math.random(4,6) + subterrane:giant_shroom(vi, area, data, c_stem, c_cap, c_gills, stem_height, cap_radius) end \ No newline at end of file