package com.acethewildfire.acesbs.effect;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;

import java.util.Random;

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

    Random r = new Random();

    @Override
    public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
        entity.setOnFireFor(1);
        World world = entity.getWorld();

        if (entity.isTouchingWater()){
//            double randomVelocityX = r.nextDouble(-0.5, 0.5);
//            double randomVelocityY = r.nextDouble(0.5, 1.0);
//            double randomVelocityZ = r.nextDouble(-0.5, 0.5);

            if (!world.isClient) {
                ((ServerWorld) world).spawnParticles(
                        ParticleTypes.CAMPFIRE_COSY_SMOKE,
                        entity.getX(),
                        entity.getY() + 0.5f,
                        entity.getZ(),
                        5,     // count
                        0.02,   // dx
                        0.2,   // dy
                        0.02,   // dz
                        0.01    // speed
                );
            }

            entity.addVelocity(0, 0.75f, 0);
        }

        return true;

    }

    @Override
    public boolean canApplyUpdateEffect(int duration, int amplifier) {
        return duration >= 19;
    }
}
