package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
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.item.DyeColor;
import java.util.Map;
import net.minecraft.world.level.block.state.properties.IntegerProperty;

public class BannerBlock extends AbstractBannerBlock {
    public static final IntegerProperty ROTATION;
    private static final Map<DyeColor, Block> BY_COLOR;
    private static final VoxelShape SHAPE;
    
    public BannerBlock(final DyeColor bdj, final Properties c) {
        super(bdj, c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, 0));
        BannerBlock.BY_COLOR.put(bdj, this);
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        return bjz.getBlockState(fk.below()).getMaterial().isSolid();
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return BannerBlock.SHAPE;
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, Mth.floor((180.0f + bcq.getRotation()) * 16.0f / 360.0f + 0.5) & 0xF);
    }
    
    @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)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, btu.rotate(byj.<Integer>getValue((Property<Integer>)BannerBlock.ROTATION), 16));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, bsu.mirror(byj.<Integer>getValue((Property<Integer>)BannerBlock.ROTATION), 16));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(BannerBlock.ROTATION);
    }
    
    public static Block byColor(final DyeColor bdj) {
        return BannerBlock.BY_COLOR.getOrDefault(bdj, Blocks.WHITE_BANNER);
    }
    
    static {
        ROTATION = BlockStateProperties.ROTATION_16;
        BY_COLOR = Maps.newHashMap();
        SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 16.0, 12.0);
    }
}
