Add support for horse-type inventories & refactor sorting system to check "safe" slots for sorting on#43
Open
kuroneko007 wants to merge 2 commits intoborknbeans:1.21.8from
Open
Conversation
- Replace deprecated key/mouse handlers with KeyInput/Click - Update SortButton to extend PressableWidget and use onPress(AbstractInput) - Adjust mixins for Inventory/Container/Shulker screens to new signatures - Keep button positioning logic the same
…h "safe" slot detection. - Added robust safe-slot mapping system to prevent sorting operations on non-inventory equipment slots (e.g. saddle and armor slots in horse/donkey GUIs). - Reworked combineLikeStacks() and sort() to use safeSlots -> handler index mapping, ensuring snapshot indices always align with actual container slot IDs. - Improved clearMouseStack() to place cursor items only into valid, insertable slots. - Added resilient error handling for skipped/unsafe clicks with automatic mouse clearing and snapshot resync. - Verified: no floating cursor items, no desync, saddle/armor remain untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.