    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.Random;
    006import net.minecraft.entity.player.EntityPlayer;
    007import net.minecraft.item.Item;
    008import net.minecraft.world.IBlockAccess;
    009import net.minecraft.world.World;
    010
    011public class BlockRedstoneRepeater extends BlockRedstoneLogic
    012{
    013    /** The offsets for the two torches in redstone repeater blocks. */
    014    public static final double[] repeaterTorchOffset = new double[] { -0.0625D, 0.0625D, 0.1875D, 0.3125D};
    015
    016    /** The states in which the redstone repeater blocks can be. */
    017    private static final int[] repeaterState = new int[] {1, 2, 3, 4};
    018
    019    protected BlockRedstoneRepeater(int par1, boolean par2)
    020    {
    021        super(par1, par2);
    022    }
    023
    024    /**
    025     * Called upon block activation (right click on the block.)
    026     */
    027    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    028    {
    029        int i1 = par1World.getBlockMetadata(par2, par3, par4);
    030        int j1 = (i1 & 12) >> 2;
    031        j1 = j1 + 1 << 2 & 12;
    032        par1World.setBlockMetadataWithNotify(par2, par3, par4, j1 | i1 & 3, 3);
    033        return true;
    034    }
    035
    036    protected int func_94481_j_(int par1)
    037    {
    038        return repeaterState[(par1 & 12) >> 2] * 2;
    039    }
    040
    041    protected BlockRedstoneLogic func_94485_e()
    042    {
    043        return Block.redstoneRepeaterActive;
    044    }
    045
    046    protected BlockRedstoneLogic func_94484_i()
    047    {
    048        return Block.redstoneRepeaterIdle;
    049    }
    050
    051    /**
    052     * Returns the ID of the items to drop on destruction.
    053     */
    054    public int idDropped(int par1, Random par2Random, int par3)
    055    {
    056        return Item.redstoneRepeater.itemID;
    057    }
    058
    059    @SideOnly(Side.CLIENT)
    060
    061    /**
    062     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    063     */
    064    public int idPicked(World par1World, int par2, int par3, int par4)
    065    {
    066        return Item.redstoneRepeater.itemID;
    067    }
    068
    069    /**
    070     * The type of render function that is called for this block
    071     */
    072    public int getRenderType()
    073    {
    074        return 15;
    075    }
    076
    077    public boolean func_94476_e(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    078    {
    079        return this.func_94482_f(par1IBlockAccess, par2, par3, par4, par5) > 0;
    080    }
    081
    082    protected boolean func_94477_d(int par1)
    083    {
    084        return isRedstoneRepeaterBlockID(par1);
    085    }
    086
    087    @SideOnly(Side.CLIENT)
    088
    089    /**
    090     * A randomly called display update to be able to add particles or other items for display
    091     */
    092    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    093    {
    094        if (this.isRepeaterPowered)
    095        {
    096            int l = par1World.getBlockMetadata(par2, par3, par4);
    097            int i1 = getDirection(l);
    098            double d0 = (double)((float)par2 + 0.5F) + (double)(par5Random.nextFloat() - 0.5F) * 0.2D;
    099            double d1 = (double)((float)par3 + 0.4F) + (double)(par5Random.nextFloat() - 0.5F) * 0.2D;
    100            double d2 = (double)((float)par4 + 0.5F) + (double)(par5Random.nextFloat() - 0.5F) * 0.2D;
    101            double d3 = 0.0D;
    102            double d4 = 0.0D;
    103
    104            if (par5Random.nextInt(2) == 0)
    105            {
    106                switch (i1)
    107                {
    108                    case 0:
    109                        d4 = -0.3125D;
    110                        break;
    111                    case 1:
    112                        d3 = 0.3125D;
    113                        break;
    114                    case 2:
    115                        d4 = 0.3125D;
    116                        break;
    117                    case 3:
    118                        d3 = -0.3125D;
    119                }
    120            }
    121            else
    122            {
    123                int j1 = (l & 12) >> 2;
    124
    125                switch (i1)
    126                {
    127                    case 0:
    128                        d4 = repeaterTorchOffset[j1];
    129                        break;
    130                    case 1:
    131                        d3 = -repeaterTorchOffset[j1];
    132                        break;
    133                    case 2:
    134                        d4 = -repeaterTorchOffset[j1];
    135                        break;
    136                    case 3:
    137                        d3 = repeaterTorchOffset[j1];
    138                }
    139            }
    140
    141            par1World.spawnParticle("reddust", d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
    142        }
    143    }
    144
    145    /**
    146     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    147     */
    148    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    149    {
    150        super.breakBlock(par1World, par2, par3, par4, par5, par6);
    151        this.func_94483_i_(par1World, par2, par3, par4);
    152    }
    153}