package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.DustParticleOptions;
import java.util.Random;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
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.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class RepeaterBlock extends DiodeBlock {
    public static final BooleanProperty LOCKED;
    public static final IntegerProperty DELAY;
    
    protected RepeaterBlock(final Properties c) {
        super(c);
        this.registerDefaultState((((((StateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)RepeaterBlock.FACING, Direction.NORTH)).setValue((Property<Comparable>)RepeaterBlock.DELAY, 1)).setValue((Property<Comparable>)RepeaterBlock.LOCKED, false)).<Comparable, Boolean>setValue((Property<Comparable>)RepeaterBlock.POWERED, false));
    }
    
    @Override
    public InteractionResult use(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec, final InteractionHand anf, final BlockHitResult deh) {
        if (!bec.abilities.mayBuild) {
            return InteractionResult.PASS;
        }
        bqb.setBlock(fu, ((StateHolder<O, BlockState>)cfj).<Comparable>cycle((Property<Comparable>)RepeaterBlock.DELAY), 3);
        return InteractionResult.sidedSuccess(bqb.isClientSide);
    }
    
    @Override
    protected int getDelay(final BlockState cfj) {
        return cfj.<Integer>getValue((Property<Integer>)RepeaterBlock.DELAY) * 2;
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        final BlockState cfj3 = super.getStateForPlacement(bin);
        return ((StateHolder<O, BlockState>)cfj3).<Comparable, Boolean>setValue((Property<Comparable>)RepeaterBlock.LOCKED, this.isLocked(bin.getLevel(), bin.getClickedPos(), cfj3));
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (!bqc.isClientSide() && fz.getAxis() != cfj1.<Direction>getValue((Property<Direction>)RepeaterBlock.FACING).getAxis()) {
            return ((StateHolder<O, BlockState>)cfj1).<Comparable, Boolean>setValue((Property<Comparable>)RepeaterBlock.LOCKED, this.isLocked(bqc, fu5, cfj1));
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public boolean isLocked(final LevelReader bqd, final BlockPos fu, final BlockState cfj) {
        return this.getAlternateSignal(bqd, fu, cfj) > 0;
    }
    
    @Override
    protected boolean isAlternateInput(final BlockState cfj) {
        return DiodeBlock.isDiode(cfj);
    }
    
    @Override
    public void animateTick(final BlockState cfj, final Level bqb, final BlockPos fu, final Random random) {
        if (!cfj.<Boolean>getValue((Property<Boolean>)RepeaterBlock.POWERED)) {
            return;
        }
        final Direction fz6 = cfj.<Direction>getValue((Property<Direction>)RepeaterBlock.FACING);
        final double double7 = fu.getX() + 0.5 + (random.nextDouble() - 0.5) * 0.2;
        final double double8 = fu.getY() + 0.4 + (random.nextDouble() - 0.5) * 0.2;
        final double double9 = fu.getZ() + 0.5 + (random.nextDouble() - 0.5) * 0.2;
        float float13 = -5.0f;
        if (random.nextBoolean()) {
            float13 = (float)(cfj.<Integer>getValue((Property<Integer>)RepeaterBlock.DELAY) * 2 - 1);
        }
        float13 /= 16.0f;
        final double double10 = float13 * fz6.getStepX();
        final double double11 = float13 * fz6.getStepZ();
        bqb.addParticle(DustParticleOptions.REDSTONE, double7 + double10, double8, double9 + double11, 0.0, 0.0, 0.0);
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(RepeaterBlock.FACING, RepeaterBlock.DELAY, RepeaterBlock.LOCKED, RepeaterBlock.POWERED);
    }
    
    static {
        LOCKED = BlockStateProperties.LOCKED;
        DELAY = BlockStateProperties.DELAY;
    }
}
