package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import javax.annotation.Nullable;
import net.minecraft.world.level.LevelReader;
import net.minecraft.core.Direction;
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.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class Lantern extends Block {
    public static final BooleanProperty HANGING;
    protected static final VoxelShape AABB;
    protected static final VoxelShape HANGING_AABB;
    
    public Lantern(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Boolean>setValue((Property<Comparable>)Lantern.HANGING, false));
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        for (final Direction fp6 : bcq.getNearestLookingDirections()) {
            if (fp6.getAxis() == Direction.Axis.Y) {
                final BlockState byj7 = ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)Lantern.HANGING, fp6 == Direction.UP);
                if (byj7.canSurvive(bcq.getLevel(), bcq.getClickedPos())) {
                    return byj7;
                }
            }
        }
        return null;
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return byj.<Boolean>getValue((Property<Boolean>)Lantern.HANGING) ? Lantern.HANGING_AABB : Lantern.AABB;
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(Lantern.HANGING);
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        final Direction fp5 = getConnectedDirection(byj).getOpposite();
        return Block.canSupportCenter(bjz, fk.relative(fp5), fp5.getOpposite());
    }
    
    protected static Direction getConnectedDirection(final BlockState byj) {
        return byj.<Boolean>getValue((Property<Boolean>)Lantern.HANGING) ? Direction.DOWN : Direction.UP;
    }
    
    @Override
    public PushReaction getPistonPushReaction(final BlockState byj) {
        return PushReaction.DESTROY;
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (getConnectedDirection(byj1).getOpposite() == fp && !byj1.canSurvive(bjx, fk5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    static {
        HANGING = BlockStateProperties.HANGING;
        AABB = Shapes.or(Block.box(5.0, 0.0, 5.0, 11.0, 7.0, 11.0), Block.box(6.0, 7.0, 6.0, 10.0, 9.0, 10.0));
        HANGING_AABB = Shapes.or(Block.box(5.0, 1.0, 5.0, 11.0, 8.0, 11.0), Block.box(6.0, 8.0, 6.0, 10.0, 10.0, 10.0));
    }
}
