yarn icon indicating copy to clipboard operation
yarn copied to clipboard

ScreenHandler.transferSlot -> quickMoveFromSlot

Open Juuxel opened this issue 2 years ago • 0 comments

This is only used for implementing SlotActionType.QUICK_MOVE in internalOnSlotClick, and in all classes where it's overridden, it implements the quick move logic. The int index parameter is the index of the slot where the items will be transferred out of (if possible).

This refactor could be impactful, but IMO it's needed so people can understand this better. This method should also be documented - especially the ItemStack return value.

Return value (yes, this deserves its own section)

The returned item stack is really weird. The default implementation in ScreenHandler just always returns the original stack in the slot, which causes an infinite loop in internalOnSlotClick (see diagram below). The method is overridden in all ScreenHandler subclasses, however, and there the return value looks like this:

  • If any items were moved out of the slot, it returns the original item stack in the slot.
  • If no items could be moved, it returns ItemStack.EMPTY.

Diagram

If this is unclear (and it probably is), here's a diagram of approximately what happens. This is simplified a bit to fit the diagram, but all the relevant details should be correct.

Note: onSlotClick refers to internalOnSlotClick

diagram of quick moving items

Juuxel avatar Dec 22 '21 15:12 Juuxel