package mezz.jei.util;

import mezz.jei.api.gui.ITickTimer;
import net.minecraft.client.Minecraft;

public class TickTimer implements ITickTimer {
	private final int ticksPerCycle;
	private final int maxValue;
	private final boolean countDown;

	private long lastUpdateWorldTime = 0;
	private int tickCount = 0;

	public TickTimer(int ticksPerCycle, int maxValue, boolean countDown) {
		this.ticksPerCycle = ticksPerCycle;
		this.maxValue = maxValue;
		this.countDown = countDown;
	}

	@Override
	public int getValue() {
		long worldTime = Minecraft.getMinecraft().world.getTotalWorldTime();
		long ticksPassed = worldTime - lastUpdateWorldTime;
		lastUpdateWorldTime = worldTime;
		tickCount += ticksPassed;
		if (tickCount > ticksPerCycle) {
			tickCount = 0;
		}

		int value = MathUtil.divideCeil(tickCount * maxValue, ticksPerCycle);
		if (countDown) {
			return maxValue - value;
		} else {
			return value;
		}
	}

	@Override
	public int getMaxValue() {
		return maxValue;
	}
}

@@ -744,16 +744,17 @@
 kCount %3E
+=
  ticksPe
@@ -812,23 +812,14 @@
 Math
-Util.divideCeil
+.round
 (tic
@@ -835,17 +835,26 @@
 maxValue
-,
+ / (float)
  ticksPe

Fix TickTimer implementation