    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        public BlockSand(int par1, int par2, Material par3Material)
    017        {
    018            super(par1, par2, par3Material);
    019        }
    020
    021        /**
    022         * Called whenever the block is added into the world. Args: world, x, y, z
    023         */
    024        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    025        {
    026            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    027        }
    028
    029        /**
    030         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    031         * their own) Args: x, y, z, neighbor blockID
    032         */
    033        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    034        {
    035            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    036        }
    037
    038        /**
    039         * Ticks the block if it's been scheduled
    040         */
    041        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    042        {
    043            if (!par1World.isRemote)
    044            {
    045                this.tryToFall(par1World, par2, par3, par4);
    046            }
    047        }
    048
    049        /**
    050         * If there is space to fall below will start this block falling
    051         */
    052        private void tryToFall(World par1World, int par2, int par3, int par4)
    053        {
    054            if (canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0)
    055            {
    056                byte var8 = 32;
    057
    058                if (!fallInstantly && par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
    059                {
    060                    if (!par1World.isRemote)
    061                    {
    062                        EntityFallingSand var9 = new EntityFallingSand(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), this.blockID, par1World.getBlockMetadata(par2, par3, par4));
    063                        this.func_82520_a(var9);
    064                        par1World.spawnEntityInWorld(var9);
    065                    }
    066                }
    067                else
    068                {
    069                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    070
    071                    while (canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0)
    072                    {
    073                        --par3;
    074                    }
    075
    076                    if (par3 > 0)
    077                    {
    078                        par1World.setBlockWithNotify(par2, par3, par4, this.blockID);
    079                    }
    080                }
    081            }
    082        }
    083
    084        protected void func_82520_a(EntityFallingSand par1EntityFallingSand) {}
    085
    086        /**
    087         * How many world ticks before ticking
    088         */
    089        public int tickRate()
    090        {
    091            return 3;
    092        }
    093
    094        /**
    095         * Checks to see if the sand can fall into the block below it
    096         */
    097        public static boolean canFallBelow(World par0World, int par1, int par2, int par3)
    098        {
    099            int var4 = par0World.getBlockId(par1, par2, par3);
    100
    101            if (var4 == 0)
    102            {
    103                return true;
    104            }
    105            else if (var4 == Block.fire.blockID)
    106            {
    107                return true;
    108            }
    109            else
    110            {
    111                Material var5 = Block.blocksList[var4].blockMaterial;
    112                return var5 == Material.water ? true : var5 == Material.lava;
    113            }
    114        }
    115
    116        public void func_82519_a_(World par1World, int par2, int par3, int par4, int par5) {}
    117    }