Skip to main content

steel_registry/blocks/
behavior.rs

1//! Block configuration and static properties.
2//!
3//! This module contains constant/static data about blocks. Dynamic behavior
4//! has been moved to `steel-core::behavior`.
5
6pub use crate::blocks::properties::NoteBlockInstrument;
7use crate::sound_types::SoundType;
8
9/// How a block reacts when pushed by a piston.
10#[derive(Debug, Clone, Copy)]
11pub enum PushReaction {
12    Normal,
13    Destroy,
14    Block,
15    Ignore,
16    PushOnly,
17}
18
19/// Static configuration for a block type.
20///
21/// This contains constant properties that don't change based on game state.
22/// Dynamic behavior is handled by `BlockBehavior` in steel-core.
23#[derive(Debug)]
24pub struct BlockConfig {
25    pub has_collision: bool,
26    pub can_occlude: bool,
27    pub explosion_resistance: f32,
28    pub is_randomly_ticking: bool,
29    pub force_solid_off: bool,
30    pub force_solid_on: bool,
31    pub push_reaction: PushReaction,
32    pub friction: f32,
33    pub speed_factor: f32,
34    pub jump_factor: f32,
35    pub dynamic_shape: bool,
36    pub destroy_time: f32,
37    pub ignited_by_lava: bool,
38    pub liquid: bool,
39    pub is_air: bool,
40    pub requires_correct_tool_for_drops: bool,
41    pub instrument: NoteBlockInstrument,
42    pub replaceable: bool,
43    pub sound_type: SoundType,
44}
45
46impl BlockConfig {
47    /// Starts building a new set of block properties.
48    #[must_use]
49    pub const fn new() -> Self {
50        Self {
51            has_collision: true,
52            can_occlude: true,
53            explosion_resistance: 0.0,
54            is_randomly_ticking: false,
55            force_solid_off: false,
56            force_solid_on: false,
57            push_reaction: PushReaction::Normal,
58            friction: 0.6,
59            speed_factor: 1.0,
60            jump_factor: 1.0,
61            dynamic_shape: false,
62            destroy_time: 0.0,
63            ignited_by_lava: false,
64            liquid: false,
65            is_air: false,
66            requires_correct_tool_for_drops: false,
67            instrument: NoteBlockInstrument::Harp,
68            replaceable: false,
69            sound_type: crate::sound_types::STONE,
70        }
71    }
72
73    #[must_use]
74    pub const fn has_collision(mut self, has_collision: bool) -> Self {
75        self.has_collision = has_collision;
76        self
77    }
78
79    #[must_use]
80    pub const fn can_occlude(mut self, can_occlude: bool) -> Self {
81        self.can_occlude = can_occlude;
82        self
83    }
84
85    #[must_use]
86    pub const fn explosion_resistance(mut self, resistance: f32) -> Self {
87        self.explosion_resistance = resistance;
88        self
89    }
90
91    #[must_use]
92    pub const fn set_is_randomly_ticking(mut self, ticking: bool) -> Self {
93        self.is_randomly_ticking = ticking;
94        self
95    }
96
97    #[must_use]
98    pub const fn force_solid_off(mut self, force: bool) -> Self {
99        self.force_solid_off = force;
100        self
101    }
102
103    #[must_use]
104    pub const fn force_solid_on(mut self, force: bool) -> Self {
105        self.force_solid_on = force;
106        self
107    }
108
109    #[must_use]
110    pub const fn push_reaction(mut self, reaction: PushReaction) -> Self {
111        self.push_reaction = reaction;
112        self
113    }
114
115    #[must_use]
116    pub const fn friction(mut self, friction: f32) -> Self {
117        self.friction = friction;
118        self
119    }
120
121    #[must_use]
122    pub const fn speed_factor(mut self, factor: f32) -> Self {
123        self.speed_factor = factor;
124        self
125    }
126
127    #[must_use]
128    pub const fn jump_factor(mut self, factor: f32) -> Self {
129        self.jump_factor = factor;
130        self
131    }
132
133    #[must_use]
134    pub const fn dynamic_shape(mut self, dynamic: bool) -> Self {
135        self.dynamic_shape = dynamic;
136        self
137    }
138
139    #[must_use]
140    pub const fn destroy_time(mut self, time: f32) -> Self {
141        self.destroy_time = time;
142        self
143    }
144
145    #[must_use]
146    pub const fn ignited_by_lava(mut self, ignited: bool) -> Self {
147        self.ignited_by_lava = ignited;
148        self
149    }
150
151    #[must_use]
152    pub const fn liquid(mut self, liquid: bool) -> Self {
153        self.liquid = liquid;
154        self
155    }
156
157    #[must_use]
158    pub const fn set_is_air(mut self, is_air: bool) -> Self {
159        self.is_air = is_air;
160        self
161    }
162
163    #[must_use]
164    pub const fn requires_correct_tool_for_drops(mut self, requires: bool) -> Self {
165        self.requires_correct_tool_for_drops = requires;
166        self
167    }
168
169    #[must_use]
170    pub const fn instrument(mut self, instrument: NoteBlockInstrument) -> Self {
171        self.instrument = instrument;
172        self
173    }
174
175    #[must_use]
176    pub const fn replaceable(mut self, replaceable: bool) -> Self {
177        self.replaceable = replaceable;
178        self
179    }
180
181    #[must_use]
182    pub const fn sound_type(mut self, sound_type: SoundType) -> Self {
183        self.sound_type = sound_type;
184        self
185    }
186}
187
188impl Default for BlockConfig {
189    fn default() -> Self {
190        Self::new()
191    }
192}