I was making realization of such feature, easiest way - create temporary invisible fluid wagon if locomotive stopped at fluid based refueling. Make nth tick event to pass fluid from fluid wagon to solid fuel placeholder in locomotive. Then your animations works fine and stable, sadly i cant provide codebase, but iam sure you got what i mean. You can check how to teleport fluid wagon on locomotive in train teleportation mod. Anyway hardest feature would be to check fluid wagon fuel inside value.