Skip to main content

steel_core/behavior/items/
food_on_a_stick.rs

1//! Food-on-a-stick item behavior implementation.
2
3use steel_macros::item_behavior;
4use steel_registry::entity_type::EntityTypeRef;
5use steel_registry::vanilla_items;
6
7use crate::behavior::{InteractionResult, ItemBehavior, UseItemContext};
8use crate::entity::Entity as _;
9
10/// Behavior for vanilla `FoodOnAStickItem`.
11#[item_behavior]
12pub struct FoodOnAStickItem {
13    #[json_arg(vanilla_entities)]
14    can_interact_with: EntityTypeRef,
15    #[json_arg(value)]
16    consume_item_damage: i32,
17}
18
19impl FoodOnAStickItem {
20    /// Creates a food-on-a-stick behavior for one controlled vehicle type.
21    #[must_use]
22    pub const fn new(can_interact_with: EntityTypeRef, consume_item_damage: i32) -> Self {
23        Self {
24            can_interact_with,
25            consume_item_damage,
26        }
27    }
28}
29
30impl ItemBehavior for FoodOnAStickItem {
31    fn use_item(&self, context: &mut UseItemContext) -> InteractionResult {
32        let Some(vehicle) = context.player.controlled_vehicle() else {
33            return Self::pass_without_boost();
34        };
35        if vehicle.entity_type() != self.can_interact_with {
36            return Self::pass_without_boost();
37        }
38        let Some(steerable) = vehicle.as_item_steerable() else {
39            return Self::pass_without_boost();
40        };
41        if !steerable.boost() {
42            return Self::pass_without_boost();
43        }
44
45        let has_infinite_materials = context.player.has_infinite_materials();
46        context.inv.with_inventory(|inventory| {
47            inventory.hurt_and_convert_item_in_hand_on_break(
48                context.hand,
49                self.consume_item_damage,
50                &vanilla_items::FISHING_ROD,
51                has_infinite_materials,
52            );
53        });
54
55        InteractionResult::SuccessServer
56    }
57}
58
59impl FoodOnAStickItem {
60    const fn pass_without_boost() -> InteractionResult {
61        // TODO: Award Stats.ITEM_USED once the stat foundation exists.
62        InteractionResult::Pass
63    }
64}