[PR #455] [MERGED] Command blocks: placing, the edit screen, and running commands #2579

Closed
opened 2026-11-02 15:57:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/455
Author: @ludovic111
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @ludovic111

Base: main ← Head: fix/command-blocks


📝 Commits (1)

  • d9deabd Command blocks: placing, the edit screen, and running commands

📊 Changes

14 files changed (+1008 additions, -10 deletions)

View changed files

➕ crates/horizon-client/src/command_block.rs (+256 -0)
📝 crates/horizon-client/src/containers.rs (+18 -3)
📝 crates/horizon-client/src/game.rs (+39 -4)
📝 crates/horizon-client/src/game/agent.rs (+1 -0)
➕ crates/horizon-client/src/game/command_blocks.rs (+637 -0)
📝 crates/horizon-client/src/game/commands.rs (+10 -1)
📝 crates/horizon-client/src/game/commands/execute.rs (+5 -0)
📝 crates/horizon-client/src/game/control.rs (+2 -0)
📝 crates/horizon-client/src/game/debug_keys.rs (+1 -1)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/save.rs (+2 -0)
📝 crates/horizon-world/examples/block_update_fixture.rs (+3 -1)
📝 crates/horizon-world/src/level/mod.rs (+25 -0)
📝 crates/horizon-world/src/level/tick.rs (+8 -0)

📄 Description

Fixes #444

What vanilla does (26.3)

  • Placing / using: command, chain and repeating command blocks are GameMasterBlocks. GameMasterBlockItem places them, and CommandBlock.useWithoutItem opens CommandBlockEditScreen, only when Player.canUseGameMasterBlocks() holds (creative, plus game master permission). CommandBlock.setPlacedBy sets TrackOutput from sendCommandFeedback, then setPoweredAndUpdate. newBlockEntity makes chain blocks automatic.
  • Edit screen (AbstractCommandBlockEditScreen + CommandBlockEditScreen): "Set Console Command for Block", the 300-px command box, Previous Output (read-only) with the O/X Track Output toggle, Impulse/Chain/Repeat, Conditional/Unconditional, Needs Redstone/Always Active, Done/Cancel. Enter is Done. ServerGamePacketListenerImpl.handleSetCommandBlock swaps the block for the mode (keeping the block entity), sets conditional, command, tracking and auto (setAutomatic, onModeSwitch), and replies "Command set: …".
  • Running: CommandBlock.setPoweredAndUpdate + tick + execute + executeChain, and CommandBlockEntity.markConditionMet. BaseCommandBlock.performCommand runs once per game tick at GAMEMASTER level, from the block's centre, rotated to its facing, and counts successes. CloseableCommandBlockSource stamps feedback as [HH:mm:ss] … into LastOutput, and broadcastToAdmins sends [@: …] (gray italic) under commandBlockOutput. Gamerules commandBlocksWork and maxCommandSequenceLength apply. Comparators read SuccessCount.

What Horizon had

The world library already knew the redstone hook and the "game master" gates, but the client hard-coded can_use_game_master_blocks: false / game_master: false. There was no command block entity, and the scheduled tick did nothing, so command blocks could neither be placed nor used.

Change

  • horizon_client::command_block: the block entity (vanilla NBT fields, load/save) and the pure tick rules, with unit tests.
  • game/command_blocks.rs: setPlacedBy, the level hooks (set_command_block_powered with markConditionMet, the comparator signal), tick / execute / executeChain / performCommand through Horizon's command system, the output routing (Source::block: feedback/failures go to the block's last output and the admin broadcast instead of chat), and the edit screen with handleSetCommandBlock.
  • The world library emits a command_block block event for the scheduled tick. Behaviours::schedule_tick and update_neighbour_for_output_signal are now public.
  • Game master check: creative and the player's command permission ≥ 2 (ui.registries.permission, which #407 ties to Allow Commands).

Verified in game (offscreen, control socket, Mac mini)

  • Creative: place … --item minecraft:command_block → command_block[facing=north] (facing the player). Right-click opens the screen; the screenshot matches vanilla's layout.
  • Impulse: command setblock ~ ~2 ~ minecraft:gold_block, Done → "Command set: …". A redstone block beside it → gold block 2 above, [@: Changed the block at -31, 72, 4] in chat, and Previous Output [03:27:45] Changed the block at -31, 72, 4.
  • Chain: impulse → conditional chain → unconditional chain, powered from below → all three ran. With the impulse command failing ("Could not set the block" in its output), the conditional block was skipped and the unconditional one still ran.
  • Repeat + Always Active: scoreboard players add #c t 1 counts about one per tick (22 after 20 ticks, 45 after 40). A comparator lights a lamp from the success count and goes off with gamerule command_blocks_work false.
  • Save, quit, reopen: command and Previous Output kept.

Self-check (integration branch with #446 #447 #448)

  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-world -p horizon-client: all pass (incl. the 4 new command_block tests).
  • Parity harnesses (tools/parity.py --changed origin/main, 284 harnesses): results in the thread report / a follow-up comment.

Follow-ups (not in this PR)

  • Command suggestions in the edit box (CommandSuggestions).
  • The creative Operator Utilities tab (operatorItemsTab option + permission); use /give or pick-block for now.
  • Items carrying block_entity_data (pre-set commands) aren't applied on placement.
  • LastOutput is saved as a plain-string component (styles and translations are flattened after a reload).
  • Command block minecarts; on servers the edit screen isn't sent (ServerboundSetCommandBlockPacket).
  • Feedback from commands vanilla sends with broadcast=false is still broadcast as [@: …] (Horizon's feedback has no such flag yet).
  • The in-world blur behind the screen (no in-game screen has it in Horizon yet).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/455 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/command-blocks` --- ### 📝 Commits (1) - [`d9deabd`](https://github.com/horizon-rust/horizon/commit/d9deabd54e470fa74a3910ab2844066e3bd3d7f6) Command blocks: placing, the edit screen, and running commands ### 📊 Changes **14 files changed** (+1008 additions, -10 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/src/command_block.rs` (+256 -0) 📝 `crates/horizon-client/src/containers.rs` (+18 -3) 📝 `crates/horizon-client/src/game.rs` (+39 -4) 📝 `crates/horizon-client/src/game/agent.rs` (+1 -0) ➕ `crates/horizon-client/src/game/command_blocks.rs` (+637 -0) 📝 `crates/horizon-client/src/game/commands.rs` (+10 -1) 📝 `crates/horizon-client/src/game/commands/execute.rs` (+5 -0) 📝 `crates/horizon-client/src/game/control.rs` (+2 -0) 📝 `crates/horizon-client/src/game/debug_keys.rs` (+1 -1) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/save.rs` (+2 -0) 📝 `crates/horizon-world/examples/block_update_fixture.rs` (+3 -1) 📝 `crates/horizon-world/src/level/mod.rs` (+25 -0) 📝 `crates/horizon-world/src/level/tick.rs` (+8 -0) </details> ### 📄 Description Fixes #444 ## What vanilla does (26.3) - **Placing / using:** command, chain and repeating command blocks are `GameMasterBlock`s. `GameMasterBlockItem` places them, and `CommandBlock.useWithoutItem` opens `CommandBlockEditScreen`, only when `Player.canUseGameMasterBlocks()` holds (creative, plus game master permission). `CommandBlock.setPlacedBy` sets `TrackOutput` from `sendCommandFeedback`, then `setPoweredAndUpdate`. `newBlockEntity` makes chain blocks automatic. - **Edit screen** (`AbstractCommandBlockEditScreen` + `CommandBlockEditScreen`): "Set Console Command for Block", the 300-px command box, Previous Output (read-only) with the O/X Track Output toggle, Impulse/Chain/Repeat, Conditional/Unconditional, Needs Redstone/Always Active, Done/Cancel. Enter is Done. `ServerGamePacketListenerImpl.handleSetCommandBlock` swaps the block for the mode (keeping the block entity), sets conditional, command, tracking and auto (`setAutomatic`, `onModeSwitch`), and replies "Command set: …". - **Running:** `CommandBlock.setPoweredAndUpdate` + `tick` + `execute` + `executeChain`, and `CommandBlockEntity.markConditionMet`. `BaseCommandBlock.performCommand` runs once per game tick at `GAMEMASTER` level, from the block's centre, rotated to its facing, and counts successes. `CloseableCommandBlockSource` stamps feedback as `[HH:mm:ss] …` into `LastOutput`, and `broadcastToAdmins` sends `[@: …]` (gray italic) under `commandBlockOutput`. Gamerules `commandBlocksWork` and `maxCommandSequenceLength` apply. Comparators read `SuccessCount`. ## What Horizon had The world library already knew the redstone hook and the "game master" gates, but the client hard-coded `can_use_game_master_blocks: false` / `game_master: false`. There was no command block entity, and the scheduled tick did nothing, so command blocks could neither be placed nor used. ## Change - `horizon_client::command_block`: the block entity (vanilla NBT fields, load/save) and the pure tick rules, with unit tests. - `game/command_blocks.rs`: `setPlacedBy`, the level hooks (`set_command_block_powered` with `markConditionMet`, the comparator signal), `tick` / `execute` / `executeChain` / `performCommand` through Horizon's command system, the output routing (`Source::block`: feedback/failures go to the block's last output and the admin broadcast instead of chat), and the edit screen with `handleSetCommandBlock`. - The world library emits a `command_block` block event for the scheduled tick. `Behaviours::schedule_tick` and `update_neighbour_for_output_signal` are now public. - Game master check: creative and the player's command permission ≥ 2 (`ui.registries.permission`, which #407 ties to Allow Commands). ## Verified in game (offscreen, control socket, Mac mini) - Creative: `place … --item minecraft:command_block` → `command_block[facing=north]` (facing the player). Right-click opens the screen; the screenshot matches vanilla's layout. - Impulse: command `setblock ~ ~2 ~ minecraft:gold_block`, Done → "Command set: …". A redstone block beside it → gold block 2 above, `[@: Changed the block at -31, 72, 4]` in chat, and Previous Output `[03:27:45] Changed the block at -31, 72, 4`. - Chain: impulse → conditional chain → unconditional chain, powered from below → all three ran. With the impulse command failing ("Could not set the block" in its output), the conditional block was skipped and the unconditional one still ran. - Repeat + Always Active: `scoreboard players add #c t 1` counts about one per tick (22 after 20 ticks, 45 after 40). A comparator lights a lamp from the success count and goes off with `gamerule command_blocks_work false`. - Save, quit, reopen: command and Previous Output kept. ## Self-check (integration branch with #446 #447 #448) - `cargo fmt --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-world -p horizon-client`: all pass (incl. the 4 new `command_block` tests). - Parity harnesses (`tools/parity.py --changed origin/main`, 284 harnesses): results in the thread report / a follow-up comment. ## Follow-ups (not in this PR) - Command suggestions in the edit box (`CommandSuggestions`). - The creative Operator Utilities tab (`operatorItemsTab` option + permission); use `/give` or pick-block for now. - Items carrying `block_entity_data` (pre-set commands) aren't applied on placement. - `LastOutput` is saved as a plain-string component (styles and translations are flattened after a reload). - Command block minecarts; on servers the edit screen isn't sent (`ServerboundSetCommandBlockPacket`). - Feedback from commands vanilla sends with `broadcast=false` is still broadcast as `[@: …]` (Horizon's `feedback` has no such flag yet). - The in-world blur behind the screen (no in-game screen has it in Horizon yet). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:57:20 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2579
No description provided.