[PR #5089] [MERGED] Keep a locked container locked #6067

Closed
opened 2026-11-03 06:11:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/locked-containers


📝 Commits (3)

  • 554451b Keep a locked container locked
  • 94df2b6 Merge origin/main: keep locked_message beside the vehicle menus
  • d4d5c08 Restore #5251's compile fixes that the merge commit dropped

📊 Changes

9 files changed (+248 additions, -6 deletions)

View changed files

📝 crates/horizon-client-render/src/containers.rs (+11 -0)
📝 crates/horizon-client-render/src/world.rs (+78 -0)
📝 crates/horizon-client/src/advancements.rs (+39 -0)
📝 crates/horizon-client/src/game/advancements.rs (+15 -0)
📝 crates/horizon-client/src/game/commands.rs (+5 -1)
📝 crates/horizon-client/src/game/commands/data.rs (+4 -5)
📝 crates/horizon-client/src/game/lan_actions.rs (+53 -0)
📝 crates/horizon-client/src/game/spill.rs (+1 -0)
📝 crates/horizon-client/src/save.rs (+42 -0)

📄 Description

Fixes the LockCode.canUnlock row (and the BaseContainerBlockEntity.createMenu refusal it drives) in the port ledger. (No issue.)

Vanilla's LockCode.canUnlock(player) is player.isSpectator() || unlocksWith(player.getMainHandItem()), and BaseContainerBlockEntity.createMenu refuses everyone else: an action-bar container.isLocked message naming the container, and one block.chest.locked at its centre — for every container in that subtree (chest, trapped and copper chest, barrel, hopper, dispenser, dropper, shulker box, crafter, the furnace family, brewing stand). A double chest checks both halves and sounds the locked note between them.

Horizon kept the tag on disk — the loader's ChunkExtras::block_entity_sources and the canonical savers both preserve it — and read it nowhere: grep LockCode found one doc comment, container.isLocked appeared nowhere, and decode_block_entity dropped the key, so /data get could not show a lock and /setblock//data merge could not create one. A locked chest simply opened.

The lock now lives where the loader already put it rather than a new field on seven block-entity types: World::{block_lock, set_block_lock, forget_block_entity_source} read and write the source tag, /data get uses a data get-shaped encode that includes it, /setblock and /data merge write it (and treat a lock change as a change), breaking a container forgets the source so a fresh one at that position starts unlocked, and the open funnel refuses with vanilla's message and sound. The predicate reuses the existing advancements::item, so an items:/#tag/components lock works as it does everywhere else.

Proven: on a build box, cargo test -p horizon-client --lib a_lock_takes → 1 passed (a gold ingot opens, a stick is refused, an empty hand is refused, a spectator is accepted with and without the item, and lock:{} accepts an empty hand) and cargo test -p horizon-client --lib a_locked_chest → 1 passed (a chest's lock survives decode_block_entity → the data get encode, which also documents that the plain encode alone drops it). cargo check -p horizon-client --lib --bins is clean.

Not proven: nothing in a game — the honest checks are /setblock ~ ~ ~ chest{lock:{items:"minecraft:gold_ingot"}} opened with and without the ingot, /data get block, a double chest with one locked half, and a spectator.

Five things deliberately left, all stated because they are divergences rather than details: a beacon has its own lock and opens through the station path, so a locked beacon still opens; the lid's open and close sounds still play on a refused open (Horizon counts openers in the menu-provider step, vanilla after the lock check); a locked container's loot table is still unpacked, so player_generates_container_loot fires where vanilla would not; /execute if blocks compares the encode-only tag and is blind to lock as it already is to CustomName; and a lock arriving from a structure template or generated structure is neither shown nor honoured, because those paths register no source tag.


🔄 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/5089 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/locked-containers` --- ### 📝 Commits (3) - [`554451b`](https://github.com/horizon-rust/horizon/commit/554451b083eb93f64a405bdb33c1868acfb6281a) Keep a locked container locked - [`94df2b6`](https://github.com/horizon-rust/horizon/commit/94df2b61839fad48e26e8657184317d5e955d157) Merge origin/main: keep locked_message beside the vehicle menus - [`d4d5c08`](https://github.com/horizon-rust/horizon/commit/d4d5c08c388860cb5c38c52c7f977a613f49b2f3) Restore #5251's compile fixes that the merge commit dropped ### 📊 Changes **9 files changed** (+248 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/containers.rs` (+11 -0) 📝 `crates/horizon-client-render/src/world.rs` (+78 -0) 📝 `crates/horizon-client/src/advancements.rs` (+39 -0) 📝 `crates/horizon-client/src/game/advancements.rs` (+15 -0) 📝 `crates/horizon-client/src/game/commands.rs` (+5 -1) 📝 `crates/horizon-client/src/game/commands/data.rs` (+4 -5) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+53 -0) 📝 `crates/horizon-client/src/game/spill.rs` (+1 -0) 📝 `crates/horizon-client/src/save.rs` (+42 -0) </details> ### 📄 Description Fixes the `LockCode.canUnlock` row (and the `BaseContainerBlockEntity.createMenu` refusal it drives) in the port ledger. (No issue.) Vanilla's `LockCode.canUnlock(player)` is `player.isSpectator() || unlocksWith(player.getMainHandItem())`, and `BaseContainerBlockEntity.createMenu` refuses everyone else: an action-bar `container.isLocked` message naming the container, and one `block.chest.locked` at its centre — for every container in that subtree (chest, trapped and copper chest, barrel, hopper, dispenser, dropper, shulker box, crafter, the furnace family, brewing stand). A double chest checks **both** halves and sounds the locked note between them. Horizon kept the tag on disk — the loader's `ChunkExtras::block_entity_sources` and the canonical savers both preserve it — and read it nowhere: `grep LockCode` found one doc comment, `container.isLocked` appeared nowhere, and `decode_block_entity` dropped the key, so `/data get` could not show a lock and `/setblock`/`/data merge` could not create one. A locked chest simply opened. The lock now lives where the loader already put it rather than a new field on seven block-entity types: `World::{block_lock, set_block_lock, forget_block_entity_source}` read and write the source tag, `/data get` uses a `data get`-shaped encode that includes it, `/setblock` and `/data merge` write it (and treat a lock change as a change), breaking a container forgets the source so a fresh one at that position starts unlocked, and the open funnel refuses with vanilla's message and sound. The predicate reuses the existing `advancements::item`, so an `items:`/`#tag`/components lock works as it does everywhere else. **Proven:** on a build box, `cargo test -p horizon-client --lib a_lock_takes` → 1 passed (a gold ingot opens, a stick is refused, an empty hand is refused, a spectator is accepted with and without the item, and `lock:{}` accepts an empty hand) and `cargo test -p horizon-client --lib a_locked_chest` → 1 passed (a chest's `lock` survives `decode_block_entity` → the `data get` encode, which also documents that the plain encode alone drops it). `cargo check -p horizon-client --lib --bins` is clean. **Not proven:** nothing in a game — the honest checks are `/setblock ~ ~ ~ chest{lock:{items:"minecraft:gold_ingot"}}` opened with and without the ingot, `/data get block`, a double chest with one locked half, and a spectator. Five things deliberately left, all stated because they are divergences rather than details: a **beacon** has its own lock and opens through the station path, so a locked beacon still opens; the lid's open and close sounds still play on a refused open (Horizon counts openers in the menu-provider step, vanilla after the lock check); a locked container's loot table is still unpacked, so `player_generates_container_loot` fires where vanilla would not; `/execute if blocks` compares the encode-only tag and is blind to `lock` as it already is to `CustomName`; and a `lock` arriving from a structure template or generated structure is neither shown nor honoured, because those paths register no source tag. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:11:22 +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#6067
No description provided.