From eed39364df0247934f453111783aaf42e79d8800 Mon Sep 17 00:00:00 2001 From: dani162 <34603476+dani162@users.noreply.github.com> Date: Thu, 22 Sep 2022 00:12:31 +0200 Subject: [PATCH] Set time of day #55 (#76) * Set time of day #55 * fix typo * Update src/client.rs Co-authored-by: Ryan Johnson * format file Co-authored-by: Ryan Johnson --- src/client.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index b81b55f..bb2151b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -35,7 +35,7 @@ use crate::protocol::packets::s2c::play::{ SetEntityVelocity, SetExperience, SetHeadRotation, SetHealth, SetRenderDistance, SetSubtitleText, SetTitleText, SoundCategory, SynchronizePlayerPosition, SystemChatMessage, TeleportEntity, UnloadChunk, UpdateAttributes, UpdateEntityPosition, - UpdateEntityPositionAndRotation, UpdateEntityRotation, + UpdateEntityPositionAndRotation, UpdateEntityRotation, UpdateTime, }; use crate::protocol::{BoundedInt, BoundedString, ByteAngle, NbtBridge, RawBytes, VarInt}; use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer}; @@ -673,6 +673,17 @@ impl Client { }); } + /// Sets the world_age and the current in-game time. + /// + /// To stop time from passing, the `time_of_day` parameter must be + /// negative. The client stops the time at the absolute value. + pub fn set_time(&mut self, world_age: i64, time_of_day: i64) { + self.send_packet(UpdateTime { + world_age, + time_of_day, + }); + } + /// Gets the client's current settings. pub fn settings(&self) -> Option<&Settings> { self.settings.as_ref()