azalea_block/
behavior.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
pub struct BlockBehavior {
    pub friction: f32,
    pub jump_factor: f32,
    pub destroy_time: f32,
    pub explosion_resistance: f32,
    pub requires_correct_tool_for_drops: bool,
}

impl Default for BlockBehavior {
    fn default() -> Self {
        Self {
            friction: 0.6,
            jump_factor: 1.0,
            destroy_time: 0.,
            explosion_resistance: 0.,
            requires_correct_tool_for_drops: false,
        }
    }
}

impl BlockBehavior {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn friction(mut self, friction: f32) -> Self {
        self.friction = friction;
        self
    }

    pub fn jump_factor(mut self, jump_factor: f32) -> Self {
        self.jump_factor = jump_factor;
        self
    }

    pub fn destroy_time(mut self, destroy_time: f32) -> Self {
        self.destroy_time = destroy_time;
        self
    }

    pub fn explosion_resistance(mut self, explosion_resistance: f32) -> Self {
        self.explosion_resistance = f32::max(0., explosion_resistance);
        self
    }

    pub fn strength(self, destroy_time: f32, explosion_resistance: f32) -> Self {
        self.destroy_time(destroy_time)
            .explosion_resistance(explosion_resistance)
    }

    pub fn requires_correct_tool_for_drops(mut self) -> Self {
        self.requires_correct_tool_for_drops = true;
        self
    }
}