aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-client/src/client.rs14
-rw-r--r--azalea-core/src/delta.rs10
-rwxr-xr-xazalea-core/src/resource_location.rs3
-rw-r--r--azalea-entity/src/lib.rs2
-rw-r--r--azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs6
-rw-r--r--azalea-world/src/lib.rs40
-rw-r--r--bot/src/main.rs2
7 files changed, 42 insertions, 35 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index a7841637..6efe521b 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -433,20 +433,16 @@ impl Client {
// println!("Got rotate head packet {:?}", p);
}
GamePacket::ClientboundMoveEntityPosPacket(p) => {
- // println!("Got move entity pos packet {:?}", p);
+ let mut state_lock = state.lock()?;
+ let world = state_lock.world.as_mut().unwrap();
+
+ world.move_entity_with_delta(p.entity_id, &p.delta)?;
}
GamePacket::ClientboundMoveEntityPosRotPacket(p) => {
let mut state_lock = state.lock()?;
let world = state_lock.world.as_mut().unwrap();
- // world.move_entity(
- // p.entity_id,
- // EntityPos {
- // x: p.x,
- // y: p.y,
- // z: p.z,
- // },
- // )?;
+ world.move_entity_with_delta(p.entity_id, &p.delta)?;
}
GamePacket::ClientboundMoveEntityRotPacket(p) => {
println!("Got move entity rot packet {:?}", p);
diff --git a/azalea-core/src/delta.rs b/azalea-core/src/delta.rs
index 339e52cd..41923ffb 100644
--- a/azalea-core/src/delta.rs
+++ b/azalea-core/src/delta.rs
@@ -20,10 +20,12 @@ impl PositionDelta {
}
impl EntityPos {
- pub fn apply_delta(&mut self, delta: &PositionDelta) {
+ pub fn with_delta(&self, delta: &PositionDelta) -> EntityPos {
let (x, y, z) = delta.float();
- self.x += x;
- self.y += y;
- self.z += z;
+ EntityPos {
+ x: self.x + x,
+ y: self.y + y,
+ z: self.z + z,
+ }
}
}
diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs
index 61ae8a20..acca0c58 100755
--- a/azalea-core/src/resource_location.rs
+++ b/azalea-core/src/resource_location.rs
@@ -93,7 +93,8 @@ mod tests {
let mut buf = Vec::new();
ResourceLocation::new("minecraft:dirt")
.unwrap()
- .write_into(&mut buf)?;
+ .write_into(&mut buf)
+ .unwrap();
let mut buf = Cursor::new(buf);
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
index 93ed5ea8..065413a5 100644
--- a/azalea-entity/src/lib.rs
+++ b/azalea-entity/src/lib.rs
@@ -14,7 +14,7 @@ pub struct Entity {
/// The incrementing numerical id of the entity.
pub id: u32,
pub uuid: Uuid,
- pub pos: EntityPos,
+ pos: EntityPos,
}
impl Entity {
diff --git a/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs b/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs
index 3dc789a9..63428dd8 100644
--- a/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs
@@ -1,11 +1,11 @@
-use azalea_core::{EntityPos, PositionDelta};
-use packet_macros::GamePacket;
use azalea_buf::McBuf;
+use azalea_core::PositionDelta;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityPosPacket {
#[var]
- pub entity_id: i32,
+ pub entity_id: u32,
pub delta: PositionDelta,
pub on_ground: bool,
}
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index cbc5c633..bc73c13d 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -6,7 +6,7 @@ mod entity;
mod palette;
use azalea_block::BlockState;
-use azalea_core::{BlockPos, ChunkPos, EntityPos};
+use azalea_core::{BlockPos, ChunkPos, EntityPos, PositionDelta};
use azalea_entity::Entity;
pub use bit_storage::BitStorage;
pub use chunk::{Chunk, ChunkStorage};
@@ -61,6 +61,7 @@ impl World {
.entity_storage
.get_mut_by_id(entity_id)
.ok_or_else(|| "Moving entity that doesn't exist".to_string())?;
+
let old_chunk = ChunkPos::from(entity.pos());
let new_chunk = ChunkPos::from(&new_pos);
// this is fine because we update the chunk below
@@ -72,21 +73,28 @@ impl World {
Ok(())
}
- // pub fn move_entity_with_delta(&mut self, entity_id: u32, delta: PositionDelta) -> Result<(), String> {
- // let entity = self
- // .entity_storage
- // .get_mut_by_id(entity_id)
- // .ok_or_else(|| "Moving entity that doesn't exist".to_string())?;
- // let old_chunk = ChunkPos::from(entity.pos());
- // let new_chunk = ChunkPos::from(&new_pos);
- // // this is fine because we update the chunk below
- // entity.unsafe_move(new_pos);
- // if old_chunk != new_chunk {
- // self.entity_storage
- // .update_entity_chunk(entity_id, &old_chunk, &new_chunk);
- // }
- // Ok(())
- // }
+ pub fn move_entity_with_delta(
+ &mut self,
+ entity_id: u32,
+ delta: &PositionDelta,
+ ) -> Result<(), String> {
+ let entity = self
+ .entity_storage
+ .get_mut_by_id(entity_id)
+ .ok_or_else(|| "Moving entity that doesn't exist".to_string())?;
+ let new_pos = entity.pos().with_delta(delta);
+
+ let old_chunk = ChunkPos::from(entity.pos());
+ let new_chunk = ChunkPos::from(&new_pos);
+ // this is fine because we update the chunk below
+
+ entity.unsafe_move(new_pos);
+ if old_chunk != new_chunk {
+ self.entity_storage
+ .update_entity_chunk(entity_id, &old_chunk, &new_chunk);
+ }
+ Ok(())
+ }
pub fn add_entity(&mut self, entity: Entity) {
self.entity_storage.insert(entity);
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 1cb209e5..02f802a5 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -6,7 +6,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Hello, world!");
// let address = "95.111.249.143:10000";
- let address = "localhost:52722";
+ let address = "localhost:49982";
// let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
// .await
// .unwrap();