package net.minecraft.world.level.block;

import net.minecraft.world.level.LevelAccessor;
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.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public class ConcretePowderBlock extends FallingBlock {
    private final BlockState concrete;
    
    public ConcretePowderBlock(final Block bph, final Properties c) {
        super(c);
        this.concrete = bph.defaultBlockState();
    }
    
    @Override
    public void onLand(final Level bjw, final BlockPos fk, final BlockState byj3, final BlockState byj4) {
        if (shouldSolidify(bjw, fk, byj4)) {
            bjw.setBlock(fk, this.concrete, 3);
        }
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final BlockGetter bjg3 = bcq.getLevel();
        final BlockPos fk4 = bcq.getClickedPos();
        final BlockState byj5 = bjg3.getBlockState(fk4);
        if (shouldSolidify(bjg3, fk4, byj5)) {
            return this.concrete;
        }
        return super.getStateForPlacement(bcq);
    }
    
    private static boolean shouldSolidify(final BlockGetter bjg, final BlockPos fk, final BlockState byj) {
        return canSolidify(byj) || touchesLiquid(bjg, fk);
    }
    
    private static boolean touchesLiquid(final BlockGetter bjg, final BlockPos fk) {
        boolean boolean3 = false;
        final BlockPos.MutableBlockPos a4 = new BlockPos.MutableBlockPos(fk);
        for (final Direction fp8 : Direction.values()) {
            BlockState byj9 = bjg.getBlockState(a4);
            if (fp8 != Direction.DOWN || canSolidify(byj9)) {
                a4.set(fk).move(fp8);
                byj9 = bjg.getBlockState(a4);
                if (canSolidify(byj9) && !byj9.isFaceSturdy(bjg, fk, fp8.getOpposite())) {
                    boolean3 = true;
                    break;
                }
            }
        }
        return boolean3;
    }
    
    private static boolean canSolidify(final BlockState byj) {
        return byj.getFluidState().is(FluidTags.WATER);
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (touchesLiquid(bjx, fk5)) {
            return this.concrete;
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
}
