package com.acethewildfire.acesbs.effect;

import com.acethewildfire.acesbs.sounds.ModSounds;
import net.minecraft.entity.Flutterer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class BrickedUpEffect extends StatusEffect {
    protected BrickedUpEffect(StatusEffectCategory category, int color) {
        super(category, color);
    }

    @Override
    public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {

        int durationLeft = entity.getStatusEffect(ModEffects.BRICKED_UP).getDuration();
        int idealLen = 160;
        World world = entity.getWorld();

        if(durationLeft > idealLen - 1){
            world.playSound(entity, entity.getBlockPos(), ModSounds.BRICKED_UP, SoundCategory.PLAYERS, 2f, 1f);
        }
        else if(durationLeft > idealLen - 120){
            float p = entity.getWorld().getBlockState(entity.getBlockPos()).getBlock().getSlipperiness();
            float f = entity.isOnGround() ? p * 0.91F : 0.91F;
            Vec3d vec3d6 = entity.applyMovementInput(entity.getMovement(), p);
            double q = vec3d6.y;
            q += (0.05 * 7.75 - vec3d6.y) * 0.2;

            entity.setVelocity(vec3d6.x * (double)f, this instanceof Flutterer ? q * (double)f : q * 0.9800000190734863, vec3d6.z * (double)f);
        }
//        else if (durationLeft < idealLen - 80 && durationLeft > idealLen - 120) {
//
//            // Freeze in place
//            entity.setVelocity(0, 0, 0);
//
////            float p = entity.getWorld().getBlockState(entity.getBlockPos()).getBlock().getSlipperiness();
////            float f = entity.isOnGround() ? p * 0.91F : 0.91F;
////            Vec3d vec3d6 = entity.applyMovementInput(entity.getMovement(), p);
////            double q = vec3d6.y;
////            q += (0.05 * 7 - vec3d6.y) * 0.2;
////
////            entity.setVelocity(vec3d6.x * (double)f, this instanceof Flutterer ? q * (double)f : q * 0.9800000190734863, vec3d6.z * (double)f);
//        }
//        else if (durationLeft < idealLen - 120 && durationLeft > idealLen - 122) {
//            world.playSound(entity, entity.getBlockPos(), ModSounds.FART, SoundCategory.PLAYERS, 5f, 1f);
//        }
        else {
            float p = entity.getWorld().getBlockState(entity.getBlockPos()).getBlock().getSlipperiness();
            float f = entity.isOnGround() ? p * 0.91F : 0.91F;
            Vec3d vec3d6 = entity.applyMovementInput(entity.getMovement(), p);
            double q = vec3d6.y;
            q += (0.05 * 250 - vec3d6.y) * 0.2;

            entity.setVelocity(vec3d6.x * (double)f, this instanceof Flutterer ? q * (double)f : q * 0.9800000190734863, vec3d6.z * (double)f);
        }


        return true;

    }

    @Override
    public boolean canApplyUpdateEffect(int duration, int amplifier) {
        return true;
    }

}
