ores_stats/init.lua

153 lines
3.2 KiB
Lua
Raw Normal View History

2018-06-04 19:03:44 +02:00
--[[
Ores' Statistics - Provides informations about ores' percentages
2020-07-23 00:53:00 +02:00
Copyright © 2018, 2020 Hamlet and contributors.
2018-06-04 19:03:44 +02:00
2019-10-29 11:31:40 +01:00
Licensed under the EUPL, Version 1.2 or as soon they will be
approved by the European Commission subsequent versions of the
EUPL (the "Licence");
You may not use this work except in compliance with the Licence.
You may obtain a copy of the Licence at:
2018-06-04 19:03:44 +02:00
2019-10-29 11:31:40 +01:00
https://joinup.ec.europa.eu/software/page/eupl
https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017D0863
Unless required by applicable law or agreed to in writing,
software distributed under the Licence is distributed on an
"AS IS" basis,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the Licence for the specific language governing permissions
and limitations under the Licence.
2018-06-04 19:03:44 +02:00
--]]
--
2020-07-23 00:53:00 +02:00
-- Constants
2018-06-04 19:03:44 +02:00
--
2020-07-23 00:53:00 +02:00
-- Global mod's namespace
ores_stats = {}
2019-10-29 11:31:40 +01:00
2020-07-23 00:53:00 +02:00
-- Database handler
ores_stats.t_MOD_DATABASE = minetest.get_mod_storage()
2019-10-29 11:31:40 +01:00
2020-07-23 11:46:18 +02:00
-- Default ore value
ores_stats.f_GOLD_VALUE = minetest.settings:get('ores_stats_gold_value')
or 50.0
2020-08-19 23:31:10 +02:00
-- Support for More Ores
ores_stats.b_MORE_ORES = false
if (minetest.get_modpath('moreores') ~= nil) then
ores_stats.b_MORE_ORES = true
end
2020-07-23 11:46:18 +02:00
2018-06-04 19:03:44 +02:00
--
2020-07-23 00:53:00 +02:00
-- Variables
2018-06-04 19:03:44 +02:00
--
2020-07-23 00:53:00 +02:00
ores_stats.i_TotalOres = 0
2018-06-04 19:03:44 +02:00
--
2020-07-23 00:53:00 +02:00
-- Procedures
2018-06-04 19:03:44 +02:00
--
2020-07-23 00:53:00 +02:00
-- Minetest logger
local pr_LogMessage = function()
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
-- Constant
local s_LOG_LEVEL = minetest.settings:get('debug_log_level')
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
-- Body
if (s_LOG_LEVEL == nil)
or (s_LOG_LEVEL == 'action')
or (s_LOG_LEVEL == 'info')
or (s_LOG_LEVEL == 'verbose')
then
2020-08-19 23:31:10 +02:00
minetest.log('action', '[Mod] Ores Stats [v1.1.0] loaded.')
2018-06-04 19:03:44 +02:00
end
end
2020-07-23 00:53:00 +02:00
-- Subfiles loader
local pr_LoadSubFiles = function()
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
-- Constant
local s_MOD_PATH = minetest.get_modpath('ores_stats')
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
-- Body
dofile(s_MOD_PATH .. '/core/functions.lua')
dofile(s_MOD_PATH .. '/core/procedures.lua')
dofile(s_MOD_PATH .. '/core/minetest_game.lua')
2020-08-19 23:31:10 +02:00
-- Support for More Ores' nodes
if (ores_stats.b_MORE_ORES == true) then
dofile(s_MOD_PATH .. '/core/moreores_procedures.lua')
dofile(s_MOD_PATH .. '/core/moreores.lua')
end
2020-07-23 00:53:00 +02:00
dofile(s_MOD_PATH .. '/core/formspec.lua')
2018-06-04 19:03:44 +02:00
end
--
2020-07-23 00:53:00 +02:00
-- Main body
2018-06-04 19:03:44 +02:00
--
2020-07-23 00:53:00 +02:00
pr_LoadSubFiles()
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
ores_stats.pr_MTGupdateFromDB()
ores_stats.pr_MTGupdateFromDBperc()
2020-07-23 11:46:18 +02:00
ores_stats.pr_MTGupdateFromDBvalue()
2018-06-04 19:03:44 +02:00
2020-08-19 23:31:10 +02:00
-- Support for More Ores' nodes
if (ores_stats.b_MORE_ORES == true) then
ores_stats.pr_MOupdateFromDB()
ores_stats.pr_MOupdateFromDBperc()
ores_stats.pr_MOupdateFromDBvalue()
end
2018-06-04 19:03:44 +02:00
-- Voxel manipulator
minetest.register_on_generated(function()
local vm, emin, emax = minetest.get_mapgen_object"voxelmanip"
local data = vm:get_data()
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
for i in area:iterp(emin, emax) do
2020-07-23 00:53:00 +02:00
ores_stats.pr_OresScanner(data[i])
2018-06-04 19:03:44 +02:00
end
2020-07-23 00:53:00 +02:00
ores_stats.pr_CalcTotalOres()
ores_stats.pr_OresPercentages()
2020-07-23 11:46:18 +02:00
ores_stats.pr_CalcValues()
2018-06-04 19:03:44 +02:00
2020-08-19 23:31:10 +02:00
-- Support for More Ores' nodes
if (ores_stats.b_MORE_ORES == true) then
ores_stats.pr_MOCalcValues()
end
2020-07-23 00:53:00 +02:00
ores_stats.pr_MTGupdateSaveDB()
ores_stats.pr_MTGupdateSaveDBperc()
2020-07-23 11:46:18 +02:00
ores_stats.pr_MTGupdateSaveDBvalue()
2018-06-04 19:03:44 +02:00
2020-08-19 23:31:10 +02:00
-- Support for More Ores' nodes
if (ores_stats.b_MORE_ORES == true) then
ores_stats.pr_MOupdateSaveDB()
ores_stats.pr_MOupdateSaveDBperc()
ores_stats.pr_MOupdateSaveDBvalue()
end
2020-07-23 00:53:00 +02:00
ores_stats.pr_UpdateFormspec()
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
end)
2018-06-04 19:03:44 +02:00
2020-07-23 00:53:00 +02:00
pr_LogMessage()