pub struct Client<C: Config> {
pub state: C::ClientState,
/* private fields */
}
Expand description
Represents a remote connection to a client after successfully logging in.
Much like an Entity
, clients possess a location, rotation, and UUID.
However, clients are handled separately from entities and are partially
managed by the library.
By default, clients have no influence over the worlds they reside in. They
cannot break blocks, hurt entities, or see other clients. Interactions with
the server must be handled explicitly with Self::pop_event
.
Additionally, clients possess Player
entity data which is only visible
to themselves. This can be accessed with Self::player
and
Self::player_mut
.
The Difference Between a “Client” and a “Player”
Normally in Minecraft, players and clients are one and the same. Players are simply a subtype of the entity base class backed by a remote connection.
In Valence however, clients and players are decoupled. This separation allows for greater flexibility and enables parallelism.
Fields
state: C::ClientState
Custom state.
Implementations
sourceimpl<C: Config> Client<C>
impl<C: Config> Client<C>
sourcepub fn created_this_tick(&self) -> bool
pub fn created_this_tick(&self) -> bool
If the client joined the game this tick.
sourcepub fn textures(&self) -> Option<&SignedPlayerTextures>
pub fn textures(&self) -> Option<&SignedPlayerTextures>
Gets the player textures of this client. If the client does not have
a skin, then None
is returned.
sourcepub fn player_list(&self) -> Option<&PlayerListId>
pub fn player_list(&self) -> Option<&PlayerListId>
Gets the player list this client sees.
sourcepub fn set_player_list(
&mut self,
id: impl Into<Option<PlayerListId>>
) -> Option<PlayerListId>
pub fn set_player_list(
&mut self,
id: impl Into<Option<PlayerListId>>
) -> Option<PlayerListId>
Sets the player list this client sees.
The previous player list ID is returned.
sourcepub fn set_flat(&mut self, flat: bool)
pub fn set_flat(&mut self, flat: bool)
Sets if this client sees the world as superflat. Superflat worlds have a horizon line lower than normal worlds.
The player must be (re)spawned for changes to take effect.
sourcepub fn is_flat(&self) -> bool
pub fn is_flat(&self) -> bool
Gets if this client sees the world as superflat. Superflat worlds have a horizon line lower than normal worlds.
sourcepub fn spawn(&mut self, world: WorldId)
pub fn spawn(&mut self, world: WorldId)
Changes the world this client is located in and respawns the client. This can be used to respawn the client after death.
The given WorldId
must be valid. Otherwise, the client is
disconnected.
sourcepub fn send_message(&mut self, msg: impl Into<Text>)
pub fn send_message(&mut self, msg: impl Into<Text>)
Sends a system message to the player which is visible in the chat. The message is only visible to this client.
sourcepub fn position(&self) -> Vec3<f64>
pub fn position(&self) -> Vec3<f64>
Gets the absolute position of this client in the world it is located in.
sourcepub fn teleport(&mut self, pos: impl Into<Vec3<f64>>, yaw: f32, pitch: f32)
pub fn teleport(&mut self, pos: impl Into<Vec3<f64>>, yaw: f32, pitch: f32)
Changes the position and rotation of this client in the world it is located in.
If you want to change the client’s world, use Self::spawn
.
sourcepub fn set_velocity(&mut self, velocity: impl Into<Vec3<f32>>)
pub fn set_velocity(&mut self, velocity: impl Into<Vec3<f32>>)
Sets the client’s velocity in m/s.
sourcepub fn spawn_position(&self) -> BlockPos
pub fn spawn_position(&self) -> BlockPos
Gets the spawn position. The client will see minecraft:compass
items
point at the returned position.
sourcepub fn set_spawn_position(&mut self, pos: impl Into<BlockPos>, yaw_degrees: f32)
pub fn set_spawn_position(&mut self, pos: impl Into<BlockPos>, yaw_degrees: f32)
Sets the spawn position. The client will see minecraft:compass
items
point at the provided position.
sourcepub fn death_location(&self) -> Option<(DimensionId, BlockPos)>
pub fn death_location(&self) -> Option<(DimensionId, BlockPos)>
Gets the last death location of this client. The client will see
minecraft:recovery_compass
items point at the returned position.
If the client’s current dimension differs from the returned
dimension or the location is None
then the compass will spin
randomly.
sourcepub fn set_death_location(&mut self, location: Option<(DimensionId, BlockPos)>)
pub fn set_death_location(&mut self, location: Option<(DimensionId, BlockPos)>)
Sets the last death location. The client will see
minecraft:recovery_compass
items point at the provided position.
If the client’s current dimension differs from the provided
dimension or the location is None
then the compass will spin
randomly.
Changes to the last death location take effect when the client (re)spawns.
sourcepub fn set_game_mode(&mut self, game_mode: GameMode)
pub fn set_game_mode(&mut self, game_mode: GameMode)
Sets the client’s game mode.
sourcepub fn set_title(
&mut self,
title: impl Into<Text>,
subtitle: impl Into<Text>,
animation: impl Into<Option<TitleFade>>
)
pub fn set_title(
&mut self,
title: impl Into<Text>,
subtitle: impl Into<Text>,
animation: impl Into<Option<TitleFade>>
)
Sets the title this client sees.
A title is a large piece of text displayed in the center of the screen
which may also include a subtitle underneath it. The title
can be configured to fade in and out using the
TitleFade
struct.
sourcepub fn attack_speed(&self) -> f64
pub fn attack_speed(&self) -> f64
Gets the attack cooldown speed.
sourcepub fn set_attack_speed(&mut self, speed: f64)
pub fn set_attack_speed(&mut self, speed: f64)
Sets the attack cooldown speed.
sourcepub fn movement_speed(&self) -> f64
pub fn movement_speed(&self) -> f64
Gets the speed at which the client can run on the ground.
sourcepub fn set_movement_speed(&mut self, speed: f64)
pub fn set_movement_speed(&mut self, speed: f64)
Sets the speed at which the client can run on the ground.
sourcepub fn clear_title(&mut self)
pub fn clear_title(&mut self)
Removes the current title from the client’s screen.
sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Gets whether or not the client is connected to the server.
A disconnected client object will never become reconnected. It is your
responsibility to remove disconnected clients from the Clients
container.
sourcepub fn events(
&self
) -> impl DoubleEndedIterator<Item = &ClientEvent> + ExactSizeIterator + FusedIterator + Clone + '_
pub fn events(
&self
) -> impl DoubleEndedIterator<Item = &ClientEvent> + ExactSizeIterator + FusedIterator + Clone + '_
Returns an iterator over all pending client events in the order they will be removed from the queue.
sourcepub fn pop_event(&mut self) -> Option<ClientEvent>
pub fn pop_event(&mut self) -> Option<ClientEvent>
Removes a ClientEvent
from the event queue.
If there are no remaining events, None
is returned.
Any remaining client events are deleted at the end of the current tick.
sourcepub fn push_entity_event(&mut self, event: EntityEvent)
pub fn push_entity_event(&mut self, event: EntityEvent)
Pushes an entity event to the queue.
sourcepub fn view_distance(&self) -> u8
pub fn view_distance(&self) -> u8
The current view distance of this client measured in chunks. The client will not be able to see chunks and entities past this distance.
The result is in 2..=32
.
sourcepub fn set_view_distance(&mut self, dist: u8)
pub fn set_view_distance(&mut self, dist: u8)
Sets the view distance. The client will not be able to see chunks and entities past this distance.
The new view distance is measured in chunks and is clamped to 2..=32
.
sourcepub fn set_hardcore(&mut self, hardcore: bool)
pub fn set_hardcore(&mut self, hardcore: bool)
Enables hardcore mode. This changes the design of the client’s hearts.
To have any visible effect, this function must be called on the same tick the client joins the server.
sourcepub fn is_hardcore(&self) -> bool
pub fn is_hardcore(&self) -> bool
Gets if hardcore mode is enabled.
sourcepub fn disconnect(&mut self, reason: impl Into<Text>)
pub fn disconnect(&mut self, reason: impl Into<Text>)
Disconnects this client from the server with the provided reason. This has no effect if the client is already disconnected.
All future calls to Self::is_disconnected
will return true
.
sourcepub fn disconnect_no_reason(&mut self)
pub fn disconnect_no_reason(&mut self)
Like Self::disconnect
, but no reason for the disconnect is
displayed.
sourcepub fn player(&self) -> &Player
pub fn player(&self) -> &Player
Returns an immutable reference to the client’s own Player
data.
sourcepub fn player_mut(&mut self) -> &mut Player
pub fn player_mut(&mut self) -> &mut Player
Returns a mutable reference to the client’s own Player
data.
Changes made to this data is only visible to this client.
sourcepub fn send_packet(&mut self, packet: impl Into<S2cPlayPacket>)
pub fn send_packet(&mut self, packet: impl Into<S2cPlayPacket>)
Attempts to enqueue a play packet to be sent to this client. The client is disconnected if the clientbound packet buffer is full.
Auto Trait Implementations
impl<C> RefUnwindSafe for Client<C>where
<C as Config>::ClientState: RefUnwindSafe,
impl<C> Send for Client<C>
impl<C> Sync for Client<C>
impl<C> Unpin for Client<C>where
<C as Config>::ClientState: Unpin,
impl<C> UnwindSafe for Client<C>where
<C as Config>::ClientState: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted. Read more
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes self
to use its Octal
implementation when Debug
-formatted. Read more
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
Formats each item in a sequence. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
Pipes by value. This is generally the method you want to use. Read more
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the Deref::Target
of a value. Read more
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the Deref::Target
of a value. Read more
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more