package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.server.level.ServerLevel;
import java.util.Random;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;

public class Seagrass extends BushBlock implements BonemealableBlock, LiquidBlockContainer {
    protected static final VoxelShape SHAPE;
    
    protected Seagrass(final Properties c) {
        super(c);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return Seagrass.SHAPE;
    }
    
    @Override
    protected boolean mayPlaceOn(final BlockState byj, final BlockGetter bjg, final BlockPos fk) {
        return byj.isFaceSturdy(bjg, fk, Direction.UP) && byj.getBlock() != Blocks.MAGMA_BLOCK;
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final FluidState coj3 = bcq.getLevel().getFluidState(bcq.getClickedPos());
        if (coj3.is(FluidTags.WATER) && coj3.getAmount() == 8) {
            return super.getStateForPlacement(bcq);
        }
        return null;
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        final BlockState byj4 = super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
        if (!byj4.isAir()) {
            bjx.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bjx));
        }
        return byj4;
    }
    
    @Override
    public boolean isValidBonemealTarget(final BlockGetter bjg, final BlockPos fk, final BlockState byj, final boolean boolean4) {
        return true;
    }
    
    @Override
    public boolean isBonemealSuccess(final Level bjw, final Random random, final BlockPos fk, final BlockState byj) {
        return true;
    }
    
    @Override
    public FluidState getFluidState(final BlockState byj) {
        return Fluids.WATER.getSource(false);
    }
    
    @Override
    public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byj) {
        final BlockState byj2 = Blocks.TALL_SEAGRASS.defaultBlockState();
        final BlockState byj3 = ((AbstractStateHolder<O, BlockState>)byj2).<DoubleBlockHalf, DoubleBlockHalf>setValue(TallSeagrass.HALF, DoubleBlockHalf.UPPER);
        final BlockPos fk2 = fk.above();
        if (xd.getBlockState(fk2).getBlock() == Blocks.WATER) {
            xd.setBlock(fk, byj2, 2);
            xd.setBlock(fk2, byj3, 2);
        }
    }
    
    @Override
    public boolean canPlaceLiquid(final BlockGetter bjg, final BlockPos fk, final BlockState byj, final Fluid coi) {
        return false;
    }
    
    @Override
    public boolean placeLiquid(final LevelAccessor bjx, final BlockPos fk, final BlockState byj, final FluidState coj) {
        return false;
    }
    
    static {
        SHAPE = Block.box(2.0, 0.0, 2.0, 14.0, 12.0, 14.0);
    }
}
