2017-04-19 11:08:58 +02:00
moremesecons = { }
2017-04-19 18:33:36 +02:00
function moremesecons . setting ( modname , settingname , default , min )
2017-04-19 11:08:58 +02:00
local setting = " moremesecons_ " .. modname .. " . " .. settingname
2017-04-19 13:27:06 +02:00
if type ( default ) == " boolean " then
2017-04-19 11:08:58 +02:00
local ret = minetest.setting_getbool ( setting )
if ret == nil then
ret = default
end
return ret
elseif type ( default ) == " string " then
return minetest.setting_get ( setting ) or default
elseif type ( default ) == " number " then
local ret = tonumber ( minetest.setting_get ( setting ) ) or default
2017-05-21 19:11:12 +02:00
if not ret then
minetest.log ( " warning " , " [moremesecons_ " .. modname .. " ]: setting ' " .. setting .. " ' must be a number. Set to default value ( " .. tostring ( default ) .. " ). " )
ret = default
elseif ret ~= ret then -- NaN
2017-04-19 18:33:36 +02:00
minetest.log ( " warning " , " [moremesecons_ " .. modname .. " ]: setting ' " .. setting .. " ' is NaN. Set to default value ( " .. tostring ( default ) .. " ). " )
2017-04-19 11:08:58 +02:00
ret = default
end
2017-04-19 18:33:36 +02:00
if min and ret < min then
minetest.log ( " warning " , " [moremesecons_ " .. modname .. " ]: setting ' " .. setting .. " ' is under minimum value " .. tostring ( min ) .. " . Set to minimum value ( " .. tostring ( min ) .. " ). " )
ret = min
2017-04-19 11:08:58 +02:00
end
return ret
end
end
2017-04-19 21:41:10 +02:00
-- 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