2020-07-22

This commit is contained in:
Hamlet 2020-07-23 00:53:00 +02:00
parent faecfff52d
commit fea50b369e
No known key found for this signature in database
GPG Key ID: 30C286622B0B63F9
8 changed files with 550 additions and 313 deletions

19
bower.json Normal file

@ -0,0 +1,19 @@
{
"name": "ores_stats",
"description": "Provides informations about ores' percentages collected on map generation.",
"keywords": [
"mapgen"
],
"homepage": "https://content.minetest.net/packages/Hamlet/ores_stats/",
"forum": "https://forum.minetest.net/viewtopic.php?t=19930",
"screenshots": [
"https://codeberg.org/Hamlet/ores_stats/src/branch/master/screenshot.png"
],
"authors": [
"Hamlet"
],
"license": "EUPL-1.2",
"dependencies": {
"default": "https://github.com/minetest/minetest_game/tree/master/mods/default"
}
}

134
core/formspec.lua Normal file

@ -0,0 +1,134 @@
--[[
Ores' Statistics - Provides informations about ores' percentages
Copyright © 2018, 2020 Hamlet and contributors.
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:
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.
--]]
-- Used for localization
local S = minetest.get_translator('ores_stats')
--
-- Formspec registration
--
sfinv.register_page('ores_stats:ores_stats', {
title = 'Ores\' Stats',
get = function(self, player, context)
local s_oresPerc =
',' ..
S("Ores' percentages") .. ',' ..
'========================' .. ',' ..
S('Coal: ') .. string.format("%.3f", ores_stats.f_percCoal)
.. '%' .. ',' ..
S('Copper: ') .. string.format("%.3f", ores_stats.f_percCopper)
.. '%' .. ',' ..
S('Diamonds: ') .. string.format("%.3f", ores_stats.f_percDiamonds)
.. '%' .. ',' ..
S('Gold: ') .. string.format("%.3f", ores_stats.f_percGold)
.. '%' .. ',' ..
S('Iron: ') .. string.format("%.3f", ores_stats.f_percIron)
.. '%' .. ',' ..
S('Mese: ') .. string.format("%.3f", ores_stats.f_percMese)
.. '%' .. ',' ..
S('Tin: ') .. string.format("%.3f", ores_stats.f_percTin)
.. '%' .. ','
local s_oresValue =
',' ..
S("Ores' values") .. ',' ..
'========================' .. ',' ..
S('Coal: ') .. string.format("%.3f", ores_stats.f_valueCoal)
.. '%' .. ',' ..
S('Copper: ') .. string.format("%.3f", ores_stats.f_valueCopper)
.. '%' .. ',' ..
S('Diamonds: ') .. string.format("%.3f", ores_stats.f_valueDiamonds)
.. '%' .. ',' ..
S('Gold: ') .. string.format("%.3f", ores_stats.f_valueGold)
.. '%' .. ',' ..
S('Iron: ') .. string.format("%.3f", ores_stats.f_valueIron)
.. '%' .. ',' ..
S('Mese: ') .. string.format("%.3f", ores_stats.f_valueMese)
.. '%' .. ',' ..
S('Tin: ') .. string.format("%.3f", ores_stats.f_valueTin)
.. '%' .. ','
return sfinv.make_formspec(player, context,
'textlist[0,0;7.8,9.2;;' ..
s_oresPerc .. s_oresValue .. ']', false)
end
})
--
-- Formspec updating
--
ores_stats.pr_UpdateFormspec = function()
sfinv.override_page('ores_stats:ores_stats', {
title = 'Ores\' Stats',
get = function(self, player, context)
local s_oresPerc =
',' ..
S("Ores' percentages") .. ',' ..
'========================' .. ',' ..
S('Coal: ') .. string.format("%.3f", ores_stats.f_percCoal)
.. '%' .. ',' ..
S('Copper: ') .. string.format("%.3f", ores_stats.f_percCopper)
.. '%' .. ',' ..
S('Diamonds: ') .. string.format("%.3f",
ores_stats.f_percDiamonds)
.. '%' .. ',' ..
S('Gold: ') .. string.format("%.3f", ores_stats.f_percGold)
.. '%' .. ',' ..
S('Iron: ') .. string.format("%.3f", ores_stats.f_percIron)
.. '%' .. ',' ..
S('Mese: ') .. string.format("%.3f", ores_stats.f_percMese)
.. '%' .. ',' ..
S('Tin: ') .. string.format("%.3f", ores_stats.f_percTin)
.. '%' .. ','
local s_oresValue =
',' ..
S("Ores' values") .. ',' ..
'========================' .. ',' ..
S('Coal: ') .. string.format("%.3f", ores_stats.f_valueCoal)
.. '%' .. ',' ..
S('Copper: ') .. string.format("%.3f", ores_stats.f_valueCopper)
.. '%' .. ',' ..
S('Diamonds: ') .. string.format("%.3f",
ores_stats.f_valueDiamonds)
.. '%' .. ',' ..
S('Gold: ') .. string.format("%.3f", ores_stats.f_valueGold)
.. '%' .. ',' ..
S('Iron: ') .. string.format("%.3f", ores_stats.f_valueIron)
.. '%' .. ',' ..
S('Mese: ') .. string.format("%.3f", ores_stats.f_valueMese)
.. '%' .. ',' ..
S('Tin: ') .. string.format("%.3f", ores_stats.f_valueTin)
.. '%' .. ','
return sfinv.make_formspec(player, context,
'textlist[0,0;7.8,9.2;;' ..
s_oresPerc .. s_oresValue .. ']', false)
end
})
end

38
core/functions.lua Normal file

@ -0,0 +1,38 @@
--[[
Ores' Statistics - Provides informations about ores' percentages
Copyright © 2018, 2020 Hamlet and contributors.
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:
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.
--]]
--
-- Functions
--
-- Used to calculate an ore's percentage
ores_stats.fn_CalcPercentage = function(a_i_ore, a_i_total_ores)
local f_percentage = 0.0
if (a_i_total_ores ~= 0) then
f_percentage = ((a_i_ore * 100) / a_i_total_ores)
end
return f_percentage
end

65
core/minetest_game.lua Normal file

@ -0,0 +1,65 @@
--[[
Ores' Statistics - Provides informations about ores' percentages
Copyright © 2018, 2020 Hamlet and contributors.
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:
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.
--]]
--
-- Constants
--
ores_stats.id_coal = minetest.get_content_id('default:stone_with_coal')
ores_stats.id_copper = minetest.get_content_id('default:stone_with_copper')
ores_stats.id_diamonds = minetest.get_content_id('default:stone_with_diamond')
ores_stats.id_gold = minetest.get_content_id('default:stone_with_gold')
ores_stats.id_iron = minetest.get_content_id('default:stone_with_iron')
ores_stats.id_mese = minetest.get_content_id('default:stone_with_mese')
ores_stats.id_mese_block = minetest.get_content_id('default:mese')
ores_stats.id_tin = minetest.get_content_id('default:stone_with_tin')
--
-- Variables
--
ores_stats.i_foundCoal = 0
ores_stats.i_foundCopper = 0
ores_stats.i_foundDiamonds = 0
ores_stats.i_foundGold = 0
ores_stats.i_foundIron = 0
ores_stats.i_foundMese = 0
ores_stats.i_foundTin = 0
ores_stats.f_percCoal = 0.0
ores_stats.f_percCopper = 0.0
ores_stats.f_percDiamonds = 0.0
ores_stats.f_percGold = 0.0
ores_stats.f_percIron = 0.0
ores_stats.f_percMese = 0.0
ores_stats.f_percTin = 0.0
ores_stats.f_valueCoal = 0.0
ores_stats.f_valueCopper = 0.0
ores_stats.f_valueDiamonds = 0.0
ores_stats.f_valueGold = 0.0
ores_stats.f_valueIron = 0.0
ores_stats.f_valueMese = 0.0
ores_stats.f_valueTin = 0.0

245
core/procedures.lua Normal file

@ -0,0 +1,245 @@
--[[
Ores' Statistics - Provides informations about ores' percentages
Copyright © 2018, 2020 Hamlet and contributors.
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:
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.
--]]
--
-- Procedures
--
-- Used to update the Minetest Game's variables
ores_stats.pr_MTGupdateFromDB = function()
ores_stats.i_foundCoal =
ores_stats.t_MOD_DATABASE:get_int('i_found_coal') or 0
ores_stats.i_foundCopper =
ores_stats.t_MOD_DATABASE:get_int('i_found_copper') or 0
ores_stats.i_foundDiamonds =
ores_stats.t_MOD_DATABASE:get_int('i_found_diamonds') or 0
ores_stats.i_foundGold =
ores_stats.t_MOD_DATABASE:get_int('i_found_gold') or 0
ores_stats.i_foundIron =
ores_stats.t_MOD_DATABASE:get_int('i_found_iron') or 0
ores_stats.i_foundMese =
ores_stats.t_MOD_DATABASE:get_int('i_found_mese') or 0
ores_stats.i_foundTin =
ores_stats.t_MOD_DATABASE:get_int('i_found_tin') or 0
end
-- Used to save the Minetest Game's variables
ores_stats.pr_MTGupdateSaveDB = function()
ores_stats.t_MOD_DATABASE:set_int('i_found_coal', ores_stats.i_foundCoal)
ores_stats.t_MOD_DATABASE:set_int('i_found_copper',
ores_stats.i_foundCopper)
ores_stats.t_MOD_DATABASE:set_int('i_found_diamonds',
ores_stats.i_foundDiamonds)
ores_stats.t_MOD_DATABASE:set_int('i_found_gold', ores_stats.i_foundGold)
ores_stats.t_MOD_DATABASE:set_int('i_found_iron', ores_stats.i_foundIron)
ores_stats.t_MOD_DATABASE:set_int('i_found_mese', ores_stats.i_foundMese)
ores_stats.t_MOD_DATABASE:set_int('i_found_tin', ores_stats.i_foundTin)
end
-- Used to update the Minetest Game's percentages variables
ores_stats.pr_MTGupdateFromDBperc = function()
ores_stats.f_percCoal =
ores_stats.t_MOD_DATABASE:get_float('f_percCoal') or 0.0
ores_stats.f_percCopper =
ores_stats.t_MOD_DATABASE:get_float('f_percCopper') or 0.0
ores_stats.f_percDiamonds =
ores_stats.t_MOD_DATABASE:get_float('f_percDiamonds') or 0.0
ores_stats.f_percGold =
ores_stats.t_MOD_DATABASE:get_float('f_percGold') or 0.0
ores_stats.f_percIron =
ores_stats.t_MOD_DATABASE:get_float('f_percIron') or 0.0
ores_stats.f_percMese =
ores_stats.t_MOD_DATABASE:get_float('f_percMese') or 0.0
ores_stats.f_percTin =
ores_stats.t_MOD_DATABASE:get_float('f_percTin') or 0.0
end
-- Used to save the Minetest Game's percentages variables
ores_stats.pr_MTGupdateSaveDBperc = function()
ores_stats.t_MOD_DATABASE:set_float('f_percCoal', ores_stats.f_percCoal)
ores_stats.t_MOD_DATABASE:set_float('f_percCopper',
ores_stats.f_percCopper)
ores_stats.t_MOD_DATABASE:set_float('f_percDiamonds',
ores_stats.f_percDiamonds)
ores_stats.t_MOD_DATABASE:set_float('f_percGold', ores_stats.f_percGold)
ores_stats.t_MOD_DATABASE:set_float('f_percIron', ores_stats.f_percIron)
ores_stats.t_MOD_DATABASE:set_float('f_percMese', ores_stats.f_percMese)
ores_stats.t_MOD_DATABASE:set_float('f_percTin', ores_stats.f_percTin)
end
-- Used to update the total ores found variable
ores_stats.pr_CalcTotalOres = function()
ores_stats.i_TotalOres = (
ores_stats.i_foundCoal + ores_stats.i_foundCopper +
ores_stats.i_foundDiamonds + ores_stats.i_foundGold +
ores_stats.i_foundIron + ores_stats.i_foundMese +
ores_stats.i_foundTin
)
end
-- Used to update the amounts of the ores found
ores_stats.pr_OresScanner = function(a_s_node_id)
if (a_s_node_id == ores_stats.id_coal) then
ores_stats.i_foundCoal = (ores_stats.i_foundCoal + 1)
elseif (a_s_node_id == ores_stats.id_copper) then
ores_stats.i_foundCopper = (ores_stats.i_foundCopper + 1)
elseif (a_s_node_id == ores_stats.id_diamonds) then
ores_stats.i_foundDiamonds = (ores_stats.i_foundDiamonds + 1)
elseif (a_s_node_id == ores_stats.id_gold) then
ores_stats.i_foundGold = (ores_stats.i_foundGold + 1)
elseif (a_s_node_id == ores_stats.id_iron) then
ores_stats.i_foundIron = (ores_stats.i_foundIron + 1)
elseif (a_s_node_id == ores_stats.id_mese) then
ores_stats.i_foundMese = (ores_stats.i_foundMese + 1)
elseif (a_s_node_id == ores_stats.id_mese_block) then
ores_stats.i_foundMese = (ores_stats.i_foundMese + 9)
elseif (a_s_node_id == ores_stats.id_tin) then
ores_stats.i_foundTin = (ores_stats.i_foundTin + 1)
end
end
-- Used to update the amounts of the ores found
ores_stats.pr_OresPercentages = function()
ores_stats.f_percCoal =
ores_stats.fn_CalcPercentage(ores_stats.i_foundCoal,
ores_stats.i_TotalOres)
ores_stats.f_percCopper =
ores_stats.fn_CalcPercentage(ores_stats.i_foundCopper,
ores_stats.i_TotalOres)
ores_stats.f_percDiamonds =
ores_stats.fn_CalcPercentage(ores_stats.i_foundDiamonds,
ores_stats.i_TotalOres)
ores_stats.f_percGold =
ores_stats.fn_CalcPercentage(ores_stats.i_foundGold,
ores_stats.i_TotalOres)
ores_stats.f_percIron =
ores_stats.fn_CalcPercentage(ores_stats.i_foundIron,
ores_stats.i_TotalOres)
ores_stats.f_percMese =
ores_stats.fn_CalcPercentage(ores_stats.i_foundMese,
ores_stats.i_TotalOres)
ores_stats.f_percMese =
ores_stats.fn_CalcPercentage(ores_stats.i_foundMese,
ores_stats.i_TotalOres)
ores_stats.f_percTin =
ores_stats.fn_CalcPercentage(ores_stats.i_foundTin,
ores_stats.i_TotalOres)
end
-- Used to update the Minetest Game's value variables
ores_stats.pr_MTGupdateFromDBvalue = function()
ores_stats.f_valueCoal =
ores_stats.t_MOD_DATABASE:get_float('f_valueCoal') or 0.0
ores_stats.f_valueCopper =
ores_stats.t_MOD_DATABASE:get_float('f_valueCopper') or 0.0
ores_stats.f_valueDiamonds =
ores_stats.t_MOD_DATABASE:get_float('f_valueDiamonds') or 0.0
ores_stats.f_valueGold =
ores_stats.t_MOD_DATABASE:get_float('f_valueGold') or 0.0
ores_stats.f_valueIron =
ores_stats.t_MOD_DATABASE:get_float('f_valueIron') or 0.0
ores_stats.f_valueMese =
ores_stats.t_MOD_DATABASE:get_float('f_valueMese') or 0.0
ores_stats.f_valueTin =
ores_stats.t_MOD_DATABASE:get_float('f_valueTin') or 0.0
end
-- Used to save the Minetest Game's value variables
ores_stats.pr_MTGupdateSaveDBvalue = function()
ores_stats.t_MOD_DATABASE:set_float('f_valueCoal',
ores_stats.f_valueCoal)
ores_stats.t_MOD_DATABASE:set_float('f_valueCopper',
ores_stats.f_valueCopper)
ores_stats.t_MOD_DATABASE:set_float('f_valueDiamonds',
ores_stats.f_valueDiamonds)
ores_stats.t_MOD_DATABASE:set_float('f_valueGold',
ores_stats.f_valueGold)
ores_stats.t_MOD_DATABASE:set_float('f_valueIron',
ores_stats.f_valueIron)
ores_stats.t_MOD_DATABASE:set_float('f_valueMese',
ores_stats.f_valueMese)
ores_stats.t_MOD_DATABASE:set_float('f_valueTin',
ores_stats.f_valueTin)
end

346
init.lua

@ -1,6 +1,6 @@
--[[
Ores' Statistics - Provides informations about ores' percentages
Copyright © 2018, 2019 Hamlet <hamlatmesehub@riseup.net> and contributors.
Copyright © 2018, 2020 Hamlet and contributors.
Licensed under the EUPL, Version 1.2 or as soon they will be
approved by the European Commission subsequent versions of the
@ -23,339 +23,87 @@
--
-- Configuration
-- Constants
--
local console_output = false
local ores_stats_profiler = minetest.settings:get_bool("ores_stats_profiler")
-- Global mod's namespace
ores_stats = {}
if (ores_stats_profiler == nil) then
ores_stats_profiler = false
end
-- Database handler
ores_stats.t_MOD_DATABASE = minetest.get_mod_storage()
--
-- Variables
--
-- Used for localization
ores_stats.i_TotalOres = 0
local S = minetest.get_translator("ores_stats")
--
-- General variables
-- Procedures
--
local mod_database = minetest.get_mod_storage()
local id_character = nil
-- Minetest logger
local pr_LogMessage = function()
local found_coal = nil
local found_iron = nil
local found_copper = nil
local found_tin = nil
local found_gold = nil
local found_mese = nil
local found_diamonds = nil
-- Constant
local s_LOG_LEVEL = minetest.settings:get('debug_log_level')
local total_ores = nil
local perc_coal = nil
local perc_iron = nil
local perc_copper = nil
local perc_tin = nil
local perc_gold = nil
local perc_mese = nil
local perc_diamonds = nil
local scanned_nodes = 0
local vm_start_time = 0
local vm_elapsed_time = 0
--
-- Ores IDs' constants
--
local id_coal = minetest.get_content_id("default:stone_with_coal")
local id_iron = minetest.get_content_id("default:stone_with_iron")
local id_copper = minetest.get_content_id("default:stone_with_copper")
local id_tin = minetest.get_content_id("default:stone_with_tin")
local id_gold = minetest.get_content_id("default:stone_with_gold")
local id_mese = minetest.get_content_id("default:stone_with_mese")
local id_diamonds = minetest.get_content_id("default:stone_with_diamond")
--
-- Functions
--
local function read_database(keyword)
local value = mod_database:get_int(keyword)
return value
end
local function write_database(keyword, number)
mod_database:set_int(keyword, number)
end
local function calc_total_ores()
local sum = found_coal + found_iron + found_copper + found_tin +
found_gold + found_mese + found_diamonds
return sum
end
local function update_database()
write_database("found_coal", found_coal)
write_database("found_iron", found_iron)
write_database("found_copper", found_copper)
write_database("found_tin", found_tin)
write_database("found_gold", found_gold)
write_database("found_mese", found_mese)
write_database("found_diamonds", found_diamonds)
write_database("total_ores", total_ores)
end
local function calc_percentage(ore_name, tot_ores)
local percentage = 0.0
if (tot_ores ~= 0) then
percentage = (ore_name * 100) / tot_ores
end
return percentage
end
local function update_percentages()
perc_coal = calc_percentage(found_coal, total_ores)
perc_iron = calc_percentage(found_iron, total_ores)
perc_copper = calc_percentage(found_copper, total_ores)
perc_tin = calc_percentage(found_tin, total_ores)
perc_gold = calc_percentage(found_gold, total_ores)
perc_mese = calc_percentage(found_mese, total_ores)
perc_diamonds = calc_percentage(found_diamonds, total_ores)
end
local function ores_scanner(node_id)
scanned_nodes = scanned_nodes + 1
if (node_id == id_coal) then
found_coal = found_coal + 1
elseif (node_id == id_iron) then
found_iron = found_iron + 1
elseif (node_id == id_copper) then
found_copper = found_copper + 1
elseif (node_id == id_tin) then
found_tin = found_tin + 1
elseif (node_id == id_gold) then
found_gold = found_gold + 1
elseif (node_id == id_mese) then
found_mese = found_mese + 1
elseif (node_id == id_diamonds) then
found_diamonds = found_diamonds + 1
-- Body
if (s_LOG_LEVEL == nil)
or (s_LOG_LEVEL == 'action')
or (s_LOG_LEVEL == 'info')
or (s_LOG_LEVEL == 'verbose')
then
minetest.log('action', '[Mod] Ores Stats [v0.3.0] loaded.')
end
end
local function console_print()
local prefix = "Stone with "
-- Subfiles loader
local pr_LoadSubFiles = function()
print(prefix .. "coal: " .. found_coal ..
" (" .. string.format("%.3f", perc_coal) .. "%)")
-- Constant
local s_MOD_PATH = minetest.get_modpath('ores_stats')
print(prefix .. "iron: " .. found_iron ..
" (" .. string.format("%.3f", perc_iron) .. "%)")
-- Body
dofile(s_MOD_PATH .. '/core/functions.lua')
dofile(s_MOD_PATH .. '/core/procedures.lua')
dofile(s_MOD_PATH .. '/core/minetest_game.lua')
dofile(s_MOD_PATH .. '/core/formspec.lua')
print(prefix .. "copper: " .. found_copper ..
" (" .. string.format("%.3f", perc_copper) .. "%)")
print(prefix .. "tin: " .. found_tin ..
" (" .. string.format("%.3f", perc_tin) .. "%)")
print(prefix .. "gold: " .. found_gold ..
" (" .. string.format("%.3f", perc_gold) .. "%)")
print(prefix .. "mese: " .. found_mese ..
" (" .. string.format("%.3f", perc_mese) .. "%)")
print(prefix .. "diamonds: " .. found_diamonds ..
" (" .. string.format("%.3f", perc_diamonds) .. "%)")
print("Total ores found: " .. total_ores)
print("Total scanned nodes: " .. scanned_nodes .. "\n" ..
"(default: 1404928 per mapchunk; i.e. (16*16*16)*(7*7*7))\n")
if (ores_stats_profiler == true) then
print(string.format("Elapsed Voxel Manipulator time: %.2fms\n\n",
vm_elapsed_time))
end
end
local function chat_print()
minetest.chat_send_player(id_character:get_player_name(),
S("Coal: ") .. string.format("%.3f", perc_coal) .. "% | " ..
S("Iron: ") .. string.format("%.3f", perc_iron) .. "% | " ..
S("Copper: ") .. string.format("%.3f", perc_copper) .. "% | " ..
S("Tin: ") .. string.format("%.3f", perc_tin) .. "% | " ..
S("Gold: ") .. string.format("%.3f", perc_gold) .. "% | " ..
S("Mese: ") .. string.format("%.3f", perc_mese) .. "% | " ..
S("Diamonds: ") .. string.format("%.3f", perc_diamonds) .. "%"
)
if (ores_stats_profiler == true) then
minetest.chat_send_player(id_character:get_player_name(),
S("Elapsed Voxel Manipulator time: ") ..
string.format("%.2fms", vm_elapsed_time)
)
end
end
--
-- Initialisation
--
-- Character's ObjRef detection on join time
minetest.register_on_joinplayer(function(player)
id_character = player
end)
-- Load preexisting data, if any
found_coal = read_database("found_coal")
found_iron = read_database("found_iron")
found_copper = read_database("found_copper")
found_tin = read_database("found_tin")
found_gold = read_database("found_gold")
found_mese = read_database("found_mese")
found_diamonds = read_database("found_diamonds")
total_ores = read_database("total_ores")
-- Set data to zero, if nil
if (found_coal == nil) then
found_coal = 0
write_database("found_coal", 0)
end
if (found_iron == nil) then
found_iron = 0
write_database("found_iron", 0)
end
if (found_copper == nil) then
found_copper = 0
write_database("found_copper", 0)
end
if (found_tin == nil) then
found_tin = 0
write_database("found_tin", 0)
end
if (found_gold == nil) then
found_gold = 0
write_database("found_gold", 0)
end
if (found_mese == nil) then
found_mese = 0
write_database("found_mese", 0)
end
if (found_diamonds == nil) then
found_diamonds = 0
write_database("found_diamonds", 0)
end
if (total_ores == nil) then
total_ores = 0
write_database("total_ores", 0)
end
-- Register chat command
minetest.register_chatcommand("orestats", {
params = "<console> | <chat>",
description = S("Toggle ores' statistics view on or off."),
privs = {},
func = function(name, param)
if (param == "console") then
if (console_output == false) then
console_output = true
minetest.chat_send_player(name,
S("Ores Stats - console output enabled."))
elseif (console_output == true) then
console_output = false
minetest.chat_send_player(name,
S("Ores Stats - console output disabled."))
end
elseif (param == "chat") then
update_percentages()
chat_print()
else
minetest.chat_send_player(name,
S("Ores Stats - invalid parameter. Use /help orestats"))
end
end,
}
)
--
-- Main body
--
pr_LoadSubFiles()
ores_stats.pr_MTGupdateFromDB()
ores_stats.pr_MTGupdateFromDBperc()
-- Voxel manipulator
--
minetest.register_on_generated(function()
if (ores_stats_profiler == true) then
vm_start_time = os.clock()
end
local vm, emin, emax = minetest.get_mapgen_object"voxelmanip"
local data = vm:get_data()
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
scanned_nodes = 0
for i in area:iterp(emin, emax) do
ores_scanner(data[i])
ores_stats.pr_OresScanner(data[i])
end
total_ores = calc_total_ores()
update_database()
update_percentages()
ores_stats.pr_CalcTotalOres()
ores_stats.pr_OresPercentages()
if (ores_stats_profiler == true) then
vm_elapsed_time = (os.clock() - vm_start_time) * 1000
vm_start_time = nil
end
ores_stats.pr_MTGupdateSaveDB()
ores_stats.pr_MTGupdateSaveDBperc()
ores_stats.pr_UpdateFormspec()
if (console_output == true) then
console_print()
end
end)
--
-- Minetest engine debug logging
--
if (minetest.settings:get("debug_log_level") == nil)
or (minetest.settings:get("debug_log_level") == "action")
or (minetest.settings:get("debug_log_level") == "info")
or (minetest.settings:get("debug_log_level") == "verbose")
then
minetest.log("action", "[Mod] Ores' Statistics [v0.2.0] loaded.")
end
pr_LogMessage()

@ -7,10 +7,4 @@ Tin: =Stagno:
Gold: =Oro:
Mese: =Mese:
Diamonds: =Diamanti:
Elapsed Voxel Manipulator time: =Voxel Manipulator, tempo trascorso:
Toggle ores' statistics view on or off.=Attiva o disattiva la visualizzazione delle statistiche minerarie.
Ores Stats - console output enabled.=Ores Stats - abilitata stampa informazioni su console.
Ores Stats - console output disabled.=Ores Stats - disabilitata stampa informazioni so console.
# NOTE: "/help orestats" must not be translated.
Ores Stats - invalid parameter. Use /help orestats=Ores Stats - parametro non valido. Usa /help orestats
Ores' percentages=Percentuali dei minerali

@ -7,10 +7,4 @@ Tin: =
Gold: =
Mese: =
Diamonds: =
Elapsed Voxel Manipulator time: =
Toggle ores' statistics view on or off.=
Ores Stats - console output enabled.=
Ores Stats - console output disabled.=
# NOTE: "/help orestats" must not be translated.
Ores Stats - invalid parameter. Use /help orestats=
Ores' percentages=