From 17b1bcf2ce41e11c28e3163d7560b34a789f0b81 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 11 Oct 2026 17:11:05 +0200 Subject: [PATCH] Destroy blocks for /setblock and /fill destroy as Level.destroyBlock does Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/commands.rs | 36 +++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 880091491..85cd17609 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1520,10 +1520,7 @@ impl Game<'_> { return Err(err("commands.setblock.failed", &[])); } if ctx.has("destroy") && current != self.world.air { - let creative = self.creative; - self.creative = false; - let _ = self.break_block(pos); - self.creative = creative; + self.destroy_block_dropping(pos)?; } let placed = self.place_state(pos, state, ctx.has("strict"))?; let loaded = match &b.nbt { @@ -1539,6 +1536,32 @@ impl Game<'_> { )); Ok(1) } + /// `Level.destroyBlock(pos, true)`: the block's drops without a tool or + /// breaker (its loot table, contents of a container), then air. + pub(super) fn destroy_block_dropping(&mut self, pos: [i32; 3]) -> R<()> { + let state = self.world.block(pos[0], pos[1], pos[2]); + self.destroy_particles(pos, state); + self.jukebox_removed(pos); + if let Some(entity) = self.world.block_entities.remove(&(pos[0], pos[1], pos[2])) { + let name = self.res.facts.get(state).name.clone(); + self.release_contents(pos, entity, &name); + } + let drops = self.res.items.block_drops_in( + self.res.assets.registry, + state, + None, + &mut self.world.random, + Some((&mut self.rand_sequences, self.level.seed)), + ); + for d in drops { + if &*d.item != "minecraft:air" { + self.pop_resource(pos, d); + } + } + let air = self.world.air; + self.place_state(pos, air, false)?; + Ok(()) + } /// The block entity part of `BlockInput.place`: load the block entity /// from the argument's tag; true when its saved data changed. pub(super) fn load_block_entity_nbt(&mut self, pos: [i32; 3], nbt: &str) -> bool { @@ -1620,10 +1643,7 @@ impl Game<'_> { || z == max[2]; let mut affected = false; if destroy && current != air { - let creative = self.creative; - self.creative = false; - let _ = self.break_block([x, y, z]); - self.creative = creative; + self.destroy_block_dropping([x, y, z])?; affected = true; } let target = if (outline || hollow) && !edge {