mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 09:27:58 +01:00
fix title ticks
This commit is contained in:
parent
87b30a8361
commit
f2897eedca
@ -115,8 +115,9 @@ public class TitlePacket implements ServerPacket {
|
||||
// times packet
|
||||
Title.Times times = title.times();
|
||||
if (times != null) {
|
||||
packets.add(new TitlePacket(TickUtils.fromDuration(times.fadeIn()), TickUtils.fromDuration(times.stay()),
|
||||
TickUtils.fromDuration(times.fadeOut())));
|
||||
packets.add(new TitlePacket(TickUtils.fromDuration(times.fadeIn(), TickUtils.CLIENT_TICK_MS),
|
||||
TickUtils.fromDuration(times.stay(), TickUtils.CLIENT_TICK_MS),
|
||||
TickUtils.fromDuration(times.fadeOut(), TickUtils.CLIENT_TICK_MS)));
|
||||
}
|
||||
|
||||
return packets;
|
||||
|
@ -10,6 +10,15 @@ import java.time.Duration;
|
||||
* Tick related utilities.
|
||||
*/
|
||||
public class TickUtils {
|
||||
/**
|
||||
* Number of ticks per second for the default Java-edition client.
|
||||
*/
|
||||
public static final int CLIENT_TPS = 20;
|
||||
|
||||
/**
|
||||
* Length of time per tick for the default Java-edition client.
|
||||
*/
|
||||
public static final int CLIENT_TICK_MS = 50;
|
||||
|
||||
/**
|
||||
* Creates a number of ticks from a given duration, based on {@link MinecraftServer#TICK_MS}.
|
||||
@ -18,8 +27,19 @@ public class TickUtils {
|
||||
* @throws IllegalArgumentException if duration is negative
|
||||
*/
|
||||
public static int fromDuration(@NotNull Duration duration) {
|
||||
return TickUtils.fromDuration(duration, MinecraftServer.TICK_MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a number of ticks from a given duration.
|
||||
* @param duration the duration
|
||||
* @param msPerTick the number of milliseconds per tick
|
||||
* @return the number of ticks
|
||||
* @throws IllegalArgumentException if duration is negative
|
||||
*/
|
||||
public static int fromDuration(@NotNull Duration duration, int msPerTick) {
|
||||
Validate.isTrue(!duration.isNegative(), "Duration cannot be negative");
|
||||
|
||||
return (int) (duration.toMillis() / MinecraftServer.TICK_MS);
|
||||
return (int) (duration.toMillis() / msPerTick);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user