From aa810a88023a2ab2649a7b820e36949a1cd0e1c2 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 10 Oct 2026 06:37:52 +0200 Subject: [PATCH] WIP: block update harness fixes Work in progress on the block update differential harness fixtures and redstone/piston update fixes. Co-Authored-By: Claude Sonnet 5.5 --- crates/horizon-client/src/items.rs | 11 +++- .../examples/block_update_fixture.rs | 14 +++++ crates/horizon-world/src/level/pistons.rs | 3 ++ crates/horizon-world/src/level/redstone.rs | 54 +++++++++++-------- crates/horizon-world/src/level/update.rs | 10 +++- 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/crates/horizon-client/src/items.rs b/crates/horizon-client/src/items.rs index a09aa3066..439e2516b 100644 --- a/crates/horizon-client/src/items.rs +++ b/crates/horizon-client/src/items.rs @@ -509,7 +509,16 @@ impl Items { return vec![]; }; let name = block.name.trim_start_matches("minecraft:"); - let Some(table) = self.loot.get(&format!("minecraft:blocks/{name}")) else { + // `Blocks.wallVariant`: wall signs, banners, heads, fans and torches + // reuse the standing block's loot table. + let standing = name.replacen("_wall_", "_", 1); + let standing = standing.strip_prefix("wall_").unwrap_or(&standing); + let standing = standing.replacen("wall_", "", 1); + let table = self + .loot + .get(&format!("minecraft:blocks/{name}")) + .or_else(|| self.loot.get(&format!("minecraft:blocks/{standing}"))); + let Some(table) = table else { return vec![]; }; let ctx = LootContext { diff --git a/crates/horizon-world/examples/block_update_fixture.rs b/crates/horizon-world/examples/block_update_fixture.rs index 2cf7bdc28..c5015f7fd 100644 --- a/crates/horizon-world/examples/block_update_fixture.rs +++ b/crates/horizon-world/examples/block_update_fixture.rs @@ -272,6 +272,10 @@ fn main() -> Result<(), Box> { LevelEvent::DropResources { state, .. } => { let name = behaviours.table.name(*state); let short = name.strip_prefix("minecraft:").unwrap_or(name); + // `Blocks.wallVariant` reuses the standing block's loot table. + let short = short.replacen("_wall_", "_", 1); + let short = short.strip_prefix("wall_").unwrap_or(&short); + let short = short.replacen("wall_", "", 1); let _ = writeln!(result, "D minecraft:blocks/{short}"); } LevelEvent::FallingBlock { .. } => { @@ -297,6 +301,16 @@ fn main() -> Result<(), Box> { } } } + for e in &ticks.block_events { + let _ = writeln!( + result, + "B {} {} {} {}", + p(e.pos), + behaviours.table.info(e.block).name, + e.param_a, + e.param_b + ); + } let _ = writeln!(result, "rng {}", level.random.next_long()); out.write_all(result.as_bytes())?; } diff --git a/crates/horizon-world/src/level/pistons.rs b/crates/horizon-world/src/level/pistons.rs index 0beb512c8..299959e0b 100644 --- a/crates/horizon-world/src/level/pistons.rs +++ b/crates/horizon-world/src/level/pistons.rs @@ -111,6 +111,9 @@ impl Sim<'_, L> { let data = self.b.data(state); if data.is(super::classes::Class::PistonBase) { self.piston_trigger_event(pos, state, a, b) + } else if data.is(super::classes::Class::Note) { + self.note_trigger_event(pos, state); + true } else { false } diff --git a/crates/horizon-world/src/level/redstone.rs b/crates/horizon-world/src/level/redstone.rs index 87ebe8810..02d62b929 100644 --- a/crates/horizon-world/src/level/redstone.rs +++ b/crates/horizon-world/src/level/redstone.rs @@ -1067,35 +1067,45 @@ impl Sim<'_, L> { self.set_block(pos, b.table.set_bool(next, p.powered, signal), 3); } } - /// `NoteBlock.playNote` (block event; instrument pitch from `note`). + /// `NoteBlock.playNote`: queues the block event and emits the game event. pub(crate) fn note_play(&mut self, pos: BlockPos, state: BlockStateId) { + let b = self.b; + let instrument = b.table.text(state, b.props.instrument); + let mob_head = super::data::INSTRUMENTS + .iter() + .position(|n| *n == instrument) + .is_some_and(|i| super::data::instrument_works_above(i as u8)); + if mob_head || b.is_air(self.above_state(pos)) { + self.block_event(pos, b.block(state), 0, 0); + self.game_event(pos, "minecraft:note_block_play"); + } + } + /// `NoteBlock.triggerEvent`: the note's sound. + pub(crate) fn note_trigger_event(&mut self, pos: BlockPos, state: BlockStateId) { let b = self.b; let instrument = b.table.text(state, b.props.instrument).to_owned(); let mob_head = super::data::INSTRUMENTS .iter() .position(|n| *n == instrument) .is_some_and(|i| super::data::instrument_works_above(i as u8)); - if mob_head || b.is_air(self.above_state(pos)) { - let note = b.table.int(state, b.props.note); - let pitch = if mob_head { - 1.0 - } else { - 2f64.powf(f64::from(note - 12) / 12.0) as f32 - }; - let sound = match instrument.as_str() { - "custom_head" => "minecraft:ui.button.click".to_owned(), - "dragon" => "minecraft:block.note_block.imitate.ender_dragon".to_owned(), - name if mob_head => format!("minecraft:block.note_block.imitate.{name}"), - name => format!("minecraft:block.note_block.{name}"), - }; - self.emit(LevelEvent::Sound { - pos, - sound: sound.into(), - volume: 3.0, - pitch, - }); - self.game_event(pos, "minecraft:note_block_play"); - } + let note = b.table.int(state, b.props.note); + let pitch = if mob_head { + 1.0 + } else { + 2f64.powf(f64::from(note - 12) / 12.0) as f32 + }; + let sound = match instrument.as_str() { + "custom_head" => "minecraft:ui.button.click".to_owned(), + "dragon" => "minecraft:block.note_block.imitate.ender_dragon".to_owned(), + name if mob_head => format!("minecraft:block.note_block.imitate.{name}"), + name => format!("minecraft:block.note_block.{name}"), + }; + self.emit(LevelEvent::Sound { + pos, + sound: sound.into(), + volume: 3.0, + pitch, + }); } pub(crate) fn note_neighbor_changed(&mut self, pos: BlockPos, state: BlockStateId) { let b = self.b; diff --git a/crates/horizon-world/src/level/update.rs b/crates/horizon-world/src/level/update.rs index 7a0e6d933..5ce173648 100644 --- a/crates/horizon-world/src/level/update.rs +++ b/crates/horizon-world/src/level/update.rs @@ -1,6 +1,6 @@ //! `Level.setBlock`, `LevelChunk.setBlockState` and the //! `CollectingNeighborUpdater` that orders neighbour and shape updates. -use super::{LevelAccess, LevelEvent, Sim, flags, states::BlockId}; +use super::{LevelAccess, LevelEvent, Sim, classes::Class, flags, states::BlockId}; use crate::{fluid::FluidState, registry::BlockStateId}; use horizon_core::{ geometry::Direction, @@ -338,7 +338,13 @@ impl Sim<'_, L> { if self.b.is_air(state) { return false; } - self.level_event(2001, pos, state.0 as i32); + let is_fire = { + let data = self.b.data(state); + data.is(Class::BaseFire) || data.is(Class::Fire) || data.is(Class::SoulFire) + }; + if !is_fire { + self.level_event(2001, pos, state.0 as i32); + } if drop { self.drop_resources(state, pos); }