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 sky.rs
use crate::math;
use std::f32::consts::PI;
pub const TICKS_PER_DAY: i64 = 24_000;
/// Port of `WorldProvider.calculateCelestialAngle`.
pub fn celestial_angle(time: i64, partial_ticks: f32) -> f32 {
let mut angle = ((time % TICKS_PER_DAY) as f32 + partial_ticks) / TICKS_PER_DAY as f32 - 0.25;
if angle < 0.0 {
angle += 1.0;
}
if angle > 1.0 {
angle -= 1.0;
}
let eased = 1.0 - (((f64::from(angle) * std::f64::consts::PI).cos() + 1.0) / 2.0) as f32;
angle + (eased - angle) / 3.0
}
/// Port of `World.calculateSkylightSubtracted`: night, rain and thunder darken the sky.
pub fn sky_darkness(angle: f32, rain: f32, thunder: f32) -> u32 {
let light = 1.0 - (math::cos(angle * PI * 2.0) * 2.0 + 0.5);
let mut light = 1.0 - light.clamp(0.0, 1.0);
light = (f64::from(light) * (1.0 - f64::from(rain * 5.0) / 16.0)) as f32;
light = (f64::from(light) * (1.0 - f64::from(thunder * 5.0) / 16.0)) as f32;
((1.0 - light) * 11.0) as u32
}