mc173 0.2.0

Minecraft beta 1.7.3 base data structures and logic for running a world
Documentation
//! Piston behaviors.

use crate::geom::Face;


/// Get the facing of the piston base or extension.
#[inline]
pub fn get_face(metadata: u8) -> Option<Face> {
    Some(match metadata & 7 {
        0 => Face::NegY,
        1 => Face::PosY,
        2 => Face::NegZ,
        3 => Face::PosZ,
        4 => Face::NegX,
        5 => Face::PosX,
        _ => return None
    })
}

/// Set the facing of the piston base or extension.
#[inline]
pub fn set_face(metadata: &mut u8, face: Face) {
    *metadata &= !7;
    *metadata |= face as u8;
}

/// Get if a piston base has extended or not.
#[inline]
pub fn is_extended(metadata: u8) -> bool {
    metadata & 8 != 0
}

/// Set if a piston base has extended or not.
#[inline]
pub fn set_extended(metadata: &mut u8, extended: bool) {
    *metadata &= !8;
    *metadata |= (extended as u8) << 3;
}