001package net.minecraft.block;
002
003import java.util.Random;
004import net.minecraft.block.material.Material;
005import net.minecraft.world.IBlockAccess;
006import net.minecraft.world.World;
007
008public 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 l = par1World.getBlockMetadata(par2, par3, par4);
046        par1World.setBlockAndMetadataWithNotify(par2, par3, par4, this.blockID - 1, l, 2);
047        par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID - 1, this.tickRate(par1World));
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 l = par5Random.nextInt(3);
058            int i1;
059            int j1;
060
061            for (i1 = 0; i1 < l; ++i1)
062            {
063                par2 += par5Random.nextInt(3) - 1;
064                ++par3;
065                par4 += par5Random.nextInt(3) - 1;
066                j1 = par1World.getBlockId(par2, par3, par4);
067
068                if (j1 == 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.func_94575_c(par2, par3, par4, Block.fire.blockID);
073                        return;
074                    }
075                }
076                else if (Block.blocksList[j1].blockMaterial.blocksMovement())
077                {
078                    return;
079                }
080            }
081
082            if (l == 0)
083            {
084                i1 = par2;
085                j1 = par4;
086
087                for (int k1 = 0; k1 < 3; ++k1)
088                {
089                    par2 = i1 + par5Random.nextInt(3) - 1;
090                    par4 = j1 + par5Random.nextInt(3) - 1;
091
092                    if (par1World.isAirBlock(par2, par3 + 1, par4) && this.isFlammable(par1World, par2, par3, par4))
093                    {
094                        par1World.func_94575_c(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}