Module:Calculator

local getArgs = require('Module:Arguments').getArgs

local p = {}

local lang = mw.language.getContentLanguage local serverTimeOffset = require('Module:HypixelServerTime') .. ' hours' local MONTHNAMES = { 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' }

-- For Template:Calculator/Ticks and Calculator:Ticks function p.miningSpeedToTicks( frame ) local args = getArgs(frame) local ms = tonumber(args.mining_speed) or 0 local bs = tonumber(args.block_strength) or 0 local bl = args.block or "Any other blocks" return p._miningSpeedToTicks(ms, bs, bl) end

-- Module Access Point function p._miningSpeedToTicks(mining_speed, block_strength, block) if mining_speed >= (block_strength * 60) then return 1 elseif string.match(string.lower(block), 'netherrack') and mining_speed >= (block_strength * 30) then return 1 else return math.max(('%.0f'):format(block_strength * 30 / mining_speed), 4) end end

-- For Template:Calculator/Mining Speed and Calculator:Mining Speed function p.ticksToMiningSpeed( frame ) local args = getArgs(frame) local tk = tonumber(args.ticks) or 0 local bs = tonumber(args.block_strength) or 0 local bl = args.block or "Any other blocks" return p._ticksToMiningSpeed(tk, bs, bl) end

-- Module Access Point function p._ticksToMiningSpeed(ticks, block_strength, block) if ticks == 1 and string.match(string.lower(block), 'netherrack') then return block_strength * 30 elseif ticks == 1 then return block_strength * 60 else return math.ceil(block_strength * 30 / (math.max(ticks, 4) + 0.49999)) end end

-- For Template:Kuudra Follower Helmet and Calculator:Kuudra Follower Helmet function p.kuudraFollowerHelmet(frame) local args = getArgs(frame) local useCurrent = (args.dateOpt == 'Current Date') local result, datestring, isoDayOfYear, nameLength = p._kuudraFollowerHelmet(useCurrent, args.playerName, args.year, args.month, args.day) return mw.getCurrentFrame:preprocess('Result: Date (ET): ' .. datestring .. '; Day of Year: ' .. isoDayOfYear .. '; Player Name Length: ' .. nameLength) end

function p._kuudraFollowerHelmet(useCurrent, playerName, year, month, day) -- formula: 13331996 + 2*(Day of the Year in ET)^2 - 58*(Player Name Length) local timestamp = useCurrent and lang:formatDate('U', serverTimeOffset) or		lang:formatDate('U', ('%s %s %s'):format(MONTHNAMES[tonumber(month)] or MONTHNAMES[1], day or 1, year or '')) local datestring = lang:formatDate('Y-m-d', '@' .. timestamp) local isoDayOfYear = lang:formatDate('z', '@' .. timestamp) + 1 local nameLength = #(mw.text.trim(playerName or '')) local result = 13331996 + 2 * (isoDayOfYear ^ 2) - 58 * nameLength return result, datestring, isoDayOfYear, nameLength end

-- Template:CalcEncode -- Encode arguments to a JSCalc readable string function p.calcEncode(frame) local args = getArgs(frame) local ret = {} for k, v in pairs(args) do		table.insert(ret, ('|%s = %s'):format(k, v)) end return table.concat(ret) end p.argslist = p.calcEncode -- p.argslist deprecated, please remove after removing all usages

return p