Skip to main content

steel_core/behavior/blocks/building/
conduit_block.rs

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