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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-10 06:37:52 +02:00
parent 3d8bdf6b39
commit aa810a8802
5 changed files with 67 additions and 25 deletions
+10 -1
View File
@@ -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 {
@@ -272,6 +272,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
}
}
}
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())?;
}
@@ -111,6 +111,9 @@ impl<L: LevelAccess + ?Sized> 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
}
+32 -22
View File
@@ -1067,35 +1067,45 @@ impl<L: LevelAccess + ?Sized> 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;
+8 -2
View File
@@ -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<L: LevelAccess + ?Sized> 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);
}