steel_core/behavior/blocks/building/
wet_sponge_block.rs1use std::sync::Arc;
2
3use steel_macros::block_behavior;
4use steel_protocol::packets::game::SoundSource;
5use steel_registry::blocks::BlockRef;
6use steel_registry::{level_events, sound_events, vanilla_blocks};
7use steel_utils::{BlockPos, BlockStateId, types::UpdateFlags};
8
9use crate::behavior::{BlockBehavior, BlockPlaceContext};
10use crate::world::World;
11
12#[block_behavior]
13pub struct WetSpongeBlock {
15 block: BlockRef,
16}
17
18impl WetSpongeBlock {
19 #[must_use]
21 pub const fn new(block: BlockRef) -> Self {
22 Self { block }
23 }
24}
25
26impl BlockBehavior for WetSpongeBlock {
27 fn get_state_for_placement(&self, _context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
28 Some(self.block.default_state())
29 }
30
31 fn on_place(
32 &self,
33 _state: BlockStateId,
34 world: &Arc<World>,
35 pos: BlockPos,
36 _old_state: BlockStateId,
37 _moved_by_piston: bool,
38 ) {
39 if !world.dimension_type.water_evaporates {
40 return;
41 }
42
43 world.set_block(
44 pos,
45 vanilla_blocks::SPONGE.default_state(),
46 UpdateFlags::UPDATE_ALL,
47 );
48 world.level_event(level_events::PARTICLES_WATER_EVAPORATING, pos, 0, None);
49 world.play_sound(
50 &sound_events::BLOCK_WET_SPONGE_DRIES,
51 SoundSource::Blocks,
52 pos,
53 1.0,
54 (1.0 + rand::random::<f32>() * 0.2) * 0.7,
55 None,
56 );
57 }
58}