Fix `[sheet` usage in particle spawner.master
commitbcdd06b6a33822cbb5478c73111b8cbcd293f257
authorAuke Kok <sofar@foo-projects.org>
Wed, 4 Sep 2024 05:54:36 +0000 (3 22:54 -0700)
committerAuke Kok <sofar@foo-projects.org>
Wed, 4 Sep 2024 05:54:36 +0000 (3 22:54 -0700)
tree74b5411d444b95056e665f21e79d163790690753
parent23f6ee25a25378101cf61b63a36ce52e171d7aa5
Fix `[sheet` usage in particle spawner.

This particle spawner creates random 4x4 pixel particles based on the
original texture of the item that is broken by a mech node. It uses the
"sheet" method which it used to split up the original 16x16 texture into
16 subsquares and pick a random one using rng().

Except that rng(N) in lua is a number in the range [1,N]. And if using a
4x4 sheet, the positions have to be [0,3] and not [1,4]. The rng may
therefore be out of bounds and cause a 'tile position' invalid from
imagesource.cpp.

Now, the reason it was most of the times not showing is because the rng
only hits the error case once in a while, so it's entirely possible not
to see this until you play a box that uses mech to break nodes, and the
rng(4) results in `4`.
mods/mech/init.lua