package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.block.state.StateDefinition;
import java.util.Iterator;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class ChorusPlantBlock extends PipeBlock {
    protected ChorusPlantBlock(final Properties c) {
        super(0.3125f, c);
        this.registerDefaultState((((((((StateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)ChorusPlantBlock.NORTH, false)).setValue((Property<Comparable>)ChorusPlantBlock.EAST, false)).setValue((Property<Comparable>)ChorusPlantBlock.SOUTH, false)).setValue((Property<Comparable>)ChorusPlantBlock.WEST, false)).setValue((Property<Comparable>)ChorusPlantBlock.UP, false)).<Comparable, Boolean>setValue((Property<Comparable>)ChorusPlantBlock.DOWN, false));
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        return this.getStateForPlacement(bin.getLevel(), bin.getClickedPos());
    }
    
    public BlockState getStateForPlacement(final BlockGetter bpg, final BlockPos fu) {
        final Block bvr4 = bpg.getBlockState(fu.below()).getBlock();
        final Block bvr5 = bpg.getBlockState(fu.above()).getBlock();
        final Block bvr6 = bpg.getBlockState(fu.north()).getBlock();
        final Block bvr7 = bpg.getBlockState(fu.east()).getBlock();
        final Block bvr8 = bpg.getBlockState(fu.south()).getBlock();
        final Block bvr9 = bpg.getBlockState(fu.west()).getBlock();
        return (((((((StateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)ChorusPlantBlock.DOWN, bvr4 == this || bvr4 == Blocks.CHORUS_FLOWER || bvr4 == Blocks.END_STONE)).setValue((Property<Comparable>)ChorusPlantBlock.UP, bvr5 == this || bvr5 == Blocks.CHORUS_FLOWER)).setValue((Property<Comparable>)ChorusPlantBlock.NORTH, bvr6 == this || bvr6 == Blocks.CHORUS_FLOWER)).setValue((Property<Comparable>)ChorusPlantBlock.EAST, bvr7 == this || bvr7 == Blocks.CHORUS_FLOWER)).setValue((Property<Comparable>)ChorusPlantBlock.SOUTH, bvr8 == this || bvr8 == Blocks.CHORUS_FLOWER)).<Comparable, Boolean>setValue((Property<Comparable>)ChorusPlantBlock.WEST, bvr9 == this || bvr9 == Blocks.CHORUS_FLOWER);
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (!cfj1.canSurvive(bqc, fu5)) {
            bqc.getBlockTicks().scheduleTick(fu5, this, 1);
            return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
        }
        final boolean boolean8 = cfj3.getBlock() == this || cfj3.is(Blocks.CHORUS_FLOWER) || (fz == Direction.DOWN && cfj3.is(Blocks.END_STONE));
        return ((StateHolder<O, BlockState>)cfj1).<Comparable, Boolean>setValue((Property<Comparable>)ChorusPlantBlock.PROPERTY_BY_DIRECTION.get(fz), boolean8);
    }
    
    @Override
    public void tick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (!cfj.canSurvive(zd, fu)) {
            zd.destroyBlock(fu, true);
        }
    }
    
    @Override
    public boolean canSurvive(final BlockState cfj, final LevelReader bqd, final BlockPos fu) {
        final BlockState cfj2 = bqd.getBlockState(fu.below());
        final boolean boolean6 = !bqd.getBlockState(fu.above()).isAir() && !cfj2.isAir();
        for (final Direction fz8 : Direction.Plane.HORIZONTAL) {
            final BlockPos fu2 = fu.relative(fz8);
            final Block bvr10 = bqd.getBlockState(fu2).getBlock();
            if (bvr10 == this) {
                if (boolean6) {
                    return false;
                }
                final Block bvr11 = bqd.getBlockState(fu2.below()).getBlock();
                if (bvr11 == this || bvr11 == Blocks.END_STONE) {
                    return true;
                }
                continue;
            }
        }
        final Block bvr12 = cfj2.getBlock();
        return bvr12 == this || bvr12 == Blocks.END_STONE;
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(ChorusPlantBlock.NORTH, ChorusPlantBlock.EAST, ChorusPlantBlock.SOUTH, ChorusPlantBlock.WEST, ChorusPlantBlock.UP, ChorusPlantBlock.DOWN);
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        return false;
    }
}
