package net.minecraft.client.particle;

import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.Fluid;

public class DripParticle extends TextureSheetParticle {
    private final Fluid type;
    
    private DripParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi) {
        super(bjw, double2, double3, double4);
        this.setSize(0.01f, 0.01f);
        this.gravity = 0.06f;
        this.type = coi;
    }
    
    @Override
    public ParticleRenderType getRenderType() {
        return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
    }
    
    public int getLightColor(final float float1) {
        if (this.type.is(FluidTags.LAVA)) {
            return 240;
        }
        return super.getLightColor(float1);
    }
    
    @Override
    public void tick() {
        this.xo = this.x;
        this.yo = this.y;
        this.zo = this.z;
        this.preMoveUpdate();
        if (this.removed) {
            return;
        }
        this.yd -= this.gravity;
        this.move(this.xd, this.yd, this.zd);
        this.postMoveUpdate();
        if (this.removed) {
            return;
        }
        this.xd *= 0.9800000190734863;
        this.yd *= 0.9800000190734863;
        this.zd *= 0.9800000190734863;
        final BlockPos fk2 = new BlockPos(this.x, this.y, this.z);
        final FluidState coj3 = this.level.getFluidState(fk2);
        if (coj3.getType() == this.type && this.y < fk2.getY() + coj3.getHeight(this.level, fk2)) {
            this.remove();
        }
    }
    
    protected void preMoveUpdate() {
        if (this.lifetime-- <= 0) {
            this.remove();
        }
    }
    
    protected void postMoveUpdate() {
    }
    
    static class DripHangParticle extends DripParticle {
        private final ParticleOptions fallingParticle;
        
        private DripHangParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi, final ParticleOptions gt) {
            super(bjw, double2, double3, double4, coi, null);
            this.fallingParticle = gt;
            this.gravity *= 0.02f;
            this.lifetime = 40;
        }
        
        @Override
        protected void preMoveUpdate() {
            if (this.lifetime-- <= 0) {
                this.remove();
                this.level.addParticle(this.fallingParticle, this.x, this.y, this.z, this.xd, this.yd, this.zd);
            }
        }
        
        @Override
        protected void postMoveUpdate() {
            this.xd *= 0.02;
            this.yd *= 0.02;
            this.zd *= 0.02;
        }
    }
    
    static class CoolingDripHangParticle extends DripHangParticle {
        private CoolingDripHangParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi, final ParticleOptions gt) {
            super(bjw, double2, double3, double4, coi, gt);
        }
        
        @Override
        protected void preMoveUpdate() {
            this.rCol = 1.0f;
            this.gCol = 16.0f / (40 - this.lifetime + 16);
            this.bCol = 4.0f / (40 - this.lifetime + 8);
            super.preMoveUpdate();
        }
    }
    
    static class FallAndLandParticle extends FallingParticle {
        protected final ParticleOptions landParticle;
        
        private FallAndLandParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi, final ParticleOptions gt) {
            super(bjw, double2, double3, double4, coi);
            this.landParticle = gt;
        }
        
        @Override
        protected void postMoveUpdate() {
            if (this.onGround) {
                this.remove();
                this.level.addParticle(this.landParticle, this.x, this.y, this.z, 0.0, 0.0, 0.0);
            }
        }
    }
    
    static class HoneyFallAndLandParticle extends FallAndLandParticle {
        private HoneyFallAndLandParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi, final ParticleOptions gt) {
            super(bjw, double2, double3, double4, coi, gt);
        }
        
        @Override
        protected void postMoveUpdate() {
            if (this.onGround) {
                this.remove();
                this.level.addParticle(this.landParticle, this.x, this.y, this.z, 0.0, 0.0, 0.0);
                this.level.playLocalSound(this.x + 0.5, this.y, this.z + 0.5, SoundEvents.BEEHIVE_DRIP, SoundSource.BLOCKS, 0.3f + this.level.random.nextFloat() * 2.0f / 3.0f, 1.0f, false);
            }
        }
    }
    
    static class FallingParticle extends DripParticle {
        private FallingParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi) {
            super(bjw, double2, double3, double4, coi, null);
            this.lifetime = (int)(64.0 / (Math.random() * 0.8 + 0.2));
        }
        
        @Override
        protected void postMoveUpdate() {
            if (this.onGround) {
                this.remove();
            }
        }
    }
    
    static class DripLandParticle extends DripParticle {
        private DripLandParticle(final Level bjw, final double double2, final double double3, final double double4, final Fluid coi) {
            super(bjw, double2, double3, double4, coi, null);
            this.lifetime = (int)(16.0 / (Math.random() * 0.8 + 0.2));
        }
    }
    
    public static class WaterHangProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public WaterHangProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new DripHangParticle(bjw, double3, double4, double5, (Fluid)Fluids.WATER, (ParticleOptions)ParticleTypes.FALLING_WATER);
            doi16.setColor(0.2f, 0.3f, 1.0f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
    
    public static class WaterFallProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public WaterFallProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new FallAndLandParticle(bjw, double3, double4, double5, (Fluid)Fluids.WATER, (ParticleOptions)ParticleTypes.SPLASH);
            doi16.setColor(0.2f, 0.3f, 1.0f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
    
    public static class LavaHangProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public LavaHangProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final CoolingDripHangParticle a16 = new CoolingDripHangParticle(bjw, double3, double4, double5, (Fluid)Fluids.LAVA, (ParticleOptions)ParticleTypes.FALLING_LAVA);
            a16.pickSprite(this.sprite);
            return a16;
        }
    }
    
    public static class LavaFallProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public LavaFallProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new FallAndLandParticle(bjw, double3, double4, double5, (Fluid)Fluids.LAVA, (ParticleOptions)ParticleTypes.LANDING_LAVA);
            doi16.setColor(1.0f, 0.2857143f, 0.083333336f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
    
    public static class LavaLandProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public LavaLandProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new DripLandParticle(bjw, double3, double4, double5, (Fluid)Fluids.LAVA);
            doi16.setColor(1.0f, 0.2857143f, 0.083333336f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
    
    public static class HoneyHangProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public HoneyHangProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripHangParticle dripHangParticle;
            final DripHangParticle b16 = dripHangParticle = new DripHangParticle(bjw, double3, double4, double5, Fluids.EMPTY, (ParticleOptions)ParticleTypes.FALLING_HONEY);
            dripHangParticle.gravity *= 0.01f;
            b16.lifetime = 100;
            b16.setColor(0.622f, 0.508f, 0.082f);
            b16.pickSprite(this.sprite);
            return b16;
        }
    }
    
    public static class HoneyFallProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public HoneyFallProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new HoneyFallAndLandParticle(bjw, double3, double4, double5, Fluids.EMPTY, (ParticleOptions)ParticleTypes.LANDING_HONEY);
            doi16.gravity = 0.01f;
            doi16.setColor(0.582f, 0.448f, 0.082f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
    
    public static class HoneyLandProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public HoneyLandProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new DripLandParticle(bjw, double3, double4, double5, Fluids.EMPTY);
            doi16.lifetime = (int)(128.0 / (Math.random() * 0.8 + 0.2));
            doi16.setColor(0.522f, 0.408f, 0.082f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
    
    public static class NectarFallProvider implements ParticleProvider<SimpleParticleType> {
        protected final SpriteSet sprite;
        
        public NectarFallProvider(final SpriteSet dpm) {
            this.sprite = dpm;
        }
        
        @Override
        public Particle createParticle(final SimpleParticleType gw, final Level bjw, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
            final DripParticle doi16 = new FallingParticle(bjw, double3, double4, double5, Fluids.EMPTY);
            doi16.lifetime = (int)(16.0 / (Math.random() * 0.8 + 0.2));
            doi16.gravity = 0.007f;
            doi16.setColor(0.92f, 0.782f, 0.72f);
            doi16.pickSprite(this.sprite);
            return doi16;
        }
    }
}
