package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.material.PushReaction;
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.item.BlockPlaceContext;
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.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;

public class EndRodBlock extends DirectionalBlock {
    protected static final VoxelShape Y_AXIS_AABB;
    protected static final VoxelShape Z_AXIS_AABB;
    protected static final VoxelShape X_AXIS_AABB;
    
    protected EndRodBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Direction>setValue((Property<Comparable>)EndRodBlock.FACING, Direction.UP));
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)EndRodBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)EndRodBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)EndRodBlock.FACING, bsu.mirror(byj.<Direction>getValue((Property<Direction>)EndRodBlock.FACING)));
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        switch (byj.<Direction>getValue((Property<Direction>)EndRodBlock.FACING).getAxis()) {
            default: {
                return EndRodBlock.X_AXIS_AABB;
            }
            case Z: {
                return EndRodBlock.Z_AXIS_AABB;
            }
            case Y: {
                return EndRodBlock.Y_AXIS_AABB;
            }
        }
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final Direction fp3 = bcq.getClickedFace();
        final BlockState byj4 = bcq.getLevel().getBlockState(bcq.getClickedPos().relative(fp3.getOpposite()));
        if (byj4.getBlock() == this && byj4.<Comparable>getValue((Property<Comparable>)EndRodBlock.FACING) == fp3) {
            return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)EndRodBlock.FACING, fp3.getOpposite());
        }
        return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)EndRodBlock.FACING, fp3);
    }
    
    @Override
    public void animateTick(final BlockState byj, final Level bjw, final BlockPos fk, final Random random) {
        final Direction fp6 = byj.<Direction>getValue((Property<Direction>)EndRodBlock.FACING);
        final double double7 = fk.getX() + 0.55 - random.nextFloat() * 0.1f;
        final double double8 = fk.getY() + 0.55 - random.nextFloat() * 0.1f;
        final double double9 = fk.getZ() + 0.55 - random.nextFloat() * 0.1f;
        final double double10 = 0.4f - (random.nextFloat() + random.nextFloat()) * 0.4f;
        if (random.nextInt(5) == 0) {
            bjw.addParticle(ParticleTypes.END_ROD, double7 + fp6.getStepX() * double10, double8 + fp6.getStepY() * double10, double9 + fp6.getStepZ() * double10, random.nextGaussian() * 0.005, random.nextGaussian() * 0.005, random.nextGaussian() * 0.005);
        }
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(EndRodBlock.FACING);
    }
    
    @Override
    public PushReaction getPistonPushReaction(final BlockState byj) {
        return PushReaction.NORMAL;
    }
    
    static {
        Y_AXIS_AABB = Block.box(6.0, 0.0, 6.0, 10.0, 16.0, 10.0);
        Z_AXIS_AABB = Block.box(6.0, 6.0, 0.0, 10.0, 10.0, 16.0);
        X_AXIS_AABB = Block.box(0.0, 6.0, 6.0, 16.0, 10.0, 10.0);
    }
}
