Skip to main content

basalt_api/components/
item.rs

1//! Item and container components.
2
3use crate::components::Component;
4
5/// A dropped item on the ground.
6///
7/// Entities with this component represent items that can be picked up
8/// by players. Combined with `Position`, `Velocity`, `BoundingBox`,
9/// and `Lifetime` to create a full dropped item entity.
10#[derive(Debug, Clone)]
11pub struct DroppedItem {
12    /// The item stack (ID, count, component data).
13    pub slot: basalt_types::Slot,
14}
15impl Component for DroppedItem {}
16
17/// Auto-despawn countdown.
18///
19/// Decremented each tick. When it reaches zero, the entity is
20/// despawned. Used for dropped items (5 minutes = 6000 ticks),
21/// arrows, experience orbs, etc.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct Lifetime {
24    /// Remaining ticks before despawn.
25    pub remaining_ticks: u32,
26}
27impl Component for Lifetime {}
28
29/// Tracks that a player currently has a non-inventory window open.
30///
31/// Present on the player entity from the moment an OpenWindow packet
32/// is sent until a CloseWindow packet is received (or the player
33/// disconnects). Removed on close.
34#[derive(Debug, Clone)]
35pub struct OpenContainer {
36    /// Protocol window ID (1-127) assigned when opening.
37    pub window_id: u8,
38    /// The kind of inventory that was opened.
39    pub inventory_type: crate::container::InventoryType,
40    /// How the container is backed in the world.
41    pub backing: crate::container::ContainerBacking,
42}
43impl Component for OpenContainer {}
44
45/// Pickup delay before a dropped item can be collected.
46///
47/// Decremented each tick. While remaining > 0, the item cannot be
48/// picked up by any player. Default: 10 ticks (0.5s) for block drops.
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub struct PickupDelay {
51    /// Remaining ticks before the item is pickable.
52    pub remaining_ticks: u32,
53}
54impl Component for PickupDelay {}