package net.minecraft.world.level.material;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.tags.Tag;
import net.minecraft.tags.FluidTags;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.state.properties.Property;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Item;

public abstract class WaterFluid extends FlowingFluid {
    @Override
    public Fluid getFlowing() {
        return Fluids.FLOWING_WATER;
    }
    
    @Override
    public Fluid getSource() {
        return Fluids.WATER;
    }
    
    @Override
    public Item getBucket() {
        return Items.WATER_BUCKET;
    }
    
    public void animateTick(final Level bqb, final BlockPos fu, final FluidState cxa, final Random random) {
        if (!cxa.isSource() && !cxa.<Boolean>getValue((Property<Boolean>)WaterFluid.FALLING)) {
            if (random.nextInt(64) == 0) {
                bqb.playLocalSound(fu.getX() + 0.5, fu.getY() + 0.5, fu.getZ() + 0.5, SoundEvents.WATER_AMBIENT, SoundSource.BLOCKS, random.nextFloat() * 0.25f + 0.75f, random.nextFloat() + 0.5f, false);
            }
        }
        else if (random.nextInt(10) == 0) {
            bqb.addParticle(ParticleTypes.UNDERWATER, fu.getX() + random.nextDouble(), fu.getY() + random.nextDouble(), fu.getZ() + random.nextDouble(), 0.0, 0.0, 0.0);
        }
    }
    
    @Nullable
    public ParticleOptions getDripParticle() {
        return ParticleTypes.DRIPPING_WATER;
    }
    
    @Override
    protected boolean canConvertToSource() {
        return true;
    }
    
    @Override
    protected void beforeDestroyingBlock(final LevelAccessor bqc, final BlockPos fu, final BlockState cfj) {
        final BlockEntity cdl5 = cfj.getBlock().isEntityBlock() ? bqc.getBlockEntity(fu) : null;
        Block.dropResources(cfj, bqc.getLevel(), fu, cdl5);
    }
    
    public int getSlopeFindDistance(final LevelReader bqd) {
        return 4;
    }
    
    public BlockState createLegacyBlock(final FluidState cxa) {
        return ((StateHolder<O, BlockState>)Blocks.WATER.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)LiquidBlock.LEVEL, FlowingFluid.getLegacyLevel(cxa));
    }
    
    @Override
    public boolean isSame(final Fluid cwz) {
        return cwz == Fluids.WATER || cwz == Fluids.FLOWING_WATER;
    }
    
    public int getDropOff(final LevelReader bqd) {
        return 1;
    }
    
    @Override
    public int getTickDelay(final LevelReader bqd) {
        return 5;
    }
    
    public boolean canBeReplacedWith(final FluidState cxa, final BlockGetter bpg, final BlockPos fu, final Fluid cwz, final Direction fz) {
        return fz == Direction.DOWN && !cwz.is(FluidTags.WATER);
    }
    
    @Override
    protected float getExplosionResistance() {
        return 100.0f;
    }
    
    public static class Source extends WaterFluid {
        @Override
        public int getAmount(final FluidState cxa) {
            return 8;
        }
        
        @Override
        public boolean isSource(final FluidState cxa) {
            return true;
        }
    }
    
    public static class Flowing extends WaterFluid {
        @Override
        protected void createFluidStateDefinition(final StateDefinition.Builder<Fluid, FluidState> a) {
            super.createFluidStateDefinition(a);
            a.add(Flowing.LEVEL);
        }
        
        @Override
        public int getAmount(final FluidState cxa) {
            return cxa.<Integer>getValue((Property<Integer>)Flowing.LEVEL);
        }
        
        @Override
        public boolean isSource(final FluidState cxa) {
            return false;
        }
    }
}
