Add End flashes to the End sky and lighting
EndFlashState: one flash per 600 clock ticks with seeded offset, duration and direction; the end_flash sprite in the sky, the flash intensity added to the lightmap sky factor and the delayed weather.end_flash sound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4184,6 +4184,7 @@ impl Game<'_> {
|
||||
let mut sky = environment.sample(self.world.day_time, info.sky, info.fog);
|
||||
let (rain, thunder) = if self.dim == Dim::Overworld { self.world.weather.levels(alpha as f32) } else { (0.0, 0.0) };
|
||||
horizon_client::environment::apply_weather(&mut sky, rain, thunder);
|
||||
self.end_flash_sky(&mut sky, alpha);
|
||||
if self.flash > 0 {
|
||||
// Lightning flash brightens the sky (LevelRenderer skyFlashTime).
|
||||
sky.sky_color = [0.9, 0.9, 1.0];
|
||||
|
||||
@@ -45,6 +45,52 @@ pub(super) struct EndState {
|
||||
locator: std::sync::Mutex<Option<Arc<VanillaTerrain>>>,
|
||||
/// Thrown eyes of ender in flight.
|
||||
eyes: Vec<EyeOfEnder>,
|
||||
flash: EndFlash,
|
||||
}
|
||||
|
||||
/// EndFlashState: a purple flash in the End sky every 600 ticks that also
|
||||
/// lights the world (the lightmap's sky factor).
|
||||
#[derive(Default)]
|
||||
struct EndFlash {
|
||||
seed: Option<i64>,
|
||||
offset: i32,
|
||||
duration: i32,
|
||||
intensity: f32,
|
||||
old_intensity: f32,
|
||||
x_angle: f32,
|
||||
y_angle: f32,
|
||||
/// Ticks until the delayed weather.end_flash sound.
|
||||
sound_in: Option<u32>,
|
||||
}
|
||||
impl EndFlash {
|
||||
fn tick(&mut self, clock: i64) {
|
||||
let seed = clock.div_euclid(600);
|
||||
if self.seed != Some(seed) {
|
||||
let mut random = LegacyRandom::new(seed);
|
||||
random.next_float();
|
||||
let between = |r: &mut LegacyRandom, lo: i32, hi: i32| {
|
||||
r.next_int_bound(hi - lo + 1).unwrap_or(0) + lo
|
||||
};
|
||||
self.offset = between(&mut random, 0, 200);
|
||||
self.duration = between(&mut random, 100, 380.min(600 - self.offset));
|
||||
self.x_angle = random.next_float() * 70.0 - 60.0;
|
||||
self.y_angle = random.next_float() * 360.0 - 180.0;
|
||||
self.seed = Some(seed);
|
||||
}
|
||||
self.old_intensity = self.intensity;
|
||||
let t = clock.rem_euclid(600) as i32;
|
||||
self.intensity = if t >= self.offset && t <= self.offset + self.duration {
|
||||
((t - self.offset) as f32 * std::f32::consts::PI / self.duration as f32).sin()
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
if self.intensity > 0.0 && self.old_intensity <= 0.0 {
|
||||
self.sound_in = Some(30);
|
||||
}
|
||||
}
|
||||
fn intensity(&self, partial: f32) -> f32 {
|
||||
self.old_intensity + (self.intensity - self.old_intensity) * partial
|
||||
}
|
||||
}
|
||||
impl EndState {
|
||||
pub(super) fn set_locator(&self, terrain: Option<Arc<VanillaTerrain>>) {
|
||||
@@ -139,9 +185,48 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// SkyRenderer.renderEndFlash: the end_flash sprite at height 100, scale 60.
|
||||
let intensity = self.end.flash.intensity(self.clock.fraction() as f32);
|
||||
if intensity > 1e-5
|
||||
&& let Some(r) = self
|
||||
.res
|
||||
.atlas
|
||||
.sprites
|
||||
.get("environment/celestial/end_flash")
|
||||
.copied()
|
||||
{
|
||||
let flash = &self.end.flash;
|
||||
let pose = glam::Mat4::from_rotation_y((180.0 - flash.y_angle).to_radians())
|
||||
* glam::Mat4::from_rotation_x((-90.0 - flash.x_angle).to_radians());
|
||||
let level = (intensity.clamp(0.0, 1.0) * 255.0) as u32;
|
||||
let color = level << 24 | level << 16 | level << 8 | level;
|
||||
let corners = [
|
||||
(-1.0, -1.0, [r.u0, r.v0]),
|
||||
(1.0, -1.0, [r.u1, r.v0]),
|
||||
(1.0, 1.0, [r.u1, r.v1]),
|
||||
(-1.0, 1.0, [r.u0, r.v1]),
|
||||
];
|
||||
for (x, z, uv) in corners {
|
||||
let p = pose.transform_point3(glam::Vec3::new(x * 60.0, 100.0, z * 60.0));
|
||||
out.push(Vertex {
|
||||
pos: p.to_array(),
|
||||
uv,
|
||||
layer: 2,
|
||||
color,
|
||||
light: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// LightmapRenderStateExtractor: End flashes add to the sky light factor.
|
||||
pub(super) fn end_flash_sky(&self, sky: &mut horizon_client::environment::Sky, partial: f64) {
|
||||
if self.dim == Dim::End {
|
||||
sky.sky_light_factor += self.end.flash.intensity(partial as f32);
|
||||
}
|
||||
}
|
||||
|
||||
fn block_name(&self, p: [i32; 3]) -> std::sync::Arc<str> {
|
||||
self.res
|
||||
.facts
|
||||
@@ -260,6 +345,17 @@ impl Game<'_> {
|
||||
self.end.gateway_cooldown = self.end.gateway_cooldown.saturating_sub(1);
|
||||
self.scan_portals();
|
||||
self.tick_eyes();
|
||||
if self.dim == Dim::End {
|
||||
self.end.flash.tick(self.world.game_time);
|
||||
if let Some(n) = self.end.flash.sound_in.as_mut() {
|
||||
*n = n.saturating_sub(1);
|
||||
if *n == 0 {
|
||||
self.end.flash.sound_in = None;
|
||||
self.audio
|
||||
.play("minecraft:weather.end_flash", None, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.dim == Dim::End {
|
||||
self.ensure_exit_portal()?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user