Class GuiSlots

All Implemented Interfaces:
BackgroundRender, ElementEvents, GuiParent<GuiSlots>, TooltipHandler<GuiSlots>

public class GuiSlots extends GuiElement<GuiSlots> implements BackgroundRender
This element is used to manage and render a grid of inventory slots in a GUI. The width and height of this element are automatically constrained based on the slot configuration. However, you can override those constraints, The slot grid will always render in the center of the element nomater the element size.

This can be used to render all slots in a SlotGroup or a sub-set of slots within a group.

Created by brandon3055 on 08/09/2023

  • Field Details

    • ARMOR_SLOTS

      public static final Material[] ARMOR_SLOTS
    • OFF_HAND_SLOT

      public static final Material OFF_HAND_SLOT
  • Constructor Details

    • GuiSlots

      public GuiSlots(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots, int gridColumns)
      Parameters:
      slots - The slot group containing the slots that this element will manage.
      gridColumns - The width of the inventory grid (Typically 9 for standard player or chest inventories)
    • GuiSlots

      public GuiSlots(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots, int firstSlot, int slotCount, int gridColumns)
      Parameters:
      slots - The slot group containing the slots that this element will manage.
      firstSlot - Index of the fist slot within the slot group.
      slotCount - The number of slots that this element will manage.
      gridColumns - The width of the inventory grid (Typically 9 for standard player or chest inventories)
  • Method Details

    • singleSlot

      public static GuiSlots singleSlot(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots)
    • singleSlot

      public static GuiSlots singleSlot(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots, int index)
    • player

      public static GuiSlots.Player player(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots)
    • player

      public static GuiSlots.Player player(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, int hotBarSpacing)
    • playerWithArmor

      public static GuiSlots.PlayerWithArmor playerWithArmor(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots)
    • playerWithArmor

      public static GuiSlots.PlayerWithArmor playerWithArmor(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots, int groupSpacing, boolean slotIcons)
    • playerAllSlots

      public static GuiSlots.PlayerAll playerAllSlots(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots, SlotGroup offhandSlots)
    • playerAllSlots

      public static GuiSlots.PlayerAll playerAllSlots(@NotNull @NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots, SlotGroup offhandSlots, int groupSpacing, boolean slotIcons)
    • setSlotTexture

      public GuiSlots setSlotTexture(Material slotTexture)
      Allows you to use a custom slot texture, The default is the standard vanilla slot.
    • setSlotTexture

      public GuiSlots setSlotTexture(Function<net.minecraft.world.inventory.Slot,Material> slotTexture)
      Allows you to use a custom per-slot slot textures, The default is the standard vanilla texture for all slots.
    • setSlotTextureI

      public GuiSlots setSlotTextureI(Function<Integer,Material> slotTexture)
      Allows you to use a custom per-slot slot textures, The default is the standard vanilla texture for all slots.

      Similar to setSlotTexture(Function) except you are given the index of the slot within the GuiSlots element.

    • setHighlightColour

      public GuiSlots setHighlightColour(int highlightColour)
      Sets a custom slot highlight colour (The highlight you get when your cursor is over a slot.)
    • setHighlightColour

      public GuiSlots setHighlightColour(Function<net.minecraft.world.inventory.Slot,Integer> highlightColour)
      Allows you to set per-slot highlight colours, The integer passed to the function is the index of the slot within the SlotGroup
    • setHighlightColourI

      public GuiSlots setHighlightColourI(Function<Integer,Integer> highlightColour)
      Allows you to set per-slot highlight colours, The integer passed to the function is the index of the slot within the SlotGroup

      Similar to setHighlightColour(Function) except you are given the index of the slot within the GuiSlots element.

    • setEmptyIcon

      public GuiSlots setEmptyIcon(Material texture)
      Applies a single empty slot icon to all slots. Recommended texture size is 16x16
    • setEmptyIcon

      public GuiSlots setEmptyIcon(Function<net.minecraft.world.inventory.Slot,Material> slotIcons)
      Allows you to provide a texture to be rendered in each slot when the slot is empty. Recommended texture size is 16x16
      Parameters:
      slotIcons - A function that is given the slot index within the SlotGroup, and should return a material or null.
    • setEmptyIconI

      public GuiSlots setEmptyIconI(Function<Integer,Material> slotIcons)
      Allows you to provide a texture to be rendered in each slot when the slot is empty. Recommended texture size is 16x16

      Similar to setEmptyIcon(Function) except you are given the index of the slot within the GuiSlots element.

      Parameters:
      slotIcons - A function that is given the slot index within the SlotGroup, and should return a material or null.
    • setSlotOverlay

      public GuiSlots setSlotOverlay(org.apache.logging.log4j.util.TriConsumer<net.minecraft.world.inventory.Slot,Position,GuiRender> slotOverlay)
      Allows you to attach an overlay renderer that will get called for each slot, after all slots have been rendered. This can be used to render pretty much anything you want to overtop the slot.
      Parameters:
      slotOverlay - Render callback providing the slot, screen position of the slot (top-left corner) and the active GuiRender.
    • setSlotOverlayI

      public GuiSlots setSlotOverlayI(org.apache.logging.log4j.util.TriConsumer<Integer,Position,GuiRender> slotOverlay)
      Allows you to attach an overlay renderer that will get called for each slot, after all slots have been rendered. This can be used to render pretty much anything you want to overtop the slot.

      Similar to setSlotOverlay(TriConsumer) except you are given the index of the slot within the GuiSlots element.

      Parameters:
      slotOverlay - Render callback providing the slot, screen position of the slot (top-left corner) and the active GuiRender.
    • setXSlotSpacing

      public GuiSlots setXSlotSpacing(int xSlotSpacing)
    • setYSlotSpacing

      public GuiSlots setYSlotSpacing(int ySlotSpacing)
    • setSlotSpacing

      public GuiSlots setSlotSpacing(int xSlotSpacing, int ySlotSpacing)
    • getBackgroundDepth

      public double getBackgroundDepth()
      Description copied from interface: BackgroundRender
      Specifies the z depth of the background content. After BackgroundRender.renderBackground(GuiRender, double, double, float) is called, the PoseStack will be translated by this amount in the z direction before any assigned child elements are rendered. Recommended minimum depth is 0.01 or 0.035 if this element renders text. (text shadows are rendered with a 0.03 offset)
      Specified by:
      getBackgroundDepth in interface BackgroundRender
      Returns:
      the z height of the background content.
    • tick

      public void tick(double mouseX, double mouseY)
      Description copied from class: GuiElement
      Called every tick to update the element. Note this is called regardless of weather or not the element is actually enabled.
      Overrides:
      tick in class GuiElement<GuiSlots>
      Parameters:
      mouseX - Current mouse X position
      mouseY - Current mouse Y position
    • renderBackground

      public void renderBackground(GuiRender render, double mouseX, double mouseY, float partialTicks)
      Description copied from interface: BackgroundRender
      Used to render content behind this elements child elements. When rendering element content, always use the PoseStack available via the provided GuiRender Where applicable, always use push/pop to ensure the stack is returned to its original state after your rendering is complete.
      Specified by:
      renderBackground in interface BackgroundRender
      Parameters:
      render - Contains gui context information as well as essential render methods/utils including the PoseStack.