package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.Direction;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
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.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class RedStoneOreBlock extends Block {
    public static final BooleanProperty LIT;
    
    public RedStoneOreBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((StateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, false));
    }
    
    @Override
    public void attack(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec) {
        interact(cfj, bqb, fu);
        super.attack(cfj, bqb, fu, bec);
    }
    
    @Override
    public void stepOn(final Level bqb, final BlockPos fu, final Entity aom) {
        interact(bqb.getBlockState(fu), bqb, fu);
        super.stepOn(bqb, fu, aom);
    }
    
    @Override
    public InteractionResult use(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec, final InteractionHand anf, final BlockHitResult deh) {
        if (bqb.isClientSide) {
            spawnParticles(bqb, fu);
        }
        else {
            interact(cfj, bqb, fu);
        }
        final ItemStack bki8 = bec.getItemInHand(anf);
        if (bki8.getItem() instanceof BlockItem && new BlockPlaceContext(bec, anf, bki8, deh).canPlace()) {
            return InteractionResult.PASS;
        }
        return InteractionResult.SUCCESS;
    }
    
    private static void interact(final BlockState cfj, final Level bqb, final BlockPos fu) {
        spawnParticles(bqb, fu);
        if (!cfj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
            bqb.setBlock(fu, ((StateHolder<O, BlockState>)cfj).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, true), 3);
        }
    }
    
    @Override
    public boolean isRandomlyTicking(final BlockState cfj) {
        return cfj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT);
    }
    
    @Override
    public void randomTick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (cfj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
            zd.setBlock(fu, ((StateHolder<O, BlockState>)cfj).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, false), 3);
        }
    }
    
    @Override
    public void spawnAfterBreak(final BlockState cfj, final Level bqb, final BlockPos fu, final ItemStack bki) {
        super.spawnAfterBreak(cfj, bqb, fu, bki);
        if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, bki) == 0) {
            final int integer6 = 1 + bqb.random.nextInt(5);
            this.popExperience(bqb, fu, integer6);
        }
    }
    
    @Override
    public void animateTick(final BlockState cfj, final Level bqb, final BlockPos fu, final Random random) {
        if (cfj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
            spawnParticles(bqb, fu);
        }
    }
    
    private static void spawnParticles(final Level bqb, final BlockPos fu) {
        final double double3 = 0.5625;
        final Random random5 = bqb.random;
        for (final Direction fz9 : Direction.values()) {
            final BlockPos fu2 = fu.relative(fz9);
            if (!bqb.getBlockState(fu2).isSolidRender(bqb, fu2)) {
                final Direction.Axis a11 = fz9.getAxis();
                final double double4 = (a11 == Direction.Axis.X) ? (0.5 + 0.5625 * fz9.getStepX()) : random5.nextFloat();
                final double double5 = (a11 == Direction.Axis.Y) ? (0.5 + 0.5625 * fz9.getStepY()) : random5.nextFloat();
                final double double6 = (a11 == Direction.Axis.Z) ? (0.5 + 0.5625 * fz9.getStepZ()) : random5.nextFloat();
                bqb.addParticle(DustParticleOptions.REDSTONE, fu.getX() + double4, fu.getY() + double5, fu.getZ() + double6, 0.0, 0.0, 0.0);
            }
        }
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(RedStoneOreBlock.LIT);
    }
    
    static {
        LIT = RedstoneTorchBlock.LIT;
    }
}
