alex/beta-minecraft-rust
Minecraft Beta 1.7.3 Rewrite
BRANCH main
SNAPSHOT Draw terrain GPU-driven from packed per-section buffers with GPU occlusion culling, add a render distance slider (2-128) with a quad/disk shape, cut chunk bookkeeping at high render distances, and fix a light underflow at y=0
DOWNLOAD
root crates common src world bed.rs
//! `BlockBed` metadata and the standing spots around a bed.
use super::shape::BlockView;
/// `BlockBed.headBlockToFootBlockMap`: from the foot half to the head half, per direction.
pub const HEAD_OFFSETS: [[i32; 2]; 4] = [[0, 1], [-1, 0], [0, -1], [1, 0]];
/// `ModelBed.footInvisibleFaceRemap`, which redstone wire also uses to find repeater inputs.
pub const FOOT_INVISIBLE_FACES: [i32; 4] = [2, 3, 0, 1];
/// `ModelBed.bedDirection`: the bed's face texture for each direction and side.
pub const BED_DIRECTION: [[u8; 6]; 4] = [
[1, 0, 3, 2, 5, 4],
[1, 0, 5, 4, 2, 3],
[1, 0, 2, 3, 4, 5],
[1, 0, 4, 5, 3, 2],
];
pub fn direction(metadata: u8) -> usize {
usize::from(metadata & 3)
}
/// `BlockBed.isBlockFootOfBed`, which despite its name marks the pillow half.
pub fn is_head(metadata: u8) -> bool {
metadata & 8 != 0
}
pub fn is_occupied(metadata: u8) -> bool {
metadata & 4 != 0
}
/// `BlockBed.getNearestEmptyChunkCoordinates`: the `skip`th free spot around the bed at `bed`.
pub fn standing_spot(
world: &impl BlockView,
[x, y, z]: [i32; 3],
mut skip: u32,
) -> Option<[i32; 3]> {
let [dx, dz] = HEAD_OFFSETS[direction(world.metadata(x, y, z))];
for step in 0..=1 {
let (x0, z0) = (x - dx * step - 1, z - dz * step - 1);
for sx in x0..=x0 + 2 {
for sz in z0..=z0 + 2 {
if world.block(sx, y - 1, sz).is_normal_cube()
&& world.block(sx, y, sz).is_air()
&& world.block(sx, y + 1, sz).is_air()
{
if skip == 0 {
return Some([sx, y, sz]);
}
skip -= 1;
}
}
}
}
None
}