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 server src populate nether.rs
//! `ChunkProviderHell.populate`: lava springs, fire, glowstone and mushrooms.
use common::JavaRandom;
use common::world::{Block, ChunkPos};
use super::{plants, springs};
use crate::level::{Level, NEIGHBORS};
pub fn populate(level: &mut Level, pos: ChunkPos) {
let mut rand = std::mem::replace(&mut level.hell_rng, JavaRandom::new(0));
let (x0, z0) = (pos.min_block_x(), pos.min_block_z());
let point = |rand: &mut JavaRandom, height: i32, offset: i32| {
let x = x0 + rand.next_int(16) + 8;
let y = rand.next_int(height) + offset;
[x, y, z0 + rand.next_int(16) + 8]
};
for _ in 0..8 {
springs::hell_lava(level, point(&mut rand, 120, 4));
}
let bound = rand.next_int(10) + 1;
for _ in 0..rand.next_int(bound) + 1 {
fire(level, point(&mut rand, 120, 4), &mut rand);
}
let bound = rand.next_int(10) + 1;
for _ in 0..rand.next_int(bound) {
glowstone(level, point(&mut rand, 120, 4), &mut rand);
}
for _ in 0..10 {
glowstone(level, point(&mut rand, 128, 0), &mut rand);
}
for mushroom in [Block::BROWN_MUSHROOM, Block::RED_MUSHROOM] {
if rand.next_int(1) == 0 {
plants::flowers(level, point(&mut rand, 128, 0), &mut rand, mushroom);
}
}
level.hell_rng = rand;
}
/// `WorldGenFire`.
fn fire(level: &mut Level, [x, y, z]: [i32; 3], rand: &mut JavaRandom) {
for _ in 0..64 {
let px = x + rand.next_int(8) - rand.next_int(8);
let py = y + rand.next_int(4) - rand.next_int(4);
let pz = z + rand.next_int(8) - rand.next_int(8);
if level.is_air(px, py, pz) && level.block(px, py - 1, pz) == Block::NETHERRACK {
level.set_block_notify(px, py, pz, Block::FIRE);
}
}
}
/// `WorldGenGlowStone1` and `WorldGenGlowStone2`: a cluster hanging from netherrack.
fn glowstone(level: &mut Level, [x, y, z]: [i32; 3], rand: &mut JavaRandom) {
if !level.is_air(x, y, z) || level.block(x, y + 1, z) != Block::NETHERRACK {
return;
}
level.set_block_notify(x, y, z, Block::GLOWSTONE);
for _ in 0..1500 {
let px = x + rand.next_int(8) - rand.next_int(8);
let py = y - rand.next_int(12);
let pz = z + rand.next_int(8) - rand.next_int(8);
if !level.is_air(px, py, pz) {
continue;
}
let touching = NEIGHBORS
.iter()
.filter(|&&(dx, dy, dz)| level.block(px + dx, py + dy, pz + dz) == Block::GLOWSTONE)
.count();
if touching == 1 {
level.set_block_notify(px, py, pz, Block::GLOWSTONE);
}
}
}