I have walked through the code and there isn't any max of 54 items for each rarity.
This is the game logic:
1. Start a count at 0.
2. Go through all of the items in the game (this includes all dlc, mods, etc). If that item matches the given rarity (ie: Common) then add that items liklihood to the count.
ex: Spear, rarity Common, liklihood 20, count = 20 (former count + 20)
Hate Stone, rarity Common, liklihood 20, count = 40 (former count + 20)
Amulet of Haste, rarity Uncommon, skipped
3. Once it has cycled through all the games items it has a count which is equal to the sum of all the objects of that rarity. It then generates a random number between 0 and that total count.
4. The game goes through all the items again, if the item matches the supplied rarity it subtracts its liklihood form the random number it generated.
5. Once the random number get to 0 or below it stops and the item it is on is the one that is given.
Now this isn't quite the function I would have written for this (we can certainly come up with examples that do the same in one pass), but it works. The problem prior to 1.7 was that the data type it uses to store the total liklihood wasnt large enough for all the liklihoods added up. Once that number hit its max, no toehr items were counter. This wasnt a problem with the base game, but you could run into it with mods and/or DLC. To fix it we reduced the liklihoods to a tenth of what they were (base liklihood on common went from 400 to 40) so we can now cycle through 10 times as many items.
Mods would also have to be updated to use the same scale or else items from them will drop a lot more frequently than base game items or they run the risk of running out of the count cycle (if they have as many items as the base game).