Skip to content

Commit 338a7a0

Browse files
committed
feat: magma block damage
1 parent f226993 commit 338a7a0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

crates/vanilla-behaviors/src/module/natural_damage.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl Module for NaturalDamageModule {
7878
},
7979
);
8080

81+
#[allow(clippy::excessive_nesting)]
8182
system!("natural block damage", world, &Compose($), &Blocks($), &Position, &EntitySize, &Gamemode)
8283
.with::<Player>()
8384
.each_iter(|it, row, (compose, blocks, position, size, gamemode)| {
@@ -89,6 +90,7 @@ impl Module for NaturalDamageModule {
8990
let entity = it.entity(row);
9091

9192
let (min, max) = block_bounds(**position, *size);
93+
let min = min.with_y(min.y-1);
9294
let bounding_box = aabb(**position, *size);
9395

9496
blocks.get_blocks(min, max, |pos, block| {
@@ -108,19 +110,30 @@ impl Module for NaturalDamageModule {
108110
BlockKind::Cactus => {
109111
damage_player(&entity, 1., DamageCause::new(DamageType::Cactus), compose, system);
110112
}
111-
BlockKind::Fire => {
112-
// Todo check for overlap not just collision
113-
damage_player(&entity, 1., DamageCause::new(DamageType::InFire), compose, system);
114-
}
115-
BlockKind::SoulFire => {
116-
damage_player(&entity, 2., DamageCause::new(DamageType::InFire), compose, system);
113+
BlockKind::MagmaBlock => {
114+
if position.y > pos.y {
115+
damage_player(&entity, 1., DamageCause::new(DamageType::HotFloor), compose, system);
116+
}
117117
}
118118
_ => {}
119119
}
120120
return ControlFlow::Break(());
121121
}
122122
}
123123

124+
let aabb = Aabb::new(Vec3::ZERO, Vec3::ONE).move_by(pos);
125+
126+
if Aabb::overlap(&aabb, &bounding_box).is_some() {
127+
match kind {
128+
BlockKind::Fire => {
129+
damage_player(&entity, 1., DamageCause::new(DamageType::InFire), compose, system);
130+
}
131+
BlockKind::SoulFire => {
132+
damage_player(&entity, 2., DamageCause::new(DamageType::InFire), compose, system);
133+
}
134+
_ => {}
135+
}
136+
}
124137
ControlFlow::Continue(())
125138
});
126139
});

0 commit comments

Comments
 (0)