[GH-ISSUE #6248] Native mods: breathing, LivingBreatheEvent #2034

Closed
opened 2026-11-02 15:51:30 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @levzzz5154 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6248

Originally assigned to: @levzzz5154 on GitHub.

🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally.

Part of #4953 ("Living: breathing, and equipment changes of mobs"). This issue is the breathing half; equipment changes of mobs are #6242.

Problem

A mod that adds a breathing apparatus, an air-tight armour set, a gas that drowns the player, or a mob that never needs air has no way to change how a player or mob loses and refills its air supply. Vanilla's rules are hard-coded in the player's motion (motion/environment.rs) and in the mobs' tick (mobs/ai.rs).

Vanilla and NeoForge

  • Vanilla: LivingEntity.baseTick (server side, living entities): an entity whose eyes are in water (and not in a bubble column) that can drown (no canBreatheUnderwater, no water breathing, not a creative player) has its air supply lowered by decreaseAirSupply (1, or 0 by the Respiration / oxygen bonus chance), and at -20 it is set to 0 and takes 2 drowning damage; otherwise the air is raised by increaseAirSupply (+4, up to the maximum, 300). Axolotls and water animals add their own handleAirSupply after it.
  • NeoForge: LivingBreatheEvent(entity, canBreathe, consumeAirAmount, refillAirAmount) is posted from that block every tick (CommonHooks.onLivingBreathe) with vanilla's answers as defaults; a listener can change whether the entity can breathe and how much air it consumes or refills; then the air changes by that. It cannot be cancelled. (LivingDrownEvent is another event, not part of this.)

Proposal

One hook point, API from a fragment (tools/native-hook-fragments/living_breathe.json), a free function in the library next to the code that uses it, as the loot and menu hooks are, because the player's motion has no Game to call:

  • native_living_breathe(entity, kind, can_breathe, consume, refill) with out parameters, run for every player and mob that Horizon ticks on a server and that has vanilla's generic air logic: players (motion/environment.rs) and mobs (mobs/ai.rs). A mod sets can_breathe, consume (how much air it loses when it cannot breathe) and refill (how much it gains when it can); several mods can hook one point. The defaults are what Horizon does today, so nothing changes for a player without a mod. Drowning damage follows the air supply as before.

Not in this step: axolotls, fish and other WaterAnimals (their own air logic overwrites the generic block's in vanilla too), the nautilus, LivingDrownEvent, a client's prediction (the hook runs on servers only).

Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6248 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #4953 ("Living: breathing, and equipment changes of mobs"). This issue is the breathing half; equipment changes of mobs are #6242. ## Problem A mod that adds a breathing apparatus, an air-tight armour set, a gas that drowns the player, or a mob that never needs air has no way to change how a player or mob loses and refills its air supply. Vanilla's rules are hard-coded in the player's motion (`motion/environment.rs`) and in the mobs' tick (`mobs/ai.rs`). ## Vanilla and NeoForge - Vanilla: `LivingEntity.baseTick` (server side, living entities): an entity whose eyes are in water (and not in a bubble column) that can drown (no `canBreatheUnderwater`, no water breathing, not a creative player) has its air supply lowered by `decreaseAirSupply` (1, or 0 by the Respiration / oxygen bonus chance), and at -20 it is set to 0 and takes 2 drowning damage; otherwise the air is raised by `increaseAirSupply` (+4, up to the maximum, 300). Axolotls and water animals add their own `handleAirSupply` after it. - NeoForge: `LivingBreatheEvent(entity, canBreathe, consumeAirAmount, refillAirAmount)` is posted from that block every tick (`CommonHooks.onLivingBreathe`) with vanilla's answers as defaults; a listener can change whether the entity can breathe and how much air it consumes or refills; then the air changes by that. It cannot be cancelled. (`LivingDrownEvent` is another event, not part of this.) ## Proposal One hook point, API from a fragment (`tools/native-hook-fragments/living_breathe.json`), a free function in the library next to the code that uses it, as the loot and menu hooks are, because the player's motion has no `Game` to call: - `native_living_breathe(entity, kind, can_breathe, consume, refill)` with out parameters, run for every player and mob that Horizon ticks on a server and that has vanilla's generic air logic: players (`motion/environment.rs`) and mobs (`mobs/ai.rs`). A mod sets `can_breathe`, `consume` (how much air it loses when it cannot breathe) and `refill` (how much it gains when it can); several mods can hook one point. The defaults are what Horizon does today, so nothing changes for a player without a mod. Drowning damage follows the air supply as before. Not in this step: axolotls, fish and other `WaterAnimal`s (their own air logic overwrites the generic block's in vanilla too), the nautilus, `LivingDrownEvent`, a client's prediction (the hook runs on servers only).
Author
Owner

@levzzz5154 commented on GitHub (Nov 1, 2026):

/claim

<!-- gh-comment-id:6562053425 --> @levzzz5154 commented on GitHub (Nov 1, 2026): /claim
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2034
No description provided.