ghast-physics 0.5.6

Vanilla-exact, pure and deterministic player movement for the ghast Minecraft Java Edition client library (1.8.9, 1.12.2, 1.16.5, 26.1, 26.2 and 26.3), verified bit for bit against the real game
Documentation
//! Minecraft 1.12.2 (protocol 340) client player movement; the rules hold for every 1.12 release.
//!
//! [`tick`] advances a [`PlayerState`] by one client tick against a [`BlockView`] of 1.12 block
//! states and returns the movement packets of that tick. The rules reproduce vanilla 1.12.2's
//! `ClientPlayerEntity` bit for bit (verified against the oracle's golden vectors, see the crate
//! README). What changed since 1.8.9 is listed in the crate README ("1.12.2").
//!
//! [`BlockView`]: crate::BlockView

mod blocks;
mod boat;
mod body;
pub mod drop;
pub mod entity;
mod ext;
mod fluid;
pub mod launch;
mod minecart;
mod mount;
mod piston;
mod player;
pub mod projectile;
mod ray;

pub use crate::nonliving::Side;

pub use boat::{BOAT_HEIGHT, BOAT_WIDTH, Boat, BoatLocation, BoatSeat, boat_item_fits, tick_boat};
pub use entity::{
    PushKind, Pusher, blocks_boat, collides, entity_climbing, hits_pushable,
    lily_pads_broken_by_boat, push_by, push_by_with, push_kind, step_height,
};
pub use ext::PlayerExt;
pub use minecart::{MINECART_HEIGHT, MINECART_WIDTH, Minecart, tick_minecart};
pub use mount::{
    HORSE_EATING, HORSE_REARING, HORSE_SADDLED, HORSE_TAME, Mount, MountKind, RiderJump,
    tick_mount, tick_watched,
};
pub use player::{
    Effects, GLIDE_HEIGHT, HEIGHT, MovementInput, Options, PlayerState, SLEEP_SIZE, SNEAK_HEIGHT,
    STEP_HEIGHT, SentState, WIDTH, box_at, is_climbing, is_touching_lava, rocket_boost, tick,
    tick_ext, tick_in, tick_with,
};

/// The 1.12 block state the world view returns (re-exported from `ghast-data`).
pub use ghast_data::v1_12::BlockState;
pub use piston::{
    Edits, Facing, MOVING_PISTON, MovingBlock, PistonCarry, PistonEntity, Pistons, PlayerPlace,
    search_finds, tick_player_among_pistons, tick_with_pistons,
};
pub use ray::{RayShape, ray_shape};

use crate::input::{Packets, TickInput};
use crate::math::Aabb;
use crate::world::BlockView;

/// `World.collidesWithAnyBlock(box)` (no entity, no world border): a block collision box
/// intersects `b`. A player's size update keeps its old box when the new one does not fit.
pub fn collides_with_any_block<W: BlockView<State = BlockState>>(world: &W, b: &Aabb) -> bool {
    body::collides_any(world, b)
}

/// The 1.12.2 rule set as a type, for code generic over versions (see [`crate::Ruleset`]).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct V1_12;

impl crate::Ruleset for V1_12 {
    type BlockState = BlockState;
    type Player = PlayerState;
    type Options = Options;

    #[inline]
    fn tick_with<W: BlockView<State = BlockState>>(
        player: &mut PlayerState,
        input: &TickInput,
        world: &W,
        options: &Options,
        out: &mut Packets,
    ) {
        tick_with(player, input, world, options, out);
    }
}

/// A [`crate::MemoryWorld`] of 1.12 block states (raw values decoded the vanilla way).
pub type MemoryWorld = crate::MemoryWorld<BlockState>;

/// An empty 1.12 [`MemoryWorld`] (nothing loaded).
#[must_use]
pub fn memory_world() -> MemoryWorld {
    crate::MemoryWorld::new(BlockState::from_raw_vanilla)
}

/// Every collision box of the block at `(x, y, z)`, block-local shapes placed in the world with
/// their actual state (neighbour connections) applied: what the player collides with there.
#[must_use]
pub fn collision_boxes<W: BlockView<State = BlockState>>(
    world: &W,
    x: i32,
    y: i32,
    z: i32,
) -> Vec<Aabb> {
    blocks::boxes_of(world, x, y, z)
}

#[cfg(test)]
mod tests;