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