/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.content.particle;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@OnlyIn(Dist.CLIENT)
public class VerticalWhipSweepParticle extends TextureSheetParticle {
    private final SpriteSet sprites;

    protected VerticalWhipSweepParticle(ClientLevel level, double x, double y, double z,
                                        double xd, double yd, double zd, SpriteSet spriteSet) {
        super(level, x, y, z, xd, yd, zd);
        this.sprites = spriteSet;

        // 粒子属性
        this.lifetime = 10; // 存活时间（刻）
        this.quadSize = 1.8F; // 初始大小
        this.gravity = 0.0F; // 无重力
        this.friction = 0.96F; // 摩擦力

        // 颜色（鞭子的颜色 - 深红/暗红色）
        this.rCol = 0.8F;
        this.gCol = 0.2F;
        this.bCol = 0.2F;
        this.alpha = 0.8F;

        // 设置精灵
        this.setSpriteFromAge(spriteSet);
    }

    @Override
    public void tick() {
        super.tick();

        // 随时间变化
        this.quadSize *= 0.92F; // 逐渐缩小
        this.alpha *= 0.85F; // 逐渐透明

        // 颜色变化（从红到橙）
        if (this.age < this.lifetime / 2) {
            this.gCol += 0.01F; // 逐渐增加绿色分量
        }

        // 更新精灵
        this.setSpriteFromAge(this.sprites);

        // 添加轻微的运动
        this.yd += 0.001; // 轻微向下飘落
    }

    @Override
    public @NotNull ParticleRenderType getRenderType() {
        return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
    }

    @Override
    public int getLightColor(float partialTick) {
        // 使粒子发光
        return 15728880;
    }

    @OnlyIn(Dist.CLIENT)
    public static class Provider implements ParticleProvider<SimpleParticleType> {
        private final SpriteSet sprites;

        public Provider(SpriteSet spriteSet) {
            this.sprites = spriteSet;
        }

        @Override
        public @Nullable Particle createParticle(@NotNull SimpleParticleType type, @NotNull ClientLevel level,
                                                 double x, double y, double z,
                                                 double xSpeed, double ySpeed, double zSpeed) {
            return new VerticalWhipSweepParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, this.sprites);
        }
    }
}
