    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.Random;
    006
    007    public class BlockRedstoneOre extends Block
    008    {
    009        private boolean glowing;
    010
    011        public BlockRedstoneOre(int par1, int par2, boolean par3)
    012        {
    013            super(par1, par2, Material.rock);
    014
    015            if (par3)
    016            {
    017                this.setTickRandomly(true);
    018            }
    019
    020            this.glowing = par3;
    021        }
    022
    023        /**
    024         * How many world ticks before ticking
    025         */
    026        public int tickRate()
    027        {
    028            return 30;
    029        }
    030
    031        /**
    032         * Called when the block is clicked by a player. Args: x, y, z, entityPlayer
    033         */
    034        public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    035        {
    036            this.glow(par1World, par2, par3, par4);
    037            super.onBlockClicked(par1World, par2, par3, par4, par5EntityPlayer);
    038        }
    039
    040        /**
    041         * Called whenever an entity is walking on top of this block. Args: world, x, y, z, entity
    042         */
    043        public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity par5Entity)
    044        {
    045            this.glow(par1World, par2, par3, par4);
    046            super.onEntityWalking(par1World, par2, par3, par4, par5Entity);
    047        }
    048
    049        /**
    050         * Called upon block activation (right click on the block.)
    051         */
    052        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    053        {
    054            this.glow(par1World, par2, par3, par4);
    055            return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
    056        }
    057
    058        /**
    059         * The redstone ore glows.
    060         */
    061        private void glow(World par1World, int par2, int par3, int par4)
    062        {
    063            this.sparkle(par1World, par2, par3, par4);
    064
    065            if (this.blockID == Block.oreRedstone.blockID)
    066            {
    067                par1World.setBlockWithNotify(par2, par3, par4, Block.oreRedstoneGlowing.blockID);
    068            }
    069        }
    070
    071        /**
    072         * Ticks the block if it's been scheduled
    073         */
    074        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    075        {
    076            if (this.blockID == Block.oreRedstoneGlowing.blockID)
    077            {
    078                par1World.setBlockWithNotify(par2, par3, par4, Block.oreRedstone.blockID);
    079            }
    080        }
    081
    082        /**
    083         * Returns the ID of the items to drop on destruction.
    084         */
    085        public int idDropped(int par1, Random par2Random, int par3)
    086        {
    087            return Item.redstone.shiftedIndex;
    088        }
    089
    090        /**
    091         * Returns the usual quantity dropped by the block plus a bonus of 1 to 'i' (inclusive).
    092         */
    093        public int quantityDroppedWithBonus(int par1, Random par2Random)
    094        {
    095            return this.quantityDropped(par2Random) + par2Random.nextInt(par1 + 1);
    096        }
    097
    098        /**
    099         * Returns the quantity of items to drop on block destruction.
    100         */
    101        public int quantityDropped(Random par1Random)
    102        {
    103            return 4 + par1Random.nextInt(2);
    104        }
    105
    106        /**
    107         * Drops the block items with a specified chance of dropping the specified items
    108         */
    109        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    110        {
    111            super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);
    112
    113            if (this.idDropped(par5, par1World.rand, par7) != this.blockID)
    114            {
    115                int var8 = 1 + par1World.rand.nextInt(5);
    116                this.dropXpOnBlockBreak(par1World, par2, par3, par4, var8);
    117            }
    118        }
    119
    120        @SideOnly(Side.CLIENT)
    121
    122        /**
    123         * A randomly called display update to be able to add particles or other items for display
    124         */
    125        public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    126        {
    127            if (this.glowing)
    128            {
    129                this.sparkle(par1World, par2, par3, par4);
    130            }
    131        }
    132
    133        /**
    134         * The redstone ore sparkles.
    135         */
    136        private void sparkle(World par1World, int par2, int par3, int par4)
    137        {
    138            Random var5 = par1World.rand;
    139            double var6 = 0.0625D;
    140
    141            for (int var8 = 0; var8 < 6; ++var8)
    142            {
    143                double var9 = (double)((float)par2 + var5.nextFloat());
    144                double var11 = (double)((float)par3 + var5.nextFloat());
    145                double var13 = (double)((float)par4 + var5.nextFloat());
    146
    147                if (var8 == 0 && !par1World.isBlockOpaqueCube(par2, par3 + 1, par4))
    148                {
    149                    var11 = (double)(par3 + 1) + var6;
    150                }
    151
    152                if (var8 == 1 && !par1World.isBlockOpaqueCube(par2, par3 - 1, par4))
    153                {
    154                    var11 = (double)(par3 + 0) - var6;
    155                }
    156
    157                if (var8 == 2 && !par1World.isBlockOpaqueCube(par2, par3, par4 + 1))
    158                {
    159                    var13 = (double)(par4 + 1) + var6;
    160                }
    161
    162                if (var8 == 3 && !par1World.isBlockOpaqueCube(par2, par3, par4 - 1))
    163                {
    164                    var13 = (double)(par4 + 0) - var6;
    165                }
    166
    167                if (var8 == 4 && !par1World.isBlockOpaqueCube(par2 + 1, par3, par4))
    168                {
    169                    var9 = (double)(par2 + 1) + var6;
    170                }
    171
    172                if (var8 == 5 && !par1World.isBlockOpaqueCube(par2 - 1, par3, par4))
    173                {
    174                    var9 = (double)(par2 + 0) - var6;
    175                }
    176
    177                if (var9 < (double)par2 || var9 > (double)(par2 + 1) || var11 < 0.0D || var11 > (double)(par3 + 1) || var13 < (double)par4 || var13 > (double)(par4 + 1))
    178                {
    179                    par1World.spawnParticle("reddust", var9, var11, var13, 0.0D, 0.0D, 0.0D);
    180                }
    181            }
    182        }
    183
    184        /**
    185         * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
    186         * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
    187         */
    188        protected ItemStack createStackedBlock(int par1)
    189        {
    190            return new ItemStack(Block.oreRedstone);
    191        }
    192    }