package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
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 net.minecraft.world.item.ItemStack;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
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.properties.BooleanProperty;

public class RedStoneOreBlock extends Block {
    public static final BooleanProperty LIT;
    
    public RedStoneOreBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, false));
    }
    
    @Override
    public int getLightEmission(final BlockState byj) {
        return byj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT) ? super.getLightEmission(byj) : 0;
    }
    
    @Override
    public void attack(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj) {
        interact(byj, bjw, fk);
        super.attack(byj, bjw, fk, ayj);
    }
    
    @Override
    public void stepOn(final Level bjw, final BlockPos fk, final Entity akq) {
        interact(bjw.getBlockState(fk), bjw, fk);
        super.stepOn(bjw, fk, akq);
    }
    
    @Override
    public InteractionResult use(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj, final InteractionHand ajk, final BlockHitResult cvg) {
        if (bjw.isClientSide) {
            spawnParticles(bjw, fk);
            return InteractionResult.SUCCESS;
        }
        interact(byj, bjw, fk);
        return InteractionResult.PASS;
    }
    
    private static void interact(final BlockState byj, final Level bjw, final BlockPos fk) {
        spawnParticles(bjw, fk);
        if (!byj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
            bjw.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, true), 3);
        }
    }
    
    @Override
    public void tick(final BlockState byj, final ServerLevel xd, final BlockPos fk, final Random random) {
        if (byj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
            xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, false), 3);
        }
    }
    
    @Override
    public void spawnAfterBreak(final BlockState byj, final Level bjw, final BlockPos fk, final ItemStack ben) {
        super.spawnAfterBreak(byj, bjw, fk, ben);
        if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, ben) == 0) {
            final int integer6 = 1 + bjw.random.nextInt(5);
            this.popExperience(bjw, fk, integer6);
        }
    }
    
    @Override
    public void animateTick(final BlockState byj, final Level bjw, final BlockPos fk, final Random random) {
        if (byj.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
            spawnParticles(bjw, fk);
        }
    }
    
    private static void spawnParticles(final Level bjw, final BlockPos fk) {
        final double double3 = 0.5625;
        final Random random5 = bjw.random;
        for (final Direction fp9 : Direction.values()) {
            final BlockPos fk2 = fk.relative(fp9);
            if (!bjw.getBlockState(fk2).isSolidRender(bjw, fk2)) {
                final Direction.Axis a11 = fp9.getAxis();
                final double double4 = (a11 == Direction.Axis.X) ? (0.5 + 0.5625 * fp9.getStepX()) : random5.nextFloat();
                final double double5 = (a11 == Direction.Axis.Y) ? (0.5 + 0.5625 * fp9.getStepY()) : random5.nextFloat();
                final double double6 = (a11 == Direction.Axis.Z) ? (0.5 + 0.5625 * fp9.getStepZ()) : random5.nextFloat();
                bjw.addParticle(DustParticleOptions.REDSTONE, fk.getX() + double4, fk.getY() + double5, fk.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;
    }
}
