mirror of
https://github.com/minetest-mods/digtron.git
synced 2025-01-03 09:37:27 +01:00
protect against extremely large builder periods causing entities to be added out of range
This commit is contained in:
parent
445140abaa
commit
aa927fe26a
31
util.lua
31
util.lua
@ -391,32 +391,45 @@ digtron.is_soft_material = function(target)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- If someone sets very large offsets or intervals for the offset markers they might be added too far
|
||||||
|
-- away. safe_add_entity causes these attempts to be ignored rather than crashing the game.
|
||||||
|
-- returns the entity if successful, nil otherwise
|
||||||
|
function safe_add_entity(pos, name)
|
||||||
|
success, ret = pcall(minetest.add_entity, pos, name)
|
||||||
|
if success then return ret else return nil end
|
||||||
|
end
|
||||||
|
|
||||||
digtron.show_offset_markers = function(pos, offset, period)
|
digtron.show_offset_markers = function(pos, offset, period)
|
||||||
local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2)
|
local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2)
|
||||||
local x_pos = math.floor((buildpos.x+offset)/period)*period - offset
|
local x_pos = math.floor((buildpos.x+offset)/period)*period - offset
|
||||||
minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker")
|
safe_add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker")
|
||||||
if x_pos >= buildpos.x then
|
if x_pos >= buildpos.x then
|
||||||
minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
|
safe_add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
|
||||||
end
|
end
|
||||||
if x_pos <= buildpos.x then
|
if x_pos <= buildpos.x then
|
||||||
minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
|
safe_add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
|
||||||
end
|
end
|
||||||
|
|
||||||
local y_pos = math.floor((buildpos.y+offset)/period)*period - offset
|
local y_pos = math.floor((buildpos.y+offset)/period)*period - offset
|
||||||
minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical")
|
safe_add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical")
|
||||||
if y_pos >= buildpos.y then
|
if y_pos >= buildpos.y then
|
||||||
minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical")
|
safe_add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical")
|
||||||
end
|
end
|
||||||
if y_pos <= buildpos.y then
|
if y_pos <= buildpos.y then
|
||||||
minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical")
|
safe_add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical")
|
||||||
end
|
end
|
||||||
|
|
||||||
local z_pos = math.floor((buildpos.z+offset)/period)*period - offset
|
local z_pos = math.floor((buildpos.z+offset)/period)*period - offset
|
||||||
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708)
|
|
||||||
|
local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker")
|
||||||
|
if entity ~= nil then entity:setyaw(1.5708) end
|
||||||
|
|
||||||
if z_pos >= buildpos.z then
|
if z_pos >= buildpos.z then
|
||||||
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708)
|
local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker")
|
||||||
|
if entity ~= nil then entity:setyaw(1.5708) end
|
||||||
end
|
end
|
||||||
if z_pos <= buildpos.z then
|
if z_pos <= buildpos.z then
|
||||||
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708)
|
local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker")
|
||||||
|
if entity ~= nil then entity:setyaw(1.5708) end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user