Skip to content

Commit 4c27370

Browse files
committed
prevent crash when igniting portal
Happens when trying to ignite a portal to the cloudlands, but the cloudlands mod hasn't inited yet because it hasn't needed to generate any islands: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'default' in callback item_OnPlace(): ...\minetest-5 latest\bin\..\mods\cloudlands/cloudlands.lua:591: attempt to index upvalue 'noise_heightMap' (a nil value) stack traceback: ...\minetest-5 latest\bin\..\mods\cloudlands/cloudlands.lua:591: in function 'is_within_realm' ...ble)\minetest-5 latest\bin\..\mods\nether/portal_api.lua:1356: in function 'ignite_portal' ...ble)\minetest-5 latest\bin\..\mods\nether/portal_api.lua:2159: in function <...ble)\minetest-5 latest\bin\..\mods\nether/portal_api.lua:2156>
1 parent 1e14d3e commit 4c27370

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

cloudlands.lua

+32-27
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ interop.split_nodename = function(nodeName)
318318
result_nodename = nodeName:sub(pos + 1)
319319
end
320320
return result_modname, result_nodename
321-
end;
321+
end
322322

323323
-- returns a unique id for the biome, normally this is numeric but with mapgen v6 it can be a string name.
324324
interop.get_biome_key = function(pos)
@@ -381,7 +381,7 @@ end
381381
Portals
382382
==============================]]--
383383

384-
local addDetail_ancientPortal = nil;
384+
local addDetail_ancientPortal = nil
385385

386386
if ENABLE_PORTALS and minetest.get_modpath("nether") ~= nil and minetest.global_exists("nether") and nether.register_portal ~= nil then
387387
-- The Portals API is available
@@ -398,7 +398,7 @@ if ENABLE_PORTALS and minetest.get_modpath("nether") ~= nil and minetest.global_
398398
local coreList = cloudlands.get_island_details(
399399
{x = island_info.x - searchRadius, z = island_info.z - searchRadius},
400400
{x = island_info.x + searchRadius, z = island_info.z + searchRadius}
401-
);
401+
)
402402

403403
-- Deterministically sample the island for a low location that isn't water.
404404
-- Seed the prng so this function always returns the same coords for the island
@@ -486,7 +486,7 @@ if ENABLE_PORTALS and minetest.get_modpath("nether") ~= nil and minetest.global_
486486
clust_num_ores = 6,
487487
clust_size = 3,
488488
y_max = nether.DEPTH_CEILING or nether.DEPTH,
489-
y_min = nether.DEPTH_FLOOR or -32000,
489+
y_min = nether.DEPTH_FLOOR or -32000,
490490
})
491491

492492
local _ = {name = "air", prob = 0}
@@ -499,10 +499,10 @@ if ENABLE_PORTALS and minetest.get_modpath("nether") ~= nil and minetest.global_
499499
deco_type = "schematic",
500500
place_on = "nether:rack",
501501
sidelen = 80,
502-
fill_ratio = 0.0002,
502+
fill_ratio = 0.00018,
503503
biomes = {"nether_caverns"},
504504
y_max = nether.DEPTH_CEILING or nether.DEPTH,
505-
y_min = nether.DEPTH_FLOOR or -32000,
505+
y_min = nether.DEPTH_FLOOR or -32000,
506506
schematic = {
507507
size = {x = 4, y = 4, z = 1},
508508
data = {
@@ -587,8 +587,10 @@ if ENABLE_PORTALS and minetest.get_modpath("nether") ~= nil and minetest.global_
587587
-- return true if pos is in the cloudlands
588588
-- I'm doing this based off height for speed, so it sometimes gets it wrong when the
589589
-- Hallelujah mountains start reaching the ground.
590+
if noise_heightMap == nil then cloudlands.init() end
590591
local largestCoreType = cloudlands.coreTypes[1] -- the first island type is the biggest/thickest
591592
local island_bottom = ALTITUDE - (largestCoreType.depthMax * 0.66) + round(noise_heightMap:get2d({x = pos.x, y = pos.z}))
593+
592594
return pos.y > math_max(40, island_bottom)
593595
end,
594596

@@ -669,7 +671,7 @@ if ENABLE_PORTALS and minetest.get_modpath("nether") ~= nil and minetest.global_
669671

670672
minetest.add_particlespawner(particleSpawnerDef)
671673

672-
velocity = vector.multiply(velocity, -1);
674+
velocity = vector.multiply(velocity, -1)
673675
particleSpawnerDef.minvel, particleSpawnerDef.maxvel = velocity, velocity
674676
minetest.add_particlespawner(particleSpawnerDef)
675677
end
@@ -1145,7 +1147,7 @@ if not minetest.global_exists("SkyTrees") then -- If SkyTrees added into other m
11451147

11461148
-- returns a new position vector, rotated around (0, 0) to match the schematic rotation (provided the schematic_size is correct!)
11471149
local function rotatePositon(position, schematic_size, rotation)
1148-
local result = vector.new(position);
1150+
local result = vector.new(position)
11491151
if rotation == 90 then
11501152
result.x = position.z
11511153
result.z = schematic_size.x - position.x - 1
@@ -1159,7 +1161,7 @@ if not minetest.global_exists("SkyTrees") then -- If SkyTrees added into other m
11591161
return result
11601162
end
11611163

1162-
local rotatedCenter = rotatePositon(schematicInfo.center, schematicInfo.size, rotation);
1164+
local rotatedCenter = rotatePositon(schematicInfo.center, schematicInfo.size, rotation)
11631165
local treePos = vector.subtract(position, rotatedCenter)
11641166

11651167
if themeName == nil then themeName = SkyTrees.selectTheme(position, schematicInfo) end
@@ -1211,7 +1213,7 @@ if not minetest.global_exists("SkyTrees") then -- If SkyTrees added into other m
12111213
plan_obj:read_from_schem_file(filename, replacements)
12121214
plan_obj.data.ground_y = -1 -- prevent read_from_schem_file() from automatically adjusting the height when it encounters dirt in the schematic (SkyTrees sometimes have dirt up in their nooks)
12131215
plan_obj.data.facedir = round(rotation / 90)
1214-
rotatedCenter = plan_obj:get_world_pos(vector.add(vector.multiply(schematicInfo.center, -1), -1), position); -- this function performs the rotation I require, even if it's named/intended for something else.
1216+
rotatedCenter = plan_obj:get_world_pos(vector.add(vector.multiply(schematicInfo.center, -1), -1), position) -- this function performs the rotation I require, even if it's named/intended for something else.
12151217
plan_obj.data.anchor_pos = rotatedCenter
12161218

12171219
if DEBUG_SKYTREES then minetest.log("info", "building tree at " .. dump(position) .. "rotated to " .. dump(treePos) .. "rotatedCenter " .. dump(rotatedCenter) .. ", " .. schematicInfo.filename) end
@@ -1253,7 +1255,7 @@ if not minetest.global_exists("SkyTrees") then -- If SkyTrees added into other m
12531255

12541256
end
12551257

1256-
SkyTrees.init();
1258+
SkyTrees.init()
12571259

12581260

12591261
--[[==============================
@@ -1280,7 +1282,7 @@ local function init_mapgen()
12801282
biomes["Taiga"] = {node_top="mapgen_dirt_with_snow", node_filler="mapgen_dirt", node_stone="mapgen_stone"}
12811283
else
12821284
for k,v in pairs(minetest.registered_biomes) do
1283-
biomes[minetest.get_biome_id(k)] = v;
1285+
biomes[minetest.get_biome_id(k)] = v
12841286
end
12851287
end
12861288
if DEBUG then minetest.log("info", "registered biomes: " .. dump(biomes)) end
@@ -1328,7 +1330,7 @@ local function addCores(coreList, coreType, x1, z1, x2, z2)
13281330

13291331
-- this function is used by the API functions, so may be invoked without our on_generated
13301332
-- being called
1331-
cloudlands.init();
1333+
cloudlands.init()
13321334

13331335
for z = math_floor(z1 / coreType.territorySize), math_floor(z2 / coreType.territorySize) do
13341336
for x = math_floor(x1 / coreType.territorySize), math_floor(x2 / coreType.territorySize) do
@@ -1401,12 +1403,12 @@ local function addCores(coreList, coreType, x1, z1, x2, z2)
14011403
break
14021404
end
14031405
end
1404-
end;
1406+
end
14051407
end
14061408

14071409
if spaceConditionMet then
14081410
-- all conditions met, we've located a new island core
1409-
--minetest.log("Adding core "..x..","..y..","..z..","..radius);
1411+
--minetest.log("Adding core "..x..","..y..","..z..","..radius)
14101412
local y = round(noise_heightMap:get2d({x = coreX, y = coreZ}))
14111413
local newCore = {
14121414
x = coreX,
@@ -1493,7 +1495,7 @@ cloudlands.get_island_details = function(minp, maxp)
14931495
-- settings from rearranging islands.
14941496
if region_restrictions then removeUnwantedIslands(result) end
14951497

1496-
return result;
1498+
return result
14971499
end
14981500

14991501

@@ -1527,7 +1529,7 @@ cloudlands.find_nearest_island = function(x, z, search_radius)
15271529
if result == nil or core.distance < result.distance then result = core end
15281530
end
15291531

1530-
return result;
1532+
return result
15311533
end
15321534

15331535

@@ -1536,7 +1538,7 @@ end
15361538
-- having to recalculate it during each call to get_height_at().
15371539
cloudlands.get_height_at = function(x, z, coreList)
15381540

1539-
local result, isWater = nil, false;
1541+
local result, isWater = nil, false
15401542

15411543
if coreList == nil then
15421544
local pos = {x = x, z = z}
@@ -1927,7 +1929,7 @@ local function addDetail_skyTree(decoration_list, core, minp, maxp)
19271929
end
19281930
end
19291931

1930-
local maxOffsetFromCenter = core.radius - (tree.requiredIslandRadius - 4); -- 4 is an arbitrary number, to allow trees to get closer to the edge
1932+
local maxOffsetFromCenter = core.radius - (tree.requiredIslandRadius - 4) -- 4 is an arbitrary number, to allow trees to get closer to the edge
19311933

19321934
-- Use a known PRNG implementation
19331935
local prng = PcgRandom(
@@ -1973,7 +1975,7 @@ local function addDetail_skyTree(decoration_list, core, minp, maxp)
19731975
if DEBUG_SKYTREES then minetest.log("info", "core x: "..coreX.." y: ".. coreZ .. " treePos: " .. treePos.x .. ", y: " .. treePos.y) end
19741976

19751977
SkyTrees.placeTree(treePos, treeAngle, tree, nil, core.biome.node_top)
1976-
return true;
1978+
return true
19771979
end
19781980

19791981

@@ -2676,7 +2678,7 @@ local function renderCores(cores, minp, maxp, blockseed)
26762678
if DEBUG_GEOMETRIC then surfaceNoise = SURFACEMAP_OFFSET end
26772679
local surface = round(surfaceNoise * 3 * (core.thickness + 1) * horz_easing) -- if you change this formular then update maxSufaceRise in on_generated()
26782680
local coreBottom = math_floor(coreTop - (core.thickness + core.depth))
2679-
local noisyDepthOfFiller = depth_filler;
2681+
local noisyDepthOfFiller = depth_filler
26802682
if noisyDepthOfFiller >= 3 then noisyDepthOfFiller = noisyDepthOfFiller + math_floor(randomNumbers[(x + z) % 256] * 3) - 1 end
26812683

26822684
local yBottom = math_max(minp.y, coreBottom - 4) -- the -4 is for rare instances when density noise pushes the bottom of the island deeper
@@ -2713,7 +2715,7 @@ local function renderCores(cores, minp, maxp, blockseed)
27132715
-- ensure nodeId_top blocks also cover the rounded sides of islands (which may be lower
27142716
-- than the flat top), then dust the top surface.
27152717
if topBlockIndex >= 0 then
2716-
voxelsWereManipulated = true;
2718+
voxelsWereManipulated = true
27172719

27182720
-- we either have the highest block, or overdrawTop - but we don't want to set overdrawTop nodes to nodeId_top
27192721
-- (we will err on the side of caution when we can't distinguish the top of a island's side from overdrawTop)
@@ -2775,10 +2777,10 @@ local function renderCores(cores, minp, maxp, blockseed)
27752777
else
27762778
data[vi] = nodeId_filler
27772779
end
2778-
end;
2780+
end
27792781
end
27802782
end
2781-
end;
2783+
end
27822784

27832785
end
27842786
end
@@ -2897,6 +2899,10 @@ cloudlands.init = function()
28972899
init_mapgen()
28982900
init_secrets()
28992901
end
2902+
if noise_eddyField == nil then
2903+
-- See comment in init_mapgen() about when this can be called
2904+
minetest.log("warning", "cloudlands.init() unable to init - was probably invoked before the the environment was created")
2905+
end
29002906
end
29012907

29022908
local function on_generated(minp, maxp, blockseed)
@@ -2916,13 +2922,12 @@ local function on_generated(minp, maxp, blockseed)
29162922
return
29172923
end
29182924

2919-
cloudlands.init();
29202925
local cores = cloudlands.get_island_details(minp, maxp)
29212926

29222927
if DEBUG then
29232928
minetest.log("info", "Cores for on_generated(): " .. #cores)
29242929
for _,core in pairs(cores) do
2925-
minetest.log("core ("..core.x..","..core.y..","..core.z..") r"..core.radius);
2930+
minetest.log("core ("..core.x..","..core.y..","..core.z..") r"..core.radius)
29262931
end
29272932
end
29282933

@@ -2951,4 +2956,4 @@ minetest.register_on_mapgen_init(
29512956
worldSeed = mgparams.seed
29522957
--if DEBUG then minetest.set_mapgen_params({mgname = "singlenode"--[[, flags = "nolight"]]}) end
29532958
end
2954-
)
2959+
)

0 commit comments

Comments
 (0)