Interface Click

All Known Subinterfaces:
Click.Drag, Click.DropCursor
All Known Implementing Classes:
Click.Double, Click.DropSlot, Click.HotbarSwap, Click.Left, Click.LeftDrag, Click.LeftDropCursor, Click.LeftShift, Click.Middle, Click.MiddleDrag, Click.MiddleDropCursor, Click.OffhandSwap, Click.Right, Click.RightDrag, Click.RightDropCursor, Click.RightShift

A tagged union representing possible clicks from the client.
  • Method Details

    • slot

      default int slot()
      Gets the slot of this click. -999 indicates the click either drops the cursor item in some way (implements Click.DropCursor) or is a drag click, which support multiple slots (implements Click.Drag). Otherwise, this represents a slot inside the relevant inventory, so inventory.getItemStack(click.slot())) will return the "clicked" item.
    • toWindow

      @Internal @NotNull static Click.Window toWindow(@NotNull @NotNull Click click, @Nullable @Nullable Integer containerSize)
      Converts any clicks that are fully within the player inventory into clicks that are considered as being inside the player inventory. This is useful for making click event APIs much less obfuscated due to how the protocol is structured.
      Essentially, if the player has an inventory open but clicks inside their own inventory, the packet sent will be inside the opened inventory but have a slot ID greater than the size of the opened inventory. For cases where this happens, this function will convert it into a click that's considered inside the player inventory instead, adjusting the slot ID as necessary. On the returned Click.Window instance, the boolean field indicates which inventory the click is in (since it was unambiguous previously, but is not now).
      Parameters:
      click - the click to convert
      containerSize - the size of the opened container, or null if the player inventory is open
      Returns:
      the (possibly) converted click
    • fromWindow

      @Internal @NotNull static @NotNull Click fromWindow(@NotNull Click.Window window, @Nullable @Nullable Integer containerSize)
      Converts a click from window-specific context back to "normal" click information.
      This is the inverse of toWindow(Click, Integer); read that for more information
      Parameters:
      window - the click, along with whether or not it was inside the window
      containerSize - the size of the opened container, or null if the player inventory is open
      Returns:
      the (potentially) converted click information