Class ItemStackedOnOtherEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.ItemStackedOnOtherEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class ItemStackedOnOtherEvent extends net.neoforged.bus.api.Event implements net.neoforged.bus.api.ICancellableEvent

This event provides the functionality of the pair of functions used for the Bundle, in one event:

This event is fired before either of the above are called, when a carried item is clicked on top of another in a GUI slot.

This event (and items stacking on others in general) is fired on both sides, but only on the client in the creative menu.

This event is cancellable. If the event is cancelled, the two vanilla methods described above will not be called. The remaining logic depends on the cancellation result:

  • If it is true, then the container's logic halts, the carried item and the slot will not be swapped, and handling is assumed to have been done by the event listener.
  • If it is false, vanilla processing continues except for the two vanilla methods mentioned above.
  • Field Details

    • carriedItem

      private final ItemStack carriedItem
    • stackedOnItem

      private final ItemStack stackedOnItem
    • slot

      private final Slot slot
    • action

      private final ClickAction action
    • player

      private final Player player
    • carriedSlotAccess

      private final SlotAccess carriedSlotAccess
    • cancelResult

      private boolean cancelResult
  • Constructor Details

  • Method Details

    • getCarriedItem

      public ItemStack getCarriedItem()
      Returns the stack being carried by the mouse, which may be empty.
      Returns:
      the stack being carried by the mouse, which may be empty
    • getStackedOnItem

      public ItemStack getStackedOnItem()
      Returns the stack currently in the slot being clicked on, which may be empty.
      Returns:
      the stack currently in the slot being clicked on, which may be empty
    • getSlot

      public Slot getSlot()
      Returns the slot being clicked on.
      Returns:
      the slot being clicked on
    • getClickAction

      public ClickAction getClickAction()
      Returns the click action being used. The click actions do not necessarily map to specific mouse buttons, as they may be rebound by the client. For default key mappings, the primary click action corresponds to a mouse left-click, and the secondary click action to a mouse right-click.
      Returns:
      the click action being used
    • getPlayer

      public Player getPlayer()
      Returns the player doing the item swap attempt.
      Returns:
      the player doing the item swap attempt
    • getCarriedSlotAccess

      public SlotAccess getCarriedSlotAccess()
      Returns a fake slot allowing the listener to see and change what item is being carried.
      Returns:
      a fake slot allowing the listener to see and change what item is being carried
    • setCancellationResult

      public void setCancellationResult(boolean cancelResult)
      Sets the cancellation result of this event, which is used to determine further processing of the click when this event is cancelled. See the javadocs of this class for more details.
      Parameters:
      cancelResult - the cancel result
      See Also:
    • getCancellationResult

      public boolean getCancellationResult()
      Returns the cancellation result.. This is used only when the event is cancelled; see the javadocs of this class for more details.
      Returns:
      the cancellation result
    • cancelWithResult

      public void cancelWithResult(boolean cancelResult)
      Parameters:
      cancelResult - the cancel result
      See Also: