fix perlin noise returns null on some rarte cases as reported in minetest
* i was first checked at https://forum.minetest.net/viewtopic.php?t=8157 as "minetest.get_perlin() and minetest.get_perlin_map() Return nil" by prestidigitator The `minetest.get_perlin()` function returns nil since 0.4.8+ until 5.1.0 The `PerlinNoise()` constructor does return a valid object, on the other hand, barely documented as alternatrive cos is internally used only and not api public cos can only call it after the environment is created, so the code must bne inside `minetest.after(0, ...)` it only works the first time, or must be used an alternative * was reported also https://github.com/minetest/minetest/issues/10385 that does not properly handle large world seeds * Close https://codeberg.org/Wuzzy/minetest_tsm_pyramids/issues/2 * Close https://codeberg.org/minetest-stuffs/minetest-mod-tsm_pyramids/issues/2 * Also uses older get2d vs get_2d for newer engines older pre 5.0.0 as seen on https://github.com/minetest-LOTR/Lord-of-the-Test/issues/139 detect newer engine and uses proper method to get agains perlin object Closes https://codeberg.org/minetest-stuffs/minetest-mod-tsm_pyramids/issues/2
This commit is contained in:
parent
6b53a21c96
commit
762b2d7838
23
init.lua
23
init.lua
@ -38,7 +38,7 @@ local is_50 = minetest.has_feature("object_use_texture_alpha")
|
|||||||
tsm_pyramids = {}
|
tsm_pyramids = {}
|
||||||
tsm_pyramids.is_50 = is_50
|
tsm_pyramids.is_50 = is_50
|
||||||
tsm_pyramids.S = S
|
tsm_pyramids.S = S
|
||||||
tsm_pyramids.perlin1 -- perlin noise buffer, make it global cos we need to acess in 5.0 after load all the rest of mods
|
tsm_pyramids.perlin1 = nil -- perlin noise buffer, make it global cos we need to acess in 5.0 after load all the rest of mods
|
||||||
|
|
||||||
dofile(minetest.get_modpath(modpath).."/mummy.lua")
|
dofile(minetest.get_modpath(modpath).."/mummy.lua")
|
||||||
dofile(minetest.get_modpath(modpath).."/nodes.lua")
|
dofile(minetest.get_modpath(modpath).."/nodes.lua")
|
||||||
@ -273,6 +273,12 @@ local perl1
|
|||||||
-- if mg v6 set this {SEED1 = 9130, OCTA1 = 3, PERS1 = 0.5, SCAL1 = 250} -- Values should match minetest mapgen V6 desert noise.
|
-- if mg v6 set this {SEED1 = 9130, OCTA1 = 3, PERS1 = 0.5, SCAL1 = 250} -- Values should match minetest mapgen V6 desert noise.
|
||||||
perl1 = { SEED1 = 9130, OCTA1 = 1, PERS1 = 0.5, SCAL1 = 25 } -- Values should match minetest mapgen V7 desert noise.
|
perl1 = { SEED1 = 9130, OCTA1 = 1, PERS1 = 0.5, SCAL1 = 25 } -- Values should match minetest mapgen V7 desert noise.
|
||||||
|
|
||||||
|
if tsm_pyramids.is_50 then
|
||||||
|
tsm_pyramids.perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
|
||||||
|
else
|
||||||
|
tsm_pyramids.perlin1 = PerlinNoise(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
|
||||||
|
end
|
||||||
|
|
||||||
local function hlp_fnct(pos, name)
|
local function hlp_fnct(pos, name)
|
||||||
local n = minetest.get_node_or_nil(pos)
|
local n = minetest.get_node_or_nil(pos)
|
||||||
if n and n.name and n.name == name then
|
if n and n.name and n.name == name then
|
||||||
@ -281,6 +287,7 @@ local function hlp_fnct(pos, name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ground(pos, old)
|
local function ground(pos, old)
|
||||||
local p2 = table.copy(pos)
|
local p2 = table.copy(pos)
|
||||||
while hlp_fnct(p2, "air") do
|
while hlp_fnct(p2, "air") do
|
||||||
@ -361,12 +368,18 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
return pos
|
return pos
|
||||||
end
|
end
|
||||||
|
|
||||||
if tsm_pyramids.perlin1 == nil then
|
local noise1 = nil
|
||||||
|
if not tsm_pyramids.perlin1 or tsm_pyramids.perlin1 == nil then
|
||||||
|
if tsm_pyramids.is_50 then
|
||||||
tsm_pyramids.perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
|
tsm_pyramids.perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
|
||||||
|
noise1 = tsm_pyramids.perlin1:get_2d({x=minp.x,y=minp.y})
|
||||||
|
else
|
||||||
|
tsm_pyramids.perlin1 = PerlinNoise(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
|
||||||
|
noise1 = tsm_pyramids.perlin1:get2d({x=minp.x,y=minp.y})
|
||||||
end
|
end
|
||||||
local noise1 = tsm_pyramids.perlin1:get_2d({x=minp.x,y=minp.y})
|
end
|
||||||
if noise1 == nil then
|
|
||||||
minetest.log("warning", "[tsm_pyramids] canot get 2d noise from perlin buffer---------------------------- ")
|
if not tsm_pyramids.perlin1 or tsm_pyramids.perlin1 == nil or not noise1 or noise1 == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user