Improved Tick utility class

This commit is contained in:
Marc Baloup 2023-10-28 23:16:54 +02:00
parent 8f31ea54d1
commit 2f0b59a032

View File

@ -4,30 +4,38 @@ package fr.pandacube.lib.util;
* Provides methods related to Minecraft Java server ticks.
*/
public class Tick {
public static final int TPS = 20;
public static final int MS_PER_TICK = 1000 / TPS;
/**
* Returns the number of tick is the provided number of seconds.
* @param seconds the duration in second
* Returns the number of ticks for the provided number of seconds.
* @param seconds the duration in seconds
* @return the same duration as provided, but in Minecraft server ticks
*/
public static long sec(long seconds) {
return seconds * 20;
public static long ofSec(long seconds) {
return seconds * TPS;
}
/**
* Returns the number of tick is the provided number of minutes.
* Returns the number of ticks for the provided number of minutes.
* @param minutes the duration in minutes
* @return the same duration as provided, but in Minecraft server ticks
*/
public static long min(long minutes) {
return minutes * 1200;
public static long ofMin(long minutes) {
return minutes * TPS * 60;
}
/**
* Returns the number of milliseconds for the provided number of ticks.
* @param tick the duration in ticks
* @return the same duration as provided, but in milliseconds
*/
public static long toMs(long tick) {
return tick * MS_PER_TICK;
}
}