use super::records::RECORDED_VEHICLE_PACKETS;
use super::*;
impl WorldView for Sim16 {
world_view_forwards!(age: age);
fn column(&self, chunk_x: i32, chunk_z: i32) -> Option<&ghast_world::Column> {
self.world.column(chunk_x, chunk_z)
}
fn raw_block(&self, x: i32, y: i32, z: i32) -> Option<u32> {
self.world.block_state(x, y, z).map(|s| u32::from(s.id()))
}
fn block_query(&self, x: i32, y: i32, z: i32) -> Option<BlockQuery> {
let s = self.world.block_state(x, y, z)?;
let info = s.block().info();
let air = s.block().is_air();
let passable = matches!(
info.name,
"water" | "lava" | "fire" | "nether_portal" | "end_portal"
);
Some(BlockQuery {
exact: Some(crate::hands::ExactDig::V1_16_5),
air,
water: info.name == "water",
block: s.block().id(),
hardness: if info.diggable {
info.hardness.unwrap_or(-1.0)
} else {
-1.0
},
dig_material: info.material,
harvest_tools: info.harvest_tools,
selection: if air || passable {
None
} else {
Some(union(s.shape()).unwrap_or([0.0, 0.0, 0.0, 1.0, 1.0, 1.0]))
},
stairs: None,
activates: activates_1_16(info.name),
})
}
fn crosshair(
&self,
eyes: Vec3,
(yaw, pitch): (f32, f32),
_look: Vec3,
reach: f64,
) -> Option<crate::BlockHit> {
use ghast_physics::pick::v1_16_5 as pick;
let eye = [eyes.x, eyes.y, eyes.z];
let hit = pick::pick(
&self.world,
eye,
pick::rotation_vector(yaw, pitch),
reach,
None,
);
block_hit(&hit, eye)
}
}
impl Sim for Sim16 {
fn crosshair_target(&self, q: &PickQuery<'_>) -> Crosshair {
use ghast_physics::pick::v1_16_5 as pick;
let held_block = q
.held
.and_then(ghast_data::v1_16_5::Item::from_id)
.and_then(|i| ghast_data::v1_16_5::Block::from_name(i.info().name));
let eye = if q.now {
[
q.eyes.x,
self.player.pos[1] + f64::from(self.player.eye_height()),
q.eyes.z,
]
} else {
[q.eyes.x, q.eyes.y, q.eyes.z]
};
let look = pick::rotation_vector(q.rotation.0, q.rotation.1);
if q.entities.is_empty() {
let reach = if q.creative {
pick::CREATIVE_REACH
} else {
pick::REACH
};
let hit = pick::pick(&self.world, eye, look, reach, held_block);
return Crosshair::Block(block_hit(&hit, eye));
}
let t = pick::pick_target(
&self.world,
&q.player_bb,
eye,
look,
q.creative,
held_block,
q.entities,
);
modern_crosshair(t, eye)
}
fn crosshair_now(
&self,
eyes: Vec3,
(yaw, pitch): (f32, f32),
_look: Vec3,
held: Option<u16>,
) -> Option<crate::BlockHit> {
use ghast_physics::pick::v1_16_5 as pick;
let held_block = held
.and_then(ghast_data::v1_16_5::Item::from_id)
.and_then(|i| ghast_data::v1_16_5::Block::from_name(i.info().name));
let eye = [eyes.x, eyes.y, eyes.z];
let hit = pick::pick(
&self.world,
eye,
pick::rotation_vector(yaw, pitch),
crate::hands::REACH,
held_block,
);
block_hit(&hit, eye)
}
fn world_packet(&mut self, raw: &RawPacket) -> Result<(), SimError> {
{
use ghast_protocol::v1_16_5::play::clientbound::id;
self.session.note(raw, id::LOGIN, id::RESPAWN);
}
if let Some(t) = &mut self.entities
&& t.wants(raw.id)
{
t.apply(raw)?;
if self.nonliving.is_some() {
self.nonliving_packet(raw)?;
}
}
if self.rec.is_some() {
self.record_vehicle_packet(raw);
}
use ghast_protocol::v1_16_5::play::clientbound as cb;
if self.entities.is_some()
&& (raw.id == cb::id::SPAWN_ENTITY
|| (self.fishing.active() && raw.id == cb::id::ENTITY_METADATA))
{
self.fishing_packet(raw)?;
}
if raw.id == cb::id::TEAMS {
if let Some(t) = &mut self.teams
&& !t.apply(&raw.body, super::teams::TeamLayout::Legacy1_16)
{
log::debug!("bad teams packet ({} B)", raw.body.len());
}
return Ok(());
}
if self.entities.is_some()
&& matches!(
raw.id,
cb::id::ENTITY_UPDATE_ATTRIBUTES
| cb::id::ENTITY_METADATA
| cb::id::ENTITY_VELOCITY
)
{
self.mount_data_packet(raw)?;
}
if raw.id == cb::id::ENTITY_METADATA {
return self.own_metadata(raw);
}
if matches!(raw.id, cb::id::SET_PASSENGERS | cb::id::VEHICLE_MOVE) {
return self.vehicle_packet(raw);
}
if raw.id == cb::id::SPAWN_ENTITY_LIVING && self.entities.is_some() {
self.mount_spawn(raw)?;
}
if !self.mounts.seen.is_empty()
&& matches!(
raw.id,
cb::id::ENTITY_TELEPORT
| cb::id::REL_ENTITY_MOVE
| cb::id::ENTITY_MOVE_LOOK
| cb::id::ENTITY_LOOK
| cb::id::ENTITY_HEAD_ROTATION
| cb::id::ENTITY_DESTROY
)
{
self.watched_packet(raw)?;
}
if matches!(self.ride.as_deref(), Some(Ride16::Mount(_)))
&& matches!(
raw.id,
cb::id::ENTITY_TELEPORT
| cb::id::REL_ENTITY_MOVE
| cb::id::ENTITY_MOVE_LOOK
| cb::id::ENTITY_LOOK
| cb::id::ENTITY_HEAD_ROTATION
| cb::id::ENTITY_DESTROY
)
{
self.mount_packet(raw)?;
}
if matches!(self.ride.as_deref(), Some(Ride16::Boat(_)))
&& matches!(
raw.id,
cb::id::ENTITY_TELEPORT
| cb::id::REL_ENTITY_MOVE
| cb::id::ENTITY_MOVE_LOOK
| cb::id::ENTITY_LOOK
)
{
self.boat_packet(raw)?;
}
if matches!(self.ride.as_deref(), Some(Ride16::Cart(_)))
&& matches!(
raw.id,
cb::id::ENTITY_TELEPORT
| cb::id::REL_ENTITY_MOVE
| cb::id::ENTITY_MOVE_LOOK
| cb::id::ENTITY_LOOK
| cb::id::ENTITY_DESTROY
)
{
self.cart_packet(raw)?;
}
if matches!(raw.id, cb::id::SPAWN_ENTITY | cb::id::ENTITY_DESTROY) {
if self.glide.watch {
self.rocket_packet(raw)?;
}
return Ok(());
}
let w = &mut self.world;
match raw.id {
cb::id::UPDATE_TIME => {
let p: cb::UpdateTime = raw.decode_as()?;
self.piston_time = p.age;
}
cb::id::LOGIN => {
let p: cb::Login = raw.decode_as()?;
self.pistons.clear();
self.piston_carry.clear();
self.piston_time = 0;
w.apply_login(&p);
self.rt.own_id = p.entity_id;
self.rt.rain_level = 0.0;
self.new_world(&p.dimension, p.hashed_seed);
if let Some(t) = &mut self.teams {
t.clear();
}
self.unacked.clear();
}
cb::id::RESPAWN => {
let p: cb::Respawn = raw.decode_as()?;
let new = *p.world_name != *w.world_name();
self.pistons.clear();
self.piston_carry.clear();
w.apply_respawn(&p);
if new {
self.rt.rain_level = 0.0;
self.new_world(&p.dimension, p.hashed_seed);
}
}
cb::id::MAP_CHUNK => {
let p: cb::MapChunk = raw.decode_as()?;
if p.ground_up && !self.pistons.is_empty() {
self.pistons.chunk_replaced(p.x, p.z);
}
w.apply_map_chunk(&p)?;
}
cb::id::UNLOAD_CHUNK => {
let p: cb::UnloadChunk = raw.decode_as()?;
if !self.pistons.is_empty() {
self.pistons.chunk_replaced(p.chunk_x, p.chunk_z);
}
w.apply_unload_chunk(&p);
}
cb::id::UPDATE_VIEW_POSITION => {
w.apply_view_position(&raw.decode_as()?);
}
cb::id::UPDATE_VIEW_DISTANCE => {
w.apply_view_distance(&raw.decode_as()?);
}
cb::id::BLOCK_CHANGE => {
let p: cb::BlockChange = raw.decode_as()?;
self.updates.push(p.location, p.r#type as u32);
w.apply_block_change(&p);
self.prune_pistons();
}
cb::id::BLOCK_ACTION => return self.block_action(raw),
cb::id::MULTI_BLOCK_CHANGE => {
let p: cb::MultiBlockChange = raw.decode_as()?;
let c = &p.chunk_coordinates;
let sy = ((c.y << 12) as i32) >> 12;
for &r in &p.records {
let local = (r & 0xFFF) as i32;
let pos = BlockPos::new(
c.x * 16 + ((local >> 8) & 15),
sy.wrapping_mul(16).wrapping_add(local & 15),
c.z * 16 + ((local >> 4) & 15),
);
self.updates.push(pos, ((r as u64) >> 12) as u32);
}
w.apply_multi_block_change(&p);
self.prune_pistons();
}
cb::id::EXPLOSION => {
w.apply_explosion(&raw.decode_as()?);
self.prune_pistons();
}
cb::id::ACKNOWLEDGE_PLAYER_DIGGING => {
self.action_answer(&raw.decode_as()?);
}
cb::id::WORLD_BORDER => {
w.apply_world_border(&raw.decode_as()?);
}
cb::id::TILE_ENTITY_DATA if self.block_entities => {
w.apply_tile_entity_data(&raw.decode_as()?);
}
_ => {}
}
Ok(())
}
fn reset_player(&mut self) {
let abilities = self.player.abilities;
let food = self.player.food_level;
self.player = ghast_physics::v1_16_5::PlayerState::new([0.0; 3], 0.0, 0.0);
self.piston_uncertain_at = None;
self.pistons.reset_player();
self.filed_pos = [0.0; 3];
self.player.abilities = abilities;
self.player.food_level = food;
self.ext.spin_attack = false;
self.ext.riptide_ticks = 0;
self.ext.fall_flying = false;
self.ext.glide_pose = false;
self.ext.sleeping = false;
self.glide.rockets.clear();
self.glide.pending.clear();
self.ride = None;
self.mounts.seen.clear();
self.rt.using = None;
self.rt.held.hands.set([(0, false, -1); 2]);
self.server_flags = None;
self.absorption_dirty |= self.absorption != 0.0;
self.absorption = 0.0;
self.update_slow();
}
fn teleport(&mut self, pose: &mut Pose, t: &Teleport) {
if self.ride.is_some() && self.player.age > 0 {
self.teleport_off();
}
self.player.yaw = pose.yaw;
self.player.pitch = pose.pitch;
let _reply =
self.player
.apply_teleport([t.x, t.y, t.z], t.yaw, t.pitch, rel_flags(t.flags));
if let Some(r) = &mut self.rec {
let p = &self.player;
r.teleport(
[t.x, t.y, t.z],
t.yaw,
t.pitch,
t.flags,
t.teleport_id,
p.pos,
p.yaw,
p.pitch,
);
}
sync_pose_16(pose, &self.player);
}
fn abilities(&mut self, a: Abilities) {
let a = physics_abilities(a);
if let Some(r) = &mut self.rec {
r.abilities(&a);
}
self.player.apply_abilities(a);
}
fn food(&mut self, food: i32) {
self.player.food_level = food;
}
fn sign_at(&self, pos: ghast_protocol::BlockPos) -> Option<bool> {
self.world
.block_state(pos.x, pos.y, pos.z)
.map(|s| s.block().name().ends_with("_sign"))
}
fn velocity(&mut self, v: Vec3, add: bool) {
if let Some(r) = &mut self.rec {
if add {
r.note("explosion push not representable");
} else {
r.velocity([
(v.x * 8000.0).round() as i32,
(v.y * 8000.0).round() as i32,
(v.z * 8000.0).round() as i32,
]);
}
}
let p = &mut self.player;
if add {
p.vel[0] += v.x;
p.vel[1] += v.y;
p.vel[2] += v.z;
} else {
p.vel = [v.x, v.y, v.z];
}
}
fn movement_speed(&mut self, base: f64, modifiers: &[(u128, f64, u8)]) {
if let Some(r) = &mut self.rec {
r.speed_attribute(base, modifiers);
}
self.player.apply_speed_attribute(base, modifiers);
}
fn status_effects(&mut self, effects: &std::collections::BTreeMap<i8, i8>) {
if let Some(r) = &mut self.rec {
r.effects(effects);
}
let e = &mut self.player.effects;
e.jump_boost = effects.get(&8).map(|a| i32::from(*a));
e.blindness = effects.contains_key(&15);
e.levitation = effects.get(&25).map(|a| i32::from(*a));
e.slow_falling = effects.contains_key(&28);
e.dolphins_grace = effects.contains_key(&30);
}
#[inline]
fn hands_at_packet(&mut self, inv: &ghast_inventory::Inventory) {
if matches!(self.ride.as_deref(), Some(Ride16::Mount(m)) if !m.mount.kind.is_horse_family())
{
self.stick_hands(inv);
}
}
fn hand_items(&mut self, inv: &mut ghast_inventory::Inventory) {
if !inv.take_player_touched() {
return;
}
let hands = [inv.held().map(|s| s.id()), inv.offhand().map(|s| s.id())];
if self.mounts.hands != hands {
self.hands_changed(hands);
}
}
fn boots(&mut self, depth_strider: u8, soul_speed: u8) {
self.player.enchantments.depth_strider = depth_strider;
self.player.enchantments.soul_speed = soul_speed;
}
fn spectator(&mut self, on: bool) {
self.player.spectator = on;
}
fn set_flying(&mut self, flying: bool, out: &mut Vec<Outbound>) {
let a = &mut self.player.abilities;
if a.flying == flying || (flying && !a.allow_flying) {
return;
}
a.flying = flying;
let a = *a;
if let Some(r) = &mut self.rec {
r.abilities(&a);
}
out.push(Outbound::Abilities {
flags: abilities_flags(&a),
flying_speed: a.fly_speed,
walking_speed: a.walk_speed,
});
}
fn collect_block_updates(&mut self, on: bool) {
self.updates.on = on;
if !on {
self.updates.list.clear();
}
}
fn drain_block_updates(&mut self, out: &mut Vec<(BlockPos, u32)>) -> usize {
out.append(&mut self.updates.list);
std::mem::take(&mut self.updates.dropped)
}
#[cfg(all(test, ghast_modern, feature = "v1_8", feature = "v1_16_5"))]
fn test_set_own_id(&mut self, id: i32) {
self.rt.own_id = id;
}
fn eye_height(&self) -> Option<f64> {
Some(f64::from(self.player.eye_height()))
}
fn attack_hurts(&self, e: &ghast_entity::Entity) -> bool {
if e.is_player() {
return true;
}
ghast_entity::v1_16_5::info(e.entity_type()).is_some_and(|i| {
matches!(
i.name,
"boat" | "end_crystal" | "fireball" | "shulker_bullet"
) || i.name.ends_with("minecart")
})
}
fn attack_slow(&mut self, _target: i32, _yaw: f32, knockback: i32, sprint_bonus: bool) {
let p = &mut self.player;
if super::attack_knockback_applies(knockback, p.sprinting, sprint_bonus) {
p.vel[0] *= 0.6;
p.vel[2] *= 0.6;
p.set_sprinting(false);
if let Some(r) = &mut self.rec {
r.note("attack slow-down not representable");
}
}
}
fn sprinting(&self) -> bool {
self.player.sprinting
}
fn server_flags(&self) -> Option<u8> {
self.server_flags
}
fn search_order(&self, e: &ghast_entity::Entity) -> Option<(i32, i32, i32, u32)> {
self.entities.as_ref()?.search_order(e.id())
}
#[inline]
fn take_living_flags(&mut self) -> Option<u8> {
self.living_flags.take()
}
#[inline]
fn take_absorption(&mut self) -> Option<f32> {
std::mem::take(&mut self.absorption_dirty).then_some(self.absorption)
}
fn take_sleep(&mut self, pose: &mut Pose) -> Option<Option<ghast_protocol::BlockPos>> {
self.sleep?;
let s = self.sleep.take()?;
if s.is_some() {
let [x, y, z] = self.player.pos;
pose.pos = Vec3::new(x, y, z);
}
Some(s)
}
fn fishing(&self) -> Option<&crate::fishing::Bobber> {
self.fishing.bobber()
}
#[inline(always)]
fn fishing_news(&self) -> bool {
self.fishing.has_events()
}
fn drain_fishing(&mut self, out: &mut Vec<crate::fishing::FishingEvent>) {
self.fishing.drain(out);
}
fn velocity_now(&self) -> Vec3 {
let v = self.player.vel;
Vec3::new(v[0], v[1], v[2])
}
fn world_packet_ids(&self) -> Vec<i32> {
use ghast_protocol::v1_16_5::play::clientbound as cb;
let mut ids: Vec<i32> = self.world.packet_ids().collect();
ids.push(cb::id::ACKNOWLEDGE_PLAYER_DIGGING);
ids.push(cb::id::ENTITY_METADATA);
ids.extend([cb::id::SET_PASSENGERS, cb::id::VEHICLE_MOVE]);
ids.push(cb::id::BLOCK_ACTION);
if self.glide.watch {
ids.extend([cb::id::SPAWN_ENTITY, cb::id::ENTITY_DESTROY]);
}
if self.rec.is_some() {
ids.extend(RECORDED_VEHICLE_PACKETS);
}
ids
}
fn take_filter_dirty(&mut self) -> bool {
self.rt.held.filter_dirty.replace(false)
}
#[inline(never)]
fn weather(&mut self, reason: u8, value: f32) {
self.rt.rain_level = match reason {
1 => 0.0,
2 => 1.0,
_ => value.clamp(0.0, 1.0),
};
}
#[inline(never)]
fn item_use_facts(
&self,
stack: &ghast_inventory::Stack,
off_hand: bool,
mut held: HeldItem,
) -> HeldItem {
let trident = u16::try_from(stack.id())
.ok()
.and_then(ghast_data::v1_16_5::Item::from_id)
.is_some_and(|i| i.info().name == "trident");
let mut level = 0;
if trident {
let (lvl, damage) = trident_nbt(stack);
level = lvl;
held.usable = held.usable && damage < 250 - 1 && (lvl == 0 || self.wet());
if lvl > 0 && !self.rt.held.watch.replace(true) {
self.rt.held.filter_dirty.set(true);
}
}
held.swing_on_use = held.swing_on_use
|| (self.ext.fall_flying
&& u16::try_from(stack.id())
.ok()
.and_then(ghast_data::v1_16_5::Item::from_id)
.is_some_and(|i| i.info().name == "firework_rocket"));
let starts =
held.usable && (!held.food || held.always_edible || self.player.food_level < 20);
let mut h = self.rt.held.hands.get();
h[usize::from(off_hand)] = (level, starts, self.player.age);
self.rt.held.hands.set(h);
held
}
fn entity_config(&self) -> Option<ghast_entity::Config> {
self.entities.as_ref().map(|t| t.config())
}
fn set_entities(&mut self, config: Option<ghast_entity::Config>) {
if self.entity_config() == config {
return;
}
self.teams = config.is_some().then(Box::default);
self.entities = config.map(|c| {
let mut t = Self::tracker(c);
self.session.replay(|r| {
if let Err(e) = t.apply(r) {
log::debug!("entity tracker: session packet 0x{:02x}: {e}", r.id);
}
});
t
});
if let Some(n) = &mut self.nonliving {
n.clear();
}
if self.fishing.gone() {
self.rt.held.filter_dirty.set(true);
}
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);
}
self.update_slow();
}
fn entity_packet_ids(&self) -> Vec<i32> {
use ghast_protocol::v1_16_5::play::clientbound as cb;
let fishing: &[i32] = if self.fishing.active() {
&[cb::id::ENTITY_METADATA]
} else {
&[]
};
self.entities
.as_ref()
.map(|t| {
t.packet_ids()
.chain([cb::id::TEAMS])
.chain(fishing.iter().copied())
.collect()
})
.unwrap_or_default()
}
#[inline(always)]
fn tick_entities(&mut self, pose: &mut Pose) {
if let Some(t) = self.entities.as_mut() {
t.self_filed(self.filed_pos);
self.tick_tracked(pose);
if let Some(Ride16::Mount(r)) = self.ride.as_deref()
&& let Some(t) = self.entities.as_mut()
{
mount_view(t, r.id, &r.mount);
}
if self.nonliving.is_some() {
self.tick_nonliving();
}
if self.fishing.active() {
self.tick_fishing();
}
}
if self.slow && !self.glide.rockets.is_empty() {
let (yaw, pitch) = (self.player.yaw, self.player.pitch);
self.tick_rockets(false, yaw, pitch);
let p = &self.player;
pose.motion = Vec3::new(p.vel[0], p.vel[1], p.vel[2]);
}
if !self.pistons.is_empty() && self.ride.is_none() {
self.tick_piston_phase(pose);
}
self.piston_time = self.piston_time.wrapping_add(1);
}
#[inline(always)]
fn modern_inputs(&self) -> bool {
!self.player.on_ground
}
fn pre_tick(&mut self, inv: &ghast_inventory::Inventory, t: &crate::sim::PreTick) -> bool {
if t.controls.jump {
let e = Self::elytra_equipped(inv);
if e != self.ext.elytra {
self.ext.elytra = e;
self.update_slow();
}
if e && !self.glide.watch {
self.glide.watch = true;
self.rt.held.filter_dirty.set(true);
}
}
true
}
fn gliding(&self) -> bool {
self.ext.fall_flying
}
fn vehicle(&self) -> Option<crate::common::Vehicle> {
if let Some(Ride16::Mount(r)) = self.ride.as_deref() {
let m = &r.mount;
return Some(crate::common::Vehicle {
entity_id: r.id,
pos: Vec3::new(m.pos[0], m.pos[1], m.pos[2]),
yaw: m.yaw,
pitch: m.pitch,
on_ground: m.on_ground,
controlled: m.controlled(),
});
}
if let Some(Ride16::Cart(c)) = self.ride.as_deref() {
let m = &c.cart;
return Some(crate::common::Vehicle {
entity_id: c.id,
pos: Vec3::new(m.pos[0], m.pos[1], m.pos[2]),
yaw: m.yaw,
pitch: m.pitch,
on_ground: false,
controlled: false,
});
}
let Some(Ride16::Boat(r)) = self.ride.as_deref() else {
return None;
};
let b = &r.boat;
Some(crate::common::Vehicle {
entity_id: r.id,
pos: Vec3::new(b.pos[0], b.pos[1], b.pos[2]),
yaw: b.yaw,
pitch: b.pitch,
on_ground: b.on_ground,
controlled: true,
})
}
fn mount_rules(&self, entity_id: i32) -> Option<ghast_inventory::MountRules> {
use ghast_inventory::{MountArmor, MountRules};
let t = self.entities.as_ref()?;
let e = t.get(entity_id)?;
let armor = match ghast_entity::v1_16_5::info(e.entity_type())?.name {
"llama" | "trader_llama" => return Some(MountRules::new(false, MountArmor::Carpet)),
"horse" => MountArmor::HorseArmor,
"donkey" | "mule" | "zombie_horse" | "skeleton_horse" => MountArmor::None,
_ => return None,
};
if !t.config().metadata {
return None;
}
let m = e.metadata();
let alive = ghast_entity::v1_16_5::health(e).is_none_or(|h| h > 0.0);
let baby = matches!(m.get(15), Some(ghast_entity::MetaValue::Bool(true)));
let tame = m.byte(16).unwrap_or(0) & 2 != 0;
Some(MountRules::new(alive && !baby && tame, armor))
}
fn take_reply(&mut self) -> Option<Outbound> {
self.reply.take()
}
fn entities_mut(&mut self) -> Option<&mut ghast_entity::Entities> {
self.entities.as_mut().map(|t| t.store_mut())
}
fn set_entity_push(&mut self, on: bool) {
self.entity_push = on;
}
fn set_entity_physics(&mut self, on: bool) {
self.set_nonliving(on);
}
fn predict_air(&mut self, x: i32, y: i32, z: i32) {
self.world
.set_block_state(x, y, z, ghast_data::v1_16_5::BlockState::AIR);
}
fn dig_sent(
&mut self,
pos: BlockPos,
status: crate::common::DigStatus,
broken: bool,
_sequence: i32,
player: Vec3,
) {
use crate::common::DigStatus;
if matches!(
status,
DigStatus::Start | DigStatus::Abort | DigStatus::Finish
) {
self.unacked
.put(pos, status.id() as u8, [player.x, player.y, player.z]);
}
if broken {
use ghast_data::FluidKind;
use ghast_data::v1_16_5::{Block, BlockState};
let Some(old) = self.world.block_state(pos.x, pos.y, pos.z) else {
return;
};
let left = match old.fluid().map(|f| f.kind) {
Some(FluidKind::Water) => Block::WATER.default_state(),
Some(FluidKind::Lava) => Block::LAVA.default_state(),
None => BlockState::AIR,
};
log::debug!(
"predicted the break of {} at {pos:?}: {}",
old.block().name(),
left.block().name()
);
self.world.set_block_state(pos.x, pos.y, pos.z, left);
}
}
fn place_rules(
&self,
q: &crate::sim::predict::PlaceQuery<'_>,
) -> crate::sim::predict::PlaceRules {
crate::sim::place116::rules(&self.world, &self.player.bb, q)
}
fn air_use(&self, q: &crate::sim::predict::AirQuery<'_>) -> crate::sim::predict::AirAnswer {
let p = &self.player;
crate::sim::use116::air_use(
&crate::sim::use116::Ctx {
world: &self.world,
bb: p.bb,
climbing: !p.spectator && crate::sim::use116::climbing(&self.world, p.pos),
eye_y: p.pos[1] + f64::from(p.eye_height()),
ultrawarm: self.ext.ultrawarm,
fall_flying: self.ext.fall_flying,
entities: self.entities.as_deref(),
own_id: self.rt.own_id,
},
q,
)
}
fn air_use_sent(&mut self, blocks: &[(BlockPos, u32)]) {
for &(p, id) in blocks {
if let Some(s) = u16::try_from(id)
.ok()
.and_then(ghast_data::v1_16_5::BlockState::from_id)
{
log::debug!("item use set {} at {p:?}", s.block().name());
self.world.set_block_state(p.x, p.y, p.z, s);
}
}
}
fn place_sent(&mut self, p: &crate::sim::predict::PlaceSent<'_>) -> bool {
let player = self.player.bb;
if let Some(used) = crate::sim::place116::sent(&mut self.world, &player, p) {
log::debug!("place at {:?}: item used {used}", p.pos);
return used;
}
let Some((at, state)) = self.plain_placement(p) else {
return false;
};
log::debug!("predicted {} at {at:?}", state.block().name());
self.world.set_block_state(at.x, at.y, at.z, state);
true
}
#[cfg(test)]
fn set_player_pos(&mut self, p: Vec3) {
self.player.set_position(p.x, p.y, p.z);
}
#[inline(always)]
fn records_digs(&self) -> bool {
true
}
fn take_snap(&mut self) -> Option<Vec3> {
if !std::mem::take(&mut self.snapped) {
return None;
}
let p = self.player.pos;
Some(Vec3::new(p[0], p[1], p[2]))
}
fn held_item(&self, id: u16, count: u8, efficiency: u8) -> HeldItem {
held_item_facts(DataSet::V1_16_5, id, count, efficiency)
}
fn step(
&mut self,
pose: &mut Pose,
controls: Controls,
using_item: bool,
entity_id: i32,
out: &mut Vec<Outbound>,
) {
let input = ghast_physics::TickInput {
keys: keys(controls),
yaw: pose.yaw,
pitch: pose.pitch,
using_item,
};
self.packets.clear();
if let Some(r) = &mut self.rec
&& !r.started()
{
r.entity_id = (self.rt.own_id != i32::MIN).then_some(self.rt.own_id);
r.start_1_16(&self.player);
}
if let Some(r) = &mut self.rec {
let w = &self.world;
r.observe(self.player.pos, |x, y, z| {
w.is_column_loaded(x >> 4, z >> 4)
.then(|| w.block_state(x, y, z).map_or(0, |s| u32::from(s.id())))
});
}
if self.slow || using_item || !self.pistons.is_empty() {
self.slow_tick(&input, out);
} else {
ghast_physics::v1_16_5::tick(&mut self.player, &input, &self.world, &mut self.packets);
}
self.filed_pos = self.player.pos;
if self.force_step_position != ForceStepPosition::Off {
let p = &mut self.player;
let cur = p.pos;
force_position(
&mut self.packets,
cur,
&mut p.sent.pos,
&mut p.sent.ticks_since_pos,
self.force_step_position,
);
}
if self.rec.is_some() {
self.record_tick(&input);
}
push_packets(&self.packets, entity_id, out);
sync_pose_16(pose, &self.player);
self.world.advance_time(50);
}
}