package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import java.util.Random;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
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.core.Direction;
import java.util.Map;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

public class WallTorchBlock extends TorchBlock {
    public static final DirectionProperty FACING;
    private static final Map<Direction, VoxelShape> AABBS;
    
    protected WallTorchBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, Direction.NORTH));
    }
    
    @Override
    public String getDescriptionId() {
        return this.asItem().getDescriptionId();
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return getShape(byj);
    }
    
    public static VoxelShape getShape(final BlockState byj) {
        return WallTorchBlock.AABBS.get(byj.getValue((Property<Object>)WallTorchBlock.FACING));
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        final Direction fp5 = byj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING);
        final BlockPos fk2 = fk.relative(fp5.getOpposite());
        final BlockState byj2 = bjz.getBlockState(fk2);
        return byj2.isFaceSturdy(bjz, fk2, fp5);
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        BlockState byj3 = this.defaultBlockState();
        final LevelReader bjz4 = bcq.getLevel();
        final BlockPos fk5 = bcq.getClickedPos();
        final Direction[] nearestLookingDirections;
        final Direction[] arr6 = nearestLookingDirections = bcq.getNearestLookingDirections();
        for (final Direction fp10 : nearestLookingDirections) {
            if (fp10.getAxis().isHorizontal()) {
                final Direction fp11 = fp10.getOpposite();
                byj3 = ((AbstractStateHolder<O, BlockState>)byj3).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, fp11);
                if (byj3.canSurvive(bjz4, fk5)) {
                    return byj3;
                }
            }
        }
        return null;
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (fp.getOpposite() == byj1.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING) && !byj1.canSurvive(bjx, fk5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return byj1;
    }
    
    @Override
    public void animateTick(final BlockState byj, final Level bjw, final BlockPos fk, final Random random) {
        final Direction fp6 = byj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING);
        final double double7 = fk.getX() + 0.5;
        final double double8 = fk.getY() + 0.7;
        final double double9 = fk.getZ() + 0.5;
        final double double10 = 0.22;
        final double double11 = 0.27;
        final Direction fp7 = fp6.getOpposite();
        bjw.addParticle(ParticleTypes.SMOKE, double7 + 0.27 * fp7.getStepX(), double8 + 0.22, double9 + 0.27 * fp7.getStepZ(), 0.0, 0.0, 0.0);
        bjw.addParticle(ParticleTypes.FLAME, double7 + 0.27 * fp7.getStepX(), double8 + 0.22, double9 + 0.27 * fp7.getStepZ(), 0.0, 0.0, 0.0);
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return byj.rotate(bsu.getRotation(byj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING)));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(WallTorchBlock.FACING);
    }
    
    static {
        FACING = HorizontalDirectionalBlock.FACING;
        AABBS = Maps.<Direction, Object>newEnumMap(ImmutableMap.<Direction, VoxelShape>of(Direction.NORTH, Block.box(5.5, 3.0, 11.0, 10.5, 13.0, 16.0), Direction.SOUTH, Block.box(5.5, 3.0, 0.0, 10.5, 13.0, 5.0), Direction.WEST, Block.box(11.0, 3.0, 5.5, 16.0, 13.0, 10.5), Direction.EAST, Block.box(0.0, 3.0, 5.5, 5.0, 13.0, 10.5)));
    }
}
