Compare commits

...

3 Commits

Author SHA1 Message Date
4297ae029d Fixed a crash due to vague or illogical comparisons for mummies
* seems the mummy is a mob, and `get_objects_inside_radius` also
  gets players, dropped items, etc... cos this function checks
  for all loaded entities on the server, so you'll need to check
  for that mummy around if those objects are only mobs, or not mobs
  or players or nodes.. this check is not made by upstream stupid developer,
  he just said "works for me"! and close the issue
* that function may returns nil/null if the name of the object is
  not EXACT the same, as made `if lua.name == "tsm_pyramids:mummy_spawmer"`
  then that the name could fails in rare cases becouse is used as index
  also the comparison is made with same olbject that seems
  do not have much effect
* The error of a nul vector is related only to the engine!
* Closes https://codeberg.org/minetest-stuffs/minetest-mod-tsm_pyramids/issues/4
* Closes https://github.com/EdenLostMinetest/tsm_pyramids/issues/1
* Closes https://codeberg.org/Wuzzy/minetest_tsm_pyramids/issues/4
2024-04-29 10:35:00 -04:00
2c9ea6faca workaround for bulk_set_node newer implementations on onder engines
* the `bulk_set_node` seems the function is since minetest 5.0 but
  it seems does not show in the git-shit-hub search, so found it
  manually at 584d00a01c
  that is only an optimized bulk way of `set_node` using a list of positions
  now with this pyramids will work in older versions of minetest too
* Closes https://codeberg.org/minetest-stuffs/minetest-mod-tsm_pyramids/issues/5
* incorporate a detection of 5.4+ versions of engine
2024-04-29 10:29:47 -04:00
762b2d7838 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
2024-04-29 10:17:25 -04:00
3 changed files with 67 additions and 17 deletions

View File

@ -34,11 +34,14 @@ local PYRA_MIN_Y = 1
local PYRA_MAX_Y = 1000 local PYRA_MAX_Y = 1000
-- minetest 5.x check -- minetest 5.x check
local is_50 = minetest.has_feature("object_use_texture_alpha") local is_50 = minetest.has_feature("object_use_texture_alpha")
-- minetest 5.5 check
local is_54 = minetest.has_feature("use_texture_alpha_string_modes") or nil
tsm_pyramids = {} tsm_pyramids = {}
tsm_pyramids.is_50 = is_50 tsm_pyramids.is_50 = is_50
tsm_pyramids.is_54 = is_54
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")
@ -220,6 +223,17 @@ local function make_entrance(pos, rot, brick, sand, flood_sand)
end end
end end
local wa_bulk_set_node
if not minetest.bulk_set_node then
wa_bulk_set_node = function(poslist, nodename)
for _, pos in ipairs(poslist) do
minetest.set_node(pos, nodename)
end
end
else
wa_bulk_set_node = minetest.bulk_set_node
end
local function make_pyramid(pos, brick, sandstone, stone, sand) local function make_pyramid(pos, brick, sandstone, stone, sand)
local set_to_brick = {} local set_to_brick = {}
local set_to_stone = {} local set_to_stone = {}
@ -234,8 +248,8 @@ local function make_pyramid(pos, brick, sandstone, stone, sand)
end end
end end
end end
minetest.bulk_set_node(set_to_stone , {name=stone}) wa_bulk_set_node(set_to_stone, {name=stone})
minetest.bulk_set_node(set_to_brick, {name=brick}) wa_bulk_set_node(set_to_brick, {name=brick})
end end
local function make(pos, brick, sandstone, stone, sand, ptype, room_id) local function make(pos, brick, sandstone, stone, sand, ptype, room_id)
@ -270,9 +284,15 @@ local function make(pos, brick, sandstone, stone, sand, ptype, room_id)
end end
local perl1 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 +301,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 +382,18 @@ minetest.register_on_generated(function(minp, maxp, seed)
return pos return pos
end end
if tsm_pyramids.perlin1 == nil then local noise1 = nil
tsm_pyramids.perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1) 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)
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 end
local noise1 = tsm_pyramids.perlin1:get_2d({x=minp.x,y=minp.y})
if noise1 == nil then if not tsm_pyramids.perlin1 or tsm_pyramids.perlin1 == nil or not noise1 or noise1 == nil then
minetest.log("warning", "[tsm_pyramids] canot get 2d noise from perlin buffer---------------------------- ")
return return
end end

View File

@ -101,17 +101,36 @@ local MUMMY_DEF = {
} }
-- Returns true if a mummy spawner entity was found at pos. -- Returns true if a mummy spawner entity was found at pos.
-- If self is provided, this object does not count. -- If self is provided, upstream pointed that is not count but must be checked if are the same
local function check_if_mummy_spawner_entity_exists(pos, self) local function check_if_mummy_spawner_entity_exists(pos, self)
local ents = minetest.get_objects_inside_radius(pos, 0.5) local ents = minetest.get_objects_inside_radius(pos, 0.5)
if not ents then return false end
for e=1, #ents do for e=1, #ents do
if (not self) or (ents[e] ~= ents[e]) then local objent = ents[e]
local lua = ents[e]:get_luaentity() local lua = objent:get_luaentity()
if lua then if self then
if lua.name == "tsm_pyramids:mummy_spawner" then if objent ~= self.object then
-- entity found local sobj = self.object:get_luaentity()
return true if sobj.name then
if sobj.name == "tsm_pyramids:mummy_spawner" then return true end
if sobj.name == "mummy_spawner" then return true end
else
return false -- BUG could be a mob spawner but cannot get the name?
end end
else
return false -- same object, is duplicate cos "self" is provided!
end
else
if type(lua) ~= "userdata" then -- not a player could be a spawner or a node
if lua then
-- entity found
if lua.name then
if lua.name == "tsm_pyramids:mummy_spawner" then return true end
if lua.name == "mummy_spawner" then return true end
end
end
else
return false
end end
end end
end end

View File

@ -1183,6 +1183,10 @@ function tsm_pyramids.flood_sand(pos, stype)
end end
end end
end end
minetest.bulk_set_node(set_to_sand, {name=nn}) if tsm_pyramids.is_54 then
minetest.bulk_set_node(set_to_sand, {name=nn})
else
for _, xpos in ipairs(set_to_sand) do minetest.set_node(xpos, {name=nn}) end
end
end end