Fix chunk offset for building arrival Nether portal, log generating chunk coordinates

This commit is contained in:
kay27 2021-03-17 17:49:14 +04:00 committed by Nils Dagsson Moskopp
parent 0eda8b4d0a
commit cb71d0a4c2
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
3 changed files with 11 additions and 6 deletions

View File

@ -33,6 +33,7 @@ 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)
mcl_vars.central_chunk_offset_in_nodes = central_chunk_offset * mcl_vars.MAP_BLOCKSIZE
mcl_vars.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 + mcl_vars.chunk_size_in_nodes - 1

View File

@ -51,9 +51,9 @@ minetest.register_on_shutdown(function()
storage:set_string("nether_exits", minetest.serialize(exits))
end)
local get_node = function(pos)
mcl_portals.get_node = function(pos)
if mcl_mapgen_core and mcl_mapgen_core.get_node then
get_node = mcl_mapgen_core.get_node
mcl_portals.get_node = mcl_mapgen_core.get_node
end
return minetest.get_node(pos)
end
@ -73,6 +73,7 @@ local limits = {
-- 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.
local function add_exit(p)
local get_node = mcl_portals.get_node
if not p or not p.y or not p.z or not p.x then return end
local x, y, z = floor(p.x), floor(p.y), floor(p.z)
local p = {x = x, y = y, z = z}
@ -176,6 +177,7 @@ local function destroy_nether_portal(pos, node)
local nn, orientation = node.name, node.param2
local obsidian = nn == OBSIDIAN
local get_node = mcl_portals.get_node
local check_remove = function(pos, orientation)
local node = get_node(pos)
if node and (node.name == PORTAL and (orientation == nil or (node.param2 == orientation))) then
@ -297,6 +299,7 @@ function build_nether_portal(pos, width, height, orientation, name)
pos = light_frame(pos.x, pos.y, pos.z, pos.x + (1 - orientation) * (width - 1), pos.y + height - 1, pos.z + orientation * (width - 1))
local get_node = mcl_portals.get_node
-- Build obsidian platform:
for x = pos.x - orientation, pos.x + orientation + (width - 1) * (1 - orientation), 1 + orientation do
for z = pos.z - 1 + orientation, pos.z + 1 - orientation + (width - 1) * orientation, 2 - orientation do
@ -345,7 +348,7 @@ local function finalize_teleport(obj, exit)
-- If player stands, player is at ca. something+0.5 which might cause precision problems, so we used ceil for objpos.y
objpos = {x = floor(objpos.x+0.5), y = ceil(objpos.y), z = floor(objpos.z+0.5)}
if get_node(objpos).name ~= PORTAL then return end
if mcl_portals.get_node(objpos).name ~= PORTAL then return end
-- Enable teleportation cooloff for some seconds, to prevent back-and-forth teleportation
teleport_cooloff(obj)
@ -431,7 +434,7 @@ local function create_portal(pos, limit1, limit2, name, obj)
-- we need to emerge the area here, but currently (mt5.4/mcl20.71) map generation is slow
-- so we'll emerge single chunk only: 5x5x5 blocks, 80x80x80 nodes maximum
local pos1 = mul(mcl_vars.pos_to_chunk(pos), mcl_vars.chunk_size_in_nodes)
local pos1 = sub(mul(mcl_vars.pos_to_chunk(pos), mcl_vars.chunk_size_in_nodes), mcl_vars.central_chunk_offset_in_nodes)
local pos2 = add(pos1, mcl_vars.chunk_size_in_nodes - 1)
if limit1 and limit1.x and limit1.y and limit1.z then
@ -445,7 +448,7 @@ local function create_portal(pos, limit1, limit2, name, obj)
end
local function available_for_nether_portal(p)
local nn = get_node(p).name
local nn = mcl_portals.get_node(p).name
local obsidian = nn == OBSIDIAN
if nn ~= "air" and minetest.get_item_group(nn, "fire") ~= 1 then
return false, obsidian
@ -547,7 +550,7 @@ local function teleport_no_delay(obj, pos)
-- If player stands, player is at ca. something+0.5 which might cause precision problems, so we used ceil for objpos.y
objpos = {x = floor(objpos.x+0.5), y = ceil(objpos.y), z = floor(objpos.z+0.5)}
if get_node(objpos).name ~= PORTAL then return end
if mcl_portals.get_node(objpos).name ~= PORTAL then return end
local target, dim = get_target(objpos)
if not target then return end

View File

@ -1847,6 +1847,7 @@ local generate_nether_decorations = function(minp, maxp, seed)
end
minetest.register_on_generated(function(minp, maxp, blockseed)
minetest.log("action", "[mcl_mapgen_core] Generating chunk " .. minetest.pos_to_string(minp) .. " ... " .. minetest.pos_to_string(maxp))
add_chunk(minp)
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