Compatibility
Minecraft: Java Edition
Platforms
Supported environments
Links
Tags
Creators
Details
Milk Bar

Milk Bar is a server-side Fabric mod for Minecraft 26.2. It adds a configurable survival challenge: every player has a private milk bar that drains while they are online. Drinking milk restores the bar. When it reaches zero, the player dies.
The mod is designed for both singleplayer and multiplayer. All challenge state is server-authoritative and stored per player using Fabric's persistent Data Attachment API.
Rules
A player receives the configured number of starter milk buckets only when their challenge state is initialized for the first time. The starter reward is never granted again because of death, respawn, reconnects, dimension changes, or server restarts.
The milk bar drains only while the player is alive and online. Offline time does not drain the bar.
When the bar reaches zero, the player is killed immediately. On every respawn, regardless of the cause of death, the milk bar is reset to its configured maximum. No additional starter milk is granted.
The boss bar is private to each player. One player's value is never sent to another player's boss bar.
Normal Minecraft milk consumption remains intact. A milk bucket restores the configured amount when its drinking action completes. If the bar is already full and consumeMilkWhenFull is enabled, the bucket is still consumed according to vanilla behavior but the challenge value cannot exceed the maximum.
If starter milk does not fully fit in the inventory, the remainder is dropped at the player's position instead of being silently lost.
Commands
All commands require permission level 2 or higher.
/milkbar status/milkbar status <player>/milkbar set <player> <value>/milkbar refill <player>/milkbar reload
set clamps the value to the configured maximum. refill sets the value directly to the configured maximum. reload reloads config/milkbar.json and refreshes active boss bars without restarting the server.
Configuration
The file is created at config/milkbar.json.
{
"enabled": true,
"maxValue": 100,
"drainAmount": 1,
"drainIntervalTicks": 20,
"milkRestoreAmount": 100,
"starterMilkBuckets": 1,
"giveStarterMilk": true,
"consumeMilkWhenFull": true,
"bossBarVisible": true,
"bossBarTitle": "Milk: %value% / %max%",
"bossBarColor": "GREEN",
"bossBarOverlay": "PROGRESS",
"bossBarDarkenScreen": false,
"bossBarPlayMusic": false,
"bossBarCreateFog": false
}
maxValue is the maximum bar value and accepts values from 1 to 1,000,000.
drainAmount is removed every drainIntervalTicks. drainIntervalTicks uses server ticks; 20 ticks is approximately one second.
milkRestoreAmount controls how much one milk bucket restores. Restoration is capped at maxValue.
starterMilkBuckets controls the one-time starter reward. giveStarterMilk disables that reward without disabling the challenge itself.
consumeMilkWhenFull controls whether a full bar still allows normal milk consumption. The current implementation does not cancel vanilla item use; when this option is false, the challenge does not restore while already full, but vanilla milk consumption is still performed.
bossBarTitle supports %value% and %max% placeholders.
bossBarColor supports the vanilla boss bar colors available in the target Minecraft version. bossBarOverlay supports the vanilla progress and notched overlays.
Boss bar visual effects are controlled by bossBarDarkenScreen, bossBarPlayMusic, and bossBarCreateFog.
Invalid numeric values are clamped to safe ranges. Invalid boss bar color and overlay values fall back to GREEN and PROGRESS.
Requirements
- Minecraft 26.2
- Fabric Loader 0.19.5 or newer
- Fabric API 0.159.0+26.2 or newer
- Java 25
Build
./gradlew build
The compiled JAR is written to build/libs/.
Changelog
1.0.0
- Fixed compilation against current mappings:
ServerBossEventnow requires an explicitUUID(a fresh random id per bar, independent of the player's own UUID),CommandSourceStackpermission checks now useLevelBasedPermissionSet/PermissionLevel, andLivingEntity#killnow requires theServerLevelargument. - Boss bar updates no longer re-apply the full configuration (color, overlay, visibility, darken-screen, music, fog) on every drain interval - only progress and title change per update now. Full reconfiguration still happens on bar creation and on
/milkbar reload(which recreates the bar). - Boss bar color/overlay parsing moved from the boss bar manager into
MilkBarConfig.normalize(), so the string-to-enum conversion (with its fallback handling) runs once per load/reload instead of on every boss bar update. - Removed a redundant per-tick state normalization call that duplicated work already done on player join and on
/milkbar reload. MilkBarCommand's command tree was restructured for readability; behavior is unchanged.
Architecture
PlayerMilkState is the persistent per-player domain state. The attachment is persistent across server restarts and copied to the respawned player instance. The controller deliberately resets only the current bar value during respawn.
MilkBarController owns gameplay state transitions, starter rewards, milk consumption detection, draining, death handling, respawn handling, and administration operations.
MilkBossBarManager owns private server boss bars and their lifecycle. Boss bars are explicitly removed and recreated across respawns so the new ServerPlayer instance always receives the correct bar.
MilkBarConfig validates configuration and supports in-place reloads so the controller and boss bar manager always reference the same configuration object.
The implementation does not use client-side code, mixins, custom networking, or a database.
License
Milk Bar is licensed under the MIT License.


