Minor improvements

This commit is contained in:
ErrorNoInternet 2023-01-18 22:36:18 +08:00
parent eba5e3f9e3
commit b710cc1566
Signed by untrusted user who does not match committer: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -360,6 +360,28 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
}
}
Event::Packet(packet) => match packet.as_ref() {
ClientboundGamePacket::AddEntity(packet) => {
if packet.entity_type.to_string() != "Player" {
let entity = Entity {
id: packet.id,
uuid: packet.uuid.as_hyphenated().to_string(),
entity_type: packet.entity_type.to_string().to_lowercase(),
};
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
mob_locations.insert(
entity,
PositionTimeData {
position: vec![packet.x as i32, packet.y as i32, packet.z as i32],
time: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs(),
},
);
*state.mob_locations.lock().unwrap() = mob_locations;
}
}
ClientboundGamePacket::MoveEntityPos(packet) => {
let world = client.world.read();
let raw_entity = match world.entity(packet.entity_id) {
@ -381,16 +403,14 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
let entity = Entity {
id: raw_entity.id,
uuid: raw_entity.uuid.as_hyphenated().to_string(),
entity_type,
entity_type: entity_type.to_owned(),
};
let entity_position = raw_entity.pos();
let mut is_player = false;
if entity_type == "player" {
let players = client.players.read().to_owned();
for (uuid, player) in players.iter().map(|item| item.to_owned()) {
if uuid.as_hyphenated().to_string() == entity.uuid {
is_player = true;
let mut player_locations =
state.player_locations.lock().unwrap().to_owned();
player_locations.insert(
@ -430,7 +450,8 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
.unwrap()
.contains(&player.profile.name)
{
let mut alert_queue = state.alert_queue.lock().unwrap().to_owned();
let mut alert_queue =
state.alert_queue.lock().unwrap().to_owned();
alert_queue.insert(
player.profile.name.to_owned(),
vec![
@ -444,8 +465,7 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
}
}
}
if !is_player {
} else {
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
mob_locations.insert(
entity,