forked from MineClone5/MineClone5
add callbacks mapgen mods can use to alter locally-saved copies of settings, reveal register_on_generated
This commit is contained in:
parent
4ade7dc769
commit
ae60960a00
|
@ -394,8 +394,6 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
|
|||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_generated = mcl_mapgen.register_chunk_generator
|
||||
|
||||
function mcl_mapgen.get_far_node(p)
|
||||
local p = p
|
||||
local node = minetest_get_node(p)
|
||||
|
@ -440,6 +438,21 @@ function mcl_mapgen.get_chunk_number(pos) -- unsigned int
|
|||
c.x + k_positive
|
||||
end
|
||||
|
||||
-- Components of this game should register functions here to update their internal
|
||||
-- state when external mods modify mapgen settings that they care about.
|
||||
local settings_changed_callbacks = {}
|
||||
function mcl_mapgen.register_on_settings_changed(callback)
|
||||
table.insert(settings_changed_callbacks, callback)
|
||||
end
|
||||
|
||||
-- this is to be called by external mods after modifying these settings
|
||||
-- to notify Mineclone that it needs to update local copies and whatever's based on them.
|
||||
function mcl_mapgen.on_settings_changed()
|
||||
for _, callback in pairs(settings_changed_callbacks) do
|
||||
callback()
|
||||
end
|
||||
end
|
||||
|
||||
mcl_mapgen.minecraft_height_limit = 256
|
||||
|
||||
mcl_mapgen.bedrock_is_rough = normal
|
||||
|
|
|
@ -2,11 +2,18 @@ mcl_worlds = {}
|
|||
|
||||
local get_connected_players = minetest.get_connected_players
|
||||
|
||||
local min1, min2, min3
|
||||
local max1, max2, max3
|
||||
local get_local_settings = function()
|
||||
min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min
|
||||
max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max+128
|
||||
end
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
-- For a given position, returns a 2-tuple:
|
||||
-- 1st return value: true if pos is in void
|
||||
-- 2nd return value: true if it is in the deadly part of the void
|
||||
local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min
|
||||
local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max+128
|
||||
function mcl_worlds.is_in_void(pos)
|
||||
local y = pos.y
|
||||
local void = not ((y < max1 and y > min1) or (y < max2 and y > min2) or (y < max3 and y > min3))
|
||||
|
|
|
@ -229,19 +229,23 @@ mobs_mc.override.spawn = {
|
|||
}
|
||||
|
||||
-- This table contains important spawn height references for the mob spawn height.
|
||||
mobs_mc.override.spawn_height = {
|
||||
water = tonumber(minetest.settings:get("water_level")) or 0, -- Water level in the Overworld
|
||||
|
||||
-- Overworld boundaries (inclusive)
|
||||
overworld_min = mcl_mapgen.overworld.min,
|
||||
overworld_max = mcl_mapgen.overworld.max,
|
||||
|
||||
-- Nether boundaries (inclusive)
|
||||
nether_min = mcl_mapgen.nether.min,
|
||||
nether_max = mcl_mapgen.nether.max,
|
||||
|
||||
-- End boundaries (inclusive)
|
||||
end_min = mcl_mapgen.end_.min,
|
||||
end_max = mcl_mapgen.end_.max,
|
||||
}
|
||||
local get_local_settings = function()
|
||||
mobs_mc.override.spawn_height = {
|
||||
water = tonumber(minetest.settings:get("water_level")) or 0, -- Water level in the Overworld
|
||||
|
||||
-- Overworld boundaries (inclusive)
|
||||
overworld_min = mcl_mapgen.overworld.min,
|
||||
overworld_max = mcl_mapgen.overworld.max,
|
||||
|
||||
-- Nether boundaries (inclusive)
|
||||
nether_min = mcl_mapgen.nether.min,
|
||||
nether_max = mcl_mapgen.nether.max,
|
||||
|
||||
-- End boundaries (inclusive)
|
||||
end_min = mcl_mapgen.end_.min,
|
||||
end_max = mcl_mapgen.end_.max,
|
||||
}
|
||||
end
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
|
|
|
@ -12,9 +12,17 @@ local floor = math.floor
|
|||
local minetest_get_gametime = minetest.get_gametime
|
||||
local get_voxel_manip = minetest.get_voxel_manip
|
||||
|
||||
local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min
|
||||
local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max + 128
|
||||
local CS = mcl_mapgen.CS_NODES
|
||||
local min1, min2, min3
|
||||
local max1, max2, max3
|
||||
local CS
|
||||
|
||||
local get_local_settings = function()
|
||||
min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min
|
||||
max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max+128
|
||||
CS = mcl_mapgen.CS_NODES
|
||||
end
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
|
|
|
@ -27,8 +27,34 @@ local DELAY = 3 -- seconds before teleporting in Nether portal in Survival mo
|
|||
local DISTANCE_MAX = 128
|
||||
local PORTAL = "mcl_portals:portal"
|
||||
local OBSIDIAN = "mcl_core:obsidian"
|
||||
local O_Y_MIN, O_Y_MAX = max(mcl_mapgen.overworld.min, -31), min(mcl_mapgen.overworld.max, 2048)
|
||||
local N_Y_MIN, N_Y_MAX = mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_top_min - H_MIN
|
||||
local O_Y_MIN, O_Y_MAX
|
||||
local N_Y_MIN, N_Y_MAX
|
||||
|
||||
local overworld_lava_max
|
||||
local nether_lava_max
|
||||
local overworld_min
|
||||
local limits
|
||||
|
||||
local get_local_settings = function()
|
||||
O_Y_MIN, O_Y_MAX = max(mcl_mapgen.overworld.min, -31), min(mcl_mapgen.overworld.max, 2048)
|
||||
N_Y_MIN, N_Y_MAX = mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_top_min - H_MIN
|
||||
overworld_min = mcl_mapgen.overworld.min
|
||||
overworld_lava_max = mcl_mapgen.overworld.lava_max
|
||||
nether_lava_max = mcl_mapgen.nether.lava_max
|
||||
|
||||
limits = {
|
||||
nether = {
|
||||
pmin = {x=LIM_MIN, y = N_Y_MIN, z = LIM_MIN},
|
||||
pmax = {x=LIM_MAX, y = N_Y_MAX, z = LIM_MAX},
|
||||
},
|
||||
overworld = {
|
||||
pmin = {x=LIM_MIN, y = O_Y_MIN, z = LIM_MIN},
|
||||
pmax = {x=LIM_MAX, y = O_Y_MAX, z = LIM_MAX},
|
||||
},
|
||||
}
|
||||
end
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
-- Alpha and particles
|
||||
local node_particles_allowed = minetest.settings:get("mcl_node_particles") or "none"
|
||||
|
@ -79,17 +105,6 @@ local get_us_time = minetest.get_us_time
|
|||
|
||||
local dimension_to_teleport = { nether = "overworld", overworld = "nether" }
|
||||
|
||||
local limits = {
|
||||
nether = {
|
||||
pmin = {x=LIM_MIN, y = N_Y_MIN, z = LIM_MIN},
|
||||
pmax = {x=LIM_MAX, y = N_Y_MAX, z = LIM_MAX},
|
||||
},
|
||||
overworld = {
|
||||
pmin = {x=LIM_MIN, y = O_Y_MIN, z = LIM_MIN},
|
||||
pmax = {x=LIM_MAX, y = O_Y_MAX, z = LIM_MAX},
|
||||
},
|
||||
}
|
||||
|
||||
-- This function registers exits from Nether portals.
|
||||
-- Incoming verification performed: two nodes must be portal nodes, and an obsidian below them.
|
||||
-- If the verification passes - position adds to the table and saves to mod storage on exit.
|
||||
|
@ -164,7 +179,7 @@ local function find_exit(p, dx, dy, dz)
|
|||
end
|
||||
end
|
||||
|
||||
-- This functon searches Nether portal nodes whitin distance specified and checks the node
|
||||
-- This function searches Nether portal nodes within distance specified and checks the node
|
||||
local function find_exit_with_check(p, dx, dy, dz)
|
||||
while true do
|
||||
local pos = find_exit(p, dx, dy, dz)
|
||||
|
@ -181,7 +196,7 @@ local function find_exit_with_check(p, dx, dy, dz)
|
|||
end
|
||||
end
|
||||
|
||||
-- Ping-Pong the coordinate for Fast Travelling, https://git.minetest.land/Wuzzy/MineClone2/issues/795#issuecomment-11058
|
||||
-- Ping-Pong the coordinate for Fast Traveling, https://git.minetest.land/Wuzzy/MineClone2/issues/795#issuecomment-11058
|
||||
local function ping_pong(x, m, l1, l2)
|
||||
if x < 0 then
|
||||
return l1 + abs(((x*m+l1) % (l1*4)) - (l1*2)), floor(x*m/l1/2) + ((ceil(x*m/l1)+1)%2) * ((x*m)%l1)/l1
|
||||
|
@ -421,9 +436,9 @@ end
|
|||
|
||||
local function get_lava_level(pos, pos1, pos2)
|
||||
if pos.y > -1000 then
|
||||
return max(min(mcl_mapgen.overworld.lava_max, pos2.y-1), pos1.y+1)
|
||||
return max(min(overworld_lava_max, pos2.y-1), pos1.y+1)
|
||||
end
|
||||
return max(min(mcl_mapgen.nether.lava_max, pos2.y-1), pos1.y+1)
|
||||
return max(min(nether_lava_max, pos2.y-1), pos1.y+1)
|
||||
end
|
||||
|
||||
local function ecb_scan_area_2(blockpos, action, calls_remaining, param)
|
||||
|
@ -746,7 +761,7 @@ minetest.register_abm({
|
|||
return
|
||||
end
|
||||
|
||||
if lower_node_name == OBSIDIAN and pos.y >= mcl_mapgen.overworld.min and random(1, 750) == 19 then
|
||||
if lower_node_name == OBSIDIAN and pos.y >= overworld_min and random(1, 750) == 19 then
|
||||
local pigman_obj = minetest.add_entity(pos, "mobs_mc:pigman")
|
||||
if pigman_obj then
|
||||
teleport_cooloff(pigman_obj)
|
||||
|
|
|
@ -32,9 +32,16 @@ local math_ceil = math.ceil
|
|||
--custom mcl_vars
|
||||
local get_node = mcl_mapgen.get_far_node
|
||||
|
||||
local min_y
|
||||
local max_y
|
||||
|
||||
local get_local_settings = function()
|
||||
min_y = math_max(mcl_mapgen.overworld.min, mcl_mapgen.overworld.bedrock_max) + 1
|
||||
max_y = mcl_mapgen.overworld.max - 1
|
||||
end
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
local min_y = math_max(mcl_mapgen.overworld.min, mcl_mapgen.overworld.bedrock_max) + 1
|
||||
local max_y = mcl_mapgen.overworld.max - 1
|
||||
-- Calculate the number of dungeon spawn attempts
|
||||
-- In Minecraft, there 8 dungeon spawn attempts Minecraft chunk (16*256*16 = 65536 blocks).
|
||||
-- Minetest chunks don't have this size, so scale the number accordingly.
|
||||
|
|
|
@ -1214,25 +1214,34 @@ if flat then
|
|||
air_layers[#air_layers + 1] = {mcl_mapgen.nether.flat_floor, mcl_mapgen.nether.flat_ceiling} -- Flat Nether
|
||||
end
|
||||
|
||||
-- Realm barrier between the Overworld void and the End
|
||||
local barrier_min = mcl_mapgen.realm_barrier_overworld_end_min
|
||||
local barrier_max = mcl_mapgen.realm_barrier_overworld_end_max
|
||||
local barrier_min
|
||||
local barrier_max
|
||||
local void_layers
|
||||
local bedrock_layers
|
||||
|
||||
local void_layers = {
|
||||
{mcl_mapgen.EDGE_MIN , mcl_mapgen.nether.min - 1 }, -- below Nether
|
||||
{mcl_mapgen.nether.max + 129, mcl_mapgen.end_.min - 1 }, -- below End (above Nether)
|
||||
{mcl_mapgen.end_.max + 1 , barrier_min - 1 }, -- below Realm Barrier, above End
|
||||
{barrier_max + 1 , mcl_mapgen.overworld.min - 1}, -- below Overworld, above Realm Barrier
|
||||
}
|
||||
local get_local_settings = function()
|
||||
-- Realm barrier between the Overworld void and the End
|
||||
barrier_min = mcl_mapgen.realm_barrier_overworld_end_min
|
||||
barrier_max = mcl_mapgen.realm_barrier_overworld_end_max
|
||||
|
||||
local bedrock_layers = {}
|
||||
if not singlenode then
|
||||
bedrock_layers = {
|
||||
{mcl_mapgen.overworld.bedrock_min , mcl_mapgen.overworld.bedrock_max },
|
||||
{mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_bottom_max},
|
||||
{mcl_mapgen.nether.bedrock_top_min , mcl_mapgen.nether.bedrock_top_max },
|
||||
void_layers = {
|
||||
{mcl_mapgen.EDGE_MIN , mcl_mapgen.nether.min - 1 }, -- below Nether
|
||||
{mcl_mapgen.nether.max + 129, mcl_mapgen.end_.min - 1 }, -- below End (above Nether)
|
||||
{mcl_mapgen.end_.max + 1 , barrier_min - 1 }, -- below Realm Barrier, above End
|
||||
{barrier_max + 1 , mcl_mapgen.overworld.min - 1}, -- below Overworld, above Realm Barrier
|
||||
}
|
||||
|
||||
bedrock_layers = {}
|
||||
if not singlenode then
|
||||
bedrock_layers = {
|
||||
{mcl_mapgen.overworld.bedrock_min , mcl_mapgen.overworld.bedrock_max },
|
||||
{mcl_mapgen.nether.bedrock_bottom_min, mcl_mapgen.nether.bedrock_bottom_max},
|
||||
{mcl_mapgen.nether.bedrock_top_min , mcl_mapgen.nether.bedrock_top_max },
|
||||
}
|
||||
end
|
||||
end
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
mcl_mapgen.register_mapgen_block_lvm(function(vm_context)
|
||||
local vm, data, area, minp, maxp, chunkseed, blockseed = vm_context.vm, vm_context.data, vm_context.area, vm_context.minp, vm_context.maxp, vm_context.chunkseed, vm_context.blockseed
|
||||
|
|
|
@ -94,13 +94,17 @@ if setting then
|
|||
end
|
||||
|
||||
-- Max. and min. heights between rail corridors are generated
|
||||
local height_min
|
||||
if mcl_mapgen.lava then
|
||||
height_min = mcl_mapgen.overworld.lava_max + 2
|
||||
else
|
||||
height_min = mcl_mapgen.overworld.bedrock_max + 2
|
||||
local height_min, height_max
|
||||
local get_local_settings = function()
|
||||
if mcl_mapgen.lava then
|
||||
height_min = mcl_mapgen.overworld.lava_max + 2
|
||||
else
|
||||
height_min = mcl_mapgen.overworld.bedrock_max + 2
|
||||
end
|
||||
height_max = mcl_worlds.layer_to_y(60)
|
||||
end
|
||||
local height_max = mcl_worlds.layer_to_y(60)
|
||||
get_local_settings()
|
||||
mcl_mapgen.register_on_settings_changed(get_local_settings)
|
||||
|
||||
-- Chaos Mode: If enabled, rail corridors don't stop generating when hitting obstacles
|
||||
local chaos_mode = minetest.settings:get_bool("tsm_railcorridors_chaos") or false
|
||||
|
|
Loading…
Reference in New Issue