Improved giant trees

This commit is contained in:
Joshua Barretto 2021-08-29 14:37:11 +01:00
parent 643807e5ff
commit 98f4e95111
2 changed files with 50 additions and 16 deletions

View File

@ -18,7 +18,7 @@
GreenSludge: None,
// Leaves all actually get interpolated.
TemperateLeaves: [
(start: (0, 91, 68), end: (124, 173, 0)),
(start: (0, 100, 50), end: (105, 175, 0)),
//(start: (178, 216, 0), end: (255, 185, 63)),
//(start: (142, 164, 0), end: (142, 164, 0)),
//(start: (168, 81, 0), end: (54, 150, 31)),

View File

@ -4,7 +4,10 @@ use crate::{
util::{FastNoise, Sampler},
Canvas, Land,
};
use common::terrain::{Block, BlockKind};
use common::{
generation::EntityInfo,
terrain::{Block, BlockKind, SpriteKind},
};
use rand::prelude::*;
use vek::*;
@ -38,7 +41,7 @@ impl Tree {
}
}
pub fn render(&self, canvas: &mut Canvas, _dynamic_rng: &mut impl Rng) {
pub fn render(&self, canvas: &mut Canvas, dynamic_rng: &mut impl Rng) {
let nz = FastNoise::new(self.seed);
canvas.foreach_col(|canvas, wpos2d, col| {
@ -51,6 +54,7 @@ impl Tree {
}
let mut above = true;
let mut last = None;
for z in (bounds.min.z..bounds.max.z + 1).rev() {
let wpos = wpos2d.with_z(self.alt + z);
let rposf = (wpos - self.origin.with_z(self.alt)).map(|e| e as f32 + 0.5);
@ -64,25 +68,55 @@ impl Tree {
Block::new(BlockKind::Snow, Rgb::new(255, 255, 255)),
);
}
}
if leaves {
let dark = Rgb::new(10, 70, 50).map(|e| e as f32);
let light = Rgb::new(80, 140, 10).map(|e| e as f32);
let leaf_col = Lerp::lerp(
dark,
light,
nz.get(rposf.map(|e| e as f64) * 0.05) * 0.5 + 0.5,
let block = if leaves {
if above && dynamic_rng.gen_bool(0.0005) {
canvas.spawn(
EntityInfo::at(wpos.map(|e| e as f32) + Vec3::unit_z())
.with_asset_expect(match dynamic_rng.gen_range(0..2) {
0 => "common.entity.wild.aggressive.deadwood",
_ => "common.entity.wild.aggressive.maneater",
}),
);
canvas.set(
wpos,
Block::new(BlockKind::Leaves, leaf_col.map(|e| e as u8)),
} else if above && dynamic_rng.gen_bool(0.0001) {
canvas.spawn(
EntityInfo::at(wpos.map(|e| e as f32) + Vec3::unit_z())
.with_asset_expect("common.entity.wild.aggressive.swamp_troll"),
);
} else if branch {
canvas.set(wpos, Block::new(BlockKind::Wood, Rgb::new(80, 32, 0)));
}
above = false;
let dark = Rgb::new(10, 70, 50).map(|e| e as f32);
let light = Rgb::new(80, 140, 10).map(|e| e as f32);
let leaf_col = Lerp::lerp(
dark,
light,
nz.get(rposf.map(|e| e as f64) * 0.05) * 0.5 + 0.5,
);
Some(Block::new(BlockKind::Leaves, leaf_col.map(|e| e as u8)))
} else if branch {
Some(Block::new(BlockKind::Wood, Rgb::new(80, 32, 0)))
} else {
None
};
// Chests in trees
if last.is_none() && block.is_some() && dynamic_rng.gen_bool(0.00025) {
canvas.set(wpos + Vec3::unit_z(), Block::air(SpriteKind::Chest));
}
if let Some(block) = block {
above = false;
canvas.set(wpos, block);
} else if last.map_or(false, |b: Block| {
matches!(b.kind(), BlockKind::Leaves | BlockKind::Wood)
}) && dynamic_rng.gen_bool(0.0005)
{
canvas.set(wpos, Block::air(SpriteKind::Beehive));
}
last = block;
}
});
}