-
Notifications
You must be signed in to change notification settings - Fork 0
Api
minhnh303 edited this page Jun 8, 2026
·
2 revisions
Yet-Another-Thirst provides a public-facing API class and helper methods in its common source set to query and manipulate thirst values or water purity.
The primary and recommended class for interacting with Yet-Another-Thirst is:
dev.minhnh.yetanotherthirst.api.YetAnotherThirstAPI
| Method | Description |
|---|---|
getThirstState(Player player) |
Returns the player's underlying ThirstState. |
getThirst(Player player) |
Returns current thirst value (0-20). |
setThirst(Player player, int thirst) |
Sets current thirst value and triggers client sync. |
getQuenched(Player player) |
Returns current quenched value (0-20). |
setQuenched(Player player, int quenched) |
Sets current quenched value and triggers client sync. |
getExhaustion(Player player) |
Returns current exhaustion value. |
setExhaustion(Player player, float exhaustion) |
Sets current exhaustion value and triggers client sync. |
addExhaustion(Player player, float amount) |
Adds current exhaustion value and triggers client sync. |
isThirstEnabled(Player player) |
Checks if thirst is enabled for the player. |
setThirstEnabled(Player player, boolean enabled) |
Toggles thirst capability state and triggers client sync. |
drink(Player player, int thirst, int quenched) |
Simulates drinking, adding thirst/quenched levels and syncing. |
sync(Player player) |
Manually syncs ServerPlayer thirst state to ClientPlayer. |
registerDrink(Item item, int thirst, int quenched) |
Programmatically registers item as a drink. |
registerFood(Item item, int thirst, int quenched) |
Programmatically registers item as juice food. |
isWaterFilledContainer(ItemStack stack) |
Checks if stack contains water (potions, water bowls, etc.). |
getPurity(ItemStack stack) |
Returns NBT purity value (0-3). |
setPurity(ItemStack stack, int purity) |
Updates stack NBT purity value (0-3). |
givePurityEffects(Player player, int purity) |
Applies poison/nausea/hunger effects based on purity level. |
Use these methods during mod initialization to register hydration values for items dynamically:
import dev.minhnh.yetanotherthirst.api.YetAnotherThirstAPI;
// Register a drink item (restores thirst, does not affect hunger)
YetAnotherThirstAPI.registerDrink(MyItems.MY_DRINK.get(), 6, 8);
// Register a food item (restores both hunger and thirst)
YetAnotherThirstAPI.registerFood(MyItems.MY_JUICY_FOOD.get(), 2, 3);Note: Code registrations will not overwrite user configurations defined in common.toml.
If your codebase accesses platform capability services via Services.PLATFORM, the platform service interface IPlatformHelper provides the following helper methods:
import dev.minhnh.yetanotherthirst.platform.Services;
import dev.minhnh.yetanotherthirst.core.thirst.ThirstState;
import net.minecraft.world.entity.player.Player;
// Retrieve the player's thirst state interface
ThirstState state = Services.PLATFORM.getThirstState(player);
int thirst = state.getThirst();
int quenched = state.getQuenched();
// Modify state
state.setThirst(15);
state.setQuenched(10);
// Sync changes
Services.PLATFORM.syncThirst(player);Water containers store a purity level ranging from 0 to 3 as an NBT integer tag (Purity).
import dev.minhnh.yetanotherthirst.api.YetAnotherThirstAPI;
// Check container status
ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
if (YetAnotherThirstAPI.isWaterFilledContainer(stack)) {
// Read purity: 0 (Dirty) to 3 (Purified)
int purity = YetAnotherThirstAPI.getPurity(stack);
// Apply purity effects (poison/nausea/hunger) to player
boolean shouldHydrate = YetAnotherThirstAPI.givePurityEffects(player, purity);
}