From c062f41892e27767be466acef510b008cf8d3d7b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 9 Oct 2026 03:33:30 +0200 Subject: [PATCH] Add real lightning bolts Thunderstorms now roll ServerLevel.tickThunder per chunk: the bolt strikes the top of the column or a living entity under open sky nearby, may bring a skeleton trap horse, and LightningBolt ticks its flashes with the thunder and impact sounds, fire, lightning rods and thunderHit (5 damage and burning, charged creepers with their energy swirl, zombified piglins, witches, mooshroom colours, turtles, burnt items). The bolt is drawn by LightningBoltRenderer's layered branches through a new additive entity pipeline, and /summon accepts lightning bolts and minecarts. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/entity_nbt.rs | 5 +- crates/horizon-client/src/game.rs | 44 +-- crates/horizon-client/src/game/chat.rs | 6 + crates/horizon-client/src/game/commands.rs | 16 + crates/horizon-client/src/game/lightning.rs | 391 ++++++++++++++++++++ crates/horizon-client/src/gfx.rs | 76 +++- crates/horizon-client/src/mobs/render.rs | 9 +- crates/horizon-world/src/level/weather.rs | 6 +- 8 files changed, 511 insertions(+), 42 deletions(-) create mode 100644 crates/horizon-client/src/game/lightning.rs diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index 3f1d69ba5..48167dd59 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -149,11 +149,11 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { for (key, value) in [ ("Fuse", Tag::Short(30)), ("ExplosionRadius", Tag::Byte(3)), - ("powered", Tag::Byte(0)), ("ignited", Tag::Byte(0)), ] { map.entry(key.into()).or_insert(value); } + map.insert("powered".into(), Tag::Byte(i8::from(m.extra.charged))); } // Skeletons are spawned holding a bow (finalizeSpawn); a mob loaded // from NBT keeps only its saved equipment. @@ -212,6 +212,9 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - m.persistent = flag(tag, "PersistenceRequired"); m.custom_name = custom_name(tag); m.name_visible = flag(tag, "CustomNameVisible"); + if m.species() == crate::mobs::Species::Creeper { + m.extra.charged = flag(tag, "powered"); + } // A mob saved mid-death finishes dying; one saved dead is dropped. if m.health <= 0.0 && m.death_time == 0 { return None; diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 12da8300a..ba1bf0c41 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -17,6 +17,7 @@ mod fov; mod frames; mod growth; mod jukebox; +mod lightning; mod machines; mod minecarts; mod music; @@ -552,6 +553,7 @@ struct Game<'a> { carts: Vec, /// Songs playing from jukeboxes (tracked sound handles). jukebox_sounds: HashMap<(i32, i32, i32), u64>, + bolts: Vec, cart_models: minecarts::CartModels, /// The boat the player rides. riding: Option, @@ -2245,6 +2247,8 @@ impl Game<'_> { self.tick_armor_stands(); self.tick_boats(); self.tick_carts(); + self.tick_thunder(); + self.tick_bolts(); self.tick_fishing(); self.tick_tridents(); self.tick_rockets(); @@ -5729,7 +5733,7 @@ impl Game<'_> { if self.flash > 0 { self.flash -= 1; } - let (rain, thunder) = self.world.weather.levels(1.0); + let (rain, _) = self.world.weather.levels(1.0); let Some(eye) = self.eye_position() else { return; }; @@ -5760,38 +5764,6 @@ impl Game<'_> { ); } } - // ServerLevel.tickChunk lightning: 1 in 100000 per chunk per tick while thundering. - if thunder > 0.0 && self.world.weather.thundering { - let chunks = self.world.chunks.len().max(1) as i32; - if self - .world - .random - .next_int_bound((100_000 / chunks).max(1)) - .unwrap_or(1) - == 0 - { - self.flash = 2; - let r = &mut self.world.random; - let (dx, dz) = ( - f64::from(r.next_int_bound(160).unwrap_or(0) - 80), - f64::from(r.next_int_bound(160).unwrap_or(0) - 80), - ); - let at = [eye[0] + dx, eye[1], eye[2] + dz]; - let pitch = 0.8 + self.world.random.next_float() * 0.2; - self.audio.play( - "minecraft:entity.lightning_bolt.thunder", - Some(at), - 10000.0, - pitch, - ); - self.audio.play( - "minecraft:entity.lightning_bolt.impact", - Some(at), - 2.0, - 0.5 + self.world.random.next_float() * 0.2, - ); - } - } } /// WeatherEffectRenderer: rain/snow columns within 10 blocks. fn weather_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec) { @@ -6384,6 +6356,10 @@ impl Game<'_> { } else { self.entity_geometry(camera, alpha) }; + let mut additive = Vec::new(); + if !title { + self.bolt_geometry(camera, &mut additive); + } let celestial = if title { self.panorama_geometry() } else if self.dim == Dim::Overworld { @@ -6460,6 +6436,7 @@ impl Game<'_> { outline, hud: &hud, entities: &entities, + additive: &additive, celestial: &celestial, hand: &hand, screen: &screen, @@ -7287,6 +7264,7 @@ pub fn run() -> Result<()> { boat_models: boats::BoatModels::load(&root), carts: Vec::new(), jukebox_sounds: HashMap::new(), + bolts: Vec::new(), cart_models: minecarts::CartModels::load(&root), riding: None, ender_items: vec![None; 27], diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index c7a043d66..71094471f 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -141,6 +141,12 @@ impl Game<'_> { "minecraft:experience_orb", "minecraft:falling_block", "minecraft:arrow", + "minecraft:lightning_bolt", + "minecraft:minecart", + "minecraft:chest_minecart", + "minecraft:hopper_minecart", + "minecraft:furnace_minecart", + "minecraft:tnt_minecart", ] .map(String::from), ); diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 3a86b2bb9..41b1977db 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1068,6 +1068,22 @@ impl Game<'_> { }); name = Text::translate("entity.minecraft.experience_orb", &[]); } + "lightning_bolt" => { + self.spawn_bolt(pos, false); + name = Text::translate("entity.minecraft.lightning_bolt", &[]); + } + k if super::minecarts::CartKind::from_id(&kind).is_some() => { + let cart_kind = super::minecarts::CartKind::from_id(&kind) + .unwrap_or(super::minecarts::CartKind::Rideable); + self.next_entity += 1; + let cart = super::minecarts::Minecart::new( + self.next_entity, + cart_kind, + Vec3::new(pos[0], pos[1], pos[2]), + ); + self.carts.push(cart); + name = Text::translate(&format!("entity.minecraft.{k}"), &[]); + } _ => return Err(err("commands.summon.failed", &[])), } } diff --git a/crates/horizon-client/src/game/lightning.rs b/crates/horizon-client/src/game/lightning.rs new file mode 100644 index 000000000..9feff6ef3 --- /dev/null +++ b/crates/horizon-client/src/game/lightning.rs @@ -0,0 +1,391 @@ +//! Lightning (`ServerLevel.tickThunder`, `LightningBolt`, +//! `LightningBoltRenderer`): strikes on the highest motion-blocking block or +//! a living entity under open sky nearby, skeleton trap horses, fire, +//! `thunderHit` (damage and burning, charged creepers, zombified piglins, +//! witches, mooshroom colours, turtles, burnt items), lightning rods, the sky +//! flash, the sounds and the branching additive bolt. +use super::Game; +use horizon_client::{ + mesher::Vertex, + mobs::{Damage, DamageKind, MobEvent, SpawnSetup, Species}, +}; +use horizon_core::{ + position::BlockPos, + random::{LegacyRandom, RandomSource}, +}; + +pub(super) struct Bolt { + at: [f64; 3], + life: i32, + flashes: i32, + seed: i64, + visual_only: bool, + /// Mooshrooms switch colour once per bolt. + converted: Vec, +} +impl Game<'_> { + /// One `tickThunder` roll per loaded chunk. + pub(super) fn tick_thunder(&mut self) { + // isRaining (rain level > 0.2) and isThundering (> 0.9, sky light, no ceiling). + let (rain, thunder) = self.world.weather.levels(1.0); + if rain <= 0.2 || thunder <= 0.9 || self.dim != super::Dim::Overworld { + return; + } + let chunks: Vec<(i32, i32)> = self.world.chunks.keys().copied().collect(); + for (cx, cz) in chunks { + if self.world.random.next_int_bound(100_000).unwrap_or(1) != 0 { + continue; + } + // getBlockRandomPos(minX, 0, minZ, 15) + let r = self.world.random.next_int(); + let (x, z) = (cx * 16 + (r & 15), cz * 16 + (r >> 16 & 15)); + let Some(pos) = self.lightning_target(x, z) else { + continue; + }; + let p = BlockPos::new(pos[0], pos[1], pos[2]); + if !self.with_level(|b, level, _| b.is_raining_at(level, p)) { + continue; + } + // Skeleton trap: effective difficulty / 100 (regional difficulty approximated). + let difficulty = f64::from(self.ui.difficulty) * 0.75; + let below = &self + .res + .facts + .get(self.world.block(pos[0], pos[1] - 1, pos[2])) + .name; + let trap = self.ui.rules.bool("spawn_mobs") + && self.world.random.next_double() < difficulty * 0.01 + && !below.ends_with("lightning_rod"); + if trap { + let at = [f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])]; + let _ = self.spawn_mob("minecraft:skeleton_horse", at, false); + } + let at = [ + f64::from(pos[0]) + 0.5, + f64::from(pos[1]), + f64::from(pos[2]) + 0.5, + ]; + self.spawn_bolt(at, trap); + } + } + /// `findLightningTargetAround`: a living entity under open sky in the + /// column (3 blocks around), else the top of the column. + fn lightning_target(&mut self, x: i32, z: i32) -> Option<[i32; 3]> { + if !self.world.loaded(x, z) { + return None; + } + let top = + self.with_level(|b, level, _| b.motion_blocking_top(level, BlockPos::new(x, 0, z))); + let sees_sky = |g: &Self, p: [i32; 3]| g.world.light(p[0], p[1], p[2]) >> 4 == 15; + let mut candidates: Vec<[i32; 3]> = self + .mobs + .iter() + .filter(|m| m.alive()) + .map(|m| { + [ + m.position.x.floor() as i32, + m.position.y.floor() as i32, + m.position.z.floor() as i32, + ] + }) + .filter(|p| (p[0] - x).abs() <= 3 && (p[2] - z).abs() <= 3 && p[1] >= top.y - 3) + .filter(|p| sees_sky(self, *p)) + .collect(); + if let Some(p) = self + .player + .as_ref() + .filter(|p| !p.health.dead_or_dying()) + .map(|p| { + [ + p.position.x.floor() as i32, + p.position.y.floor() as i32, + p.position.z.floor() as i32, + ] + }) + && (p[0] - x).abs() <= 3 + && (p[2] - z).abs() <= 3 + && p[1] >= top.y - 3 + && sees_sky(self, p) + { + candidates.push(p); + } + if !candidates.is_empty() { + let i = self + .world + .random + .next_int_bound(candidates.len() as i32) + .unwrap_or(0) as usize; + return Some(candidates[i]); + } + Some([x, top.y, z]) + } + pub(super) fn spawn_bolt(&mut self, at: [f64; 3], visual_only: bool) { + let r = &mut self.world.random; + let seed = r.next_long(); + let flashes = r.next_int_bound(3).unwrap_or(0) + 1; + self.bolts.push(Bolt { + at, + life: 2, + flashes, + seed, + visual_only, + converted: Vec::new(), + }); + } + /// `spawnFire`: fire at the strike point and `extra` random neighbours. + fn bolt_fire(&mut self, at: [f64; 3], extra: i32) { + if self.ui.difficulty < 2 { + return; + } + let base = [ + at[0].floor() as i32, + at[1].floor() as i32, + at[2].floor() as i32, + ]; + let mut spots = vec![base]; + for _ in 0..extra { + let r = &mut self.world.random; + let mut d = || r.next_int_bound(3).unwrap_or(1) - 1; + spots.push([base[0] + d(), base[1] + d(), base[2] + d()]); + } + for p in spots { + let state = self.world.block(p[0], p[1], p[2]); + if !self.res.facts.is_air(state) { + continue; + } + // BaseFireBlock.getState: soul fire on soul soil and sand. + let below = self.res.facts.get(self.world.block(p[0], p[1] - 1, p[2])); + let name = if matches!(&*below.name, "minecraft:soul_soil" | "minecraft:soul_sand") { + "minecraft:soul_fire" + } else { + "minecraft:fire" + }; + // FireBlock.canSurvive: a sturdy floor (flammable neighbours aside). + if below.sturdy_full >> 1 & 1 == 0 { + continue; + } + if let Some(fire) = self.res.assets.registry.default_state(name) { + let _ = self.level_set(p, fire); + } + } + } + /// `LightningBolt.tick` for every bolt. + pub(super) fn tick_bolts(&mut self) { + let mut bolts = std::mem::take(&mut self.bolts); + bolts.retain_mut(|b| { + if b.life == 2 { + let pitch = 0.8 + self.world.random.next_float() * 0.2; + self.audio.play( + "minecraft:entity.lightning_bolt.thunder", + Some(b.at), + 10000.0, + pitch, + ); + let pitch = 0.5 + self.world.random.next_float() * 0.2; + self.audio.play( + "minecraft:entity.lightning_bolt.impact", + Some(b.at), + 2.0, + pitch, + ); + if !b.visual_only { + self.bolt_fire(b.at, 4); + self.strike_rod(b.at); + } + } + b.life -= 1; + if b.life < 0 { + if b.flashes == 0 { + return false; + } + if b.life < -self.world.random.next_int_bound(10).unwrap_or(0) { + b.flashes -= 1; + b.life = 1; + b.seed = self.world.random.next_long(); + if !b.visual_only { + self.bolt_fire(b.at, 0); + } + } + } + if b.life >= 0 { + self.flash = 2; + if !b.visual_only { + self.thunder_hit(b); + } + } + true + }); + bolts.append(&mut self.bolts); + self.bolts = bolts; + } + /// `LightningRodBlock.onLightningStrike`: powered for 8 ticks. + fn strike_rod(&mut self, at: [f64; 3]) { + let p = [ + at[0].floor() as i32, + (at[1] - 1.0e-6).floor() as i32, + at[2].floor() as i32, + ]; + let state = self.world.block(p[0], p[1], p[2]); + if !self.res.facts.get(state).name.ends_with("lightning_rod") { + return; + } + let registry = self.res.assets.registry; + if let Some(mut s) = registry.state(state).cloned() { + s.properties.insert("powered".into(), "true".into()); + if let Some(powered) = registry.id(&s) { + // The rod's onPlace schedules the 8-tick unpowering. + let _ = self.level_set(p, powered); + } + } + } + /// `thunderHit` for entities within 3 blocks (up to 9 above). + fn thunder_hit(&mut self, b: &mut Bolt) { + let inside = |p: [f64; 3]| { + (p[0] - b.at[0]).abs() <= 3.0 + && (p[2] - b.at[2]).abs() <= 3.0 + && p[1] >= b.at[1] - 3.0 + && p[1] <= b.at[1] + 9.0 + }; + let damage = Damage { + kind: DamageKind::Generic, + attacker: None, + from: Some(b.at), + }; + let mut events = Vec::new(); + let peaceful = self.ui.difficulty == 0; + for m in self.mobs.iter_mut().filter(|m| m.alive()) { + if !inside([m.position.x, m.position.y, m.position.z]) { + continue; + } + let setup = |m: &horizon_client::mobs::Mob| SpawnSetup { + yaw: m.yaw, + persistent: true, + ..Default::default() + }; + let at = [m.position.x, m.position.y, m.position.z]; + match m.species() { + Species::Pig if !peaceful => { + m.removed = true; + events.push(MobEvent::SpawnKind { + kind: "minecraft:zombified_piglin".into(), + at, + setup: setup(m), + }); + continue; + } + Species::Villager if !peaceful => { + m.removed = true; + events.push(MobEvent::SpawnKind { + kind: "minecraft:witch".into(), + at, + setup: setup(m), + }); + continue; + } + Species::Mooshroom => { + if !b.converted.contains(&m.id) { + b.converted.push(m.id); + m.extra.variant = 1 - m.extra.variant.min(1); + self.audio + .play("minecraft:entity.mooshroom.convert", Some(at), 2.0, 1.0); + } + continue; + } + Species::Turtle => { + m.damage(f32::MAX, damage); + continue; + } + Species::Creeper => m.extra.charged = true, + _ => {} + } + // Entity.thunderHit: burning (8 seconds) and 5 lightning damage. + m.fire_ticks = if m.fire_ticks + 1 == 0 { + 160 + } else { + m.fire_ticks + 1 + }; + m.damage(5.0, damage); + } + if !events.is_empty() { + let _ = self.handle_mob_events(events); + } + if let Some(p) = self.player.as_ref().map(|p| p.position) + && inside([p.x, p.y, p.z]) + { + let fire = &mut self.creatures.player_fire; + *fire = if *fire + 1 == 0 { 160 } else { *fire + 1 }; + self.hurt_player_by("minecraft:lightning_bolt", 5.0); + } + // Dropped items burn up (ItemEntity health 5), save fire-resistant ones. + self.dropped.retain(|e| { + !inside([e.position.x, e.position.y, e.position.z]) + || e.stack.item.contains("netherite") + }); + } + /// `LightningBoltRenderer`: 4 layers of a trunk and two branches, 8 + /// segments of 16 blocks, from the bolt's seed. + pub(super) fn bolt_geometry(&self, camera: glam::DVec3, out: &mut Vec) { + let white = self.res.atlas.font.white(); + let uv = [white.u0, white.v0]; + // ARGB 0.45, 0.45, 0.5 at 0.3 alpha, packed RGBA. + let color = (76u32 << 24) | (127 << 16) | (114 << 8) | 114; + for b in &self.bolts { + let o = (glam::DVec3::from_array(b.at) - camera).as_vec3(); + let mut random = LegacyRandom::new(b.seed); + let (mut xs, mut zs) = ([0f32; 8], [0f32; 8]); + let (mut x_off, mut z_off) = (0f32, 0f32); + for i in (0..8).rev() { + xs[i] = x_off; + zs[i] = z_off; + x_off += (random.next_int_bound(11).unwrap_or(5) - 5) as f32; + z_off += (random.next_int_bound(11).unwrap_or(5) - 5) as f32; + } + for layer in 0..4 { + let mut random = LegacyRandom::new(b.seed); + for branch in 0..3 { + let trunk = branch == 0; + let start = 7 - branch; + let end = if trunk { 0 } else { start - 3 + 1 }; + let mut sx = xs[start] - x_off; + let mut sz = zs[start] - z_off; + for segment in (end..=start).rev() { + let (ex, ez) = (sx, sz); + let spread = if trunk { 11 } else { 31 }; + sx += (random.next_int_bound(spread).unwrap_or(0) - spread / 2) as f32; + sz += (random.next_int_bound(spread).unwrap_or(0) - spread / 2) as f32; + let mut top = 0.1 + layer as f32 * 0.2; + let mut bottom = top; + if trunk { + top *= segment as f32 * 0.1 + 1.0; + bottom *= (segment as f32 - 1.0) * 0.1 + 1.0; + } + for (rx, rz, lx, lz) in [ + (false, false, true, false), + (true, false, true, true), + (true, true, false, true), + (false, true, false, false), + ] { + let s = |p: bool, r: f32| if p { r } else { -r }; + let y0 = segment as f32 * 16.0; + let corners = [ + [sx + s(rx, bottom), y0, sz + s(rz, bottom)], + [ex + s(rx, top), y0 + 16.0, ez + s(rz, top)], + [ex + s(lx, top), y0 + 16.0, ez + s(lz, top)], + [sx + s(lx, bottom), y0, sz + s(lz, bottom)], + ]; + for c in corners { + out.push(Vertex { + pos: (o + glam::Vec3::from_array(c)).to_array(), + uv, + layer: 2, + color, + light: 240 | 240 << 8, + }); + } + } + } + } + } + } + } +} diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 336715c7a..44b76e51f 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -67,6 +67,8 @@ pub struct Frame<'a> { pub hud: &'a HudBatch, /// Camera-relative entity geometry textured from the shared atlas. pub entities: &'a [Vertex], + /// Additive translucent geometry after the entities (lightning, dragon rays). + pub additive: &'a [Vertex], /// Camera-relative sun, moon and stars (drawn behind everything, additive). pub celestial: &'a [Vertex], /// First-person hand and held item, drawn after clearing depth. @@ -89,6 +91,7 @@ pub struct Renderer { dark_disc: wgpu::RenderPipeline, lines: wgpu::RenderPipeline, entity_pipeline: wgpu::RenderPipeline, + additive_pipeline: wgpu::RenderPipeline, celestial_pipeline: wgpu::RenderPipeline, celestial_buffer: wgpu::Buffer, /// Screen effects: alpha-blended and vignette (`dst * (1 - src)`) pipelines. @@ -665,6 +668,52 @@ impl Renderer { multiview_mask: None, cache: None, }); + // BlendFunction.LIGHTNING: src alpha, one; no depth writes. + let additive_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Additive entities"), + layout: Some(&entity_layout), + vertex: wgpu::VertexState { + module: &entity_shader, + entry_point: Some("vs_entity"), + compilation_options: Default::default(), + buffers: &entity_vertex, + }, + primitive: wgpu::PrimitiveState { + cull_mode: None, + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: wgpu::TextureFormat::Depth32Float, + depth_write_enabled: Some(false), + depth_compare: Some(wgpu::CompareFunction::LessEqual), + stencil: Default::default(), + bias: Default::default(), + }), + multisample: Default::default(), + fragment: Some(wgpu::FragmentState { + module: &entity_shader, + entry_point: Some("fs_celestial"), + compilation_options: Default::default(), + targets: &[Some(wgpu::ColorTargetState { + format: config.format.remove_srgb_suffix(), + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + }), + write_mask: wgpu::ColorWrites::ALL, + })], + }), + multiview_mask: None, + cache: None, + }); let celestial_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Celestial bodies"), layout: Some(&entity_layout), @@ -795,6 +844,7 @@ impl Renderer { dark_disc, lines, entity_pipeline, + additive_pipeline, celestial_pipeline, celestial_buffer, screen_pipelines, @@ -1311,15 +1361,18 @@ impl Renderer { .write_buffer(&self.outline, 0, bytemuck::cast_slice(&lines)); } let mut combined; - let all_entities: &[Vertex] = if frame.hand.is_empty() { + let all_entities: &[Vertex] = if frame.hand.is_empty() && frame.additive.is_empty() { frame.entities } else { - combined = Vec::with_capacity(frame.entities.len() + frame.hand.len()); + combined = + Vec::with_capacity(frame.entities.len() + frame.additive.len() + frame.hand.len()); combined.extend_from_slice(frame.entities); + combined.extend_from_slice(frame.additive); combined.extend_from_slice(frame.hand); &combined }; let hand_quads = (frame.hand.len() / 4) as u32; + let additive_quads = (frame.additive.len() / 4) as u32; let entity_vertices = all_entities.len() as u64; if entity_vertices > self.entity_capacity { self.entity_capacity = entity_vertices.next_power_of_two(); @@ -1342,9 +1395,9 @@ impl Renderer { bytemuck::cast_slice(&frame.celestial[..celestial_vertices]), ); } - let entity_quads = (entity_vertices / 4) as u32 - hand_quads; - if entity_quads + hand_quads > self.index_quads { - self.index_quads = (entity_quads + hand_quads).next_power_of_two(); + let entity_quads = (entity_vertices / 4) as u32 - hand_quads - additive_quads; + if entity_quads + additive_quads + hand_quads > self.index_quads { + self.index_quads = (entity_quads + additive_quads + hand_quads).next_power_of_two(); self.indices = Self::quad_indices(&self.device, self.index_quads); } let view_target = surface_frame @@ -1437,6 +1490,13 @@ impl Renderer { pass.draw_indexed(0..entity_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } + if additive_quads > 0 { + pass.set_pipeline(&self.additive_pipeline); + pass.set_bind_group(0, &self.entity_group, &[]); + pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); + pass.draw_indexed(0..additive_quads * 6, (entity_quads * 4) as i32, 0..1); + pass.set_bind_group(0, &self.group, &[]); + } if outline_edges > 0 { pass.set_pipeline(&self.lines); pass.set_vertex_buffer(0, self.outline.slice(..)); @@ -1484,7 +1544,11 @@ impl Renderer { pass.set_bind_group(0, &self.entity_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed(0..hand_quads * 6, (entity_quads * 4) as i32, 0..1); + pass.draw_indexed( + 0..hand_quads * 6, + ((entity_quads + additive_quads) * 4) as i32, + 0..1, + ); } if !frame.screen.is_empty() { let vertices: Vec = diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs index 868c8c45f..814ee2e86 100644 --- a/crates/horizon-client/src/mobs/render.rs +++ b/crates/horizon-client/src/mobs/render.rs @@ -333,7 +333,14 @@ pub fn layers(m: &Mob) -> Vec { white, false, ), - S::Creeper if m.extra.charged => {} + // EnergySwirlLayer (the scroll is not reproduced: atlas sprites do not wrap). + S::Creeper if m.extra.charged => push( + &mut v, + "creeper#armor", + "entity/creeper/creeper_armor", + 0x80FF_FFFF, + true, + ), S::TropicalFish => { // TropicalFishPatternLayer: the pattern tinted with the pattern colour. let (model, letter, n) = if m.extra.variant < 6 { diff --git a/crates/horizon-world/src/level/weather.rs b/crates/horizon-world/src/level/weather.rs index 845548ce1..c43d96b15 100644 --- a/crates/horizon-world/src/level/weather.rs +++ b/crates/horizon-world/src/level/weather.rs @@ -41,7 +41,11 @@ impl Behaviours { } } /// `getHeightmapPos(MOTION_BLOCKING, pos)`. - fn motion_blocking_top(&self, level: &L, pos: BlockPos) -> BlockPos { + pub fn motion_blocking_top( + &self, + level: &L, + pos: BlockPos, + ) -> BlockPos { let blocks = self.tag("minecraft:blocks_motion_in_heightmap"); for y in (level.min_y()..level.max_y()).rev() { let state = level.block_state(BlockPos::new(pos.x, y, pos.z));