package common.pathfinding;

import common.init.Blocks;
import common.util.BlockPos;
import common.world.Chunk;
import common.world.ChunkCache;
import common.world.IBlockAccess;
import common.world.State;
import common.world.World;

public class PathCache extends ChunkCache implements IBlockAccess
{
    public PathCache(World worldIn, BlockPos posFromIn, BlockPos posToIn)
    {
        super(worldIn, posFromIn, posToIn, 0);
    }

    public State getState(BlockPos pos)
    {
        if (pos.getY() >= 0 && pos.getY() < 512)
        {
            int i = (pos.getX() >> 4) - this.chunkX;
            int j = (pos.getZ() >> 4) - this.chunkZ;

            if (i >= 0 && i < this.chunkArray.length && j >= 0 && j < this.chunkArray[i].length)
            {
                Chunk chunk = this.chunkArray[i][j];

                if (chunk != null)
                {
                    return chunk.getState(pos);
                }
            }
        }

        return Blocks.air.getState();
    }
}
