1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

EntityPos

This commit is contained in:
mat 2022-06-17 18:09:34 -05:00
parent d27d283686
commit 0a945e73ec
7 changed files with 34 additions and 6 deletions

View file

@ -1,5 +1,5 @@
use crate::Player;
use azalea_core::{resource_location::ResourceLocation, ChunkPos};
use azalea_core::{resource_location::ResourceLocation, ChunkPos, EntityPos};
use azalea_protocol::{
connect::{GameConnection, HandshakeConnection},
packets::{
@ -351,6 +351,11 @@ impl Client {
}
GamePacket::ClientboundAddEntityPacket(p) => {
println!("Got add entity packet {:?}", p);
let pos = EntityPos {
x: p.x,
y: p.y,
z: p.z,
};
}
GamePacket::ClientboundSetEntityDataPacket(p) => {
// println!("Got set entity data packet {:?}", p);

View file

@ -1,5 +1,8 @@
#[derive(Default)]
use azalea_core::EntityPos;
#[derive(Default, Debug)]
pub struct Entity {
/// The incremental numerical id of the entity.
pub id: u32,
pub pos: EntityPos,
}

View file

@ -1,6 +1,6 @@
use crate::Entity;
#[derive(Default)]
#[derive(Default, Debug)]
pub struct Player {
/// The entity attached to the player. There's some useful fields here.
pub entity: Entity,

View file

@ -11,9 +11,7 @@ mod slot;
pub use slot::{Slot, SlotData};
mod position;
pub use position::{
BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos, GlobalPos,
};
pub use position::*;
mod direction;
pub use direction::Direction;

View file

@ -147,6 +147,23 @@ pub struct GlobalPos {
pub dimension: ResourceLocation,
}
#[derive(Debug, Clone, Default)]
pub struct EntityPos {
pub x: f64,
pub y: f64,
pub z: f64,
}
impl From<&EntityPos> for BlockPos {
fn from(pos: &EntityPos) -> Self {
BlockPos {
x: pos.x as i32,
y: pos.y as i32,
z: pos.z as i32,
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -3,6 +3,7 @@ use uuid::Uuid;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAddEntityPacket {
/// The id of the entity.
#[var]
pub id: u32,
pub uuid: Uuid,

View file

@ -21,6 +21,10 @@ async fn main() {
// TODO: have a "loaded" or "ready" event that fires when all chunks are loaded
Event::Login => {}
Event::Chat(p) => {
let state = client.state.lock().await;
let world = state.world.as_ref().unwrap();
// println!("{:?}", state.player.entity);
// world.get_block_state(state.player.entity.pos);
// println!("{}", p.message.to_ansi(None));
// if p.message.to_ansi(None) == "<py5> ok" {
// let state = client.state.lock().await;