package net.minecraft.world.level.block;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.tags.Tag;
import net.minecraft.tags.FluidTags;
import net.minecraft.core.Vec3i;
import net.minecraft.core.Direction;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;

public class ConcretePowderBlock extends FallingBlock {
    private final BlockState concrete;
    
    public ConcretePowderBlock(final Block bvr, final Properties c) {
        super(c);
        this.concrete = bvr.defaultBlockState();
    }
    
    @Override
    public void onLand(final Level bqb, final BlockPos fu, final BlockState cfj3, final BlockState cfj4, final FallingBlockEntity bbf) {
        if (shouldSolidify(bqb, fu, cfj4)) {
            bqb.setBlock(fu, this.concrete, 3);
        }
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        final BlockGetter bpg3 = bin.getLevel();
        final BlockPos fu4 = bin.getClickedPos();
        final BlockState cfj5 = bpg3.getBlockState(fu4);
        if (shouldSolidify(bpg3, fu4, cfj5)) {
            return this.concrete;
        }
        return super.getStateForPlacement(bin);
    }
    
    private static boolean shouldSolidify(final BlockGetter bpg, final BlockPos fu, final BlockState cfj) {
        return canSolidify(cfj) || touchesLiquid(bpg, fu);
    }
    
    private static boolean touchesLiquid(final BlockGetter bpg, final BlockPos fu) {
        boolean boolean3 = false;
        final BlockPos.MutableBlockPos a4 = fu.mutable();
        for (final Direction fz8 : Direction.values()) {
            BlockState cfj9 = bpg.getBlockState(a4);
            if (fz8 != Direction.DOWN || canSolidify(cfj9)) {
                a4.setWithOffset(fu, fz8);
                cfj9 = bpg.getBlockState(a4);
                if (canSolidify(cfj9) && !cfj9.isFaceSturdy(bpg, fu, fz8.getOpposite())) {
                    boolean3 = true;
                    break;
                }
            }
        }
        return boolean3;
    }
    
    private static boolean canSolidify(final BlockState cfj) {
        return cfj.getFluidState().is(FluidTags.WATER);
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (touchesLiquid(bqc, fu5)) {
            return this.concrete;
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public int getDustColor(final BlockState cfj, final BlockGetter bpg, final BlockPos fu) {
        return cfj.getMapColor(bpg, fu).col;
    }
}
