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 / common / src / world / redstone.rs

//! How redstone wire links up with its neighbors, shared by its power logic and rendering.

use super::Block;
use super::shape::BlockView;

/// `BlockRedstoneWire.isPowerProviderOrWire`: what wire points towards; repeaters only from
/// their ends.
pub fn connects(view: &impl BlockView, x: i32, y: i32, z: i32, side: i32) -> bool {
    match view.block(x, y, z) {
        Block::REDSTONE_WIRE => true,
        Block::REPEATER | Block::POWERED_REPEATER => {
            side == super::bed::FOOT_INVISIBLE_FACES[usize::from(view.metadata(x, y, z) & 3)]
        }
        Block::REDSTONE_TORCH
        | Block::UNLIT_REDSTONE_TORCH
        | Block::LEVER
        | Block::BUTTON
        | Block::STONE_PRESSURE_PLATE
        | Block::WOODEN_PRESSURE_PLATE
        | Block::DETECTOR_RAIL => true,
        _ => false,
    }
}

/// Whether wire links west, east, north and south: to its neighbors on the same level, one
/// block down where nothing solid is in the way, and up the sides of solid blocks.
pub fn links(view: &impl BlockView, x: i32, y: i32, z: i32) -> [bool; 4] {
    let normal = |x, y, z| view.block(x, y, z).is_normal_cube();
    let open_above = !normal(x, y + 1, z);
    [(-1, 0, 1), (1, 0, 3), (0, -1, 2), (0, 1, 0)].map(|(dx, dz, side)| {
        let (nx, nz) = (x + dx, z + dz);
        connects(view, nx, y, nz, side)
            || !normal(nx, y, nz) && connects(view, nx, y - 1, nz, -1)
            || open_above && normal(nx, y, nz) && connects(view, nx, y + 1, nz, -1)
    })
}