VirtualInventoryItemProvider

An ItemProvider that provides the item from a specific slot in the virtual inventory. This can be used to create dynamic GUI elements that reflect the current state of the virtual inventory, allowing you to display items from the inventory in the GUI and have them update automatically when the inventory changes. The slot property can be updated to change which slot's item is being provided, and the provider will refresh to reflect the new slot's item. When clicked, this provider does nothing by default, but it can be overridden to implement custom behavior when the item is interacted with in the GUI.

Parameters

virtualInventory

The VirtualInventory instance that this provider will retrieve items from. This should be the same instance of the virtual inventory that is being used in the associated GUI.

slot

The initial slot index that this provider will retrieve items from. This should be between 0 and size-1 of the virtual inventory. You can change this slot later by setting the slot property.

Constructors

Link copied to clipboard
constructor(virtualInventory: VirtualInventory, slot: Int)

Properties

Link copied to clipboard
var slot: Int

The slot index that this provider retrieves items from in the virtual inventory. This should be between 0 and size-1 of the virtual inventory. When this property is updated, the provider will refresh to reflect the item from the new slot. You can change this slot at any time to have the provider retrieve items from a different slot in the virtual inventory.

Link copied to clipboard

Functions

Link copied to clipboard
open fun destroy()

Cleans up any resources or references when this item provider is removed from the GUI. Subclasses can override this method to perform any necessary cleanup, such as canceling tasks or clearing references.

Link copied to clipboard
open override fun getItem(): ItemStack?

Retrieves the item from the specified slot in the virtual inventory. If the slot index is out of bounds (not between 0 and size-1), this method will return null. Otherwise, it returns a clone of the ItemStack at the specified slot in the virtual inventory, allowing callers to safely modify the returned ItemStack without affecting the inventory's internal state. If the slot is empty (null), this method will also return null.

Link copied to clipboard
open override fun onClick(clickEvent: InventoryClickEvent)

Handles click events for this item provider. This method must be implemented by subclasses to define the behavior when the item is clicked in the GUI.

Link copied to clipboard
fun refresh()

Refreshes the item in the GUI. This method can be called by subclasses to update the displayed item after changes. It checks if the GUI reference is initialized and if the inventory slot is valid before attempting to refresh.

Link copied to clipboard
fun setGuiData(gui: Gui, slot: Int)

Sets the GUI reference and inventory slot for this item provider. This should be called by the GUI when adding this item provider to it.