The code works perfectly except that it sometimes fails to spawn sprites. I have tried to fix this by setting other relevant RAM addresses, such as $1A and $210D, and even by setting the layer 1 position difference, $17BD. I've also tried looking at the disassembly but I haven't been able to find anything helpful. I was wondering if anyone has run into a similar issues and what I might be able to do to fix this.
Here is the code, if anyone is curious.
Welp, I'm dumb. I found a patch that fixes this very problem!
Here is a link to the patch if anyone needs it.