Skip to main content

steel_core/behavior/blocks/container/
beehive_block.rs

1//! Beehive block behavior implementation.
2
3use std::sync::Weak;
4
5use steel_macros::block_behavior;
6use steel_registry::blocks::BlockRef;
7use steel_registry::blocks::block_state_ext::BlockStateExt;
8use steel_registry::blocks::properties::{BlockStateProperties, Direction};
9use steel_registry::vanilla_block_entity_types;
10use steel_utils::{BlockPos, BlockStateId};
11
12use crate::behavior::block::{BlockBehavior, BlockEntityCreation};
13use crate::behavior::context::BlockPlaceContext;
14use crate::block_entity::BLOCK_ENTITIES;
15use crate::world::{LevelReader, World};
16
17/// Behavior for beehive and bee nest blocks.
18// TODO: Implement full vanilla beehive interactions, bee release, smoke/fire handling, loot/data components, and ticking.
19#[block_behavior]
20pub struct BeehiveBlock {
21    block: BlockRef,
22}
23
24impl BeehiveBlock {
25    /// Creates a new beehive block behavior.
26    #[must_use]
27    pub const fn new(block: BlockRef) -> Self {
28        Self { block }
29    }
30}
31
32impl BlockBehavior for BeehiveBlock {
33    fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
34        Some(self.block.default_state().set_value(
35            &BlockStateProperties::HORIZONTAL_FACING,
36            context.horizontal_direction().opposite(),
37        ))
38    }
39
40    fn new_block_entity(
41        &self,
42        level: Weak<World>,
43        pos: BlockPos,
44        state: BlockStateId,
45    ) -> BlockEntityCreation {
46        BlockEntityCreation::from_registered_factory(BLOCK_ENTITIES.create(
47            &vanilla_block_entity_types::BEEHIVE,
48            level,
49            pos,
50            state,
51        ))
52    }
53
54    fn has_analog_output_signal(&self, _state: BlockStateId) -> bool {
55        true
56    }
57
58    fn get_analog_output_signal(
59        &self,
60        state: BlockStateId,
61        _world: &dyn LevelReader,
62        _pos: BlockPos,
63        _direction: Direction,
64    ) -> i32 {
65        state.get_value(&BlockStateProperties::LEVEL_HONEY).into()
66    }
67}