mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 22:41:30 +11:00
Document and rename default_client_event
to handle_event_default
.
This commit is contained in:
parent
bc470f3eb3
commit
65dc561868
|
@ -5,7 +5,7 @@ use log::LevelFilter;
|
||||||
use valence::block::{BlockPos, BlockState};
|
use valence::block::{BlockPos, BlockState};
|
||||||
use valence::chunk::{Chunk, UnloadedChunk};
|
use valence::chunk::{Chunk, UnloadedChunk};
|
||||||
use valence::client::{
|
use valence::client::{
|
||||||
default_client_event, ClientEvent, ClientId, GameMode, InteractWithEntityKind,
|
handle_event_default, ClientEvent, ClientId, GameMode, InteractWithEntityKind,
|
||||||
};
|
};
|
||||||
use valence::config::{Config, ServerListPing};
|
use valence::config::{Config, ServerListPing};
|
||||||
use valence::dimension::DimensionId;
|
use valence::dimension::DimensionId;
|
||||||
|
@ -213,7 +213,7 @@ impl Config for Game {
|
||||||
.get_mut(client.state.player)
|
.get_mut(client.state.player)
|
||||||
.expect("missing player entity");
|
.expect("missing player entity");
|
||||||
|
|
||||||
match default_client_event(client, player) {
|
match handle_event_default(client, player) {
|
||||||
Some(ClientEvent::StartSprinting) => {
|
Some(ClientEvent::StartSprinting) => {
|
||||||
client.state.extra_knockback = true;
|
client.state.extra_knockback = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelI
|
||||||
use valence::biome::Biome;
|
use valence::biome::Biome;
|
||||||
use valence::block::BlockState;
|
use valence::block::BlockState;
|
||||||
use valence::chunk::{Chunk, UnloadedChunk};
|
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::config::{Config, ServerListPing};
|
||||||
use valence::dimension::{Dimension, DimensionId};
|
use valence::dimension::{Dimension, DimensionId};
|
||||||
use valence::entity::types::Pose;
|
use valence::entity::types::Pose;
|
||||||
|
@ -191,7 +191,7 @@ impl Config for Game {
|
||||||
server.state.board.fill(false);
|
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 {
|
match event {
|
||||||
ClientEvent::Digging { position, .. } => {
|
ClientEvent::Digging { position, .. } => {
|
||||||
if (0..SIZE_X as i32).contains(&position.x)
|
if (0..SIZE_X as i32).contains(&position.x)
|
||||||
|
|
|
@ -8,7 +8,7 @@ use uuid::Uuid;
|
||||||
use valence::async_trait;
|
use valence::async_trait;
|
||||||
use valence::block::{BlockPos, BlockState};
|
use valence::block::{BlockPos, BlockState};
|
||||||
use valence::chunk::UnloadedChunk;
|
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::config::{Config, PlayerSampleEntry, ServerListPing};
|
||||||
use valence::dimension::DimensionId;
|
use valence::dimension::DimensionId;
|
||||||
use valence::entity::{EntityId, EntityKind};
|
use valence::entity::{EntityId, EntityKind};
|
||||||
|
@ -176,7 +176,7 @@ impl Config for Game {
|
||||||
.get_mut(client.state)
|
.get_mut(client.state)
|
||||||
.expect("missing player entity");
|
.expect("missing player entity");
|
||||||
|
|
||||||
while default_client_event(client, entity).is_some() {}
|
while handle_event_default(client, entity).is_some() {}
|
||||||
|
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ use log::LevelFilter;
|
||||||
use valence::async_trait;
|
use valence::async_trait;
|
||||||
use valence::block::{BlockPos, BlockState};
|
use valence::block::{BlockPos, BlockState};
|
||||||
use valence::chunk::UnloadedChunk;
|
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::config::{Config, ServerListPing};
|
||||||
use valence::dimension::DimensionId;
|
use valence::dimension::DimensionId;
|
||||||
use valence::entity::{EntityId, EntityKind, TrackedData};
|
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()
|
.is_some()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rayon::iter::ParallelIterator;
|
||||||
use valence::async_trait;
|
use valence::async_trait;
|
||||||
use valence::block::{BlockState, PropName, PropValue};
|
use valence::block::{BlockState, PropName, PropValue};
|
||||||
use valence::chunk::{Chunk, ChunkPos, UnloadedChunk};
|
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::config::{Config, ServerListPing};
|
||||||
use valence::dimension::DimensionId;
|
use valence::dimension::DimensionId;
|
||||||
use valence::entity::{EntityId, EntityKind};
|
use valence::entity::{EntityId, EntityKind};
|
||||||
|
@ -142,7 +142,7 @@ impl Config for Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(entity) = server.entities.get_mut(client.state) {
|
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();
|
let dist = client.view_distance();
|
||||||
|
|
|
@ -152,9 +152,19 @@ pub enum DiggingStatus {
|
||||||
Finish,
|
Finish,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Standard client event handler that stores various things a player may do.
|
/// Pops one event from the event queue of `client` and expresses the event in a
|
||||||
/// Used to avoid extra boilerplate.
|
/// reasonable way using `entity`. For instance, movement events are expressed
|
||||||
pub fn default_client_event<C: Config>(
|
/// 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>,
|
client: &mut Client<C>,
|
||||||
entity: &mut Entity<C>,
|
entity: &mut Entity<C>,
|
||||||
) -> Option<ClientEvent> {
|
) -> Option<ClientEvent> {
|
||||||
|
|
Loading…
Reference in a new issue