I think the basis of Castaneda's writings was taken from deep research of his own on metaphysical and esoteric ideas, his imagination and possibly some unconscious channeling, and very real people he met that taught him throughout his life. Two of his teachers (and I'm sure there were more) were (for a brief period of time) spent with Lord Pentland and a much longer period of time spent with Howard Y. Lee.
From Lord Pentland he probably incorporated many of Gurdjieff's psychological ideas into his writings concerning 'the warrior' and from Howard Y. Lee he probably got his ideas regarding energy and energy bodies. In a sense I guess you can say that what he wrote paralleled Gurdieff's ideas in many ways but viewed it from an energetic perspective and not from a linear intellectual one such as the the ray of creation, hydrogens, etc. Imo he had the soul of a poet, was a triskster (archetype) comedian, was brilliant and was a great 'liar' and storyteller and if you mix all the above in a blender he came up with his writings that told many an esoteric truth within a fictional framework. I think he borrowed (or stole!) many ideas and experiences from others (but which included his own) to come up with many of his written experiences.
I think that Theodore Illion when writing 'Darkness Over Tibet' did something similar to Castaneda where descriptions of some fourth density realities was incorporated into a fictional narrative including many of his descriptions of Tibet which may have been taken from the writings of Alexandra David-Néel who as I understand it did visit Tibet.
I remember my Gurdjieff teacher at about the time his fourth or fifth book came out (around 1975, 1976) was VERY impressed by his writings but she hoped he wouldn't keep writing books since that might dilute the ideas he was expressing thru fiction. In other words, writing more books (possibly for money) where the fiction might outweigh the truth he wanted to express diluting the truth's impact