    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class BlockStationary extends BlockFluid
    006    {
    007        protected BlockStationary(int par1, Material par2Material)
    008        {
    009            super(par1, par2Material);
    010            this.setTickRandomly(false);
    011
    012            if (par2Material == Material.lava)
    013            {
    014                this.setTickRandomly(true);
    015            }
    016        }
    017
    018        public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    019        {
    020            return this.blockMaterial != Material.lava;
    021        }
    022
    023        /**
    024         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    025         * their own) Args: x, y, z, neighbor blockID
    026         */
    027        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    028        {
    029            super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
    030
    031            if (par1World.getBlockId(par2, par3, par4) == this.blockID)
    032            {
    033                this.setNotStationary(par1World, par2, par3, par4);
    034            }
    035        }
    036
    037        /**
    038         * Changes the block ID to that of an updating fluid.
    039         */
    040        private void setNotStationary(World par1World, int par2, int par3, int par4)
    041        {
    042            int var5 = par1World.getBlockMetadata(par2, par3, par4);
    043            par1World.editingBlocks = true;
    044            par1World.setBlockAndMetadata(par2, par3, par4, this.blockID - 1, var5);
    045            par1World.markBlocksDirty(par2, par3, par4, par2, par3, par4);
    046            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID - 1, this.tickRate());
    047            par1World.editingBlocks = false;
    048        }
    049
    050        /**
    051         * Ticks the block if it's been scheduled
    052         */
    053        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    054        {
    055            if (this.blockMaterial == Material.lava)
    056            {
    057                int var6 = par5Random.nextInt(3);
    058                int var7;
    059                int var8;
    060
    061                for (var7 = 0; var7 < var6; ++var7)
    062                {
    063                    par2 += par5Random.nextInt(3) - 1;
    064                    ++par3;
    065                    par4 += par5Random.nextInt(3) - 1;
    066                    var8 = par1World.getBlockId(par2, par3, par4);
    067
    068                    if (var8 == 0)
    069                    {
    070                        if (this.isFlammable(par1World, par2 - 1, par3, par4) || this.isFlammable(par1World, par2 + 1, par3, par4) || this.isFlammable(par1World, par2, par3, par4 - 1) || this.isFlammable(par1World, par2, par3, par4 + 1) || this.isFlammable(par1World, par2, par3 - 1, par4) || this.isFlammable(par1World, par2, par3 + 1, par4))
    071                        {
    072                            par1World.setBlockWithNotify(par2, par3, par4, Block.fire.blockID);
    073                            return;
    074                        }
    075                    }
    076                    else if (Block.blocksList[var8].blockMaterial.blocksMovement())
    077                    {
    078                        return;
    079                    }
    080                }
    081
    082                if (var6 == 0)
    083                {
    084                    var7 = par2;
    085                    var8 = par4;
    086
    087                    for (int var9 = 0; var9 < 3; ++var9)
    088                    {
    089                        par2 = var7 + par5Random.nextInt(3) - 1;
    090                        par4 = var8 + par5Random.nextInt(3) - 1;
    091
    092                        if (par1World.isAirBlock(par2, par3 + 1, par4) && this.isFlammable(par1World, par2, par3, par4))
    093                        {
    094                            par1World.setBlockWithNotify(par2, par3 + 1, par4, Block.fire.blockID);
    095                        }
    096                    }
    097                }
    098            }
    099        }
    100
    101        /**
    102         * Checks to see if the block is flammable.
    103         */
    104        private boolean isFlammable(World par1World, int par2, int par3, int par4)
    105        {
    106            return par1World.getBlockMaterial(par2, par3, par4).getCanBurn();
    107        }
    108    }