1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! 1.12.2: elytra gliding and the firework rockets that boost it.
use super::*;
impl Sim12 {
/// Recomputes [`Sim12::glide_on`].
pub(super) fn update_glide(&mut self) {
self.glide_on = !self.ext.is_inert() || !self.glide.rockets.is_empty();
}
/// The tick with the extension state (gliding, rockets): out of line, so the plain tick
/// stays as it was.
#[cold]
#[inline(never)]
pub(super) fn step_ext(&mut self, pose: &Pose, controls: Controls, using_item: bool) {
let input = ghast_physics::TickInput {
keys: keys(controls),
yaw: pose.yaw,
pitch: pose.pitch,
using_item,
};
let solids: &[ghast_physics::math::Aabb] =
match (self.near.as_deref_mut(), self.entities.as_ref()) {
(Some(n), Some(t)) if !n.idle() => {
n.solids(t, &self.world, &self.player);
&n.solids
}
_ => &[],
};
ghast_physics::v1_12::tick_ext(
&mut self.player,
&mut self.ext,
&input,
&self.world,
&ghast_physics::v1_12::Options::default(),
solids,
&mut self.packets,
);
}
/// The attached rockets' ticks after ours (in the world's entity list after the entities
/// spawned before them; the pushes of other entities come first here).
#[cold]
#[inline(never)]
pub(super) fn tick_rockets(&mut self, pose: &mut Pose) {
for r in &mut self.glide.rockets {
ghast_physics::v1_12::rocket_boost(&mut self.player, &self.ext);
// Entity.baseTick: below y = -64 the rocket is removed, after this tick.
if r.1 < -64.0 {
r.0 = i32::MIN;
}
r.1 = self.player.pos[1];
}
self.glide.rockets.retain(|r| r.0 != i32::MIN);
self.update_glide();
let p = &self.player;
pose.motion = Vec3::new(p.vel[0], p.vel[1], p.vel[2]);
}
/// A rocket spawn, removal or entity data, or our own entity data: decoded only when it
/// can concern us.
#[cold]
#[inline(never)]
pub(super) fn glide_packet(&mut self, raw: &RawPacket) -> Result<(), SimError> {
use ghast_protocol::defs::p340::types::EntityMetadataValue as V;
use ghast_protocol::v1_12_2::play::clientbound as cb;
let g = &mut self.glide;
match raw.id {
cb::id::SPAWN_ENTITY => {
let p: cb::SpawnEntity = raw.decode_as()?;
g.pending.retain(|r| r.0 != p.entity_id);
g.rockets.retain(|r| r.0 != p.entity_id);
if p.r#type == FIREWORK_ROCKET_12 {
if g.pending.len() >= 32 {
g.pending.remove(0);
}
g.pending.push((p.entity_id, p.y));
}
}
cb::id::ENTITY_DESTROY => {
let p: cb::EntityDestroy = raw.decode_as()?;
for id in &p.entity_ids {
g.pending.retain(|r| r.0 != *id);
g.rockets.retain(|r| r.0 != *id);
}
}
cb::id::ENTITY_METADATA => {
let mut r = ghast_protocol::Reader::new(&raw.body);
let id = r.read_varint()?;
let own = id == g.own_id;
let pending = g.pending.iter().position(|r| r.0 == id);
if !own && pending.is_none() {
return Ok(());
}
let p: cb::EntityMetadata = raw.decode_as()?;
for e in &p.metadata {
match (e.key, &e.value) {
// The shared flags: sprinting, fall flying (sneaking is the input's:
// `ClientPlayerEntity.isSneaking`).
(0, V::Byte(b)) if own => {
self.server_flags = Some(*b as u8);
self.ext.apply_shared_flags(&mut self.player, *b as u8);
if let Some(r) = &mut self.rec {
r.note("own entity flags not representable");
}
}
// LivingEntity's hand flags: the server's view of our item use.
(6, V::Byte(b)) if own => self.living_flags = Some(*b as u8),
// PlayerEntity's absorption amount (its first entry: 11).
(11, V::Float(a)) if own => {
self.absorption = *a;
self.absorption_dirty = true;
}
// A rocket's shooter (an entity id, 0 for none).
(7, V::VarInt(v)) if !own => {
if let Some(k) = pending {
let (rid, y) = g.pending.remove(k);
if *v == g.own_id {
g.rockets.push((rid, y));
log::debug!("firework rocket {rid} attached to us");
}
}
}
_ => {}
}
}
}
_ => {}
}
self.update_glide();
Ok(())
}
}