The class Block has 2 methods that determine a block's icon.
getIcon(IBlockAccess world, int x, int y, int z, int side);
getIcon(int side, int meta);
The first method gets called in the world, and the second method gets called in inventories.
In the world you can just get the y level and return the texture you want, but you still have to implement the second method or let setTextureName(String) do it for you.
By default when the first method is called it automatically calls the second method, but in this case you have to override it.