Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pomme-client/src/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const DROWN_DAMAGE_THRESHOLD: i32 = -20;
const DROWN_DAMAGE: f32 = 2.0;
const AIR_RECOVERY_RATE: i32 = 4;

// TODO: migrate the remaining raw `game_mode == N` checks to shared constants
// or an enum.
/// Matches vanilla GameType.isSurvival(): Survival (0) or Adventure (2).
pub fn is_survival(game_mode: u8) -> bool {
game_mode == 0 || game_mode == 2
}

fn is_water_block(state: azalea_block::BlockState) -> bool {
if state.is_air() {
return false;
Expand Down
67 changes: 34 additions & 33 deletions pomme-client/src/ui/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,45 +143,46 @@ pub fn build_hud(
}

let status_bar_y = (hotbar_y - (XP_BAR_H + 1.0 + 2.0) * gs).round();
build_status_bar(
elements,
hotbar_x,
status_bar_y,
health,
false,
SpriteId::HeartContainer,
SpriteId::HeartFull,
SpriteId::HeartHalf,
gs,
);
build_status_bar(
elements,
hotbar_x + hotbar_w,
status_bar_y,
food as f32,
true,
SpriteId::FoodEmpty,
SpriteId::FoodFull,
SpriteId::FoodHalf,
gs,
);

if armor > 0 {
let armor_y = (status_bar_y - (ICON_SIZE + 1.0) * gs).round();
let is_survival = crate::player::is_survival(game_mode);
if is_survival {
build_status_bar(
elements,
hotbar_x,
armor_y,
armor as f32,
status_bar_y,
health,
false,
SpriteId::ArmorEmpty,
SpriteId::ArmorFull,
SpriteId::ArmorHalf,
SpriteId::HeartContainer,
SpriteId::HeartFull,
SpriteId::HeartHalf,
gs,
);
}
build_status_bar(
elements,
hotbar_x + hotbar_w,
status_bar_y,
food as f32,
true,
SpriteId::FoodEmpty,
SpriteId::FoodFull,
SpriteId::FoodHalf,
gs,
);

if armor > 0 {
let armor_y = (status_bar_y - (ICON_SIZE + 1.0) * gs).round();
build_status_bar(
elements,
hotbar_x,
armor_y,
armor as f32,
false,
SpriteId::ArmorEmpty,
SpriteId::ArmorFull,
SpriteId::ArmorHalf,
gs,
);
}

if game_mode == 0 || game_mode == 2 {
let xp_w = XP_BAR_W * gs;
let xp_h = XP_BAR_H * gs;
let xp_x = (cx - xp_w / 2.0).round();
Expand Down Expand Up @@ -253,7 +254,7 @@ pub fn build_hud(
}

let max_air = crate::player::MAX_AIR_SUPPLY;
if eyes_in_water || air_supply < max_air {
if is_survival && (eyes_in_water || air_supply < max_air) {
let air = air_supply.clamp(0, max_air);
let bubble_count =
|offset: i32| -> i32 { (((air + offset) * 10 + max_air - 1) / max_air).clamp(0, 10) };
Expand Down
Loading