Class ScrollingInventoryContainer<E>

java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
All Implemented Interfaces:
WidgetScrollBar.IScrollCallback, IContainerButtonClickAcceptorServer<ContainerExtended>, IValueNotifiable, IValueNotifier

public abstract class ScrollingInventoryContainer<E> extends InventoryContainer implements WidgetScrollBar.IScrollCallback
An inventory container that has a scrollbar and searchfield. Terminology: row: The row index from visible elements. elementIndex: The element index in all available elements visible: Currently on-screen by the user, maximum amount of elements is determined by the pageSize filtered: All items that are browsable by the user, might be more than the pageSize allows what leads to a scrollbar. unfiltered: All items, pattern searching will happen in this list.
  • Constructor Details

    • ScrollingInventoryContainer

      public ScrollingInventoryContainer(@Nullable net.minecraft.world.inventory.MenuType<?> type, int id, net.minecraft.world.entity.player.Inventory playerInventory, net.minecraft.world.Container inventory, List<E> items, ScrollingInventoryContainer.IItemPredicate<E> filterer)
  • Method Details

    • getUnfilteredItems

      protected List<E> getUnfilteredItems()
    • getFilteredItems

      protected List<org.apache.commons.lang3.tuple.Pair<Integer,E>> getFilteredItems()
    • getUnfilteredItemCount

      public int getUnfilteredItemCount()
    • getFilteredItemCount

      public int getFilteredItemCount()
    • getFirstElement

      public int getFirstElement()
    • getColumns

      public int getColumns()
      Returns:
      The maximum amount of columns to show.
    • getScrollStepSize

      public int getScrollStepSize()
      Returns:
      The stepsize for scrolling.
    • onScroll

      public void onScroll(int firstRow)
      Specified by:
      onScroll in interface WidgetScrollBar.IScrollCallback
    • getPageSize

      public abstract int getPageSize()
      Returns:
      The allowed page size.
    • enableElementAt

      protected void enableElementAt(int visibleIndex, int elementIndex, E element)
      After scrolling, this will be called to make items visible.
      Parameters:
      visibleIndex - The visible item index.
      elementIndex - The absolute element index.
      element - The element to show.
    • isElementVisible

      public boolean isElementVisible(int row)
      Check if the given element is visible.
      Parameters:
      row - The row the the given element is at.
      Returns:
      If it is visible.
    • getVisibleElement

      public E getVisibleElement(int row)
      Get the currently visible element at the given row.
      Parameters:
      row - The row the the given element is at.
      Returns:
      The elements
    • refreshFilter

      public void refreshFilter()
    • updateFilter

      public void updateFilter(String searchString)
      Update the filtered items.
      Parameters:
      searchString - The input string to search by.
    • filter

      protected List<org.apache.commons.lang3.tuple.Pair<Integer,E>> filter(List<E> input, ScrollingInventoryContainer.IItemPredicate<E> predicate, Pattern pattern)
    • additionalApplies

      protected boolean additionalApplies(E item)
      An additional conditional that can be added for filtering items.
      Parameters:
      item - The item to check.
      Returns:
      If the item should be shown.