So at first it was like:
for each planting X/Y position in this square
{
get ray from -up- to the ground
Array(Entity) entities = find all entities that could possibly be hit (broad phase)
for each entity in entities
{
test ray against entity (narrow phase)
if hit
{
set planting Z as the ray endpoint's Z
break;
}
}
}