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 texture.rs
use super::Block;
pub fn face(block: Block, metadata: u8, side: usize) -> (u8, bool) {
let base = block.properties().map_or(0, |p| p.texture);
let texture = match block {
Block::GRASS => match side {
0 => 2,
1 => 0,
_ => 3,
},
Block::LOG => match (side, metadata & 3) {
(0 | 1, _) => 21,
(_, 1) => 116,
(_, 2) => 117,
_ => 20,
},
Block::LEAVES if metadata & 3 == 1 => base + 80,
Block::SAPLING => match metadata & 3 {
1 => 63,
2 => 79,
_ => base,
},
Block::TALL_GRASS => match metadata {
0 => base + 16,
2 => base + 17,
_ => base,
},
Block::CHEST => match side {
0 | 1 => 25,
3 => 27,
_ => 26,
},
Block::CACTUS => match side {
0 => 71,
1 => 69,
_ => 70,
},
Block::SANDSTONE => match side {
0 => 208,
1 => 176,
_ => 192,
},
Block::SLAB | Block::DOUBLE_SLAB => match metadata {
0 if side <= 1 => 6,
0 => 5,
1 => face(Block::SANDSTONE, 0, side).0,
2 => 4,
3 => 16,
_ => 6,
},
Block::WOOL if metadata != 0 => {
let color = !(metadata & 15);
113 + ((color & 8) >> 3) + (color & 7) * 16
}
Block::CRAFTING_TABLE => match side {
1 => 43,
0 => 4,
2 | 4 => 60,
_ => 59,
},
Block::FURNACE | Block::LIT_FURNACE => match side {
0 | 1 => 62,
side if side == usize::from(metadata) && block == Block::LIT_FURNACE => 61,
side if side == usize::from(metadata) => 44,
_ => 45,
},
Block::DISPENSER => match side {
0 | 1 => 62,
side if side == usize::from(metadata) => 46,
_ => 45,
},
Block::FARMLAND => match side {
1 if metadata > 0 => 86,
1 => 87,
_ => 2,
},
Block::WHEAT => 88 + metadata.min(7),
Block::BOOKSHELF if side <= 1 => 4,
Block::TNT => match side {
0 => 10,
1 => 9,
_ => 8,
},
Block::WOODEN_DOOR | Block::IRON_DOOR if side > 1 => {
let state = super::shape::door_state(metadata);
if (state == 0 || state == 2) ^ (side <= 3) {
return (base, false);
}
let flip = (usize::from(state / 2)
+ ((side & 1) ^ usize::from(state))
+ usize::from((metadata & 4) / 4))
& 1
!= 0;
return (base - (metadata & 8) * 2, flip);
}
// `BlockCake`: the cut shows on the west side
Block::CAKE => match side {
0 => 124,
1 => 121,
4 if metadata > 0 => 123,
_ => 122,
},
Block::JUKEBOX if side == 1 => base + 1,
Block::PUMPKIN | Block::JACK_O_LANTERN => {
let front = matches!((metadata, side), (2, 2) | (3, 5) | (0, 3) | (1, 4));
match side {
0 | 1 => 102,
_ if front && block == Block::JACK_O_LANTERN => 120,
_ if front => 119,
_ => 118,
}
}
Block::LOCKED_CHEST => match side {
0 | 1 => base - 1,
3 => base + 1,
_ => base,
},
Block::BED if side == 0 => 4,
Block::BED => {
let facing = super::bed::BED_DIRECTION[super::bed::direction(metadata)][side];
match (super::bed::is_head(metadata), facing) {
(true, 2) => base + 18,
(true, 4 | 5) => base + 17,
(true, _) => base + 1,
(false, 3) => base + 15,
(false, 4 | 5) => base + 16,
(false, _) => base,
}
}
Block::PISTON | Block::STICKY_PISTON => match usize::from(metadata & 7) {
facing if facing > 5 => base,
facing if facing == side && metadata & 8 == 0 => base,
facing if facing == side => 110,
facing if facing ^ 1 == side => 109,
_ => 108,
},
Block::PISTON_HEAD => match usize::from(metadata & 7) {
facing if facing == side && metadata & 8 != 0 => 106,
facing if facing == side || facing ^ 1 == side => 107,
_ => 108,
},
Block::REPEATER | Block::POWERED_REPEATER => {
let powered = block == Block::POWERED_REPEATER;
match side {
0 if powered => 99,
0 => 115,
1 if powered => 147,
1 => 131,
_ => 5,
}
}
Block::RAIL if metadata >= 6 => base - 16,
Block::POWERED_RAIL if metadata & 8 == 0 => base - 16,
_ => base,
};
(texture, false)
}
pub fn inventory_face(block: Block, metadata: u8, side: usize) -> u8 {
match (block, side) {
(Block::GRASS, _) => 3,
(Block::TALL_GRASS, _) => block.properties().map_or(0, |p| p.texture),
(Block::PISTON | Block::STICKY_PISTON, 0) => 109,
(Block::PISTON, 1) => 107,
(Block::STICKY_PISTON, 1) => 106,
(Block::PISTON | Block::STICKY_PISTON, _) => 108,
(Block::FURNACE | Block::LIT_FURNACE | Block::DISPENSER, _) => face(block, 3, side).0,
_ => face(block, metadata, side).0,
}
}