package xyz.illuc.neuralgiacore.mixin.PrototypePain;

import net.adinvas.prototype_pain.PlayerHealthProvider;
import net.adinvas.prototype_pain.client.overlays.exp.SicknessOverlay;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import xyz.illuc.neuralgiacore.interfaces.IPlayerHealthDataAccessor;

@Mixin(SicknessOverlay.class)
public class MixinSicknessOverlay {

    /**
     * @author
     * @reason
     */
    @Overwrite(remap = false)
    public boolean shouldRender() {
        Minecraft mc = Minecraft.getInstance();

        return mc.player.getCapability(PlayerHealthProvider.PLAYER_HEALTH_DATA).map(h -> {
            IPlayerHealthDataAccessor accessor = (IPlayerHealthDataAccessor) h;
            return accessor.getSickness() > 0.1;
        }).orElse(false);
    }

    @ModifyVariable(
            method = "render",
            at = @At("STORE"),
            ordinal = 1,
            remap = false
    )
    private float modifySicknessValue(float original) {
        Minecraft mc = Minecraft.getInstance();

        return mc.player.getCapability(PlayerHealthProvider.PLAYER_HEALTH_DATA).map(h -> {
            IPlayerHealthDataAccessor accessor = (IPlayerHealthDataAccessor) h;
            return 1F - accessor.getSickness() / 100.0F;
        }).orElse(0.0F);
    }


}
