Skip to content

Conversation

@kuroneko007
Copy link

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.

- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant