package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
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;

public class ChorusPlantBlock extends PipeBlock {
    protected ChorusPlantBlock(final Properties c) {
        super(0.3125f, c);
        this.registerDefaultState((((((((AbstractStateHolder<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 bcq) {
        return this.getStateForPlacement(bcq.getLevel(), bcq.getClickedPos());
    }
    
    public BlockState getStateForPlacement(final BlockGetter bjg, final BlockPos fk) {
        final Block bph4 = bjg.getBlockState(fk.below()).getBlock();
        final Block bph5 = bjg.getBlockState(fk.above()).getBlock();
        final Block bph6 = bjg.getBlockState(fk.north()).getBlock();
        final Block bph7 = bjg.getBlockState(fk.east()).getBlock();
        final Block bph8 = bjg.getBlockState(fk.south()).getBlock();
        final Block bph9 = bjg.getBlockState(fk.west()).getBlock();
        return (((((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)ChorusPlantBlock.DOWN, bph4 == this || bph4 == Blocks.CHORUS_FLOWER || bph4 == Blocks.END_STONE)).setValue((Property<Comparable>)ChorusPlantBlock.UP, bph5 == this || bph5 == Blocks.CHORUS_FLOWER)).setValue((Property<Comparable>)ChorusPlantBlock.NORTH, bph6 == this || bph6 == Blocks.CHORUS_FLOWER)).setValue((Property<Comparable>)ChorusPlantBlock.EAST, bph7 == this || bph7 == Blocks.CHORUS_FLOWER)).setValue((Property<Comparable>)ChorusPlantBlock.SOUTH, bph8 == this || bph8 == Blocks.CHORUS_FLOWER)).<Comparable, Boolean>setValue((Property<Comparable>)ChorusPlantBlock.WEST, bph9 == this || bph9 == Blocks.CHORUS_FLOWER);
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (!byj1.canSurvive(bjx, fk5)) {
            bjx.getBlockTicks().scheduleTick(fk5, this, 1);
            return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
        }
        final Block bph8 = byj3.getBlock();
        final boolean boolean9 = bph8 == this || bph8 == Blocks.CHORUS_FLOWER || (fp == Direction.DOWN && bph8 == Blocks.END_STONE);
        return ((AbstractStateHolder<O, BlockState>)byj1).<Comparable, Boolean>setValue((Property<Comparable>)ChorusPlantBlock.PROPERTY_BY_DIRECTION.get(fp), boolean9);
    }
    
    @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);
        }
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        final BlockState byj2 = bjz.getBlockState(fk.below());
        final boolean boolean6 = !bjz.getBlockState(fk.above()).isAir() && !byj2.isAir();
        for (final Direction fp8 : Direction.Plane.HORIZONTAL) {
            final BlockPos fk2 = fk.relative(fp8);
            final Block bph10 = bjz.getBlockState(fk2).getBlock();
            if (bph10 == this) {
                if (boolean6) {
                    return false;
                }
                final Block bph11 = bjz.getBlockState(fk2.below()).getBlock();
                if (bph11 == this || bph11 == Blocks.END_STONE) {
                    return true;
                }
                continue;
            }
        }
        final Block bph12 = byj2.getBlock();
        return bph12 == this || bph12 == 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 byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
}
