package net.Chipperfluff.chipi.effect;

import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;

public class ChipiBlessingEvents {

    public static void register() {
        ServerTickEvents.END_SERVER_TICK.register(ChipiBlessingEvents::onServerTick);
    }

    private static void onServerTick(MinecraftServer server) {
        for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
            if (player.hasStatusEffect(ModEffects.CHIPI_BLESSING)) {
                player.getHungerManager().setExhaustion(0.0f);
            }
        }
    }

    public static boolean cancelFallDamage(ServerPlayerEntity player, DamageSource source) {
        return source.isOf(DamageTypes.FALL) && player.hasStatusEffect(ModEffects.CHIPI_BLESSING);
    }
}
