Fix biomes 2/3

This commit is contained in:
kay27 2022-02-01 04:44:05 +04:00
parent 2f6242e04f
commit 7b47e4d12b
4 changed files with 151 additions and 135 deletions

View File

@ -264,6 +264,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
end end
if #queue_unsafe_engine > 0 then if #queue_unsafe_engine > 0 then
vm_context.minp, vm_context.maxp = minp, maxp
for _, v in pairs(queue_unsafe_engine) do for _, v in pairs(queue_unsafe_engine) do
v.f(vm_context) v.f(vm_context)
end end

View File

@ -4,14 +4,18 @@ local c_snow_block = minetest.get_content_id("mcl_core:snowblock")
mcl_mapgen.register_on_generated(function(vm_context) mcl_mapgen.register_on_generated(function(vm_context)
local minp, maxp = vm_context.minp, vm_context.maxp local minp, maxp = vm_context.minp, vm_context.maxp
local min_y = minp.y local min_y, max_y = minp.y, maxp.y
if min_y > mcl_mapgen.overworld.max or maxp.y < mcl_mapgen.overworld.min then return end if min_y > mcl_mapgen.overworld.max or max_y < mcl_mapgen.overworld.min then return end
vm_context.param2_data = vm_context.param2_data or vm:get_param2_data(vm_context.lvm_param2_buffer) vm_context.param2_data = vm_context.param2_data or vm:get_param2_data(vm_context.lvm_param2_buffer)
vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object("biomemap") vm_context.biomemap = vm_context.biomemap or minetest.get_mapgen_object("biomemap")
local param2_data = vm_context.param2_data local param2_data = vm_context.param2_data
local biomemap = vm_context.biomemap local biomemap = vm_context.biomemap
local vm, data, area = vm_context.vm, vm_context.data, vm_context.area local vm, data, area = vm_context.vm, vm_context.data, vm_context.area
local min_x, min_z = minp.x, minp.z
local chunksize = max_y - min_y + 1
----- Interactive block fixing section ----- ----- Interactive block fixing section -----
----- The section to perform basic block overrides of the core mapgen generated world. ----- ----- The section to perform basic block overrides of the core mapgen generated world. -----
@ -23,16 +27,16 @@ mcl_mapgen.register_on_generated(function(vm_context)
-- Clear snowy grass blocks without snow above to ensure consistency. -- Clear snowy grass blocks without snow above to ensure consistency.
local nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:dirt_with_grass", "mcl_core:dirt_with_grass_snow"}) local nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:dirt_with_grass", "mcl_core:dirt_with_grass_snow"})
-- Flat area at y=0 to read biome 3 times faster than 5.3.0.get_biome_data(pos).biome: 43us vs 125us per iteration:
local aream = VoxelArea:new({MinEdge={x=minp.x, y=min_y, z=minp.z}, MaxEdge={x=maxp.x, y=min_y, z=maxp.z}})
for n=1, #nodes do for n=1, #nodes do
local n = nodes[n] local pos = nodes[n]
local p_pos = area:index(n.x, n.y, n.z) local x, y, z = pos.x, pos.y, pos.z
local p_pos_above = area:index(n.x, n.y+1, n.z) local p_pos = area:index(x, y, z)
local b_pos = aream:index(n.x, min_y, n.z) local p_pos_above = area:index(x, y + 1, z)
local bn = minetest.get_biome_name(biomemap[b_pos]) local biomemap_offset = (z - min_z) * chunksize + x - min_x + 1
if bn then local biome_id = biomemap[biomemap_offset]
local biome = minetest.registered_biomes[bn] local biome_name = minetest.get_biome_name(biome_id)
if biome_name then
local biome = minetest.registered_biomes[biome_name]
if biome and biome._mcl_biome_type then if biome and biome._mcl_biome_type then
param2_data[p_pos] = biome._mcl_palette_index param2_data[p_pos] = biome._mcl_palette_index
vm_context.write_param2 = true vm_context.write_param2 = true

View File

@ -65,7 +65,6 @@ local c_stone = minetest.get_content_id("mcl_core:stone")
local c_dirt = minetest.get_content_id("mcl_core:dirt") local c_dirt = minetest.get_content_id("mcl_core:dirt")
local c_dirt_with_grass = minetest.get_content_id("mcl_core:dirt_with_grass") local c_dirt_with_grass = minetest.get_content_id("mcl_core:dirt_with_grass")
local c_sand = minetest.get_content_id("mcl_core:sand") local c_sand = minetest.get_content_id("mcl_core:sand")
--local c_sandstone = minetest.get_content_id("mcl_core:sandstone")
local c_void = minetest.get_content_id("mcl_core:void") local c_void = minetest.get_content_id("mcl_core:void")
local c_lava = minetest.get_content_id("mcl_core:lava_source") local c_lava = minetest.get_content_id("mcl_core:lava_source")
local c_water = minetest.get_content_id("mcl_core:water_source") local c_water = minetest.get_content_id("mcl_core:water_source")
@ -1189,100 +1188,6 @@ function mcl_mapgen_core.generate_end_exit_portal(pos)
portal_generated = true portal_generated = true
end end
-- Generate mushrooms in caves manually.
-- Minetest's API does not support decorations in caves yet. :-(
local function generate_underground_mushrooms(minp, maxp, seed)
if not mcl_mushrooms then return end
local pr_shroom = PseudoRandom(seed-24359)
-- Generate rare underground mushrooms
-- TODO: Make them appear in groups, use Perlin noise
local min, max = mcl_mapgen.overworld.lava_max + 4, 0
if minp.y > max or maxp.y < min then
return
end
local bpos
local stone = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_core:stone", "mcl_core:dirt", "mcl_core:mycelium", "mcl_core:podzol", "mcl_core:andesite", "mcl_core:diorite", "mcl_core:granite", "mcl_core:stone_with_coal", "mcl_core:stone_with_iron", "mcl_core:stone_with_gold"})
for n = 1, #stone do
bpos = {x = stone[n].x, y = stone[n].y + 1, z = stone[n].z }
local l = minetest.get_node_light(bpos, 0.5)
if bpos.y >= min and bpos.y <= max and l and l <= 12 and pr_shroom:next(1,1000) < 4 then
if pr_shroom:next(1,2) == 1 then
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
else
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
end
end
end
end
-- Generate Nether decorations manually: Eternal fire, mushrooms
-- Minetest's API does not support decorations in caves yet. :-(
local function generate_nether_decorations(minp, maxp, seed)
if c_nether == nil then
return
end
local pr_nether = PseudoRandom(seed+667)
if minp.y > mcl_mapgen.nether.max or maxp.y < mcl_mapgen.nether.min then
return
end
minetest.log("action", "[mcl_mapgen_core] Nether decorations " .. minetest.pos_to_string(minp) .. " ... " .. minetest.pos_to_string(maxp))
-- TODO: Generate everything based on Perlin noise instead of PseudoRandom
local bpos
local rack = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:netherrack"})
local magma = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:magma"})
local ssand = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:soul_sand"})
-- Helper function to spawn “fake” decoration
local function special_deco(nodes, spawn_func)
for n = 1, #nodes do
bpos = {x = nodes[n].x, y = nodes[n].y + 1, z = nodes[n].z }
spawn_func(bpos)
end
end
-- Eternal fire on netherrack
special_deco(rack, function(bpos)
-- Eternal fire on netherrack
if pr_nether:next(1,100) <= 3 then
minetest.set_node(bpos, {name = "mcl_fire:eternal_fire"})
end
end)
-- Eternal fire on magma cubes
special_deco(magma, function(bpos)
if pr_nether:next(1,150) == 1 then
minetest.set_node(bpos, {name = "mcl_fire:eternal_fire"})
end
end)
-- Mushrooms on netherrack
-- Note: Spawned *after* the fire because of light level checks
if mcl_mushrooms then
special_deco(rack, function(bpos)
local l = minetest.get_node_light(bpos, 0.5)
if bpos.y > mcl_mapgen.nether.lava_max + 6 and l and l <= 12 and pr_nether:next(1,1000) <= 4 then
-- TODO: Make mushrooms appear in groups, use Perlin noise
if pr_nether:next(1,2) == 1 then
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
else
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
end
end
end)
end
end
-- Generate basic layer-based nodes: void, bedrock, realm barrier, lava seas, etc. -- Generate basic layer-based nodes: void, bedrock, realm barrier, lava seas, etc.
-- Also perform some basic node replacements. -- Also perform some basic node replacements.
@ -1334,7 +1239,7 @@ end
-- --
-- returns true if any node was set and lvm_used otherwise -- returns true if any node was set and lvm_used otherwise
local function set_layers(vm_context, pr, min, max, content_id, check) local function set_layers(vm_context, pr, min, max, content_id, check)
local minp, maxp = vm_context.minp, vm_context.maxp local minp, maxp, data, area = vm_context.minp, vm_context.maxp, vm_context.data, vm_context.area
if (maxp.y >= min and minp.y <= max) then if (maxp.y >= min and minp.y <= max) then
for y = math.max(min, minp.y), math.min(max, maxp.y) do for y = math.max(min, minp.y), math.min(max, maxp.y) do
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
@ -1342,10 +1247,10 @@ local function set_layers(vm_context, pr, min, max, content_id, check)
local p_pos = vm_context.area:index(x, y, z) local p_pos = vm_context.area:index(x, y, z)
if check then if check then
if type(check) == "function" and check({x=x,y=y,z=z}, data[p_pos], pr) then if type(check) == "function" and check({x=x,y=y,z=z}, data[p_pos], pr) then
vm_context.data[p_pos] = content_id data[p_pos] = content_id
vm_context.write = true vm_context.write = true
elseif check == data[p_pos] then elseif check == data[p_pos] then
vm_context.data[p_pos] = content_id data[p_pos] = content_id
vm_context.write = true vm_context.write = true
end end
else else

View File

@ -1,31 +1,137 @@
local v6 = mcl_mapgen.v6
-- Nether block fixes: local mcl_mushrooms = minetest.get_modpath("mcl_mushrooms")
-- * Replace water with Nether lava.
-- * Replace stone, sand dirt in v6 so the Nether works in v6. local c_nether = minetest.get_modpath("mcl_nether") and {
elseif minp.y <= mcl_mapgen.nether.max and maxp.y >= mcl_mapgen.nether.min then soul_sand = minetest.get_content_id("mcl_nether:soul_sand"),
if c_nether then netherrack = minetest.get_content_id("mcl_nether:netherrack"),
if v6 then lava = minetest.get_content_id("mcl_nether:nether_lava_source")
local nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"}) }
for n=1, #nodes do
local p_pos = area:index(nodes[n].x, nodes[n].y, nodes[n].z) -- Generate mushrooms in caves manually.
if data[p_pos] == c_water then -- Minetest's API does not support decorations in caves yet. :-(
data[p_pos] = c_nether.lava local function generate_underground_mushrooms(minp, maxp, seed)
lvm_used = true if not mcl_mushrooms then return end
elseif data[p_pos] == c_stone then
data[p_pos] = c_netherrack local pr_shroom = PseudoRandom(seed-24359)
lvm_used = true -- Generate rare underground mushrooms
elseif data[p_pos] == c_sand or data[p_pos] == c_dirt then -- TODO: Make them appear in groups, use Perlin noise
data[p_pos] = c_soul_sand local min, max = mcl_mapgen.overworld.lava_max + 4, 0
lvm_used = true if minp.y > max or maxp.y < min then
end return
end end
local bpos
local stone = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_core:stone", "mcl_core:dirt", "mcl_core:mycelium", "mcl_core:podzol", "mcl_core:andesite", "mcl_core:diorite", "mcl_core:granite", "mcl_core:stone_with_coal", "mcl_core:stone_with_iron", "mcl_core:stone_with_gold"})
for n = 1, #stone do
bpos = {x = stone[n].x, y = stone[n].y + 1, z = stone[n].z }
local l = minetest.get_node_light(bpos, 0.5)
if bpos.y >= min and bpos.y <= max and l and l <= 12 and pr_shroom:next(1,1000) < 4 then
if pr_shroom:next(1,2) == 1 then
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
else
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
end
end
end
end
-- Generate Nether decorations manually: Eternal fire, mushrooms
-- Minetest's API does not support decorations in caves yet. :-(
local function generate_nether_decorations(minp, maxp, seed)
if c_nether == nil then
return
end
local pr_nether = PseudoRandom(seed+667)
if minp.y > mcl_mapgen.nether.max or maxp.y < mcl_mapgen.nether.min then
return
end
minetest.log("action", "[mcl_mapgen_core] Nether decorations " .. minetest.pos_to_string(minp) .. " ... " .. minetest.pos_to_string(maxp))
-- TODO: Generate everything based on Perlin noise instead of PseudoRandom
local bpos
local rack = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:netherrack"})
local magma = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:magma"})
local ssand = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:soul_sand"})
-- Helper function to spawn “fake” decoration
local function special_deco(nodes, spawn_func)
for n = 1, #nodes do
bpos = {x = nodes[n].x, y = nodes[n].y + 1, z = nodes[n].z }
spawn_func(bpos)
end
end
-- Eternal fire on netherrack
special_deco(rack, function(bpos)
-- Eternal fire on netherrack
if pr_nether:next(1,100) <= 3 then
minetest.set_node(bpos, {name = "mcl_fire:eternal_fire"})
end
end)
-- Eternal fire on magma cubes
special_deco(magma, function(bpos)
if pr_nether:next(1,150) == 1 then
minetest.set_node(bpos, {name = "mcl_fire:eternal_fire"})
end
end)
-- Mushrooms on netherrack
-- Note: Spawned *after* the fire because of light level checks
if mcl_mushrooms then
special_deco(rack, function(bpos)
local l = minetest.get_node_light(bpos, 0.5)
if bpos.y > mcl_mapgen.nether.lava_max + 6 and l and l <= 12 and pr_nether:next(1,1000) <= 4 then
-- TODO: Make mushrooms appear in groups, use Perlin noise
if pr_nether:next(1,2) == 1 then
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
else else
local nodes = minetest.find_nodes_in_area(minp, maxp, {"group:water"}) minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
for _, n in pairs(nodes) do
data[area:index(n.x, n.y, n.z)] = c_nether.lava
end
end end
end end
end)
end
end
mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context)
local min_y, max_y = minp.y, maxp.y
-- Nether block fixes:
-- * Replace water with Nether lava.
-- * Replace stone, sand dirt in v6 so the Nether works in v6.
if min_y <= mcl_mapgen.nether.max and max_y >= mcl_mapgen.nether.min then
if c_nether then
if v6 then
local nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:water_source", "mcl_core:stone", "mcl_core:sand", "mcl_core:dirt"})
for n=1, #nodes do
local p_pos = area:index(nodes[n].x, nodes[n].y, nodes[n].z)
if data[p_pos] == c_water then
data[p_pos] = c_nether.lava
lvm_used = true
elseif data[p_pos] == c_stone then
data[p_pos] = c_netherrack
lvm_used = true
elseif data[p_pos] == c_sand or data[p_pos] == c_dirt then
data[p_pos] = c_soul_sand
lvm_used = true
end
end
else
local nodes = minetest.find_nodes_in_area(minp, maxp, {"group:water"})
for _, n in pairs(nodes) do
data[area:index(n.x, n.y, n.z)] = c_nether.lava
end
end
end
-- End block fixes: -- End block fixes:
-- * Replace water with end stone or air (depending on height). -- * Replace water with end stone or air (depending on height).
@ -73,8 +179,8 @@
if not singlenode then if not singlenode then
-- Generate special decorations -- Generate special decorations
generate_underground_mushrooms(minp, maxp, blockseed) generate_underground_mushrooms(minp, maxp, chunkseed)
generate_nether_decorations(minp, maxp, blockseed) generate_nether_decorations(minp, maxp, chunkseed)
end end
end, 1) end, 1)