diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 5ffcd9124..cc17dc64a 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1777,6 +1777,12 @@ impl Game<'_> { }); self.process_level_events() } + fn attack_block(&mut self, pos: [i32; 3]) -> Result<()> { + self.with_level(|b, level, ticks| { + b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2])); + }); + self.process_level_events() + } /// Track which chunks are ticking (Ticks needs chunk load/unload). fn sync_tick_chunks(&mut self) { if !self.tick_chunks.synchronize(&self.world.chunks) { @@ -2885,6 +2891,7 @@ impl Game<'_> { return Ok(()); } if self.mining.as_ref().is_none_or(|m| m.pos != hit.pos) { + self.attack_block(hit.pos)?; self.mining = Some(Mining { pos: hit.pos, progress: 0.0, diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs index 431e6661a..a932913af 100644 --- a/crates/horizon-client/src/game/hand.rs +++ b/crates/horizon-client/src/game/hand.rs @@ -409,7 +409,10 @@ impl HandWorld for GameHands<'_, '_> { fn within_border(&mut self, _: [i32; 3]) -> bool { true } - fn attack_block(&mut self, _: [i32; 3]) {} + fn attack_block(&mut self, pos: [i32; 3]) { + let result = self.game.attack_block(pos); + self.keep(result); + } fn destroy_progress(&mut self, pos: [i32; 3]) -> f32 { self.game.destroy_progress(pos) } diff --git a/crates/horizon-world/src/level/interact.rs b/crates/horizon-world/src/level/interact.rs index 791daf7c2..c38d81f26 100644 --- a/crates/horizon-world/src/level/interact.rs +++ b/crates/horizon-world/src/level/interact.rs @@ -513,6 +513,22 @@ impl Behaviours { sim.game_event_state(pos, "minecraft:block_change", next); } + /// The state change of `RedStoneOreBlock.attack` when mining begins. + pub fn attack_block( + &self, + level: &mut L, + ticks: &mut Ticks, + pos: BlockPos, + ) { + let mut sim = self.sim(level, ticks); + let state = sim.state(pos); + if self.data(state).chain.contains(&Class::RedStoneOre) + && !self.table.bool(state, self.props.lit) + { + sim.set_block_and_update(pos, self.table.set_bool(state, self.props.lit, true)); + } + } + /// `BlockState.useWithoutItem` for a right-click on `pos` (hit face and /// absolute hit location as in `BlockHitResult`). pub fn use_without_item( diff --git a/crates/horizon-world/src/level/tests.rs b/crates/horizon-world/src/level/tests.rs index 270ee48fa..c0ceddc6f 100644 --- a/crates/horizon-world/src/level/tests.rs +++ b/crates/horizon-world/src/level/tests.rs @@ -634,6 +634,27 @@ impl World<'_> { } } +#[test] +fn mining_lights_redstone_ore_until_its_random_tick() { + let mut w = world!(); + let pos = BlockPos::new(0, 1, 0); + for ore in ["redstone_ore", "deepslate_redstone_ore"] { + let unlit = w.id(ore, &[("lit", "false")]); + let lit = w.id(ore, &[("lit", "true")]); + w.put(pos, unlit); + w.b().attack_block(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), lit); + w.b().attack_block(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), lit); + w.b().random_tick(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), unlit); + } + let stone = w.id("stone", &[]); + w.put(pos, stone); + w.b().attack_block(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), stone); +} + #[test] fn placement_orients_blocks() { let mut w = world!();