Document and rename default_client_event to handle_event_default.

This commit is contained in:
Ryan 2022-09-11 21:59:05 -07:00
parent bc470f3eb3
commit 65dc561868
6 changed files with 23 additions and 13 deletions

View file

@ -5,7 +5,7 @@ use log::LevelFilter;
use valence::block::{BlockPos, BlockState};
use valence::chunk::{Chunk, UnloadedChunk};
use valence::client::{
default_client_event, ClientEvent, ClientId, GameMode, InteractWithEntityKind,
handle_event_default, ClientEvent, ClientId, GameMode, InteractWithEntityKind,
};
use valence::config::{Config, ServerListPing};
use valence::dimension::DimensionId;
@ -213,7 +213,7 @@ impl Config for Game {
.get_mut(client.state.player)
.expect("missing player entity");
match default_client_event(client, player) {
match handle_event_default(client, player) {
Some(ClientEvent::StartSprinting) => {
client.state.extra_knockback = true;
}

View file

@ -8,7 +8,7 @@ use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelI
use valence::biome::Biome;
use valence::block::BlockState;
use valence::chunk::{Chunk, UnloadedChunk};
use valence::client::{default_client_event, ClientEvent, Hand};
use valence::client::{handle_event_default, ClientEvent, Hand};
use valence::config::{Config, ServerListPing};
use valence::dimension::{Dimension, DimensionId};
use valence::entity::types::Pose;
@ -191,7 +191,7 @@ impl Config for Game {
server.state.board.fill(false);
}
while let Some(event) = default_client_event(client, player) {
while let Some(event) = handle_event_default(client, player) {
match event {
ClientEvent::Digging { position, .. } => {
if (0..SIZE_X as i32).contains(&position.x)

View file

@ -8,7 +8,7 @@ use uuid::Uuid;
use valence::async_trait;
use valence::block::{BlockPos, BlockState};
use valence::chunk::UnloadedChunk;
use valence::client::{default_client_event, GameMode};
use valence::client::{handle_event_default, GameMode};
use valence::config::{Config, PlayerSampleEntry, ServerListPing};
use valence::dimension::DimensionId;
use valence::entity::{EntityId, EntityKind};
@ -176,7 +176,7 @@ impl Config for Game {
.get_mut(client.state)
.expect("missing player entity");
while default_client_event(client, entity).is_some() {}
while handle_event_default(client, entity).is_some() {}
true
});

View file

@ -5,7 +5,7 @@ use log::LevelFilter;
use valence::async_trait;
use valence::block::{BlockPos, BlockState};
use valence::chunk::UnloadedChunk;
use valence::client::{default_client_event, GameMode};
use valence::client::{handle_event_default, GameMode};
use valence::config::{Config, ServerListPing};
use valence::dimension::DimensionId;
use valence::entity::{EntityId, EntityKind, TrackedData};
@ -184,7 +184,7 @@ impl Config for Game {
}
}
while default_client_event(client, server.entities.get_mut(client.state).unwrap())
while handle_event_default(client, server.entities.get_mut(client.state).unwrap())
.is_some()
{}

View file

@ -7,7 +7,7 @@ use rayon::iter::ParallelIterator;
use valence::async_trait;
use valence::block::{BlockState, PropName, PropValue};
use valence::chunk::{Chunk, ChunkPos, UnloadedChunk};
use valence::client::{default_client_event, GameMode};
use valence::client::{handle_event_default, GameMode};
use valence::config::{Config, ServerListPing};
use valence::dimension::DimensionId;
use valence::entity::{EntityId, EntityKind};
@ -142,7 +142,7 @@ impl Config for Game {
}
if let Some(entity) = server.entities.get_mut(client.state) {
while default_client_event(client, entity).is_some() {}
while handle_event_default(client, entity).is_some() {}
}
let dist = client.view_distance();

View file

@ -152,9 +152,19 @@ pub enum DiggingStatus {
Finish,
}
/// Standard client event handler that stores various things a player may do.
/// Used to avoid extra boilerplate.
pub fn default_client_event<C: Config>(
/// Pops one event from the event queue of `client` and expresses the event in a
/// reasonable way using `entity`. For instance, movement events are expressed
/// by changing the entity's position to match the received position. Rotation
/// events rotate the entity. etc.
///
/// This function's primary purpose is to reduce boilerplate code in the
/// examples, but it can be used as a quick way to get started in your own code.
/// The precise behavior of this function is left unspecified and is subject to
/// change.
///
/// The popped event is returned unmodified. `None` is returned if there are no
/// more events in `client`.
pub fn handle_event_default<C: Config>(
client: &mut Client<C>,
entity: &mut Entity<C>,
) -> Option<ClientEvent> {