Skip to main content

classicube_sys/
inventory.rs

1use crate::{
2    bindings::{BlockID, Inventory},
3    std_types::c_int,
4};
5
6/// Gets the block at the nth index in the current hotbar.
7///
8/// # Panics
9///
10/// Panics if `Inventory.Offset + idx` is negative.
11#[must_use]
12pub fn Inventory_Get(idx: c_int) -> BlockID {
13    let i = usize::try_from(unsafe { Inventory.Offset } + idx).expect("hotbar index out of range");
14    unsafe { Inventory.Table[i] }
15}
16
17/// Sets the block at the nth index in the current hotbar.
18///
19/// # Panics
20///
21/// Panics if `Inventory.Offset + idx` is negative.
22pub fn Inventory_Set(idx: c_int, block: BlockID) {
23    let i = usize::try_from(unsafe { Inventory.Offset } + idx).expect("hotbar index out of range");
24    unsafe {
25        Inventory.Table[i] = block;
26    }
27}
28
29/// Gets the currently selected block.
30#[must_use]
31pub fn Inventory_SelectedBlock() -> BlockID {
32    unsafe { Inventory_Get(Inventory.SelectedIndex) }
33}