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(net.minecraft.world.level.storage.ValueOutput, NonNullList).

Since:
1.3.0
  • Constructor Details

    • BlockEntityPreviewProvider

      public BlockEntityPreviewProvider(int defaultMaxInvSize, boolean defaultCanUseLootTables)
      Creates a BlockEntityPreviewProvider instance.
      Parameters:
      defaultMaxInvSize - 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.
      defaultCanUseLootTables - If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
      Since:
      1.3.0
    • BlockEntityPreviewProvider

      public BlockEntityPreviewProvider(int defaultMaxInvSize, boolean defaultCanUseLootTables, int defaultMaxRowSize)
      Creates a BlockEntityPreviewProvider instance.
      Parameters:
      defaultMaxInvSize - 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.
      defaultCanUseLootTables - If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
      defaultMaxRowSize - 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
    • BlockEntityPreviewProvider

      public BlockEntityPreviewProvider(int defaultMaxInvSize, boolean defaultCanUseLootTables, int defaultMaxRowSize, int defaultCompactMaxRowSize)
      Creates a BlockEntityPreviewProvider instance.
      Parameters:
      defaultMaxInvSize - 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.
      defaultCanUseLootTables - If true, previews will not be shown when the LootTable tag inside BlockEntityData is present.
      defaultMaxRowSize - The maximum number of item stacks to be displayed in a row in full preview mode. If less or equal to zero, defaults to 9.
      defaultCompactMaxRowSize - The maximum number of item stacks to be displayed in a row in compact preview mode.
      Since:
      5.2.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)
      Description copied from interface: PreviewProvider
      Returns the maximum amount of slots this preview can display.
      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 in full preview mode.
      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.
    • getCompactMaxRowSize

      public int getCompactMaxRowSize(PreviewContext context)
      Description copied from interface: PreviewProvider
      The maximum number of item stacks to be displayed in a row in compact preview mode.
      Specified by:
      getCompactMaxRowSize in interface PreviewProvider
      Parameters:
      context - The preview context.
      Returns:
      the row size in compact mode, 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.
      Returns:
      whether this container support loot tables.
      Since:
      4.0.8