Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Fix entity movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Nov 15, 2023
1 parent 84d6c21 commit dde308a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions minecraft-server/src/entities/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Handler<Player> {
WorldChange::EntityDispawned { eid } => todo!(),
WorldChange::EntityMetadata { eid, metadata } => todo!(),
WorldChange::EntityPosition { eid, position } => {
let Some(prev_position) = self.observe(|player| player.entity_prev_positions.get(&eid).cloned()).await else {return};
let Some(prev_position) = self.mutate(|player| ((player.entity_prev_positions.insert(eid, position.clone())), EntityChanges::other())).await else {return};
match prev_position {
Some(prev_position) => {
self.send_packet(PlayClientbound::UpdateEntityPosition {
Expand Down Expand Up @@ -263,7 +263,14 @@ impl Handler<Player> {
velocity_z: (velocity.z * 8000.0) as i16,
}).await;
},
WorldChange::EntityPitch { eid, pitch, yaw, head_yaw } => todo!(),
WorldChange::EntityPitch { eid, pitch, yaw, head_yaw } => {
self.send_packet(PlayClientbound::UpdateEntityRotation {
entity_id: VarInt(eid as i32),
yaw: (yaw * (256.0 / 360.0)) as u8,
pitch: (pitch * (256.0 / 360.0)) as u8,
on_ground: true, // TODO add on_ground in entity position
}).await;
},
}
}

Expand Down Expand Up @@ -320,6 +327,7 @@ impl Handler<Player> {
position.y += 20.0;
zombie.get_entity_mut().position = position;
self.world.spawn_entity::<Zombie>(AnyEntity::Zombie(zombie)).await;
debug!("zombie spawned");
}
}
packet => warn!("Unsupported packet received: {packet:?}"),
Expand Down

0 comments on commit dde308a

Please sign in to comment.