package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
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.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.core.particles.ParticleOptions;
import net.minecraft.world.level.block.state.BlockBehaviour;
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, final ParticleOptions hf) {
        super(c, hf);
        this.registerDefaultState(((StateHolder<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 cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return getShape(cfj);
    }
    
    public static VoxelShape getShape(final BlockState cfj) {
        return WallTorchBlock.AABBS.get(cfj.getValue((Property<Object>)WallTorchBlock.FACING));
    }
    
    @Override
    public boolean canSurvive(final BlockState cfj, final LevelReader bqd, final BlockPos fu) {
        final Direction fz5 = cfj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING);
        final BlockPos fu2 = fu.relative(fz5.getOpposite());
        final BlockState cfj2 = bqd.getBlockState(fu2);
        return cfj2.isFaceSturdy(bqd, fu2, fz5);
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        BlockState cfj3 = this.defaultBlockState();
        final LevelReader bqd4 = bin.getLevel();
        final BlockPos fu5 = bin.getClickedPos();
        final Direction[] nearestLookingDirections;
        final Direction[] arr6 = nearestLookingDirections = bin.getNearestLookingDirections();
        for (final Direction fz10 : nearestLookingDirections) {
            if (fz10.getAxis().isHorizontal()) {
                final Direction fz11 = fz10.getOpposite();
                cfj3 = ((StateHolder<O, BlockState>)cfj3).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, fz11);
                if (cfj3.canSurvive(bqd4, fu5)) {
                    return cfj3;
                }
            }
        }
        return null;
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (fz.getOpposite() == cfj1.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING) && !cfj1.canSurvive(bqc, fu5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return cfj1;
    }
    
    @Override
    public void animateTick(final BlockState cfj, final Level bqb, final BlockPos fu, final Random random) {
        final Direction fz6 = cfj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING);
        final double double7 = fu.getX() + 0.5;
        final double double8 = fu.getY() + 0.7;
        final double double9 = fu.getZ() + 0.5;
        final double double10 = 0.22;
        final double double11 = 0.27;
        final Direction fz7 = fz6.getOpposite();
        bqb.addParticle(ParticleTypes.SMOKE, double7 + 0.27 * fz7.getStepX(), double8 + 0.22, double9 + 0.27 * fz7.getStepZ(), 0.0, 0.0, 0.0);
        bqb.addParticle(this.flameParticle, double7 + 0.27 * fz7.getStepX(), double8 + 0.22, double9 + 0.27 * fz7.getStepZ(), 0.0, 0.0, 0.0);
    }
    
    @Override
    public BlockState rotate(final BlockState cfj, final Rotation cap) {
        return ((StateHolder<O, BlockState>)cfj).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, cap.rotate(cfj.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState cfj, final Mirror bzj) {
        return cfj.rotate(bzj.getRotation(cfj.<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)));
    }
}
