Skip to main content

yog_inventory/
lib.rs

1//! yog-inventory — real Minecraft Container/Menu screens for Yog mods.
2//!
3//! Unlike `yog-ui` (a HUD-drawn overlay screen with no real item slots), this
4//! crate describes actual vanilla-style inventory screens: a block's own
5//! slots plus, optionally, the player's own inventory grid underneath —
6//! backed by a real Minecraft `BlockEntity`/`AbstractContainerMenu` on the
7//! Java side, with real drag-and-drop and network sync for free.
8//!
9//! Stub crate — see `DESIGN.md` for the full architecture and phased plan.
10//! Data model only for now; nothing is wired to the runtime/registry yet.
11
12/// Pixel position of a single slot in vanilla GUI coordinate space.
13#[derive(Debug, Clone, Copy, PartialEq)]
14pub struct SlotLayout {
15    pub x: f32,
16    pub y: f32,
17}
18
19/// Describes one inventory-backed screen: how many slots a mod block has,
20/// where they sit, whether the player's own inventory is appended below,
21/// and which background texture to draw (vanilla default, or a mod's own).
22#[derive(Debug, Clone)]
23pub struct InventoryDef {
24    pub id: String,
25    pub slot_count: usize,
26    pub layout: Vec<SlotLayout>,
27    pub include_player_inventory: bool,
28    pub player_inv_offset: (f32, f32),
29    pub background_texture: Option<String>,
30    pub title: String,
31}
32
33impl InventoryDef {
34    pub fn new(id: impl Into<String>, slot_count: usize) -> Self {
35        Self {
36            id: id.into(),
37            slot_count,
38            layout: Vec::new(),
39            include_player_inventory: true,
40            player_inv_offset: (8.0, 84.0),
41            background_texture: None,
42            title: String::new(),
43        }
44    }
45
46    /// Explicit per-slot pixel positions, overriding the default grid.
47    pub fn layout(mut self, layout: Vec<SlotLayout>) -> Self {
48        self.layout = layout;
49        self
50    }
51
52    /// Whether the player's main inventory + hotbar (no armor/offhand) is
53    /// appended below the custom slots.
54    pub fn include_player_inventory(mut self, v: bool) -> Self {
55        self.include_player_inventory = v;
56        self
57    }
58
59    pub fn player_inv_offset(mut self, x: f32, y: f32) -> Self {
60        self.player_inv_offset = (x, y);
61        self
62    }
63
64    /// Custom background texture (resource path); `None` keeps the default
65    /// vanilla-style panel.
66    pub fn background_texture(mut self, path: impl Into<String>) -> Self {
67        self.background_texture = Some(path.into());
68        self
69    }
70
71    pub fn title(mut self, title: impl Into<String>) -> Self {
72        self.title = title.into();
73        self
74    }
75}