mirror of
https://github.com/italicsjenga/valence.git
synced 2025-02-04 17:46:35 +11:00
Add ClientEvent::InteractWithBlock (#26)
* Add ClientEvent::InteractWithBlock * Add an example of ClientEvent::InteractWithBlock to the conway example
This commit is contained in:
parent
b9b0728fd3
commit
42dfcef57d
3 changed files with 32 additions and 2 deletions
|
@ -7,7 +7,7 @@ use num::Integer;
|
|||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
|
||||
use valence::biome::Biome;
|
||||
use valence::block::BlockState;
|
||||
use valence::client::{default_client_event, ClientEvent};
|
||||
use valence::client::{default_client_event, ClientEvent, Hand};
|
||||
use valence::config::{Config, ServerListPing};
|
||||
use valence::dimension::{Dimension, DimensionId};
|
||||
use valence::entity::types::Pose;
|
||||
|
@ -209,6 +209,11 @@ impl Config for Game {
|
|||
server.state.board[index] = true;
|
||||
}
|
||||
}
|
||||
ClientEvent::InteractWithBlock { hand, .. } => {
|
||||
if hand == Hand::Main {
|
||||
client.send_message("I said left click, not right click!".italic());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -875,7 +875,16 @@ impl<C: Config> Client<C> {
|
|||
C2sPlayPacket::UpdateSign(_) => {}
|
||||
C2sPlayPacket::HandSwing(p) => self.events.push_back(ClientEvent::ArmSwing(p.hand)),
|
||||
C2sPlayPacket::SpectatorTeleport(_) => {}
|
||||
C2sPlayPacket::PlayerInteractBlock(_) => {}
|
||||
C2sPlayPacket::PlayerInteractBlock(p) => {
|
||||
self.events.push_back(ClientEvent::InteractWithBlock {
|
||||
hand: p.hand,
|
||||
location: p.location,
|
||||
face: p.face,
|
||||
cursor_pos: p.cursor_pos,
|
||||
head_inside_block: p.head_inside_block,
|
||||
sequence: p.sequence,
|
||||
})
|
||||
}
|
||||
C2sPlayPacket::PlayerInteractItem(_) => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::entity::{Entity, EntityEvent, EntityId, TrackedData};
|
|||
use crate::protocol::packets::c2s::play::BlockFace;
|
||||
pub use crate::protocol::packets::c2s::play::{ChatMode, DisplayedSkinParts, Hand, MainHand};
|
||||
pub use crate::protocol::packets::s2c::play::GameMode;
|
||||
use crate::protocol::VarInt;
|
||||
|
||||
/// Represents an action performed by a client.
|
||||
///
|
||||
|
@ -101,6 +102,20 @@ pub enum ClientEvent {
|
|||
/// The face of the block being broken.
|
||||
face: BlockFace,
|
||||
},
|
||||
InteractWithBlock {
|
||||
/// The hand that was used
|
||||
hand: Hand,
|
||||
/// The location of the block that was interacted with
|
||||
location: BlockPos,
|
||||
/// The face of the block that was clicked
|
||||
face: BlockFace,
|
||||
/// The pos inside of the block that was clicked on
|
||||
cursor_pos: Vec3<f32>,
|
||||
/// Whether or not the player's head is inside a block
|
||||
head_inside_block: bool,
|
||||
/// Sequence number
|
||||
sequence: VarInt,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
|
@ -247,6 +262,7 @@ pub fn default_client_event<C: Config>(
|
|||
ClientEvent::InteractWithEntity { .. } => {}
|
||||
ClientEvent::SteerBoat { .. } => {}
|
||||
ClientEvent::Digging { .. } => {}
|
||||
ClientEvent::InteractWithBlock { .. } => {}
|
||||
}
|
||||
|
||||
entity.set_world(client.world());
|
||||
|
|
Loading…
Add table
Reference in a new issue