From 69e1125ecbb3e695125b8e65deba3e3f7be41b70 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 17 Jun 2022 15:59:27 -0500 Subject: Slightly improve bit storage --- bot/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/src') diff --git a/bot/src/main.rs b/bot/src/main.rs index 8ad74ec4..cd27ba5a 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -6,7 +6,7 @@ async fn main() { println!("Hello, world!"); // let address = "95.111.249.143:10000"; - let address = "localhost:65519"; + let address = "localhost:51028"; // let response = azalea_client::ping::ping_server(&address.try_into().unwrap()) // .await // .unwrap(); -- cgit v1.2.3 From 0a945e73ec43b3b0389e004e138c83f41cddc532 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 17 Jun 2022 18:09:34 -0500 Subject: EntityPos --- azalea-client/src/connect.rs | 7 ++++++- azalea-client/src/entity.rs | 5 ++++- azalea-client/src/player.rs | 2 +- azalea-core/src/lib.rs | 4 +--- azalea-core/src/position.rs | 17 +++++++++++++++++ .../src/packets/game/clientbound_add_entity_packet.rs | 1 + bot/src/main.rs | 4 ++++ 7 files changed, 34 insertions(+), 6 deletions(-) (limited to 'bot/src') diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index 4ef3df63..1551ca69 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -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); diff --git a/azalea-client/src/entity.rs b/azalea-client/src/entity.rs index ed8aa68d..d91f556f 100644 --- a/azalea-client/src/entity.rs +++ b/azalea-client/src/entity.rs @@ -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, } diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs index fc54ff93..04d34f6d 100644 --- a/azalea-client/src/player.rs +++ b/azalea-client/src/player.rs @@ -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, diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs index cdb32ea9..a2632871 100755 --- a/azalea-core/src/lib.rs +++ b/azalea-core/src/lib.rs @@ -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; diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index d5c97eab..24be5f6a 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -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::*; diff --git a/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs b/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs index 8a8a713e..9ef7e05c 100644 --- a/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs @@ -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, diff --git a/bot/src/main.rs b/bot/src/main.rs index cd27ba5a..2618675e 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -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) == " ok" { // let state = client.state.lock().await; -- cgit v1.2.3 From 405a00c0d1908a4b3fbd8e6684c77dfb178ac55d Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 19 Jun 2022 13:54:43 -0500 Subject: Fix ClientboundLevelParticlesPacket The particle id is a varint --- .../src/packets/game/clientbound_entity_event_packet.rs | 4 ++-- .../src/packets/game/clientbound_level_particles_packet.rs | 11 ++++++----- bot/src/main.rs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'bot/src') diff --git a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs index 1b06bff7..d0cc7222 100644 --- a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs @@ -3,6 +3,6 @@ use packet_macros::{GamePacket, McBuf}; // we can't identify the status in azalea-protocol since they vary depending on the entity #[derive(Clone, Debug, McBuf, GamePacket)] pub struct ClientboundEntityEventPacket { - pub entity_id: i32, - pub entity_status: i8, + pub entity_id: u32, + pub event_id: u8, } diff --git a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs index a3538598..9ed08d8a 100644 --- a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs @@ -1,10 +1,11 @@ -use std::io::{Read, Write}; - +use crate::mc_buf::McBufVarReadable; use crate::mc_buf::{McBufReadable, McBufWritable, ParticleData}; use packet_macros::GamePacket; +use std::io::{Read, Write}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundLevelParticlesPacket { + #[var] pub particle_id: u32, pub override_limiter: bool, pub x: f64, @@ -14,13 +15,13 @@ pub struct ClientboundLevelParticlesPacket { pub y_dist: f32, pub z_dist: f32, pub max_speed: f32, - pub count: i32, + pub count: u32, pub data: ParticleData, } impl McBufReadable for ClientboundLevelParticlesPacket { fn read_into(buf: &mut impl Read) -> Result { - let particle_id = u32::read_into(buf)?; + let particle_id = u32::var_read_into(buf)?; let override_limiter = bool::read_into(buf)?; let x = f64::read_into(buf)?; let y = f64::read_into(buf)?; @@ -29,7 +30,7 @@ impl McBufReadable for ClientboundLevelParticlesPacket { let y_dist = f32::read_into(buf)?; let z_dist = f32::read_into(buf)?; let max_speed = f32::read_into(buf)?; - let count = i32::read_into(buf)?; + let count = u32::read_into(buf)?; let data = ParticleData::read_from_particle_id(buf, particle_id)?; diff --git a/bot/src/main.rs b/bot/src/main.rs index 2618675e..e2e87456 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -6,7 +6,7 @@ async fn main() { println!("Hello, world!"); // let address = "95.111.249.143:10000"; - let address = "localhost:51028"; + let address = "localhost:61146"; // let response = azalea_client::ping::ping_server(&address.try_into().unwrap()) // .await // .unwrap(); -- cgit v1.2.3