Class BlockEntityPreviewProvider

java.lang.Object
com.misterpemodder.shulkerboxtooltip.api.provider.BlockEntityPreviewProvider
All Implemented Interfaces:
PreviewProvider

public class BlockEntityPreviewProvider extends Object implements PreviewProvider

A PreviewProvider that works on items that carries block entity data.

Use/extend this when the target item(s) has the Inventory inside BlockEntityData as created by ContainerHelper.saveAllItems(CompoundTag, NonNullList, HolderLookup.Provider).

Since:
1.3.0
  • Field Details

    • maxInvSize

      @Deprecated(since="4.0.8", forRemoval=true) protected final int maxInvSize
      Deprecated, for removal: This API element is subject to removal in a future version.
      The maximum preview inventory size of the item (maybe lower than the actual inventory size).
    • canUseLootTables

      @Deprecated(since="4.0.8", forRemoval=true) protected final boolean canUseLootTables
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use canUseLootTables() instead.
      If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
    • maxRowSize

      @Deprecated(since="4.0.8", forRemoval=true) protected final int maxRowSize
      Deprecated, for removal: This API element is subject to removal in a future version.
      The maximum number of item stacks to be displayed in a row.
  • Constructor Details

    • BlockEntityPreviewProvider

      public BlockEntityPreviewProvider(int maxInvSize, boolean canUseLootTables)
      Creates a BlockEntityPreviewProvider instance.
      Parameters:
      maxInvSize - The maximum preview inventory size of the item (maybe lower than the actual inventory size). If the inventory size isn't constant, override getInventoryMaxSize(PreviewContext) and use maxInvSize as a default value.
      canUseLootTables - If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
      Since:
      1.3.0
    • BlockEntityPreviewProvider

      public BlockEntityPreviewProvider(int maxInvSize, boolean canUseLootTables, int maxRowSize)
      Creates a BlockEntityPreviewProvider instance.
      Parameters:
      maxInvSize - The maximum preview inventory size of the item (maybe lower than the actual inventory size). If the inventory size isn't constant, override getInventoryMaxSize(PreviewContext) and use maxInvSize as a default value.
      canUseLootTables - If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
      maxRowSize - The maximum number of item stacks to be displayed in a row. If less or equal to zero, defaults to 9.
      Since:
      2.0.0
  • Method Details

    • shouldDisplay

      public boolean shouldDisplay(PreviewContext context)
      Description copied from interface: PreviewProvider
      Queries if the preview window should be displayed for the given context. Should return false if the inventory is empty.
      Specified by:
      shouldDisplay in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      Whether the preview should be displayed.
    • showTooltipHints

      public boolean showTooltipHints(PreviewContext context)
      Description copied from interface: PreviewProvider
      Should hint be shown in the item's tooltip?
      Specified by:
      showTooltipHints in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      whether the hints should be shown.
    • getInventory

      public List<net.minecraft.world.item.ItemStack> getInventory(PreviewContext context)
      Description copied from interface: PreviewProvider
      Fetches the items to be displayed in the preview.
      Specified by:
      getInventory in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      The list of items, may not be null or contain null elements.
    • getInventoryMaxSize

      public int getInventoryMaxSize(PreviewContext context)
      Specified by:
      getInventoryMaxSize in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      The maximum inventory size for the given stack.
    • addTooltip

      public List<net.minecraft.network.chat.Component> addTooltip(PreviewContext context)
      Description copied from interface: PreviewProvider
      Adds lines the stack tooltip. Returned lines are added only if tooltip type is set to MODDED in the config.
      Specified by:
      addTooltip in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      A list of Text components. If empty, no text will be added to the tooltip.
    • getItemCountTooltip

      public static List<net.minecraft.network.chat.Component> getItemCountTooltip(List<net.minecraft.network.chat.Component> tooltip, @Nullable List<net.minecraft.world.item.ItemStack> items)
      Adds the number of items to the passed tooltip, adds 'empty' if there is no items to count.
      Parameters:
      tooltip - The tooltip in which to add the item count.
      items - The list of items to display, may be null or empty.
      Returns:
      The passed tooltip, to allow chaining.
      Since:
      2.0.0
    • getItemListTooltip

      public static List<net.minecraft.network.chat.Component> getItemListTooltip(List<net.minecraft.network.chat.Component> tooltip, @Nullable List<net.minecraft.world.item.ItemStack> items, net.minecraft.network.chat.Style style)
      Adds the number of items to the passed tooltip, adds 'empty' if there is no items to count.
      Parameters:
      tooltip - The tooltip in which to add the item count.
      items - The list of items to display, may be null or empty.
      style - The formatting style of the tooltip.
      Returns:
      The passed tooltip, to allow chaining.
      Since:
      2.0.0
    • getMaxRowSize

      public int getMaxRowSize(PreviewContext context)
      Description copied from interface: PreviewProvider
      The maximum number of item stacks to be displayed in a row.
      Specified by:
      getMaxRowSize in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      the row size, defaults to the max row size in config if 0.
    • canUseLootTables

      public boolean canUseLootTables()
      If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
      Since:
      4.0.8