Set time of day #55 (#76)

* Set time of day #55

* fix typo

* Update src/client.rs

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>

* format file

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
This commit is contained in:
dani162 2022-09-22 00:12:31 +02:00 committed by GitHub
parent 77ad1dfdd1
commit eed39364df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,7 +35,7 @@ use crate::protocol::packets::s2c::play::{
SetEntityVelocity, SetExperience, SetHeadRotation, SetHealth, SetRenderDistance, SetEntityVelocity, SetExperience, SetHeadRotation, SetHealth, SetRenderDistance,
SetSubtitleText, SetTitleText, SoundCategory, SynchronizePlayerPosition, SystemChatMessage, SetSubtitleText, SetTitleText, SoundCategory, SynchronizePlayerPosition, SystemChatMessage,
TeleportEntity, UnloadChunk, UpdateAttributes, UpdateEntityPosition, TeleportEntity, UnloadChunk, UpdateAttributes, UpdateEntityPosition,
UpdateEntityPositionAndRotation, UpdateEntityRotation, UpdateEntityPositionAndRotation, UpdateEntityRotation, UpdateTime,
}; };
use crate::protocol::{BoundedInt, BoundedString, ByteAngle, NbtBridge, RawBytes, VarInt}; use crate::protocol::{BoundedInt, BoundedString, ByteAngle, NbtBridge, RawBytes, VarInt};
use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer}; use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer};
@ -673,6 +673,17 @@ impl<C: Config> Client<C> {
}); });
} }
/// 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. /// Gets the client's current settings.
pub fn settings(&self) -> Option<&Settings> { pub fn settings(&self) -> Option<&Settings> {
self.settings.as_ref() self.settings.as_ref()