Minor improvements
This commit is contained in:
parent
eba5e3f9e3
commit
b710cc1566
34
src/main.rs
34
src/main.rs
@ -360,6 +360,28 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Packet(packet) => match packet.as_ref() {
|
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) => {
|
ClientboundGamePacket::MoveEntityPos(packet) => {
|
||||||
let world = client.world.read();
|
let world = client.world.read();
|
||||||
let raw_entity = match world.entity(packet.entity_id) {
|
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 {
|
let entity = Entity {
|
||||||
id: raw_entity.id,
|
id: raw_entity.id,
|
||||||
uuid: raw_entity.uuid.as_hyphenated().to_string(),
|
uuid: raw_entity.uuid.as_hyphenated().to_string(),
|
||||||
entity_type,
|
entity_type: entity_type.to_owned(),
|
||||||
};
|
};
|
||||||
let entity_position = raw_entity.pos();
|
let entity_position = raw_entity.pos();
|
||||||
|
|
||||||
let mut is_player = false;
|
if entity_type == "player" {
|
||||||
let players = client.players.read().to_owned();
|
let players = client.players.read().to_owned();
|
||||||
for (uuid, player) in players.iter().map(|item| item.to_owned()) {
|
for (uuid, player) in players.iter().map(|item| item.to_owned()) {
|
||||||
if uuid.as_hyphenated().to_string() == entity.uuid {
|
if uuid.as_hyphenated().to_string() == entity.uuid {
|
||||||
is_player = true;
|
|
||||||
|
|
||||||
let mut player_locations =
|
let mut player_locations =
|
||||||
state.player_locations.lock().unwrap().to_owned();
|
state.player_locations.lock().unwrap().to_owned();
|
||||||
player_locations.insert(
|
player_locations.insert(
|
||||||
@ -430,7 +450,8 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(&player.profile.name)
|
.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(
|
alert_queue.insert(
|
||||||
player.profile.name.to_owned(),
|
player.profile.name.to_owned(),
|
||||||
vec![
|
vec![
|
||||||
@ -444,8 +465,7 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if !is_player {
|
|
||||||
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
|
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
|
||||||
mob_locations.insert(
|
mob_locations.insert(
|
||||||
entity,
|
entity,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user