    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.Random;
    006import net.minecraft.block.material.Material;
    007import net.minecraft.entity.Entity;
    008import net.minecraft.entity.player.EntityPlayer;
    009import net.minecraft.item.Item;
    010import net.minecraft.item.ItemStack;
    011import net.minecraft.world.World;
    012
    013public class BlockRedstoneOre extends Block
    014{
    015    private boolean glowing;
    016
    017    public BlockRedstoneOre(int par1, boolean par2)
    018    {
    019        super(par1, Material.rock);
    020
    021        if (par2)
    022        {
    023            this.setTickRandomly(true);
    024        }
    025
    026        this.glowing = par2;
    027    }
    028
    029    /**
    030     * How many world ticks before ticking
    031     */
    032    public int tickRate(World par1World)
    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.setBlock(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.setBlock(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.itemID;
    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 j1 = 1 + par1World.rand.nextInt(5);
    122            this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1);
    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 random = par1World.rand;
    145        double d0 = 0.0625D;
    146
    147        for (int l = 0; l < 6; ++l)
    148        {
    149            double d1 = (double)((float)par2 + random.nextFloat());
    150            double d2 = (double)((float)par3 + random.nextFloat());
    151            double d3 = (double)((float)par4 + random.nextFloat());
    152
    153            if (l == 0 && !par1World.isBlockOpaqueCube(par2, par3 + 1, par4))
    154            {
    155                d2 = (double)(par3 + 1) + d0;
    156            }
    157
    158            if (l == 1 && !par1World.isBlockOpaqueCube(par2, par3 - 1, par4))
    159            {
    160                d2 = (double)(par3 + 0) - d0;
    161            }
    162
    163            if (l == 2 && !par1World.isBlockOpaqueCube(par2, par3, par4 + 1))
    164            {
    165                d3 = (double)(par4 + 1) + d0;
    166            }
    167
    168            if (l == 3 && !par1World.isBlockOpaqueCube(par2, par3, par4 - 1))
    169            {
    170                d3 = (double)(par4 + 0) - d0;
    171            }
    172
    173            if (l == 4 && !par1World.isBlockOpaqueCube(par2 + 1, par3, par4))
    174            {
    175                d1 = (double)(par2 + 1) + d0;
    176            }
    177
    178            if (l == 5 && !par1World.isBlockOpaqueCube(par2 - 1, par3, par4))
    179            {
    180                d1 = (double)(par2 + 0) - d0;
    181            }
    182
    183            if (d1 < (double)par2 || d1 > (double)(par2 + 1) || d2 < 0.0D || d2 > (double)(par3 + 1) || d3 < (double)par4 || d3 > (double)(par4 + 1))
    184            {
    185                par1World.spawnParticle("reddust", d1, d2, d3, 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}