forked from LizzyFleckenstein03/Memeclone
Add calculation of mcl_vars.mapgen_edge_min/max in mcl_init and use them for Nether portal fast travelling
This commit is contained in:
parent
4eb42c3a9a
commit
339f7c6359
|
@ -24,6 +24,25 @@ local mg_name = minetest.get_mapgen_setting("mg_name")
|
|||
local minecraft_height_limit = 256
|
||||
local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true"
|
||||
|
||||
-- Calculate mapgen_edge_min/mapgen_edge_max
|
||||
mcl_vars.chunksize = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5)
|
||||
mcl_vars.MAP_BLOCKSIZE = math.max(1, core.MAP_BLOCKSIZE or 16)
|
||||
mcl_vars.mapgen_limit = math.max(1, tonumber(minetest.get_mapgen_setting("mapgen_limit")) or 31000)
|
||||
mcl_vars.MAX_MAP_GENERATION_LIMIT = math.max(1, core.MAX_MAP_GENERATION_LIMIT or 31000)
|
||||
local central_chunk_offset = -math.floor(mcl_vars.chunksize / 2)
|
||||
local chunk_size_in_nodes = mcl_vars.chunksize * mcl_vars.MAP_BLOCKSIZE
|
||||
local central_chunk_min_pos = central_chunk_offset * mcl_vars.MAP_BLOCKSIZE
|
||||
local central_chunk_max_pos = central_chunk_min_pos + chunk_size_in_nodes - 1
|
||||
local ccfmin = central_chunk_min_pos - mcl_vars.MAP_BLOCKSIZE -- Fullminp/fullmaxp of central chunk, in nodes
|
||||
local ccfmax = central_chunk_max_pos + mcl_vars.MAP_BLOCKSIZE
|
||||
local mapgen_limit_b = math.floor(math.min(mcl_vars.mapgen_limit, mcl_vars.MAX_MAP_GENERATION_LIMIT) / mcl_vars.MAP_BLOCKSIZE)
|
||||
local mapgen_limit_min = -mapgen_limit_b * mcl_vars.MAP_BLOCKSIZE
|
||||
local mapgen_limit_max = (mapgen_limit_b + 1) * mcl_vars.MAP_BLOCKSIZE - 1
|
||||
local numcmin = math.max(math.floor((ccfmin - mapgen_limit_min) / chunk_size_in_nodes), 0) -- Number of complete chunks from central chunk
|
||||
local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / chunk_size_in_nodes), 0) -- fullminp/fullmaxp to effective mapgen limits.
|
||||
mcl_vars.mapgen_edge_min = central_chunk_min_pos - numcmin * chunk_size_in_nodes
|
||||
mcl_vars.mapgen_edge_max = central_chunk_max_pos + numcmax * chunk_size_in_nodes
|
||||
|
||||
if not superflat then
|
||||
-- Normal mode
|
||||
--[[ Realm stacking (h is for height)
|
||||
|
|
|
@ -2,6 +2,9 @@ local S = minetest.get_translator("mcl_portals")
|
|||
|
||||
-- Parameters
|
||||
|
||||
local OVERWORLD_TO_NETHER_SCALE = 8
|
||||
local LIMIT = math.min(math.abs(mcl_vars.mapgen_edge_min), math.abs(mcl_vars.mapgen_edge_max))
|
||||
|
||||
-- Portal frame sizes
|
||||
local FRAME_SIZE_X_MIN = 4
|
||||
local FRAME_SIZE_Y_MIN = 5
|
||||
|
@ -46,10 +49,9 @@ local node_particles_allowed_level = node_particles_levels[node_particles_allowe
|
|||
|
||||
-- Functions
|
||||
|
||||
-- https://git.minetest.land/Wuzzy/MineClone2/issues/795#issuecomment-11058
|
||||
-- A bit simplified Nether fast travel ping-pong formula and function by ryvnf:
|
||||
-- Ping-Pong fast travel, https://git.minetest.land/Wuzzy/MineClone2/issues/795#issuecomment-11058
|
||||
local function nether_to_overworld(x)
|
||||
return 30912 - math.abs(((x * 8 + 30912) % 123648) - 61824)
|
||||
return LIMIT - math.abs(((x * OVERWORLD_TO_NETHER_SCALE + LIMIT) % (LIMIT*4)) - (LIMIT*2))
|
||||
end
|
||||
|
||||
-- Destroy portal if pos (portal frame or portal node) got destroyed
|
||||
|
@ -153,10 +155,10 @@ minetest.register_node("mcl_portals:portal", {
|
|||
})
|
||||
|
||||
local function find_target_y(x, y, z, y_min, y_max)
|
||||
local y_org = y
|
||||
local y_org = math.max(math.min(y, y_max), y_min)
|
||||
local node = minetest.get_node_or_nil({x = x, y = y, z = z})
|
||||
if node == nil then
|
||||
return y
|
||||
return y_org
|
||||
end
|
||||
while node.name ~= "air" and y < y_max do
|
||||
y = y + 1
|
||||
|
@ -200,7 +202,7 @@ local function find_target_y(x, y, z, y_min, y_max)
|
|||
if y == y_min then
|
||||
return y_org
|
||||
end
|
||||
return y
|
||||
return math.max(math.min(y, y_max), y_min)
|
||||
end
|
||||
|
||||
local function find_nether_target_y(x, y, z)
|
||||
|
@ -341,8 +343,8 @@ local function nether_portal_get_target_position(src_pos)
|
|||
y_min = overworld_ymin
|
||||
y_max = overworld_ymax
|
||||
else -- overworld:
|
||||
x = math.floor(src_pos.x / 8 + 0.5)
|
||||
z = math.floor(src_pos.z / 8 + 0.5)
|
||||
x = math.floor(src_pos.x / OVERWORLD_TO_NETHER_SCALE + 0.5)
|
||||
z = math.floor(src_pos.z / OVERWORLD_TO_NETHER_SCALE + 0.5)
|
||||
y = math.floor((math.min(math.max(src_pos.y, overworld_ymin), overworld_ymax) - overworld_ymin) / overworld_dy * nether_dy + nether_ymin + 0.5)
|
||||
y_min = nether_ymin
|
||||
y_max = nether_ymax
|
||||
|
|
Loading…
Reference in New Issue