From 493e5f8d3a825acdf256c3f53a801a9d292644dc Mon Sep 17 00:00:00 2001 From: Alexander Krylov Date: Sat, 24 Oct 2026 19:50:45 +0300 Subject: [PATCH 1/2] Commands: a placed block keeps its block entity when a neighbour update changes its state /setblock created the block entity only when the state that landed matched the requested state exactly. HopperBlock.onPlace sets enabled=false while the block is being placed, so a hopper put into power had no inventory: /data get block answered "not a block entity", items dropped into it stayed item entities, and /setblock hopper{Items:[...]} dropped the NBT as well. Compare the block at the position with the block that was placed, the way vanilla does when it creates the entity from the placed state, before the neighbour updates run. Fixes #1506. Co-Authored-By: Hermes Agent (Nous Research) --- crates/horizon-client/src/game/commands.rs | 6 +++++- tools/command_exec_corpus.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index c5a3fc456..4dc82867d 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1783,8 +1783,12 @@ impl Game<'_> { self.level_set(pos, state) .map_err(|e| CommandError::new(Text::literal(e.to_string())))?; } + // HopperBlock.onPlace can change the state while it is being placed (a powered + // hopper arrives `enabled=false`); vanilla keeps the block entity, so compare the block. + let placed = self.world.block(pos[0], pos[1], pos[2]); + let kept = self.res.facts().get(placed).name == new; if old != new - && self.world.block(pos[0], pos[1], pos[2]) == state + && kept && let Some(entity) = horizon_client::containers::BlockEntity::for_block(&new) { self.world.block_entities.insert(key, entity); diff --git a/tools/command_exec_corpus.py b/tools/command_exec_corpus.py index b6edc009a..33976813d 100644 --- a/tools/command_exec_corpus.py +++ b/tools/command_exec_corpus.py @@ -219,6 +219,14 @@ def world_blocks(): cmd('/clone 0 205 0 4 207 4 6 205 6 masked'), cmd('/execute if blocks 0 205 0 4 207 4 6 205 6 all'), cmd('/setblock 3 206 3 minecraft:air'), + # A hopper placed into power arrives `enabled=false` and must keep its block entity. + cmd('/setblock 5 205 5 minecraft:redstone_block'), + cmd('/setblock 5 206 5 minecraft:hopper[facing=down]'), + cmd('/data get block 5 206 5 Items'), + cmd('/item replace block 5 206 5 container.0 with minecraft:diamond 3'), + cmd('/data get block 5 206 5 Items[0].count'), + cmd('/setblock 5 206 5 minecraft:air'), + cmd('/setblock 5 205 5 minecraft:air'), cmd('/fill 0 200 0 15 228 15 air'), cmd('/execute if block 0 300 0 air'), cmd('/setblock 0 400 0 stone'), From 0c6816811c1959e7268d4a587600651ccb99dd4c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 19:49:37 +0200 Subject: [PATCH 2/2] Commands: fold the block check into place_state's condition; cover /fill in the corpus The comment names vanilla's rule (LevelChunk.setBlockState keeps or creates the block entity when the block, not the state, is still there after onPlace). The corpus checks the `enabled=false` flip, drops the cleanup lines the group's closing /fill already does, and adds a powered hopper placed by /fill, which goes through the same place_state. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/commands.rs | 9 ++++----- tools/command_exec_corpus.py | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 4dc82867d..a229cbdc9 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1783,12 +1783,11 @@ impl Game<'_> { self.level_set(pos, state) .map_err(|e| CommandError::new(Text::literal(e.to_string())))?; } - // HopperBlock.onPlace can change the state while it is being placed (a powered - // hopper arrives `enabled=false`); vanilla keeps the block entity, so compare the block. - let placed = self.world.block(pos[0], pos[1], pos[2]); - let kept = self.res.facts().get(placed).name == new; + // LevelChunk.setBlockState creates it when the block, not the state, is still + // there after onPlace: a powered hopper turns itself `enabled=false`. + let landed = self.world.block(pos[0], pos[1], pos[2]); if old != new - && kept + && self.res.facts().get(landed).name == new && let Some(entity) = horizon_client::containers::BlockEntity::for_block(&new) { self.world.block_entities.insert(key, entity); diff --git a/tools/command_exec_corpus.py b/tools/command_exec_corpus.py index 33976813d..2b2a0afd1 100644 --- a/tools/command_exec_corpus.py +++ b/tools/command_exec_corpus.py @@ -219,14 +219,14 @@ def world_blocks(): cmd('/clone 0 205 0 4 207 4 6 205 6 masked'), cmd('/execute if blocks 0 205 0 4 207 4 6 205 6 all'), cmd('/setblock 3 206 3 minecraft:air'), - # A hopper placed into power arrives `enabled=false` and must keep its block entity. + # A hopper placed into power turns `enabled=false` and keeps its block entity. cmd('/setblock 5 205 5 minecraft:redstone_block'), - cmd('/setblock 5 206 5 minecraft:hopper[facing=down]'), - cmd('/data get block 5 206 5 Items'), + cmd('/setblock 5 206 5 minecraft:hopper'), + cmd('/execute if block 5 206 5 minecraft:hopper[enabled=false]'), cmd('/item replace block 5 206 5 container.0 with minecraft:diamond 3'), cmd('/data get block 5 206 5 Items[0].count'), - cmd('/setblock 5 206 5 minecraft:air'), - cmd('/setblock 5 205 5 minecraft:air'), + cmd('/fill 5 205 4 5 205 4 minecraft:hopper'), + cmd('/data get block 5 205 4 Items'), cmd('/fill 0 200 0 15 228 15 air'), cmd('/execute if block 0 300 0 air'), cmd('/setblock 0 400 0 stone'),