    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class BlockSand extends Block
    006    {
    007        /** Do blocks fall instantly to where they stop or do they fall over time */
    008        public static boolean fallInstantly = false;
    009
    010        public BlockSand(int par1, int par2)
    011        {
    012            super(par1, par2, Material.sand);
    013            this.setCreativeTab(CreativeTabs.tabBlock);
    014        }
    015
    016        /**
    017         * Called whenever the block is added into the world. Args: world, x, y, z
    018         */
    019        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    020        {
    021            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    022        }
    023
    024        /**
    025         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    026         * their own) Args: x, y, z, neighbor blockID
    027         */
    028        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    029        {
    030            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    031        }
    032
    033        /**
    034         * Ticks the block if it's been scheduled
    035         */
    036        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    037        {
    038            if (!par1World.isRemote)
    039            {
    040                this.tryToFall(par1World, par2, par3, par4);
    041            }
    042        }
    043
    044        /**
    045         * If there is space to fall below will start this block falling
    046         */
    047        private void tryToFall(World par1World, int par2, int par3, int par4)
    048        {
    049            if (canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0)
    050            {
    051                byte var8 = 32;
    052
    053                if (!fallInstantly && par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
    054                {
    055                    if (!par1World.isRemote)
    056                    {
    057                        EntityFallingSand var9 = new EntityFallingSand(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), this.blockID);
    058                        par1World.spawnEntityInWorld(var9);
    059                    }
    060                }
    061                else
    062                {
    063                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    064
    065                    while (canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0)
    066                    {
    067                        --par3;
    068                    }
    069
    070                    if (par3 > 0)
    071                    {
    072                        par1World.setBlockWithNotify(par2, par3, par4, this.blockID);
    073                    }
    074                }
    075            }
    076        }
    077
    078        /**
    079         * How many world ticks before ticking
    080         */
    081        public int tickRate()
    082        {
    083            return 3;
    084        }
    085
    086        /**
    087         * Checks to see if the sand can fall into the block below it
    088         */
    089        public static boolean canFallBelow(World par0World, int par1, int par2, int par3)
    090        {
    091            int var4 = par0World.getBlockId(par1, par2, par3);
    092
    093            if (var4 == 0)
    094            {
    095                return true;
    096            }
    097            else if (var4 == Block.fire.blockID)
    098            {
    099                return true;
    100            }
    101            else
    102            {
    103                Material var5 = Block.blocksList[var4].blockMaterial;
    104                return var5 == Material.water ? true : var5 == Material.lava;
    105            }
    106        }
    107    }