package net.minecraft.world.level.block;

import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.level.material.Material;
import net.minecraft.tags.Tag;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.FallingBlockEntity;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class FallingBlock extends Block {
    public FallingBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public void onPlace(final BlockState cfj1, final Level bqb, final BlockPos fu, final BlockState cfj4, final boolean boolean5) {
        bqb.getBlockTicks().scheduleTick(fu, this, this.getDelayAfterPlace());
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        bqc.getBlockTicks().scheduleTick(fu5, this, this.getDelayAfterPlace());
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public void tick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (!isFree(zd.getBlockState(fu.below())) || fu.getY() < 0) {
            return;
        }
        final FallingBlockEntity bbf6 = new FallingBlockEntity(zd, fu.getX() + 0.5, fu.getY(), fu.getZ() + 0.5, zd.getBlockState(fu));
        this.falling(bbf6);
        zd.addFreshEntity(bbf6);
    }
    
    protected void falling(final FallingBlockEntity bbf) {
    }
    
    protected int getDelayAfterPlace() {
        return 2;
    }
    
    public static boolean isFree(final BlockState cfj) {
        final Material cxd2 = cfj.getMaterial();
        return cfj.isAir() || cfj.is(BlockTags.FIRE) || cxd2.isLiquid() || cxd2.isReplaceable();
    }
    
    public void onLand(final Level bqb, final BlockPos fu, final BlockState cfj3, final BlockState cfj4, final FallingBlockEntity bbf) {
    }
    
    public void onBroken(final Level bqb, final BlockPos fu, final FallingBlockEntity bbf) {
    }
    
    @Override
    public void animateTick(final BlockState cfj, final Level bqb, final BlockPos fu, final Random random) {
        if (random.nextInt(16) == 0) {
            final BlockPos fu2 = fu.below();
            if (isFree(bqb.getBlockState(fu2))) {
                final double double7 = fu.getX() + random.nextDouble();
                final double double8 = fu.getY() - 0.05;
                final double double9 = fu.getZ() + random.nextDouble();
                bqb.addParticle(new BlockParticleOption(ParticleTypes.FALLING_DUST, cfj), double7, double8, double9, 0.0, 0.0, 0.0);
            }
        }
    }
    
    public int getDustColor(final BlockState cfj, final BlockGetter bpg, final BlockPos fu) {
        return -16777216;
    }
}
