Description
TLDR: If an ES Drive is moved repeatedly or placed in any position other than the first, it will get deleted. Client side, the drive will visually appear to be "stuck" in the menu, unable to be picked up or further moved, and when the menu is closed and re-opened, the drive will no longer exist. This includes deletion of ALL items inside the given drive, so this is a potentially very damaging bug (up to 64k+ items deleted at once).
To Reproduce
Steps to reproduce the behavior (seems to occur more than 50% of the time, although not always):
- Place an empty ES System anywhere.
- Place an ES Drive of any size in the menu, in any slot.
- The drive should relocate to the first spot in the menu.
- Pick up and move the drive to any other slot.
Alternatively,
- Place an ES Drive in the first slot of the menu, or shift-click the drive.
- Pick up and move the drive to any other slot.
Upon doing either of these processes, the drive will appear to be "stuck" in the menu, and can no longer be retrieved. Upon closing the GUI, the drive is deleted and no longer accessible in any way.
Expected behavior
Normally I'd expect the drive to still exist ๐
In all seriousness, the drive should automatically be moved to populate the first index in the array, which it does do, once (and only once) if the drive is placed in any spot beyond the first when it is first placed into the system. However, any subsequent attempts will cause this bug instead of relocating it to the first index. Additionally, this bug does not occur at all when using Shift+click to add or remove drives, regardless of how quickly they are clicked (likely because this forces the drive to use the next open index, rather than attempting to force the drive into an index outside the current array bounds).
Possible solutions
Utilizing my personal experience with this sort of bug, as well as having recompiled this exact mod for a previous version to fix the same issue, my possible solutions to fix this bug are:
- Rather than a dynamically sized array, create an array of fixed size 5, such that the sequential order no longer matters.
- This is technically bad practice as the array is then forced to be larger than necessary and may consume additional RAM for each ES System, and is less "efficient" although it prevents this bug.
- Restrict user input to Shift+Click only (or override default left-click behavior to function as a shift-click), as this forces the player to place drives sequentially and can no longer accidentally delete a drive by placing it out of bounds.
- This is an elegant solution as it is equally as accessible to the end user (drives are automatically placed on click), and prevents possible malicious behavior (there is no legitimate reason a player would need to place a drive in any slot other than the first open one, other than to take advantage of this bug and mass delete items), as well as keeps the code relatively efficient.
- Validate placement of drives and relocate them to the first empty index in the array, instead of taking the array index based on user input.
- This is also a relatively elegant solution, but may cause lag as it will require more CPU time to validate each placement; however, this will fix the bug, and prevent malicious behavior, and does not directly prevent the player from moving drives within their inventory (as the second solution does).
Errors
Console error output: https://pastebin.com/bX9jnL4T
TLDR: Index out of bounds, array object placement error.
Screenshots
Reproducing the bug
![image](https://user-images.githubusercontent.com/23245862/146477084-453a31b3-2fd9-49b9-8c7f-2062ac02d22f.png)
After closing and re-opening the drive menu (no drive ๐ข)
![image](https://user-images.githubusercontent.com/23245862/146477106-dc09e077-0a76-4f2a-b77e-b1c428a91f47.png)
Versions
MC: Currently hosting a server on Paper 1.18.1 (ver. git-Paper-71)
Additional context
This should be an admittedly rare bug in normal gameplay, but an accidental placement of a drive from a misclick could result in up to 60,000+ items being deleted with no in-game fix other than spawning the items back in, which is tedious in its best case scenario, and downright impossible in its worst case.
Removing drives in early indexes (eg. removing the leftmost drive[s] and leaving in the rightmost ones) appears to have no effect on the remaining drives, and said drives are properly relocated to earlier indexes upon re-opening the menu. (This is a good thing; but it is seemingly inconsistent with the behavior the bug presents.)
Another interesting side effect of this bug is that while holding several drives, it is in fact possible to retrieve a stuck drive, by merely adding other drives in the proper sequential order until the "stuck" drive is reached (which will expand the bounds of the array such that the drive is now within a proper index). However, if the player is only holding one or two drives and misclicks their valuables into the wrong spot, they'll all be gone forever ๐ข