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