Skip to main content

steel_core/inventory/menu/kinds/
ender_chest_menu.rs

1//! Ender chest menu.
2
3use steel_utils::{DowncastType, DowncastTypeKey};
4
5use crate::inventory::ender_chest::{ENDER_CHEST_SLOTS, SyncPlayerEnderChest};
6use crate::inventory::menu::kinds::chest_menu::chest_with_kind;
7use crate::inventory::prelude::*;
8use crate::player::player_inventory::PlayerInventory;
9
10/// Builds the menu over a player's ender chest container.
11#[must_use]
12pub fn ender_chest(
13    inventory: Shared<PlayerInventory>,
14    container_id: u8,
15    container: SyncPlayerEnderChest,
16) -> Menu {
17    chest_with_kind(
18        inventory,
19        container_id,
20        container.clone(),
21        ENDER_CHEST_SLOTS / 9,
22        EnderChestKind { container },
23    )
24}
25
26/// Per-menu ender chest state: the player's container, which knows which block
27/// entity the menu was opened from.
28pub struct EnderChestKind {
29    container: SyncPlayerEnderChest,
30}
31
32// SAFETY: This Steel-owned key uniquely identifies the concrete menu kind
33// within the process.
34unsafe impl DowncastType for EnderChestKind {
35    const TYPE_KEY: DowncastTypeKey = DowncastTypeKey::new("steel:menu/ender_chest");
36}
37
38impl MenuKind for EnderChestKind {
39    fn still_valid(&self, _behavior: &MenuBehavior, player: &Player) -> bool {
40        self.container.lock().still_valid(player)
41    }
42
43    /// `PlayerEnderChestContainer.stopOpen`
44    /// drops the active chest so a later validity check can't consult a stale one.
45    fn removed(&mut self, _behavior: &mut MenuBehavior, _player: &Player) {
46        self.container.lock().clear_active_chest();
47    }
48}