use super::*;
impl Sim16 {
#[cold]
#[inline(never)]
pub(super) fn hands_changed(&mut self, hands: [Option<i32>; 2]) {
self.mounts.hands = hands;
if self.rec.is_some() {
self.record_hands();
}
use ghast_physics::v1_16_5::MountKind;
let (carrot, fungus) = (
self.mounts.holds_stick(MountKind::Pig),
self.mounts.holds_stick(MountKind::Strider),
);
if let Some(t) = self.entities.as_mut() {
t.set_steering_items(carrot, fungus);
}
if let Some(m) = mount_mut(&mut self.ride) {
m.mount.rider_holds_stick = self.mounts.holds_stick(m.mount.kind);
}
}
}
pub(super) const RECORDED_VEHICLE_PACKETS: [i32; 13] =
recorded_vehicle_packets!(ghast_protocol::v1_16_5);
impl Sim16 {
#[cold]
#[inline(never)]
pub(super) fn record_vehicle_packet(&mut self, raw: &RawPacket) {
use ghast_protocol::v1_16_5::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(Ride16::Mount(_))) {
r.entity_packet(name, &raw.body);
}
return;
}
let Some(body) = crate::record::vehicle_packet_body(
raw,
cb::id::SET_PASSENGERS,
cb::id::ENTITY_DESTROY,
&mut r.vehicles,
|id| {
raw.id == cb::id::SPAWN_ENTITY_LIVING
&& self
.entities
.as_ref()
.and_then(|t| t.get(id))
.and_then(mount_kind)
.is_some()
},
) else {
return;
};
r.entity_packet(name, &body);
if raw.id == cb::id::SPAWN_ENTITY_LIVING {
self.record_hands();
}
}
#[cold]
#[inline(never)]
fn record_hands(&mut self) {
let Some(r) = self.rec.as_mut() else {
return;
};
let name = |id: Option<i32>| {
id.and_then(|i| u16::try_from(i).ok())
.and_then(ghast_data::v1_16_5::Item::from_id)
.map(|i| i.info().name)
};
r.hands_legacy(name(self.mounts.hands[0]), name(self.mounts.hands[1]));
}
#[cold]
#[inline(never)]
pub(super) fn record_tick(&mut self, input: &ghast_physics::TickInput) {
let Some(r) = self.rec.as_mut() else {
return;
};
match self.ride.as_deref() {
Some(Ride16::Boat(_) | Ride16::Cart(_)) => {
r.note_once("riding a boat or minecart not representable");
}
Some(Ride16::Mount(m)) if !r.vehicles.contains(&m.id) => {
r.note_once("riding a mount whose spawn was not recorded: not representable");
}
_ => {}
}
r.tick(
input,
&crate::record::state_1_16(&self.player),
&self.packets,
);
}
#[cold]
#[inline(never)]
pub(super) fn stick_hands(&mut self, inv: &ghast_inventory::Inventory) {
let hands = [inv.held().map(|s| s.id()), inv.offhand().map(|s| s.id())];
if self.mounts.hands != hands {
self.hands_changed(hands);
}
}
}