forked from mtcontrib/minetest-mod-snow
mapgen_v6: use a table for the contents
This commit is contained in:
parent
9cd39dc111
commit
47a8691b82
@ -78,8 +78,29 @@ local function is_plantlike(id)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local c
|
||||||
-- On generated function
|
local function define_contents()
|
||||||
|
c = {
|
||||||
|
dirt_with_grass = minetest.get_content_id("default:dirt_with_grass"),
|
||||||
|
dirt = minetest.get_content_id("default:dirt"),
|
||||||
|
tree = minetest.get_content_id("default:tree"),
|
||||||
|
apple = minetest.get_content_id("default:apple"),
|
||||||
|
snow = minetest.get_content_id("default:snow"),
|
||||||
|
snow_block = minetest.get_content_id("default:snowblock"),
|
||||||
|
dirt_with_snow = minetest.get_content_id("default:dirt_with_snow"),
|
||||||
|
air = minetest.get_content_id("air"),
|
||||||
|
ignore = minetest.get_content_id("ignore"),
|
||||||
|
stone = minetest.get_content_id("default:stone"),
|
||||||
|
dry_shrub = minetest.get_content_id("default:dry_shrub"),
|
||||||
|
leaves = minetest.get_content_id("default:leaves"),
|
||||||
|
jungleleaves = minetest.get_content_id("default:jungleleaves"),
|
||||||
|
junglegrass = minetest.get_content_id("default:junglegrass"),
|
||||||
|
ice = minetest.get_content_id("default:ice"),
|
||||||
|
water = minetest.get_content_id("default:water_source"),
|
||||||
|
papyrus = minetest.get_content_id("default:papyrus"),
|
||||||
|
sand = minetest.get_content_id("default:sand"),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
@ -92,24 +113,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local spawn_pine = snow.voxelmanip_pine
|
local spawn_pine = snow.voxelmanip_pine
|
||||||
local smooth = snow.smooth_biomes
|
local smooth = snow.smooth_biomes
|
||||||
|
|
||||||
local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass")
|
if not c then
|
||||||
local c_dirt = minetest.get_content_id("default:dirt")
|
define_contents()
|
||||||
local c_tree = minetest.get_content_id("default:tree")
|
end
|
||||||
local c_apple = minetest.get_content_id("default:apple")
|
|
||||||
local c_snow = minetest.get_content_id("default:snow")
|
|
||||||
local c_snow_block = minetest.get_content_id("default:snowblock")
|
|
||||||
local c_dirt_with_snow = minetest.get_content_id("default:dirt_with_snow")
|
|
||||||
local c_air = minetest.get_content_id("air")
|
|
||||||
local c_ignore = minetest.get_content_id("ignore")
|
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
|
||||||
local c_dry_shrub = minetest.get_content_id("default:dry_shrub")
|
|
||||||
local c_leaves = minetest.get_content_id("default:leaves")
|
|
||||||
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
|
|
||||||
local c_junglegrass = minetest.get_content_id("default:junglegrass")
|
|
||||||
local c_ice = minetest.get_content_id("default:ice")
|
|
||||||
local c_water = minetest.get_content_id("default:water_source")
|
|
||||||
local c_papyrus = minetest.get_content_id("default:papyrus")
|
|
||||||
local c_sand = minetest.get_content_id("default:sand")
|
|
||||||
|
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
||||||
@ -157,8 +163,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local ground_y = nil
|
local ground_y = nil
|
||||||
for y = maxp.y, minp.y, -1 do
|
for y = maxp.y, minp.y, -1 do
|
||||||
local nodid = data[area:index(x, y, z)]
|
local nodid = data[area:index(x, y, z)]
|
||||||
if nodid ~= c_air
|
if nodid ~= c.air
|
||||||
and nodid ~= c_ignore then
|
and nodid ~= c.ignore then
|
||||||
ground_y = y
|
ground_y = y
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -166,17 +172,17 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
|
|
||||||
if ground_y then
|
if ground_y then
|
||||||
local vi = area:index(x, ground_y, z)
|
local vi = area:index(x, ground_y, z)
|
||||||
if data[vi] == c_leaves
|
if data[vi] == c.leaves
|
||||||
or data[vi] == c_jungleleaves then
|
or data[vi] == c.jungleleaves then
|
||||||
for y = ground_y, -16, -1 do
|
for y = ground_y, -16, -1 do
|
||||||
local vi = area:index(x, y, z)
|
local vi = area:index(x, y, z)
|
||||||
local id = data[vi]
|
local id = data[vi]
|
||||||
if id ~= c_air then
|
if id ~= c.air then
|
||||||
if id == c_leaves
|
if id == c.leaves
|
||||||
or id == c_jungleleaves
|
or id == c.jungleleaves
|
||||||
or id == c_tree
|
or id == c.tree
|
||||||
or id == c_apple then
|
or id == c.apple then
|
||||||
data[vi] = c_air
|
data[vi] = c.air
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -197,7 +203,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local ground_y
|
local ground_y
|
||||||
for y = maxp.y, minp.y, -1 do
|
for y = maxp.y, minp.y, -1 do
|
||||||
local nodid = data[area:index(x, y, z)]
|
local nodid = data[area:index(x, y, z)]
|
||||||
if nodid ~= c_air and nodid ~= c_ignore then
|
if nodid ~= c.air and nodid ~= c.ignore then
|
||||||
ground_y = y
|
ground_y = y
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -207,7 +213,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local node = area:index(x, ground_y, z)
|
local node = area:index(x, ground_y, z)
|
||||||
local c_ground = data[node]
|
local c_ground = data[node]
|
||||||
|
|
||||||
if c_ground == c_dirt_with_grass then
|
if c_ground == c.dirt_with_grass then
|
||||||
if alpine
|
if alpine
|
||||||
and test > 0.53 then
|
and test > 0.53 then
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
@ -215,25 +221,25 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
-- generate stone ground
|
-- generate stone ground
|
||||||
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
||||||
local vi = area:index(x, y, z)
|
local vi = area:index(x, y, z)
|
||||||
if data[vi] == c_stone then
|
if data[vi] == c.stone then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
data[vi] = c_stone
|
data[vi] = c.stone
|
||||||
end
|
end
|
||||||
elseif shrubs
|
elseif shrubs
|
||||||
and pr:next(1,28) == 1 then
|
and pr:next(1,28) == 1 then
|
||||||
data[node] = c_dirt_with_snow
|
data[node] = c.dirt_with_snow
|
||||||
data[area:index(x, ground_y+1, z)] = c_dry_shrub
|
data[area:index(x, ground_y+1, z)] = c.dry_shrub
|
||||||
elseif pines
|
elseif pines
|
||||||
and pr:next(1,36) == 1 then
|
and pr:next(1,36) == 1 then
|
||||||
data[node] = c_dirt_with_snow
|
data[node] = c.dirt_with_snow
|
||||||
spawn_pine({x=x, y=ground_y+1, z=z}, area, data)
|
spawn_pine({x=x, y=ground_y+1, z=z}, area, data)
|
||||||
else
|
else
|
||||||
data[node] = c_dirt_with_snow
|
data[node] = c.dirt_with_snow
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1
|
num = num+1
|
||||||
end
|
end
|
||||||
elseif c_ground == c_water then
|
elseif c_ground == c.water then
|
||||||
if not icesheet
|
if not icesheet
|
||||||
and not icecave
|
and not icecave
|
||||||
and not icehole then
|
and not icehole then
|
||||||
@ -249,7 +255,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
if pr:next(1,4) == 1
|
if pr:next(1,4) == 1
|
||||||
and (cool or icebergs) then
|
and (cool or icebergs) then
|
||||||
for _,i in ipairs(nds) do
|
for _,i in ipairs(nds) do
|
||||||
if i == c_ice then
|
if i == c.ice then
|
||||||
ice = true
|
ice = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -257,10 +263,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
if not ice then
|
if not ice then
|
||||||
for _,i in ipairs(nds) do
|
for _,i in ipairs(nds) do
|
||||||
if i ~= c_water
|
if i ~= c.water
|
||||||
and i ~= c_ice
|
and i ~= c.ice
|
||||||
and i ~= c_air
|
and i ~= c.air
|
||||||
and i ~= c_ignore then
|
and i ~= c.ignore then
|
||||||
ice = true
|
ice = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -268,23 +274,23 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
local y = data[area:index(x, ground_y-1, z)]
|
local y = data[area:index(x, ground_y-1, z)]
|
||||||
if ice
|
if ice
|
||||||
or (y ~= c_water and y ~= c_ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog
|
or (y ~= c.water and y ~= c.ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog
|
||||||
or (icebergs and pr:next(1,6) == 1) then
|
or (icebergs and pr:next(1,6) == 1) then
|
||||||
data[node] = c_ice
|
data[node] = c.ice
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if icesheet
|
if icesheet
|
||||||
or icecave
|
or icecave
|
||||||
or (icehole and pr:next(1,10) > 1) then
|
or (icehole and pr:next(1,10) > 1) then
|
||||||
data[node] = c_ice
|
data[node] = c.ice
|
||||||
end
|
end
|
||||||
if icecave then
|
if icecave then
|
||||||
for y = ground_y-1, -33, -1 do
|
for y = ground_y-1, -33, -1 do
|
||||||
local vi = area:index(x, y, z)
|
local vi = area:index(x, y, z)
|
||||||
if data[vi] ~= c_water then
|
if data[vi] ~= c.water then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
data[vi] = c_air
|
data[vi] = c.air
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if icesheet then
|
if icesheet then
|
||||||
@ -293,40 +299,40 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
num = num+1
|
num = num+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif c_ground == c_leaves
|
elseif c_ground == c.leaves
|
||||||
or c_ground == c_jungleleaves
|
or c_ground == c.jungleleaves
|
||||||
or c_ground == c_apple then
|
or c_ground == c.apple then
|
||||||
if alpine then
|
if alpine then
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1
|
num = num+1
|
||||||
-- make stone pillars out of trees
|
-- make stone pillars out of trees
|
||||||
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
||||||
local stone = area:index(x, y, z)
|
local stone = area:index(x, y, z)
|
||||||
if data[stone] == c_stone then
|
if data[stone] == c.stone then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
data[stone] = c_stone
|
data[stone] = c.stone
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- put snow onto leaves
|
-- put snow onto leaves
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1
|
num = num+1
|
||||||
end
|
end
|
||||||
elseif c_ground == c_sand then
|
elseif c_ground == c.sand then
|
||||||
if icy then
|
if icy then
|
||||||
data[node] = c_ice
|
data[node] = c.ice
|
||||||
end
|
end
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1
|
num = num+1
|
||||||
elseif c_ground == c_papyrus then
|
elseif c_ground == c.papyrus then
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1
|
num = num+1
|
||||||
-- replace papyrus plants with snowblocks
|
-- replace papyrus plants with snowblocks
|
||||||
local y = ground_y
|
local y = ground_y
|
||||||
for _ = 1,7 do
|
for _ = 1,7 do
|
||||||
local vi = area:index(x, y, z)
|
local vi = area:index(x, y, z)
|
||||||
if data[vi] == c_papyrus then
|
if data[vi] == c.papyrus then
|
||||||
data[vi] = c_snow_block
|
data[vi] = c.snow_block
|
||||||
y = y-1
|
y = y-1
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
@ -334,10 +340,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
elseif is_plantlike(c_ground) then
|
elseif is_plantlike(c_ground) then
|
||||||
local vi = area:index(x, ground_y-1, z)
|
local vi = area:index(x, ground_y-1, z)
|
||||||
if data[vi] == c_dirt_with_grass then
|
if data[vi] == c.dirt_with_grass then
|
||||||
-- replace other plants with dry shrubs
|
-- replace other plants with dry shrubs
|
||||||
data[vi] = c_dirt_with_snow
|
data[vi] = c.dirt_with_snow
|
||||||
data[node] = c_dry_shrub
|
data[node] = c.dry_shrub
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -350,7 +356,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
if num ~= 1 then
|
if num ~= 1 then
|
||||||
for _,i in pairs(snow_tab) do
|
for _,i in pairs(snow_tab) do
|
||||||
-- set snow
|
-- set snow
|
||||||
data[area:index(i[3], i[1]+1, i[2])] = c_snow
|
data[area:index(i[3], i[1]+1, i[2])] = c.snow
|
||||||
end
|
end
|
||||||
local wsz, wsx
|
local wsz, wsx
|
||||||
for _,i in pairs(snow_tab) do
|
for _,i in pairs(snow_tab) do
|
||||||
@ -370,8 +376,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
for i = -1,1,2 do
|
for i = -1,1,2 do
|
||||||
for _,cord in pairs({{x+i,z}, {x,z+i}}) do
|
for _,cord in pairs({{x+i,z}, {x,z+i}}) do
|
||||||
local nd = data[area:index(cord[1], y, cord[2])]
|
local nd = data[area:index(cord[1], y, cord[2])]
|
||||||
if nd == c_air
|
if nd == c.air
|
||||||
or nd == c_dry_shrub then
|
or nd == c.dry_shrub then
|
||||||
h = h/2
|
h = h/2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -386,7 +392,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local vi = area:index(x, y, z)
|
local vi = area:index(x, y, z)
|
||||||
if h == 9 then
|
if h == 9 then
|
||||||
-- replace the snow with a snowblock because its a full node
|
-- replace the snow with a snowblock because its a full node
|
||||||
data[vi] = c_snow_block
|
data[vi] = c.snow_block
|
||||||
else
|
else
|
||||||
-- set a specific snow height
|
-- set a specific snow height
|
||||||
if not param2s then
|
if not param2s then
|
||||||
|
Loading…
Reference in New Issue
Block a user