Theme

alex/beta-minecraft-rust

Minecraft Beta 1.7.3 Rewrite

BRANCH main
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
Download file

root / crates / server / src / blocks / falling.rs

//! Port of `BlockSand`, shared by sand and gravel.

use common::world::{Block, Material};

use crate::level::Level;

/// `BlockSand.canFallBelow`.
fn can_fall_into(level: &mut Level, x: i32, y: i32, z: i32) -> bool {
    match level.block(x, y, z) {
        Block::AIR | Block::FIRE => true,
        block => matches!(block.material(), Material::Water | Material::Lava),
    }
}

/// Schedules a fall, or settles at once while populating so generation cannot flood the tick
/// list and delay falls in play.
pub fn schedule(level: &mut Level, block: Block, x: i32, y: i32, z: i32) {
    if level.instant_falling {
        try_to_fall(level, block, x, y, z);
    } else {
        level.schedule_tick(x, y, z, block, super::tick_rate(block));
    }
}

/// `BlockSand.tryToFall`, with immediate settling during generation
pub fn try_to_fall(level: &mut Level, block: Block, x: i32, mut y: i32, z: i32) {
    if !can_fall_into(level, x, y - 1, z) || y < 0 {
        return;
    }
    if !level.instant_falling && level.chunks_exist_around(x, y, z, 32) {
        level.spawn_falling(x, y, z, block);
        return;
    }
    level.set_block_notify(x, y, z, Block::AIR);
    while can_fall_into(level, x, y - 1, z) && y > 0 {
        y -= 1;
    }
    if y > 0 {
        level.set_block_notify(x, y, z, block);
    }
}