Skip to main content

steel_core/behavior/blocks/building/
heavy_core.rs

1use crate::{
2    behavior::{BlockBehavior, BlockPlaceContext, block::schedule_water_tick_if_waterlogged},
3    entity::ai::path::PathComputationType,
4    world::ScheduledTickAccess,
5};
6use steel_macros::block_behavior;
7use steel_registry::blocks::{
8    BlockRef,
9    block_state_ext::BlockStateExt,
10    properties::{BlockStateProperties, BoolProperty},
11};
12use steel_utils::{BlockPos, BlockStateId, Direction};
13
14/// Behavior for vanilla heavy core block.
15#[block_behavior]
16pub struct HeavyCoreBlock {
17    block: BlockRef,
18}
19
20const WATERLOGGED: &BoolProperty = &BlockStateProperties::WATERLOGGED;
21
22impl HeavyCoreBlock {
23    /// Creates a new heavy core block behavior.
24    #[must_use]
25    pub const fn new(block: BlockRef) -> Self {
26        Self { block }
27    }
28}
29
30impl BlockBehavior for HeavyCoreBlock {
31    fn update_shape(
32        &self,
33        state: BlockStateId,
34        world: &dyn ScheduledTickAccess,
35        pos: BlockPos,
36        _direction: Direction,
37        _neighbor_pos: BlockPos,
38        _neighbor_state: BlockStateId,
39    ) -> BlockStateId {
40        schedule_water_tick_if_waterlogged(state, world, pos);
41
42        state
43    }
44
45    fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
46        Some(
47            self.block
48                .default_state()
49                .set_value(WATERLOGGED, context.is_water_source()),
50        )
51    }
52
53    fn is_pathfindable(
54        &self,
55        _state: BlockStateId,
56        _computation_type: PathComputationType,
57    ) -> bool {
58        false
59    }
60}