use super::*;
pub(super) const RECORDED_VEHICLE_PACKETS_12: [i32; 13] =
recorded_vehicle_packets!(ghast_protocol::v1_12_2);
impl Sim12 {
#[cold]
#[inline(never)]
pub(super) fn record_vehicle_packet(&mut self, raw: &RawPacket) {
use ghast_protocol::v1_12_2::play::clientbound as cb;
let Some(r) = self.rec.as_mut() else {
return;
};
let name = match raw.id {
cb::id::SPAWN_ENTITY_LIVING => "spawn_entity_living",
cb::id::ENTITY_METADATA => "entity_metadata",
cb::id::ENTITY_UPDATE_ATTRIBUTES => "entity_update_attributes",
cb::id::ENTITY_VELOCITY => "entity_velocity",
cb::id::REL_ENTITY_MOVE => "rel_entity_move",
cb::id::ENTITY_MOVE_LOOK => "entity_move_look",
cb::id::ENTITY_LOOK => "entity_look",
cb::id::ENTITY_TELEPORT => "entity_teleport",
cb::id::ENTITY_HEAD_ROTATION => "entity_head_rotation",
cb::id::ENTITY_EQUIPMENT => "entity_equipment",
cb::id::ENTITY_DESTROY => "entity_destroy",
cb::id::SET_PASSENGERS => "set_passengers",
cb::id::VEHICLE_MOVE => "vehicle_move",
_ => return,
};
if raw.id == cb::id::VEHICLE_MOVE {
if matches!(
self.ride.as_deref(),
Some(Ride12 {
seat: Seat12::Mount(_),
..
})
) {
r.entity_packet(name, &raw.body);
}
return;
}
let spawns_mount = |_| {
raw.decode_as::<cb::SpawnEntityLiving>()
.ok()
.and_then(|p| u8::try_from(p.r#type).ok())
.and_then(|t| mount_kind_12(ghast_entity::EntityType::LegacyMob(t)))
.is_some()
};
let spawn = raw.id == cb::id::SPAWN_ENTITY_LIVING;
let Some(body) = crate::record::vehicle_packet_body(
raw,
cb::id::SET_PASSENGERS,
cb::id::ENTITY_DESTROY,
&mut r.vehicles,
|id| spawn && spawns_mount(id),
) else {
return;
};
r.entity_packet(name, &body);
}
#[cold]
#[inline(never)]
pub(super) fn record_hands(&mut self, inv: &mut ghast_inventory::Inventory) {
let Some(r) = self.rec.as_mut() else {
return;
};
if !inv.take_player_touched() && r.hands.is_some() {
return;
}
let hands = [inv.held().map(|s| s.id()), inv.offhand().map(|s| s.id())];
if r.hands == Some(hands) {
return;
}
r.hands = Some(hands);
let [main, off] = hands.map(|h| h.map(|i| i.to_string()));
r.hands_legacy(main.as_deref(), off.as_deref());
}
}