Module:Calculator

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

local p = {}

local pet_order = { Lion = { y = 0, s = 0 }, Monkey = { y = 0, s = 1 }, Giraffe = { y = 1, s = 0 }, Elephant = { y = 1, s = 1 }, ['Blue Whale'] = { y = 2, s = 0 }, Tiger = { y = 2, s = 1 }, } local pet_year_cycle = 3

function p.tzYearCycle( frame ) local args = getArgs(frame) return mw.getCurrentFrame:preprocess(p._tzYearCycle(args[1])) end

function p._tzYearCycle(name) local order = pet_order[name] local currYear = 1 + math.floor((os.time(os.date("!*t")) - 1560275700) / 446400) local increment = ((order.y + pet_year_cycle) - (currYear % pet_year_cycle)) % pet_year_cycle return (' %s'):format(currYear + increment, order.s == 0 and  or ) end

-- 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

return p