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 / material.rs

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Material {
    Air,
    Grass,
    Ground,
    Wood,
    Rock,
    Iron,
    Water,
    Lava,
    Leaves,
    Plants,
    Sponge,
    Cloth,
    Fire,
    Sand,
    Circuits,
    Glass,
    Tnt,
    Ice,
    Snow,
    BuiltSnow,
    Cactus,
    Clay,
    Pumpkin,
    Portal,
    Cake,
    Web,
    Piston,
}

impl Material {
    pub const fn is_liquid(self) -> bool {
        matches!(self, Self::Water | Self::Lava)
    }

    /// Both `Material.isSolid` and `Material.getIsSolid`, which agree for every material.
    pub const fn is_solid(self) -> bool {
        !matches!(
            self,
            Self::Air
                | Self::Water
                | Self::Lava
                | Self::Plants
                | Self::Fire
                | Self::Circuits
                | Self::Snow
                | Self::Portal
        )
    }

    /// `Material.getIsGroundCover`: blocks that placement may replace.
    pub const fn is_ground_cover(self) -> bool {
        matches!(
            self,
            Self::Air | Self::Water | Self::Lava | Self::Fire | Self::Snow
        )
    }

    pub const fn can_burn(self) -> bool {
        matches!(self, Self::Wood | Self::Leaves | Self::Cloth | Self::Tnt)
    }

    /// `Material.getIsTranslucent`, which despite its name is true for solid, non-see-through materials.
    pub const fn is_opaque(self) -> bool {
        self.is_solid()
            && !matches!(
                self,
                Self::Leaves | Self::Glass | Self::Tnt | Self::Ice | Self::Snow | Self::Cactus
            )
    }
}