Interface Ticks
-
public interface Ticks
Represents a game "tick".A game tick is a unit of work where the game processes the current state and updates the game world and all the entities in it. It is not a true unit of time, however, to ensure a consistent game play experience, each tick is given a maximum processing time (which is generally interpreted to be the expected duration of the tick, rather than the maximum) in which to complete its work. If a tick takes less time than this allotted time, the rest of the allocated time is unused and the engine simply waits for this time to elapse before processing the work for the next tick - this gives rise to the idea of a maximum ticks per second. However, if a tick takes longer than its effective minimum duration, then the next tick must wait for the current tick to finish before it can start. If multiple ticks take longer than this processing time in a row, this will have the effect of reducing the number of "ticks per second" that can run. At this point, the server may be considered "overloaded" as it cannot keep up with the demand placed upon it and not suffer from degradation in performance.
Implementations may measure the duration of some in-game mechanics using these server ticks. If this is the case, and the server is overloaded, the increased tick time will result in such mechanics taking longer to resolve. To complicate things further, implementations may choose to "skip" ticks to reduce server load (so some mechanics due to run in two tick's time may instead run in one tick's time). Thus, the use of a tick as a time period is unreliable.
For these reasons, consumers of this API should not treat a tick as a fixed unit of time. Instead, ticks are an intention of order. A mechanic due to resolve in two ticks will never resolve in a tick before a mechanic that resolves in one tick (but again, due to tick skipping, they may resolve on the same tick).
Information about the current platform and
Engine's
expected tick rate can be determined by callingsingle()
.expectedDuration(Engine)
. The tick rate is not defined by the API so may vary amongst different implementations. For all engines based on vanilla Minecraft, this is 50ms for a 20 tick per second rate.While a tick is not a reliable measure of wall-clock time, implementations may tie in-game world time to a given number of ticks. This object can thus be used as an accurate in-game duration. However, it is not defined in the API what the correlation between ticks and in-game time is, again, this may vary amongst implementations. For vanilla Minecraft, 1000 ticks corresponds to one in-game hour, meaning there is not an integer correspondence between an in-game minute or second and number of ticks.
Note that this object does not hold any context about which
Engine
the number of ticks was generated for. Consumers should use the methods on this object to determine what this object would represent on the target engine.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Ticks.Factory
ProducesTicks
objects.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.time.Duration
expectedDuration(Engine engine)
Gets the expectedDuration
of time it would take for the givenEngine
to process the number of ticks this object represents under ideal conditions.static Ticks
minecraftDay()
Represents a minecraft day on theServer
in ticks.java.time.Duration
minecraftDayTimeDuration(Engine engine)
Returns the in-game time as aDuration
represents for the givenEngine
.static Ticks
minecraftHour()
Represents a minecraft hour on theServer
in ticks.long
minecraftSeconds(Engine engine)
static Ticks
of(long ticks)
Returns aTicks
that represents the supplied number of ticks.static Ticks
ofMinecraftDays(Engine engine, long days)
static Ticks
ofMinecraftHours(Engine engine, long hours)
static Ticks
ofMinecraftMinutes(Engine engine, long minutes)
static Ticks
ofMinecraftSeconds(Engine engine, long seconds)
static Ticks
ofWallClockDays(Engine engine, int days)
static Ticks
ofWallClockHours(Engine engine, int hours)
static Ticks
ofWallClockMinutes(Engine engine, int minutes)
static Ticks
ofWallClockSeconds(Engine engine, int seconds)
static Ticks
ofWallClockTime(Engine engine, long time, java.time.temporal.TemporalUnit temporalUnit)
static Ticks
single()
Represents a single tick.long
ticks()
Gets the underlying number of ticks that this object represents.static Ticks
zero()
Represents zero ticks.
-
-
-
Method Detail
-
minecraftHour
static Ticks minecraftHour()
Represents a minecraft hour on theServer
in ticks.- Returns:
- A
Ticks
-
minecraftDay
static Ticks minecraftDay()
Represents a minecraft day on theServer
in ticks.- Returns:
- A
Ticks
-
of
static Ticks of(long ticks)
Returns aTicks
that represents the supplied number of ticks.This is platform and potentially
Engine
dependent - consult the target implementation for what a tick represents.- Parameters:
ticks
- The number of ticks- Returns:
- A
Ticks
object that represents the number of ticks.
-
ofWallClockTime
static Ticks ofWallClockTime(Engine engine, long time, java.time.temporal.TemporalUnit temporalUnit)
Returns aTicks
that would represent the supplied wall-clock time in the ideal case for the givenEngine
. If the given time would result in a non-integer number of ticks, the number of ticks will be rounded up, resulting in a slightly larger ideal duration.The supplied time is a lower bound on the wall-clock time - if the engine is overloaded the time taken to execute the number of ticks this represents will be higher.
-
ofWallClockSeconds
static Ticks ofWallClockSeconds(Engine engine, int seconds)
Returns aTicks
that would be executed in the given number of wall-clock seconds on the givenEngine
in an ideal case.- Parameters:
engine
- TheEngine
to calculate the number of ticks forseconds
- The number of seconds- Returns:
- The
Ticks
that represents the number of ticks that would be expected to be run on the given engine in an ideal scenario. - See Also:
ofWallClockTime(Engine, long, TemporalUnit)
-
ofWallClockMinutes
static Ticks ofWallClockMinutes(Engine engine, int minutes)
Returns aTicks
that would be executed in the given number of wall-clock minutes on the givenEngine
in an ideal case.- Parameters:
engine
- TheEngine
to calculate the number of ticks forminutes
- The number of minutes- Returns:
- The
Ticks
that represents the number of ticks that would be expected to be run on the given engine in an ideal scenario. - See Also:
ofWallClockTime(Engine, long, TemporalUnit)
-
ofWallClockHours
static Ticks ofWallClockHours(Engine engine, int hours)
Returns aTicks
that would be executed in the given number of wall-clock hours on the givenEngine
in an ideal case.- Parameters:
engine
- TheEngine
to calculate the number of ticks forhours
- The number of hours- Returns:
- The
Ticks
that represents the number of ticks that would be expected to be run on the given engine in an ideal scenario. - See Also:
ofWallClockTime(Engine, long, TemporalUnit)
-
ofWallClockDays
static Ticks ofWallClockDays(Engine engine, int days)
Returns aTicks
that would be executed in the given number of wall-clock days on the givenEngine
in an ideal case.- Parameters:
engine
- TheEngine
to calculate the number of ticks fordays
- The number of days- Returns:
- The
Ticks
that represents the number of ticks that would be expected to be run on the given engine in an ideal scenario. - See Also:
ofWallClockTime(Engine, long, TemporalUnit)
-
ofMinecraftSeconds
static Ticks ofMinecraftSeconds(Engine engine, long seconds)
Returns aTicks
that represents the given number of Minecraft day-time seconds on the givenEngine
.As a tick may not be an integer number of minecraft seconds, the returned
Ticks
object may be slightly larger than requested. The number of ticks returned will always be at least the requested duration.
-
ofMinecraftMinutes
static Ticks ofMinecraftMinutes(Engine engine, long minutes)
Returns aTicks
that represents the given number of Minecraft day-time seconds on the givenEngine
.As a tick may not be an integer number of minecraft minutes, the returned
Ticks
object may be slightly larger than requested. The number of ticks returned will always be at least the requested duration.
-
expectedDuration
java.time.Duration expectedDuration(Engine engine)
Gets the expectedDuration
of time it would take for the givenEngine
to process the number of ticks this object represents under ideal conditions.- Parameters:
engine
- TheEngine
to get theDuration
for- Returns:
- The effective
Duration
.
-
ticks
long ticks()
Gets the underlying number of ticks that this object represents.This number is platform and
Engine
dependent. It should not be stored and used beyond the currentEngine
session.- Returns:
- The number of ticks that this represents.
-
minecraftSeconds
long minecraftSeconds(Engine engine)
Gets the number of in-game seconds that thisTicks
represents for the givenEngine
.As there may not be a integer - integer relationship between seconds and ticks, this may be approximate. If the conversion results in a millisecond remainder, the duration is truncated rather than rounded - that is, if this object represents 6.7 seconds, this will return 6, not 7.
- Parameters:
engine
- TheEngine
to calculate the duration for.- Returns:
- The approximate number of in-game seconds
-
minecraftDayTimeDuration
java.time.Duration minecraftDayTimeDuration(Engine engine)
Returns the in-game time as aDuration
represents for the givenEngine
.This is not wall-clock time. This should not be used with any
Duration
that represents wall-clock times.- Parameters:
engine
- TheEngine
to calculate the duration for.- Returns:
- A duration representing the in game time.
-
-