2021-02-22 01:15:32 +02:00
|
|
|
|
mcl_mapgen_core = {}
|
2021-03-28 21:56:51 +03:00
|
|
|
|
local registered_generators = {}
|
2021-02-22 01:15:32 +02:00
|
|
|
|
|
|
|
|
|
local lvm, nodes, param2 = 0, 0, 0
|
2021-03-28 21:56:51 +03:00
|
|
|
|
local lvm_buffer = {}
|
2021-02-22 01:15:32 +02:00
|
|
|
|
|
2022-08-30 04:39:29 +03:00
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
local modpath = minetest.get_modpath(modname)
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
|
--
|
|
|
|
|
-- Aliases for map generator outputs
|
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
minetest.register_alias("mapgen_air", "air")
|
2017-02-01 00:32:56 +02:00
|
|
|
|
minetest.register_alias("mapgen_stone", "mcl_core:stone")
|
|
|
|
|
minetest.register_alias("mapgen_tree", "mcl_core:tree")
|
|
|
|
|
minetest.register_alias("mapgen_leaves", "mcl_core:leaves")
|
|
|
|
|
minetest.register_alias("mapgen_jungletree", "mcl_core:jungletree")
|
|
|
|
|
minetest.register_alias("mapgen_jungleleaves", "mcl_core:jungleleaves")
|
2017-03-07 23:15:58 +02:00
|
|
|
|
minetest.register_alias("mapgen_pine_tree", "mcl_core:sprucetree")
|
|
|
|
|
minetest.register_alias("mapgen_pine_needles", "mcl_core:spruceleaves")
|
2017-02-01 00:32:56 +02:00
|
|
|
|
|
|
|
|
|
minetest.register_alias("mapgen_apple", "mcl_core:leaves")
|
|
|
|
|
minetest.register_alias("mapgen_water_source", "mcl_core:water_source")
|
|
|
|
|
minetest.register_alias("mapgen_dirt", "mcl_core:dirt")
|
|
|
|
|
minetest.register_alias("mapgen_dirt_with_grass", "mcl_core:dirt_with_grass")
|
2017-04-01 07:44:02 +03:00
|
|
|
|
minetest.register_alias("mapgen_dirt_with_snow", "mcl_core:dirt_with_grass_snow")
|
2017-02-01 00:32:56 +02:00
|
|
|
|
minetest.register_alias("mapgen_sand", "mcl_core:sand")
|
|
|
|
|
minetest.register_alias("mapgen_gravel", "mcl_core:gravel")
|
|
|
|
|
minetest.register_alias("mapgen_clay", "mcl_core:clay")
|
2017-05-20 02:27:09 +03:00
|
|
|
|
minetest.register_alias("mapgen_lava_source", "air") -- Built-in lava generator is too unpredictable, we generate lava on our own
|
2017-02-01 00:32:56 +02:00
|
|
|
|
minetest.register_alias("mapgen_cobble", "mcl_core:cobble")
|
|
|
|
|
minetest.register_alias("mapgen_mossycobble", "mcl_core:mossycobble")
|
2017-03-15 04:00:20 +02:00
|
|
|
|
minetest.register_alias("mapgen_junglegrass", "mcl_flowers:fern")
|
2017-02-01 00:32:56 +02:00
|
|
|
|
minetest.register_alias("mapgen_stone_with_coal", "mcl_core:stone_with_coal")
|
|
|
|
|
minetest.register_alias("mapgen_stone_with_iron", "mcl_core:stone_with_iron")
|
|
|
|
|
minetest.register_alias("mapgen_desert_sand", "mcl_core:sand")
|
|
|
|
|
minetest.register_alias("mapgen_desert_stone", "mcl_core:sandstone")
|
|
|
|
|
minetest.register_alias("mapgen_sandstone", "mcl_core:sandstone")
|
2017-11-30 15:16:04 +02:00
|
|
|
|
if minetest.get_modpath("mclx_core") then
|
|
|
|
|
minetest.register_alias("mapgen_river_water_source", "mclx_core:river_water_source")
|
|
|
|
|
else
|
|
|
|
|
minetest.register_alias("mapgen_river_water_source", "mcl_core:water_source")
|
|
|
|
|
end
|
2017-02-01 00:32:56 +02:00
|
|
|
|
minetest.register_alias("mapgen_snow", "mcl_core:snow")
|
|
|
|
|
minetest.register_alias("mapgen_snowblock", "mcl_core:snowblock")
|
|
|
|
|
minetest.register_alias("mapgen_ice", "mcl_core:ice")
|
2017-01-27 15:04:30 +02:00
|
|
|
|
|
2017-06-05 19:40:56 +03:00
|
|
|
|
minetest.register_alias("mapgen_stair_cobble", "mcl_stairs:stair_cobble")
|
2017-02-01 00:32:56 +02:00
|
|
|
|
minetest.register_alias("mapgen_sandstonebrick", "mcl_core:sandstonesmooth")
|
2017-06-05 19:40:56 +03:00
|
|
|
|
minetest.register_alias("mapgen_stair_sandstonebrick", "mcl_stairs:stair_sandstone")
|
|
|
|
|
minetest.register_alias("mapgen_stair_sandstone_block", "mcl_stairs:stair_sandstone")
|
|
|
|
|
minetest.register_alias("mapgen_stair_desert_stone", "mcl_stairs:stair_sandstone")
|
2017-01-27 15:04:30 +02:00
|
|
|
|
|
2017-06-13 14:53:34 +03:00
|
|
|
|
local mg_name = minetest.get_mapgen_setting("mg_name")
|
2019-02-09 03:42:11 +02:00
|
|
|
|
local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true"
|
2017-06-13 14:53:34 +03:00
|
|
|
|
|
2021-04-06 16:48:17 +03:00
|
|
|
|
-- End exit portal position
|
2021-04-06 21:08:20 +03:00
|
|
|
|
local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3)
|
2017-11-21 08:24:56 +02:00
|
|
|
|
|
2017-09-11 05:24:03 +03:00
|
|
|
|
-- Content IDs
|
|
|
|
|
local c_bedrock = minetest.get_content_id("mcl_core:bedrock")
|
2017-11-21 06:39:27 +02:00
|
|
|
|
local c_obsidian = minetest.get_content_id("mcl_core:obsidian")
|
2017-09-11 05:24:03 +03:00
|
|
|
|
local c_stone = minetest.get_content_id("mcl_core:stone")
|
|
|
|
|
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_snow = minetest.get_content_id("mcl_core:dirt_with_grass_snow")
|
2022-04-18 05:28:23 +03:00
|
|
|
|
local c_reeds = minetest.get_content_id("mcl_core:reeds")
|
2017-09-11 05:24:03 +03:00
|
|
|
|
local c_sand = minetest.get_content_id("mcl_core:sand")
|
2021-04-17 10:26:37 +03:00
|
|
|
|
--local c_sandstone = minetest.get_content_id("mcl_core:sandstone")
|
2017-09-11 05:24:03 +03:00
|
|
|
|
local c_void = minetest.get_content_id("mcl_core:void")
|
|
|
|
|
local c_lava = minetest.get_content_id("mcl_core:lava_source")
|
|
|
|
|
local c_water = minetest.get_content_id("mcl_core:water_source")
|
|
|
|
|
local c_soul_sand = minetest.get_content_id("mcl_nether:soul_sand")
|
|
|
|
|
local c_netherrack = minetest.get_content_id("mcl_nether:netherrack")
|
|
|
|
|
local c_nether_lava = minetest.get_content_id("mcl_nether:nether_lava_source")
|
2021-04-17 10:26:37 +03:00
|
|
|
|
--local c_end_stone = minetest.get_content_id("mcl_end:end_stone")
|
2017-09-11 05:24:03 +03:00
|
|
|
|
local c_realm_barrier = minetest.get_content_id("mcl_core:realm_barrier")
|
|
|
|
|
local c_top_snow = minetest.get_content_id("mcl_core:snow")
|
|
|
|
|
local c_snow_block = minetest.get_content_id("mcl_core:snowblock")
|
|
|
|
|
local c_clay = minetest.get_content_id("mcl_core:clay")
|
2017-09-13 02:47:24 +03:00
|
|
|
|
local c_leaves = minetest.get_content_id("mcl_core:leaves")
|
|
|
|
|
local c_jungleleaves = minetest.get_content_id("mcl_core:jungleleaves")
|
2021-04-17 10:26:37 +03:00
|
|
|
|
--local c_jungletree = minetest.get_content_id("mcl_core:jungletree")
|
2017-09-13 02:47:24 +03:00
|
|
|
|
local c_cocoa_1 = minetest.get_content_id("mcl_cocoas:cocoa_1")
|
|
|
|
|
local c_cocoa_2 = minetest.get_content_id("mcl_cocoas:cocoa_2")
|
|
|
|
|
local c_cocoa_3 = minetest.get_content_id("mcl_cocoas:cocoa_3")
|
|
|
|
|
local c_vine = minetest.get_content_id("mcl_core:vine")
|
2017-09-11 05:24:03 +03:00
|
|
|
|
local c_air = minetest.CONTENT_AIR
|
|
|
|
|
|
2022-08-30 04:39:29 +03:00
|
|
|
|
dofile(modpath.."/ores.lua")
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
2020-06-16 02:46:07 +03:00
|
|
|
|
local mg_flags = minetest.settings:get_flags("mg_flags")
|
2020-06-16 03:33:51 +03:00
|
|
|
|
|
|
|
|
|
-- Inform other mods of dungeon setting for MCL2-style dungeons
|
|
|
|
|
mcl_vars.mg_dungeons = mg_flags.dungeons and not superflat
|
|
|
|
|
|
2020-06-16 02:46:07 +03:00
|
|
|
|
-- Disable builtin dungeons, we provide our own dungeons
|
|
|
|
|
mg_flags.dungeons = false
|
|
|
|
|
|
2022-08-30 04:40:12 +03:00
|
|
|
|
if superflat then
|
2020-06-16 02:46:07 +03:00
|
|
|
|
-- Enforce superflat-like mapgen: no caves, decor, lakes and hills
|
|
|
|
|
mg_flags.caves = false
|
|
|
|
|
mg_flags.decorations = false
|
2019-02-09 03:42:11 +02:00
|
|
|
|
minetest.set_mapgen_setting("mgflat_spflags", "nolakes,nohills", true)
|
2017-04-01 18:01:15 +03:00
|
|
|
|
end
|
|
|
|
|
|
2020-06-16 02:46:07 +03:00
|
|
|
|
local mg_flags_str = ""
|
|
|
|
|
for k,v in pairs(mg_flags) do
|
|
|
|
|
if v == false then
|
|
|
|
|
k = "no" .. k
|
|
|
|
|
end
|
|
|
|
|
mg_flags_str = mg_flags_str .. k .. ","
|
|
|
|
|
end
|
|
|
|
|
if string.len(mg_flags_str) > 0 then
|
|
|
|
|
mg_flags_str = string.sub(mg_flags_str, 1, string.len(mg_flags_str)-1)
|
|
|
|
|
end
|
|
|
|
|
minetest.set_mapgen_setting("mg_flags", mg_flags_str, true)
|
|
|
|
|
|
2022-09-10 22:39:56 +03:00
|
|
|
|
local function between(x, y, z) -- x is between y and z (inclusive)
|
|
|
|
|
return y <= x and x <= z
|
|
|
|
|
end
|
|
|
|
|
local function in_cube(tpos,wpos1,wpos2)
|
|
|
|
|
local xmax=wpos2.x
|
|
|
|
|
local xmin=wpos1.x
|
|
|
|
|
|
|
|
|
|
local ymax=wpos2.y
|
|
|
|
|
local ymin=wpos1.y
|
|
|
|
|
|
|
|
|
|
local zmax=wpos2.z
|
|
|
|
|
local zmin=wpos1.z
|
|
|
|
|
if wpos1.x > wpos2.x then
|
|
|
|
|
xmax=wpos1.x
|
|
|
|
|
xmin=wpos2.x
|
|
|
|
|
end
|
|
|
|
|
if wpos1.y > wpos2.y then
|
|
|
|
|
ymax=wpos1.y
|
|
|
|
|
ymin=wpos2.y
|
|
|
|
|
end
|
|
|
|
|
if wpos1.z > wpos2.z then
|
|
|
|
|
zmax=wpos1.z
|
|
|
|
|
zmin=wpos2.z
|
|
|
|
|
end
|
|
|
|
|
if between(tpos.x,xmin,xmax) and between(tpos.y,ymin,ymax) and between(tpos.z,zmin,zmax) then
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2017-09-10 21:35:57 +03:00
|
|
|
|
-- Helper function for converting a MC probability to MT, with
|
|
|
|
|
-- regards to MapBlocks.
|
|
|
|
|
-- Some MC generated structures are generated on per-chunk
|
|
|
|
|
-- probability.
|
|
|
|
|
-- The MC probability is 1/x per Minecraft chunk (16×16).
|
|
|
|
|
|
|
|
|
|
-- x: The MC probability is 1/x.
|
|
|
|
|
-- minp, maxp: MapBlock limits
|
|
|
|
|
-- returns: Probability (1/return_value) for a single MT mapblock
|
|
|
|
|
local function minecraft_chunk_probability(x, minp, maxp)
|
|
|
|
|
-- 256 is the MC chunk height
|
|
|
|
|
return x * (((maxp.x-minp.x+1)*(maxp.z-minp.z+1)) / 256)
|
|
|
|
|
end
|
|
|
|
|
|
2017-09-11 01:28:52 +03:00
|
|
|
|
-- Takes x and z coordinates and minp and maxp of a generated chunk
|
|
|
|
|
-- (in on_generated callback) and returns a biomemap index)
|
|
|
|
|
-- Inverse function of biomemap_to_xz
|
2021-05-25 13:52:25 +03:00
|
|
|
|
local function xz_to_biomemap_index(x, z, minp, maxp)
|
2017-09-11 01:28:52 +03:00
|
|
|
|
local xwidth = maxp.x - minp.x + 1
|
|
|
|
|
local zwidth = maxp.z - minp.z + 1
|
|
|
|
|
local minix = x % xwidth
|
|
|
|
|
local miniz = z % zwidth
|
|
|
|
|
|
|
|
|
|
return (minix + miniz * zwidth) + 1
|
|
|
|
|
end
|
2017-09-13 02:47:24 +03:00
|
|
|
|
-- Buffers for LuaVoxelManip
|
2021-02-22 01:15:32 +02:00
|
|
|
|
-- local lvm_buffer = {}
|
|
|
|
|
-- local lvm_buffer_param2 = {}
|
|
|
|
|
minetest.register_on_generated(function(minp, maxp, blockseed)
|
2021-03-22 01:14:33 +02:00
|
|
|
|
minetest.log("action", "[mcl_mapgen_core] Generating chunk " .. minetest.pos_to_string(minp) .. " ... " .. minetest.pos_to_string(maxp))
|
2021-02-22 01:15:32 +02:00
|
|
|
|
local p1, p2 = {x=minp.x, y=minp.y, z=minp.z}, {x=maxp.x, y=maxp.y, z=maxp.z}
|
|
|
|
|
if lvm > 0 then
|
|
|
|
|
local lvm_used, shadow = false, false
|
|
|
|
|
local lb2 = {} -- param2
|
|
|
|
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
|
|
|
|
local e1, e2 = {x=emin.x, y=emin.y, z=emin.z}, {x=emax.x, y=emax.y, z=emax.z}
|
|
|
|
|
local data2
|
2021-03-28 21:56:51 +03:00
|
|
|
|
local data = vm:get_data(lvm_buffer)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if param2 > 0 then
|
|
|
|
|
data2 = vm:get_param2_data(lb2)
|
|
|
|
|
end
|
|
|
|
|
local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
|
|
|
|
|
|
2022-08-29 07:11:02 +03:00
|
|
|
|
for _, rec in ipairs(registered_generators) do
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if rec.vf then
|
2021-03-28 21:56:51 +03:00
|
|
|
|
local lvm_used0, shadow0 = rec.vf(vm, data, data2, e1, e2, area, p1, p2, blockseed)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if lvm_used0 then
|
|
|
|
|
lvm_used = true
|
|
|
|
|
end
|
|
|
|
|
if shadow0 then
|
|
|
|
|
shadow = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if lvm_used then
|
|
|
|
|
-- Write stuff
|
|
|
|
|
vm:set_data(data)
|
|
|
|
|
if param2 > 0 then
|
|
|
|
|
vm:set_param2_data(data2)
|
|
|
|
|
end
|
|
|
|
|
vm:calc_lighting(p1, p2, shadow)
|
|
|
|
|
vm:write_to_map()
|
|
|
|
|
vm:update_liquids()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if nodes > 0 then
|
2022-08-29 07:11:02 +03:00
|
|
|
|
for _, rec in ipairs(registered_generators) do
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if rec.nf then
|
|
|
|
|
rec.nf(p1, p2, blockseed)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-03-28 21:56:51 +03:00
|
|
|
|
mcl_vars.add_chunk(minp)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
end)
|
|
|
|
|
|
2021-05-27 10:34:12 +03:00
|
|
|
|
function minetest.register_on_generated(node_function)
|
2022-08-29 07:11:02 +03:00
|
|
|
|
mcl_mapgen_core.register_generator("mod_"..minetest.get_current_modname().."_"..tostring(#registered_generators+1), nil, node_function)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mcl_mapgen_core.register_generator(id, lvm_function, node_function, priority, needs_param2)
|
|
|
|
|
if not id then return end
|
|
|
|
|
|
|
|
|
|
local priority = priority or 5000
|
|
|
|
|
|
|
|
|
|
if lvm_function then lvm = lvm + 1 end
|
2022-08-14 10:11:30 +03:00
|
|
|
|
if node_function then nodes = nodes + 1 end
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if needs_param2 then param2 = param2 + 1 end
|
|
|
|
|
|
|
|
|
|
local new_record = {
|
2022-08-29 07:11:02 +03:00
|
|
|
|
id = id,
|
2021-02-22 01:15:32 +02:00
|
|
|
|
i = priority,
|
|
|
|
|
vf = lvm_function,
|
|
|
|
|
nf = node_function,
|
|
|
|
|
needs_param2 = needs_param2,
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 07:11:02 +03:00
|
|
|
|
table.insert(registered_generators, new_record)
|
2021-05-29 17:12:33 +03:00
|
|
|
|
table.sort(registered_generators, function(a, b)
|
|
|
|
|
return (a.i < b.i) or ((a.i == b.i) and a.vf and (b.vf == nil))
|
|
|
|
|
end)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mcl_mapgen_core.unregister_generator(id)
|
2022-08-29 07:11:02 +03:00
|
|
|
|
local index
|
|
|
|
|
for i, gen in ipairs(registered_generators) do
|
|
|
|
|
if gen.id == id then
|
|
|
|
|
index = i
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if not index then return end
|
|
|
|
|
local rec = registered_generators[index]
|
|
|
|
|
table.remove(registered_generators, index)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if rec.vf then lvm = lvm - 1 end
|
2021-04-17 10:26:37 +03:00
|
|
|
|
if rec.nf then nodes = nodes - 1 end
|
2021-02-22 01:15:32 +02:00
|
|
|
|
if rec.needs_param2 then param2 = param2 - 1 end
|
2021-05-22 21:01:59 +03:00
|
|
|
|
--if rec.needs_level0 then level0 = level0 - 1 end
|
2021-02-22 01:15:32 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Generate basic layer-based nodes: void, bedrock, realm barrier, lava seas, etc.
|
|
|
|
|
-- Also perform some basic node replacements.
|
|
|
|
|
|
|
|
|
|
local bedrock_check
|
|
|
|
|
if mcl_vars.mg_bedrock_is_rough then
|
2021-05-25 13:52:25 +03:00
|
|
|
|
function bedrock_check(pos, _, pr)
|
2021-02-22 01:15:32 +02:00
|
|
|
|
local y = pos.y
|
|
|
|
|
-- Bedrock layers with increasing levels of roughness, until a perfecly flat bedrock later at the bottom layer
|
|
|
|
|
-- This code assumes a bedrock height of 5 layers.
|
|
|
|
|
|
|
|
|
|
local diff = mcl_vars.mg_bedrock_overworld_max - y -- Overworld bedrock
|
|
|
|
|
local ndiff1 = mcl_vars.mg_bedrock_nether_bottom_max - y -- Nether bedrock, bottom
|
|
|
|
|
local ndiff2 = mcl_vars.mg_bedrock_nether_top_max - y -- Nether bedrock, ceiling
|
|
|
|
|
|
|
|
|
|
local top
|
|
|
|
|
if diff == 0 or ndiff1 == 0 or ndiff2 == 4 then
|
|
|
|
|
-- 50% bedrock chance
|
|
|
|
|
top = 2
|
|
|
|
|
elseif diff == 1 or ndiff1 == 1 or ndiff2 == 3 then
|
|
|
|
|
-- 66.666...%
|
|
|
|
|
top = 3
|
|
|
|
|
elseif diff == 2 or ndiff1 == 2 or ndiff2 == 2 then
|
|
|
|
|
-- 75%
|
|
|
|
|
top = 4
|
|
|
|
|
elseif diff == 3 or ndiff1 == 3 or ndiff2 == 1 then
|
|
|
|
|
-- 90%
|
|
|
|
|
top = 10
|
|
|
|
|
elseif diff == 4 or ndiff1 == 4 or ndiff2 == 0 then
|
|
|
|
|
-- 100%
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
-- Not in bedrock layer
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return pr:next(1, top) <= top-1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Helper function to set all nodes in the layers between min and max.
|
|
|
|
|
-- content_id: Node to set
|
|
|
|
|
-- check: optional.
|
|
|
|
|
-- If content_id, node will be set only if it is equal to check.
|
|
|
|
|
-- If function(pos_to_check, content_id_at_this_pos), will set node only if returns true.
|
|
|
|
|
-- min, max: Minimum and maximum Y levels of the layers to set
|
|
|
|
|
-- minp, maxp: minp, maxp of the on_generated
|
|
|
|
|
-- lvm_used: Set to true if any node in this on_generated has been set before.
|
|
|
|
|
--
|
|
|
|
|
-- returns true if any node was set and lvm_used otherwise
|
|
|
|
|
local function set_layers(data, area, content_id, check, min, max, minp, maxp, lvm_used, pr)
|
|
|
|
|
if (maxp.y >= min and minp.y <= max) then
|
|
|
|
|
for y = math.max(min, minp.y), math.min(max, maxp.y) do
|
|
|
|
|
for x = minp.x, maxp.x do
|
|
|
|
|
for z = minp.z, maxp.z do
|
|
|
|
|
local p_pos = area:index(x, y, z)
|
|
|
|
|
if check then
|
|
|
|
|
if type(check) == "function" and check({x=x,y=y,z=z}, data[p_pos], pr) then
|
|
|
|
|
data[p_pos] = content_id
|
|
|
|
|
lvm_used = true
|
|
|
|
|
elseif check == data[p_pos] then
|
2017-09-06 09:36:01 +03:00
|
|
|
|
data[p_pos] = content_id
|
|
|
|
|
lvm_used = true
|
2017-08-15 21:08:41 +03:00
|
|
|
|
end
|
2021-02-22 01:15:32 +02:00
|
|
|
|
else
|
|
|
|
|
data[p_pos] = content_id
|
|
|
|
|
lvm_used = true
|
2017-08-15 21:08:41 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-09-06 09:36:01 +03:00
|
|
|
|
end
|
2021-02-22 01:15:32 +02:00
|
|
|
|
return lvm_used
|
|
|
|
|
end
|
2017-09-06 09:36:01 +03:00
|
|
|
|
|
2022-09-10 05:39:49 +03:00
|
|
|
|
local function set_palette(minp,maxp,data2,area,biomemap,nodes)
|
|
|
|
|
-- 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=0, z=minp.z}, MaxEdge={x=maxp.x, y=0, z=maxp.z}})
|
|
|
|
|
local nodes = minetest.find_nodes_in_area(minp, maxp, nodes)
|
|
|
|
|
for n=1, #nodes do
|
|
|
|
|
local n = nodes[n]
|
|
|
|
|
local p_pos = area:index(n.x, n.y, n.z)
|
|
|
|
|
local b_pos = aream:index(n.x, 0, n.z)
|
|
|
|
|
local bn = minetest.get_biome_name(biomemap[b_pos])
|
|
|
|
|
if bn then
|
|
|
|
|
local biome = minetest.registered_biomes[bn]
|
|
|
|
|
if biome and biome._mcl_biome_type then
|
|
|
|
|
data2[p_pos] = biome._mcl_palette_index
|
|
|
|
|
lvm_used = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return lvm_used
|
|
|
|
|
end
|
|
|
|
|
|
2021-02-22 01:15:32 +02:00
|
|
|
|
-- Below the bedrock, generate air/void
|
|
|
|
|
local function basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
|
2021-04-17 10:26:37 +03:00
|
|
|
|
local biomemap --ymin, ymax
|
2021-02-22 01:15:32 +02:00
|
|
|
|
local lvm_used = false
|
|
|
|
|
local pr = PseudoRandom(blockseed)
|
2017-09-06 09:36:01 +03:00
|
|
|
|
|
2021-02-25 15:36:42 +02:00
|
|
|
|
-- The Void below the Nether:
|
2021-02-22 01:15:32 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mapgen_edge_min , mcl_vars.mg_nether_min -1, minp, maxp, lvm_used, pr)
|
2021-02-25 15:36:42 +02:00
|
|
|
|
|
|
|
|
|
-- [[ THE NETHER: mcl_vars.mg_nether_min mcl_vars.mg_nether_max ]]
|
|
|
|
|
|
|
|
|
|
-- The Air on the Nether roof, https://git.minetest.land/MineClone2/MineClone2/issues/1186
|
|
|
|
|
lvm_used = set_layers(data, area, c_air , nil, mcl_vars.mg_nether_max +1, mcl_vars.mg_nether_max + 128 , minp, maxp, lvm_used, pr)
|
|
|
|
|
-- The Void above the Nether below the End:
|
|
|
|
|
lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_nether_max + 128 +1, mcl_vars.mg_end_min -1, minp, maxp, lvm_used, pr)
|
|
|
|
|
|
|
|
|
|
-- [[ THE END: mcl_vars.mg_end_min mcl_vars.mg_end_max ]]
|
|
|
|
|
|
|
|
|
|
-- The Void above the End below the Realm barrier:
|
2021-02-22 01:15:32 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_end_max +1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used, pr)
|
2017-09-06 09:36:01 +03:00
|
|
|
|
-- Realm barrier between the Overworld void and the End
|
2021-02-22 01:15:32 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_realm_barrier, nil, mcl_vars.mg_realm_barrier_overworld_end_min , mcl_vars.mg_realm_barrier_overworld_end_max , minp, maxp, lvm_used, pr)
|
2021-02-25 15:36:42 +02:00
|
|
|
|
-- The Void above Realm barrier below the Overworld:
|
2021-02-22 01:15:32 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_void , nil, mcl_vars.mg_realm_barrier_overworld_end_max+1, mcl_vars.mg_overworld_min -1, minp, maxp, lvm_used, pr)
|
2017-09-06 09:36:01 +03:00
|
|
|
|
|
2021-02-25 15:36:42 +02:00
|
|
|
|
|
2017-11-07 06:29:39 +02:00
|
|
|
|
if mg_name ~= "singlenode" then
|
|
|
|
|
-- Bedrock
|
2021-02-22 01:15:32 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_vars.mg_bedrock_overworld_min, mcl_vars.mg_bedrock_overworld_max, minp, maxp, lvm_used, pr)
|
|
|
|
|
lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_bottom_max, minp, maxp, lvm_used, pr)
|
|
|
|
|
lvm_used = set_layers(data, area, c_bedrock, bedrock_check, mcl_vars.mg_bedrock_nether_top_min, mcl_vars.mg_bedrock_nether_top_max, minp, maxp, lvm_used, pr)
|
2017-09-06 09:36:01 +03:00
|
|
|
|
|
2017-11-07 06:29:39 +02:00
|
|
|
|
-- Flat Nether
|
|
|
|
|
if mg_name == "flat" then
|
2021-02-22 01:15:32 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_air, nil, mcl_vars.mg_flat_nether_floor, mcl_vars.mg_flat_nether_ceiling, minp, maxp, lvm_used, pr)
|
2017-09-06 09:36:01 +03:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-07 06:29:39 +02:00
|
|
|
|
-- Big lava seas by replacing air below a certain height
|
|
|
|
|
if mcl_vars.mg_lava then
|
2021-03-07 04:31:43 +02:00
|
|
|
|
lvm_used = set_layers(data, area, c_lava, c_air, mcl_vars.mg_overworld_min, mcl_vars.mg_lava_overworld_max, minp, maxp, lvm_used, pr)
|
|
|
|
|
lvm_used = set_layers(data, area, c_nether_lava, c_air, mcl_vars.mg_nether_min, mcl_vars.mg_lava_nether_max, minp, maxp, lvm_used, pr)
|
2017-11-07 06:29:39 +02:00
|
|
|
|
end
|
2022-09-10 05:39:49 +03:00
|
|
|
|
end
|
2017-09-06 09:36:01 +03:00
|
|
|
|
|
2022-09-10 05:39:49 +03:00
|
|
|
|
return lvm_used, false
|
|
|
|
|
end
|
2022-05-26 08:29:28 +03:00
|
|
|
|
|
2022-09-10 05:39:49 +03:00
|
|
|
|
local function block_fixes(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
|
|
|
|
|
local biomemap = minetest.get_mapgen_object("biomemap")
|
|
|
|
|
local lvm_used = false
|
|
|
|
|
local pr = PseudoRandom(blockseed)
|
|
|
|
|
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
|
|
|
|
|
-- Set param2 (=color) of sugar cane and grass
|
|
|
|
|
lvm_used = set_palette(minp,maxp,data2,area,biomemap,{"mcl_core:reeds","mcl_core:dirt_with_grass"})
|
|
|
|
|
end
|
|
|
|
|
return lvm_used
|
|
|
|
|
end
|
2017-09-08 01:38:55 +03:00
|
|
|
|
|
2017-09-06 08:10:11 +03:00
|
|
|
|
|
2022-09-10 05:39:49 +03:00
|
|
|
|
-- End block fixes:
|
|
|
|
|
-- * Replace water with end stone or air (depending on height).
|
|
|
|
|
-- * Remove stone, sand, dirt in v6 so our End map generator works in v6.
|
|
|
|
|
-- * Generate spawn platform (End portal destination)
|
|
|
|
|
local function end_basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
|
|
|
|
|
if minp.y < -26912 or maxp.y >= mcl_vars.mg_end_max then return end
|
|
|
|
|
local biomemap --ymin, ymax
|
|
|
|
|
local lvm_used = false
|
|
|
|
|
local pr = PseudoRandom(blockseed)
|
|
|
|
|
local nodes
|
|
|
|
|
if mg_name ~= "v6" then
|
|
|
|
|
nodes = minetest.find_nodes_in_area(emin, emax, {"mcl_core:water_source"})
|
|
|
|
|
if #nodes > 0 then
|
|
|
|
|
lvm_used = true
|
|
|
|
|
for _,n in pairs(nodes) do
|
|
|
|
|
data[area:index(n.x, n.y, n.z)] = c_air
|
2017-11-07 06:29:39 +02:00
|
|
|
|
end
|
2022-09-10 05:39:49 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-09-06 08:10:11 +03:00
|
|
|
|
-- Final hackery: Set sun light level in the End.
|
|
|
|
|
-- -26912 is at a mapchunk border.
|
2022-09-10 05:39:49 +03:00
|
|
|
|
vm:set_lighting({day=15, night=15})
|
|
|
|
|
lvm_used = true
|
|
|
|
|
|
2021-02-22 01:15:32 +02:00
|
|
|
|
local shadow = true
|
2022-09-10 05:39:49 +03:00
|
|
|
|
if emin.y >= mcl_vars.mg_end_min and emax.y <= -26911 then
|
2017-08-22 01:22:53 +03:00
|
|
|
|
shadow = false
|
2017-08-18 14:56:26 +03:00
|
|
|
|
lvm_used = true
|
|
|
|
|
end
|
2021-04-20 07:41:10 +03:00
|
|
|
|
return lvm_used, shadow
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-30 04:40:12 +03:00
|
|
|
|
|
2022-09-10 05:39:49 +03:00
|
|
|
|
mcl_mapgen_core.register_generator("main", basic, nil, 1, true)
|
2022-09-10 22:39:56 +03:00
|
|
|
|
mcl_mapgen_core.register_generator("end_fixes", end_basic, nil, 20, true)
|
2022-09-10 05:39:49 +03:00
|
|
|
|
|
2022-09-10 22:39:56 +03:00
|
|
|
|
if mg_name ~= "v6" then
|
|
|
|
|
mcl_mapgen_core.register_generator("block_fixes", block_fixes, nil, 5, true)
|
|
|
|
|
end
|
2022-06-22 16:56:51 +03:00
|
|
|
|
|
|
|
|
|
mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blockseed)
|
|
|
|
|
local gennotify = minetest.get_mapgen_object("gennotify")
|
2022-06-24 03:11:24 +03:00
|
|
|
|
local has_struct = {}
|
2022-08-30 04:40:12 +03:00
|
|
|
|
local has = false
|
2022-06-24 03:11:24 +03:00
|
|
|
|
local poshash = minetest.hash_node_position(minp)
|
2022-06-22 16:56:51 +03:00
|
|
|
|
for _,struct in pairs(mcl_structures.registered_structures) do
|
2022-09-10 22:39:56 +03:00
|
|
|
|
local pr = PseudoRandom(blockseed + 42)
|
2022-06-24 18:54:34 +03:00
|
|
|
|
if struct.deco_id then
|
|
|
|
|
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
|
|
|
|
|
local realpos = vector.offset(pos,0,1,0)
|
|
|
|
|
minetest.remove_node(realpos)
|
|
|
|
|
if struct.chunk_probability == nil or (not has and pr:next(1,struct.chunk_probability) == 1 ) then
|
2022-07-02 04:44:13 +03:00
|
|
|
|
mcl_structures.place_structure(realpos,struct,pr,blockseed)
|
2022-06-24 18:54:34 +03:00
|
|
|
|
has=true
|
|
|
|
|
end
|
2022-06-24 03:11:24 +03:00
|
|
|
|
end
|
2022-09-10 22:39:56 +03:00
|
|
|
|
elseif struct.static_pos then
|
|
|
|
|
for _,p in pairs(struct.static_pos) do
|
|
|
|
|
if in_cube(p,minp,maxp) then
|
|
|
|
|
mcl_structures.place_structure(p,struct,pr,blockseed)
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-06-22 16:56:51 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end, 100, true)
|
2022-08-30 04:40:12 +03:00
|
|
|
|
|
|
|
|
|
if mg_name == "v6" then
|
|
|
|
|
dofile(modpath.."/v6.lua")
|
|
|
|
|
end
|