#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
macro_rules! world_view_forwards {
(age: $age:ident) => {
fn collisions(&self) -> (bool, bool) {
(
self.player.horizontal_collision,
self.player.vertical_collision,
)
}
fn piston_uncertain(&self) -> bool {
self.piston_uncertain_at == Some(self.player.$age)
}
fn is_column_loaded(&self, chunk_x: i32, chunk_z: i32) -> bool {
self.world.is_column_loaded(chunk_x, chunk_z)
}
fn entities(&self) -> Option<&ghast_entity::Entities> {
self.entities.as_deref()
}
fn loaded_columns(&self) -> usize {
self.world.columns().len()
}
};
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
macro_rules! piston_bookkeeping {
(moving: $moving:expr) => {
#[inline]
pub(super) fn prune_pistons(&mut self) {
if !self.pistons.is_empty() {
self.prune_pistons_slow();
}
}
#[cold]
#[inline(never)]
fn prune_pistons_slow(&mut self) {
let w = &self.world;
self.pistons.retain(|m| {
w.block_state(m.pos[0], m.pos[1], m.pos[2])
.is_some_and($moving)
});
}
};
(moving: $moving:expr, wire_id: $wire:ident) => {
piston_bookkeeping!(moving: $moving);
fn apply_piston_edits(&mut self) {
for &([x, y, z], s) in &self.piston_edits {
if self.world.set_block_state(x, y, z, s) {
self.updates
.push(BlockPos::new(x, y, z), u32::from(s.$wire()));
}
}
}
};
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
macro_rules! sync_pose_fn {
($name:ident($p:ident: $state:ty), y: $y:expr, sneaking: $sneak:ident) => {
fn $name(pose: &mut Pose, $p: &$state) {
pose.pos = Vec3::new($p.pos[0], $y, $p.pos[2]);
pose.motion = Vec3::new($p.vel[0], $p.vel[1], $p.vel[2]);
pose.yaw = $p.yaw;
pose.pitch = $p.pitch;
pose.on_ground = $p.on_ground;
pose.flying = $p.abilities.flying;
pose.sneaking = $p.$sneak();
pose.sprinting = $p.sprinting;
}
};
}
#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
macro_rules! recorded_vehicle_packets {
($($proto:ident)::+) => {{
use $($proto)::+::play::clientbound::id;
[
id::SPAWN_ENTITY_LIVING,
id::ENTITY_METADATA,
id::ENTITY_UPDATE_ATTRIBUTES,
id::ENTITY_VELOCITY,
id::REL_ENTITY_MOVE,
id::ENTITY_MOVE_LOOK,
id::ENTITY_LOOK,
id::ENTITY_TELEPORT,
id::ENTITY_HEAD_ROTATION,
id::ENTITY_EQUIPMENT,
id::ENTITY_DESTROY,
id::SET_PASSENGERS,
id::VEHICLE_MOVE,
]
}};
}
#[cfg(any(feature = "v1_16_5", ghast_modern))]
pub(super) fn aabb(b: [f64; 6]) -> ghast_physics::math::Aabb {
ghast_physics::math::Aabb::new(b[0], b[1], b[2], b[3], b[4], b[5])
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
#[derive(Debug, Default)]
pub(super) struct PlayerIdents {
map: std::collections::HashMap<i32, i32>,
next: i32,
known: std::collections::HashMap<i32, PlayerFacts>,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
#[derive(Debug, Clone, Copy)]
pub(super) struct PlayerFacts {
pub(super) uuid: uuid::Uuid,
#[cfg(ghast_modern)]
pub(super) generation: u32,
pub(super) spectator: bool,
pub(super) pos: [f64; 3],
pub(super) eye_height: f32,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
impl PlayerIdents {
pub(super) fn spawned(&mut self, id: i32) {
self.next = self.next.wrapping_add(1) | 0x4000_0000;
self.map.insert(id, self.next);
}
pub(super) fn of(&self, id: i32) -> i32 {
self.map.get(&id).copied().unwrap_or(id)
}
pub(super) fn seen(&mut self, ident: i32, facts: PlayerFacts) {
self.known.insert(ident, facts);
}
pub(super) fn eye_changed(&mut self, id: i32, eye_height: f32) {
let ident = self.of(id);
if let Some(f) = self.known.get_mut(&ident) {
f.eye_height = eye_height;
}
}
pub(super) fn facts(&self, ident: i32) -> Option<PlayerFacts> {
self.known.get(&ident).copied()
}
pub(super) fn retain(&mut self, mut keep: impl FnMut(i32) -> bool) {
self.known.retain(|&k, _| keep(k));
}
pub(super) fn clear(&mut self) {
self.map.clear();
self.known.clear();
}
}