From 2c2aa416191a5c8a8178e981a526e45139dff3a2 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 22:27:59 +0100 Subject: [PATCH] Clear a door's lower half when the tool would not drop it DoorBlock.playerWillDestroy removes the bottom half for creative or !hasCorrectToolForDrops (iron door by hand); only creative was handled. --- crates/horizon-client/src/game.rs | 6 ++++++ crates/horizon-world/src/level/hooks.rs | 6 +++--- crates/horizon-world/src/level/mod.rs | 5 +++-- crates/horizon-world/src/level/tests.rs | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 5c9a25891..57adfa03b 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -3983,12 +3983,18 @@ impl Game<'_> { // library: the block entity's side effects (containers spill), neighbour // and shape updates, and the destroy event (particles, sound). let creative = self.creative; + let correct_tool = !facts.requires_tool + || self + .res + .items() + .correct_for_drops(self.held(), &facts.name); let removed = self.with_level(|b, level, ticks| { b.player_destroy_block( level, ticks, BlockPos::new(pos[0], pos[1], pos[2]), creative, + correct_tool, ) }); if removed { diff --git a/crates/horizon-world/src/level/hooks.rs b/crates/horizon-world/src/level/hooks.rs index db5a8457f..eb9fd4906 100644 --- a/crates/horizon-world/src/level/hooks.rs +++ b/crates/horizon-world/src/level/hooks.rs @@ -386,7 +386,7 @@ impl Sim<'_, L> { /// `ServerPlayerGameMode.destroyBlock`: `playerWillDestroy` then /// `removeBlock`. Drops are the caller's (tool-dependent loot). - pub(crate) fn player_destroy(&mut self, pos: BlockPos, creative: bool) -> bool { + pub(crate) fn player_destroy(&mut self, pos: BlockPos, creative: bool, correct_tool: bool) -> bool { let b = self.b; let p = b.props; let state = self.state(pos); @@ -394,8 +394,8 @@ impl Sim<'_, L> { return false; } let data = b.data(state); - if creative - && (data.is(Class::DoublePlant) || data.is(Class::Door)) + // DoorBlock also clears the bottom half when the tool would not drop it. + if ((creative && data.is(Class::DoublePlant)) || (data.is(Class::Door) && (creative || !correct_tool))) && b.table.text(state, p.half) == "upper" { let bottom = below(pos); diff --git a/crates/horizon-world/src/level/mod.rs b/crates/horizon-world/src/level/mod.rs index 4d228f898..d6c579c30 100644 --- a/crates/horizon-world/src/level/mod.rs +++ b/crates/horizon-world/src/level/mod.rs @@ -80,7 +80,7 @@ //! behaviours.place_block(&mut level, &mut ticks, &PlaceContext { clicked_pos, face, hit, inside: false, //! yaw, pitch, sneaking, item: "minecraft:oak_stairs".into(), can_use_game_master_blocks: false }); //! behaviours.use_without_item(&mut level, &mut ticks, pos, face, hit, player_context); -//! behaviours.player_destroy_block(&mut level, &mut ticks, pos, creative); +//! behaviours.player_destroy_block(&mut level, &mut ticks, pos, creative, correct_tool); //! // Falling-block entity landed: //! behaviours.falling_block_landed(&mut level, &mut ticks, landing_pos, carried_state, false); //! ``` @@ -657,8 +657,9 @@ impl Behaviours { ticks: &mut Ticks, pos: BlockPos, creative: bool, + correct_tool: bool, ) -> bool { - self.sim(level, ticks).player_destroy(pos, creative) + self.sim(level, ticks).player_destroy(pos, creative, correct_tool) } /// `IceBlock.playerDestroy` after the drops: mined ice melts into water /// unless the tool prevents ice melting (silk touch). `destroyed` is the diff --git a/crates/horizon-world/src/level/tests.rs b/crates/horizon-world/src/level/tests.rs index da75083d2..e99d2e51b 100644 --- a/crates/horizon-world/src/level/tests.rs +++ b/crates/horizon-world/src/level/tests.rs @@ -1361,7 +1361,7 @@ fn player_breaks_fire_with_extinguish_not_generic_break_event() { w.level.events.clear(); assert!( w.f.behaviours - .player_destroy_block(&mut w.level, &mut w.ticks, pos, false) + .player_destroy_block(&mut w.level, &mut w.ticks, pos, false, true) ); let is_fire = name != "white_wool"; assert_eq!(