Add support for horse-type inventories & refactor sorting system to check "safe" slots for sorting on #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a HorseScreenMixin to handle sorting of horse-type inventories. This caused various issues due to the horse's own armor & saddle slots that required a rework of the sorting slot identification system. It should now be much more robust and work for any kind of container.
Added safe slot detection logic
- Introduced a new getSafeSlots() method that builds a mapping of valid container slot indices.
- Skips slots that can’t hold normal items (e.g. saddle, armor, or other equipment slots).
- Uses slot behavior (canInsert, getMaxItemCount, isEnabled) rather than hardcoding item names.
Refactored core sorting logic
- combineLikeStacks() and sort() now work from the safeSlots list rather than raw index offsets.
- Prevents mismatched clicks caused by filtered slots.
Improved click safety
- Integrated handling for SkippedUnsafeClickException across all operations.
- Automatically clears the cursor and resynchronizes the snapshot after any skipped click.
- Prevents floating stacks under the mouse and desyncs with the actual inventory state.
Enhanced clearMouseStack()
- Now finds the first safe empty slot that can accept the cursor stack.
- Avoids attempting to place items into invalid equipment slots.
Testing
✅ Donkey inventory with equipped saddle and chest — sorts chest slots correctly, saddle untouched.
✅ Mule and horse inventories verified.
✅ Normal chests, player inventory, and modded containers unaffected.
✅ No floating cursor or mismatched stacks.
Impact
This update makes the sorting system significantly more reliable across all container types, especially mixed player + entity inventories.
It also lays groundwork for future mod support — safe-slot detection now adapts automatically to new container layouts without needing hardcoded exclusions.