package net.minecraft.world.level.block;

import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelReader;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.block.state.BlockState;

public class KelpPlantBlock extends Block implements LiquidBlockContainer {
    private final KelpBlock top;
    
    protected KelpPlantBlock(final KelpBlock bsg, final Properties c) {
        super(c);
        this.top = bsg;
    }
    
    @Override
    public FluidState getFluidState(final BlockState byj) {
        return Fluids.WATER.getSource(false);
    }
    
    @Override
    public void tick(final BlockState byj, final ServerLevel xd, final BlockPos fk, final Random random) {
        if (!byj.canSurvive(xd, fk)) {
            xd.destroyBlock(fk, true);
        }
        super.tick(byj, xd, fk, random);
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (fp == Direction.DOWN && !byj1.canSurvive(bjx, fk5)) {
            bjx.getBlockTicks().scheduleTick(fk5, this, 1);
        }
        if (fp == Direction.UP) {
            final Block bph8 = byj3.getBlock();
            if (bph8 != this && bph8 != this.top) {
                return this.top.getStateForPlacement(bjx);
            }
        }
        bjx.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bjx));
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        final BlockPos fk2 = fk.below();
        final BlockState byj2 = bjz.getBlockState(fk2);
        final Block bph7 = byj2.getBlock();
        return bph7 != Blocks.MAGMA_BLOCK && (bph7 == this || byj2.isFaceSturdy(bjz, fk2, Direction.UP));
    }
    
    @Override
    public ItemStack getCloneItemStack(final BlockGetter bjg, final BlockPos fk, final BlockState byj) {
        return new ItemStack(Blocks.KELP);
    }
    
    @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;
    }
}
