Last active
August 29, 2015 14:18
-
-
Save est31/406f939396c4d110f330 to your computer and use it in GitHub Desktop.
craft stats script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- put this into some builtin/game/*.lua file | |
-- it will print craft stats for the mod config to stdout when you start a world. | |
local register_craft_old = core.register_craft | |
core.type_stats = {} | |
core.grouped_number = 0 | |
core.non_grouped_number = 0 | |
local function is_group_str(val) | |
return string.sub(val, 1, 6) == "group:" | |
end | |
core.register_craft = function(params) | |
local hasgroup = false | |
if params.recipe then | |
if type(params.recipe) == "string" and is_group_str(params.recipe) then | |
hasgroup = true | |
elseif type(params.recipe) == "table" then | |
for idx, val in pairs(params.recipe) do | |
if type(val) == "string" and is_group_str(val) then | |
hasgroup = true | |
break | |
elseif type(val) == "table" then | |
for iidx, vval in pairs(params.recipe) do | |
if type(vval) == "string" and is_group_str(vval) then | |
hasgroup = true | |
break | |
end | |
end | |
if hasgroup then | |
break | |
end | |
end | |
end | |
end | |
end | |
if hasgroup then | |
core.grouped_number = core.grouped_number + 1 | |
else | |
core.non_grouped_number = core.non_grouped_number + 1 | |
end | |
local type = params.type or "default" | |
core.type_stats[type] = (core.type_stats[type] or 0) + 1 | |
register_craft_old(params) | |
end | |
core.after(0.02, function() | |
print("########################################################################################\n" | |
.."grouped: " .. core.grouped_number .. ", non-grouped: " | |
.. core.non_grouped_number .. ", type stats: " .. dump(core.type_stats)) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment