2018-09-08 23:25:25 +02:00
|
|
|
--[[ MFF: Prevent trees from destroying existing blocks
|
|
|
|
This is the list of "safe" blocks in which a tree can grow
|
|
|
|
They were moved outside the local safety function for speed (I hope)
|
|
|
|
--]]
|
|
|
|
local c_air = minetest.get_content_id("air")
|
|
|
|
local c_ignore = minetest.get_content_id("ignore")
|
|
|
|
|
|
|
|
-- MFF: The local function to do safety checks
|
|
|
|
local function safely_set_block(t, k, v)
|
|
|
|
if t[k] == c_air or t[k] == c_ignore then
|
|
|
|
t[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-19 02:16:19 +01:00
|
|
|
function watershed_appletree(x, y, z, area, data)
|
|
|
|
local c_tree = minetest.get_content_id("default:tree")
|
|
|
|
local c_apple = minetest.get_content_id("default:apple")
|
2014-03-31 06:16:20 +02:00
|
|
|
local c_wsappleaf = minetest.get_content_id("watershed:appleleaf")
|
2018-09-08 23:25:25 +02:00
|
|
|
|
|
|
|
-- MFF: Higher default tree with a bit of randomness
|
|
|
|
local tree_top = 5 + math.random(0, 1)
|
|
|
|
local leaves_height = tree_top - 1
|
|
|
|
local branches_height = leaves_height - 1
|
|
|
|
|
|
|
|
for j = 0, tree_top do -- MFF: Higher tree, same design
|
|
|
|
if j >= leaves_height then
|
2014-02-19 02:16:19 +01:00
|
|
|
for i = -2, 2 do
|
|
|
|
for k = -2, 2 do
|
2014-04-15 09:03:32 +02:00
|
|
|
local vil = area:index(x + i, y + j, z + k)
|
|
|
|
if math.random(64) == 2 then
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
safely_set_block(data, vil, c_apple)
|
2014-03-31 06:16:20 +02:00
|
|
|
elseif math.random(5) ~= 2 then
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
safely_set_block(data, vil, c_wsappleaf)
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-09-08 23:25:25 +02:00
|
|
|
elseif j == branches_height then
|
2014-04-02 03:44:33 +02:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
2014-04-15 09:03:32 +02:00
|
|
|
if math.abs(i) + math.abs(k) == 2 then
|
|
|
|
local vit = area:index(x + i, y + j, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
safely_set_block(data, vit, c_tree)
|
2014-04-02 03:44:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-15 09:03:32 +02:00
|
|
|
else
|
|
|
|
local vit = area:index(x, y + j, z)
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
if j == 0 then
|
|
|
|
-- MFF: the position of the sapling itself, replace it without checking.
|
|
|
|
data[vit] = c_tree
|
|
|
|
else
|
|
|
|
safely_set_block(data, vit, c_tree)
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_pinetree(x, y, z, area, data)
|
2014-04-14 07:01:05 +02:00
|
|
|
local c_wspitree = minetest.get_content_id("watershed:pinetree")
|
2014-02-19 02:16:19 +01:00
|
|
|
local c_wsneedles = minetest.get_content_id("watershed:needles")
|
|
|
|
local c_snowblock = minetest.get_content_id("default:snowblock")
|
2018-09-08 23:25:25 +02:00
|
|
|
for j = 0, 14 do
|
2014-02-19 02:16:19 +01:00
|
|
|
if j == 3 or j == 6 or j == 9 or j == 12 then
|
|
|
|
for i = -2, 2 do
|
|
|
|
for k = -2, 2 do
|
|
|
|
if math.abs(i) == 2 or math.abs(k) == 2 then
|
2014-04-01 05:28:21 +02:00
|
|
|
if math.random(7) ~= 2 then
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
2014-02-19 02:16:19 +01:00
|
|
|
local vil = area:index(x + i, y + j, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vil, c_wsneedles)
|
2014-02-19 02:16:19 +01:00
|
|
|
local vila = area:index(x + i, y + j + 1, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vila, c_snowblock)
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-30 08:34:18 +02:00
|
|
|
elseif j == 4 or j == 7 or j == 10 then
|
2014-02-19 02:16:19 +01:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if not (i == 0 and j == 0) then
|
2014-04-01 05:28:21 +02:00
|
|
|
if math.random(11) ~= 2 then
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
2014-02-19 02:16:19 +01:00
|
|
|
local vil = area:index(x + i, y + j, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vil, c_wsneedles)
|
2014-02-19 02:16:19 +01:00
|
|
|
local vila = area:index(x + i, y + j + 1, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vila, c_snowblock)
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-30 08:34:18 +02:00
|
|
|
elseif j == 13 then
|
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if not (i == 0 and j == 0) then
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
2014-04-01 05:28:21 +02:00
|
|
|
local vil = area:index(x + i, y + j, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vil,c_wsneedles)
|
2014-04-01 05:28:21 +02:00
|
|
|
local vila = area:index(x + i, y + j + 1, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vila, c_wsneedles)
|
2014-04-01 05:28:21 +02:00
|
|
|
local vilaa = area:index(x + i, y + j + 2, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
safely_set_block(data, vilaa, c_snowblock)
|
2014-03-30 08:34:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
2014-02-19 02:16:19 +01:00
|
|
|
local vit = area:index(x, y + j, z)
|
2018-09-08 23:25:25 +02:00
|
|
|
if j == 0 then
|
|
|
|
data[vit] = c_wspitree -- No safety check for the sapling itself
|
|
|
|
else
|
|
|
|
safely_set_block(data, vit, c_wspitree)
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
2014-03-30 08:34:18 +02:00
|
|
|
local vil = area:index(x, y + 15, z)
|
|
|
|
local vila = area:index(x, y + 16, z)
|
|
|
|
local vilaa = area:index(x, y + 17, z)
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
safely_set_block(data, vil, c_wsneedles)
|
|
|
|
safely_set_block(data, vila, c_wsneedles)
|
|
|
|
safely_set_block(data, vilaa, c_snowblock)
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_jungletree(x, y, z, area, data)
|
|
|
|
local c_juntree = minetest.get_content_id("default:jungletree")
|
|
|
|
local c_wsjunleaf = minetest.get_content_id("watershed:jungleleaf")
|
2014-03-24 03:38:56 +01:00
|
|
|
local top = math.random(17,23)
|
|
|
|
local branch = math.floor(top * 0.6)
|
2018-09-08 23:25:25 +02:00
|
|
|
for j = 0, top do
|
2014-03-24 03:38:56 +01:00
|
|
|
if j == top or j == top - 1 or j == branch + 1 or j == branch + 2 then
|
|
|
|
for i = -2, 2 do -- leaves
|
2014-02-19 02:16:19 +01:00
|
|
|
for k = -2, 2 do
|
2014-03-24 03:38:56 +01:00
|
|
|
local vi = area:index(x + i, y + j, z + k)
|
2014-02-19 02:16:19 +01:00
|
|
|
if math.random(5) ~= 2 then
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
safely_set_block(data, vi, c_wsjunleaf)
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-11 06:57:49 +02:00
|
|
|
elseif j == top - 2 or j == branch then -- branches
|
2014-03-24 03:38:56 +01:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if math.abs(i) + math.abs(k) == 2 then
|
|
|
|
local vi = area:index(x + i, y + j, z + k)
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
safely_set_block(data, vi, c_juntree)
|
2014-03-22 07:40:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
2014-04-11 06:57:49 +02:00
|
|
|
if j <= top - 3 then -- trunk
|
2014-03-24 03:38:56 +01:00
|
|
|
local vi = area:index(x, y + j, z)
|
2018-09-08 23:25:25 +02:00
|
|
|
-- MFF: Prevent trees from destroying existing blocks
|
|
|
|
if j == 0 then
|
|
|
|
data[vi] = c_juntree -- No safety check for the sapling itself
|
|
|
|
else
|
|
|
|
safely_set_block(data, vi, c_juntree)
|
|
|
|
end
|
2014-03-24 03:38:56 +01:00
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-20 13:24:02 +01:00
|
|
|
function watershed_acaciatree(x, y, z, area, data)
|
2018-09-08 23:25:25 +02:00
|
|
|
local c_sapling = minetest.get_content_id("moretrees:acacia_sapling_ongen")
|
|
|
|
local vi = area:index(x, y, z)
|
|
|
|
data[vi] = c_sapling
|
2014-02-20 08:18:40 +01:00
|
|
|
end
|
|
|
|
|
2014-03-22 07:40:39 +01:00
|
|
|
function watershed_flower(data, vi, noise)
|
2014-02-19 02:16:19 +01:00
|
|
|
local c_danwhi = minetest.get_content_id("flowers:dandelion_white")
|
|
|
|
local c_danyel = minetest.get_content_id("flowers:dandelion_yellow")
|
|
|
|
local c_rose = minetest.get_content_id("flowers:rose")
|
|
|
|
local c_tulip = minetest.get_content_id("flowers:tulip")
|
|
|
|
local c_geranium = minetest.get_content_id("flowers:geranium")
|
|
|
|
local c_viola = minetest.get_content_id("flowers:viola")
|
2014-03-22 07:40:39 +01:00
|
|
|
if noise > 0.8 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_danwhi
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > 0.4 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_rose
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > 0 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_tulip
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > -0.4 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_danyel
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > -0.8 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_geranium
|
|
|
|
else
|
|
|
|
data[vi] = c_viola
|
|
|
|
end
|
2014-02-20 08:18:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_cactus(x, y, z, area, data)
|
|
|
|
local c_wscactus = minetest.get_content_id("watershed:cactus")
|
2018-09-08 23:25:25 +02:00
|
|
|
for j = 0, 4 do
|
2014-02-20 08:18:40 +01:00
|
|
|
for i = -2, 2 do
|
|
|
|
if i == 0 or j == 2 or (j == 3 and math.abs(i) == 2) then
|
|
|
|
local vic = area:index(x + i, y + j, z)
|
|
|
|
data[vic] = c_wscactus
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_papyrus(x, y, z, area, data)
|
|
|
|
local c_papyrus = minetest.get_content_id("default:papyrus")
|
|
|
|
local ph = math.random(1, 4)
|
2014-04-13 11:03:51 +02:00
|
|
|
for j = 0, ph do
|
2014-02-20 08:18:40 +01:00
|
|
|
local vip = area:index(x, y + j, z)
|
|
|
|
data[vip] = c_papyrus
|
|
|
|
end
|
2014-03-30 08:34:18 +02:00
|
|
|
end
|
|
|
|
|
2014-04-09 07:06:10 +02:00
|
|
|
-- Singlenode option
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2014-04-10 06:27:59 +02:00
|
|
|
local SINGLENODE = true
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2014-04-10 06:27:59 +02:00
|
|
|
if SINGLENODE then
|
2014-04-01 11:12:30 +02:00
|
|
|
-- Set mapgen parameters
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2018-09-08 23:25:25 +02:00
|
|
|
minetest.set_mapgen_params({mgname="singlenode", flags="nolight"})
|
2014-04-01 11:12:30 +02:00
|
|
|
|
2018-09-08 23:25:25 +02:00
|
|
|
-- Spawn player function is useless in minetestforfun
|
2014-04-10 06:27:59 +02:00
|
|
|
end
|
|
|
|
|
2014-06-10 02:26:45 +02:00
|
|
|
-- Appletree sapling
|
|
|
|
|
2018-09-08 23:25:25 +02:00
|
|
|
function default.grow_tree(pos)
|
2014-06-10 02:26:45 +02:00
|
|
|
local x = pos.x
|
|
|
|
local y = pos.y
|
|
|
|
local z = pos.z
|
|
|
|
local vm = minetest.get_voxel_manip()
|
2018-09-08 23:25:25 +02:00
|
|
|
local pos1 = {x = x - 2, y = y - 2, z = z - 2}
|
|
|
|
local pos2 = {x = x + 2, y = y + 4, z = z + 2}
|
2014-06-10 02:26:45 +02:00
|
|
|
local emin, emax = vm:read_from_map(pos1, pos2)
|
2018-09-08 23:25:25 +02:00
|
|
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
2014-06-10 02:26:45 +02:00
|
|
|
local data = vm:get_data()
|
|
|
|
watershed_appletree(x, y, z, area, data)
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map()
|
|
|
|
vm:update_map()
|
2018-09-08 23:25:25 +02:00
|
|
|
end
|
2014-06-10 02:26:45 +02:00
|
|
|
|
|
|
|
-- Pine sapling
|
|
|
|
|
2018-09-08 23:25:25 +02:00
|
|
|
function default.grow_pine_tree(pos)
|
2014-06-10 02:26:45 +02:00
|
|
|
local x = pos.x
|
|
|
|
local y = pos.y
|
|
|
|
local z = pos.z
|
|
|
|
local vm = minetest.get_voxel_manip()
|
2018-09-08 23:25:25 +02:00
|
|
|
local pos1 = {x = x - 2, y = y - 4, z = z - 2}
|
|
|
|
local pos2 = {x = x + 2, y = y + 17, z = z + 2}
|
2014-06-10 02:26:45 +02:00
|
|
|
local emin, emax = vm:read_from_map(pos1, pos2)
|
|
|
|
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
|
|
|
local data = vm:get_data()
|
|
|
|
watershed_pinetree(x, y, z, area, data)
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map()
|
|
|
|
vm:update_map()
|
2018-09-08 23:25:25 +02:00
|
|
|
end
|
2014-06-10 02:26:45 +02:00
|
|
|
|
2018-09-08 23:25:25 +02:00
|
|
|
-- Acacia sapling is already defined in Moretrees
|
2014-06-10 02:26:45 +02:00
|
|
|
|
|
|
|
-- Jungletree sapling
|
|
|
|
|
2018-09-08 23:25:25 +02:00
|
|
|
function default.grow_jungle_tree(pos)
|
2014-06-10 02:26:45 +02:00
|
|
|
local x = pos.x
|
|
|
|
local y = pos.y
|
|
|
|
local z = pos.z
|
|
|
|
local vm = minetest.get_voxel_manip()
|
2018-09-08 23:25:25 +02:00
|
|
|
local pos1 = {x = x - 2, y = y - 5, z = z - 2}
|
|
|
|
local pos2 = {x = x + 2, y = y + 23, z = z + 2}
|
2014-06-10 02:26:45 +02:00
|
|
|
local emin, emax = vm:read_from_map(pos1, pos2)
|
2018-09-08 23:25:25 +02:00
|
|
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
2014-06-10 02:26:45 +02:00
|
|
|
local data = vm:get_data()
|
|
|
|
watershed_jungletree(x, y, z, area, data)
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map()
|
|
|
|
vm:update_map()
|
2018-09-08 23:25:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
default.grow_new_apple_tree = default.grow_tree
|
|
|
|
default.grow_new_jungle_tree = default.grow_jungle_tree
|
|
|
|
default.grow_new_pine_tree = default.grow_pine_tree
|