Peculiar behavior when detecting rapidly fired snowball hits

I've made a datapack where you can throw a snowball and it will destroy the block which the snowball hit. It's based on CloudWolf's passenger concept, but I've added a bit of raycasting to make block detection more reliable.

  • How it's supposed to work: When a snowball hits a block it should destroy that block.

  • What works so far: If I fire snowballs slowly, it works flawlessly. Block is successfully detected and destroyed.

  • What goes wrong: If i stand still, aim at a specific spot, and fire snowballs rapidly (achieved by holding right click), then the snowballs don't break the blocks. After I stop firing, the last fired snowball does break the block at which i was aiming.

Honestly, I have no idea why it goes wrong. Possible points of failure could be transferring momentum to the marker entity, or the recursive nature of the raycast, etc. I've included a zip file of the datapack, made for version 1.20.4.

Continue to help post