mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2025-06-28 14:36:07 +02:00
Define vector_extras functions in moremesecons_utils
if vector_extras is not loaded Loading vector_extras is still recommended because its functions may be more up-to-date.
This commit is contained in:
@ -0,0 +1 @@
|
||||
vector_extras?
|
||||
|
@ -24,3 +24,54 @@ function moremesecons.setting(modname, settingname, default, min)
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
-- Vector helpers
|
||||
-- All the following functions are from the vector_extras mod (https://github.com/HybridDog/vector_extras).
|
||||
-- If you enable that mod, its functions will be used instead of the ones defined below
|
||||
|
||||
if not vector.get_data_from_pos then
|
||||
function vector.get_data_from_pos(tab, z,y,x)
|
||||
local data = tab[z]
|
||||
if data then
|
||||
data = data[y]
|
||||
if data then
|
||||
return data[x]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not vector.set_data_to_pos then
|
||||
function vector.set_data_to_pos(tab, z,y,x, data)
|
||||
if tab[z] then
|
||||
if tab[z][y] then
|
||||
tab[z][y][x] = data
|
||||
return
|
||||
end
|
||||
tab[z][y] = {[x] = data}
|
||||
return
|
||||
end
|
||||
tab[z] = {[y] = {[x] = data}}
|
||||
end
|
||||
end
|
||||
|
||||
if not vector.remove_data_from_pos then
|
||||
function vector.remove_data_from_pos(tab, z,y,x)
|
||||
if vector.get_data_from_pos(tab, z,y,x) == nil then
|
||||
return
|
||||
end
|
||||
tab[z][y][x] = nil
|
||||
if not next(tab[z][y]) then
|
||||
tab[z][y] = nil
|
||||
end
|
||||
if not next(tab[z]) then
|
||||
tab[z] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not vector.unpack then
|
||||
function vector.unpack(pos)
|
||||
return pos.z, pos.y, pos.x
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user