package net.minecraft.world.item;

import java.util.Map;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Block;

public class StandingAndWallBlockItem extends BlockItem {
    protected final Block wallBlock;
    
    public StandingAndWallBlockItem(final Block bph1, final Block bph2, final Properties a) {
        super(bph1, a);
        this.wallBlock = bph2;
    }
    
    @Nullable
    @Override
    protected BlockState getPlacementState(final BlockPlaceContext bcq) {
        final BlockState byj3 = this.wallBlock.getStateForPlacement(bcq);
        BlockState byj4 = null;
        final LevelReader bjz5 = bcq.getLevel();
        final BlockPos fk6 = bcq.getClickedPos();
        for (final Direction fp10 : bcq.getNearestLookingDirections()) {
            if (fp10 != Direction.UP) {
                final BlockState byj5 = (fp10 == Direction.DOWN) ? this.getBlock().getStateForPlacement(bcq) : byj3;
                if (byj5 != null && byj5.canSurvive(bjz5, fk6)) {
                    byj4 = byj5;
                    break;
                }
            }
        }
        return (byj4 != null && bjz5.isUnobstructed(byj4, fk6, CollisionContext.empty())) ? byj4 : null;
    }
    
    @Override
    public void registerBlocks(final Map<Block, Item> map, final Item bei) {
        super.registerBlocks(map, bei);
        map.put(this.wallBlock, bei);
    }
}
