Class GuiSlots
java.lang.Object
codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry<GuiSlots>
codechicken.lib.gui.modular.elements.GuiElement<GuiSlots>
codechicken.lib.gui.modular.elements.GuiSlots
- All Implemented Interfaces:
BackgroundRender,ElementEvents,GuiParent<GuiSlots>,TooltipHandler<GuiSlots>
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordstatic final record -
Field Summary
FieldsFields inherited from class codechicken.lib.gui.modular.elements.GuiElement
hoverTime, initialized -
Constructor Summary
ConstructorsConstructorDescriptionGuiSlots(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots, int gridColumns) GuiSlots(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots, int firstSlot, int slotCount, int gridColumns) -
Method Summary
Modifier and TypeMethodDescriptiondoubleSpecifies the z depth of the background content.static GuiSlots.Playerplayer(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots) static GuiSlots.Playerplayer(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, int hotBarSpacing) static GuiSlots.PlayerAllplayerAllSlots(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots, SlotGroup offhandSlots) static GuiSlots.PlayerAllplayerAllSlots(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots, SlotGroup offhandSlots, int groupSpacing, boolean slotIcons) static GuiSlots.PlayerWithArmorplayerWithArmor(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots) static GuiSlots.PlayerWithArmorplayerWithArmor(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup mainSlots, SlotGroup hotBarSlots, SlotGroup armorSlots, int groupSpacing, boolean slotIcons) voidrenderBackground(GuiRender render, double mouseX, double mouseY, float partialTicks) Used to render content behind this elements child elements.setEmptyIcon(Material texture) Applies a single empty slot icon to all slots.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.setEmptyIconI(Function<Integer, Material> slotIcons) Allows you to provide a texture to be rendered in each slot when the slot is empty.setHighlightColour(int highlightColour) Sets a custom slot highlight colour (The highlight you get when your cursor is over a slot.)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 theSlotGroupsetHighlightColourI(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 theSlotGroupsetSlotOverlay(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.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.setSlotSpacing(int xSlotSpacing, int ySlotSpacing) setSlotTexture(Material slotTexture) Allows you to use a custom slot texture, The default is the standard vanilla slot.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(Function<Integer, Material> slotTexture) Allows you to use a custom per-slot slot textures, The default is the standard vanilla texture for all slots.setXSlotSpacing(int xSlotSpacing) setYSlotSpacing(int ySlotSpacing) static GuiSlotssingleSlot(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots) static GuiSlotssingleSlot(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAccess, SlotGroup slots, int index) voidtick(double mouseX, double mouseY) Called every tick to update the element.Methods inherited from class codechicken.lib.gui.modular.elements.GuiElement
addChild, addJeiDropTargets, addJeiExclusions, adoptChild, applyQueuedChildUpdates, blockMouseEvents, blockMouseOver, bringChildToForeground, font, getChildren, getCombinedElementDepth, getJeiDropConsumer, getModularGui, getParent, getTooltip, getTooltipDelay, hoverTime, initElement, isDescendantOf, isEnabled, isJeiDropTarget, isJeiExcluded, isMouseOver, isOpaque, isRemoved, isTooltipEnabled, jeiExclude, mc, onScreenInit, removeChild, render, renderChild, renderOverlay, scaledScreenHeight, scaledScreenWidth, sendChildToBackground, sendChildToIndex, setEnabled, setEnabled, setEnableToolTip, setJeiDropTarget, setJeiExcluded, setOpaque, setRenderCull, setTooltip, setTooltipDelay, setZStacking, showToolTip, toString, updateMouseOver, updateScreenData, zStackingMethods inherited from class codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry
addBoundsToRect, clearConstraints, clearGeometryCache, constrain, get, getChildBounds, getEnclosingRect, getParent, getPosition, getRectangle, placeInside, placeInside, placeOutside, placeOutside, setHeight, setPos, setSize, setWidth, setXPos, setYPos, strictMode, validate, xCenter, xMax, xMin, xSize, yCenter, yMax, yMin, ySizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface codechicken.lib.gui.modular.lib.ElementEvents
charTyped, charTyped, keyPressed, keyPressed, keyReleased, keyReleased, mouseClicked, mouseClicked, mouseMoved, mouseReleased, mouseReleased, mouseScrolled, mouseScrolledMethods inherited from interface codechicken.lib.gui.modular.lib.geometry.GuiParent
addChild, getValueMethods inherited from interface codechicken.lib.gui.modular.lib.TooltipHandler
renderTooltip, setTooltip, setTooltip, setTooltip, setTooltipSingle, setTooltipSingle
-
Field Details
-
ARMOR_SLOTS
-
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
Allows you to use a custom slot texture, The default is the standard vanilla slot. -
setSlotTexture
Allows you to use a custom per-slot slot textures, The default is the standard vanilla texture for all slots. -
setSlotTextureI
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 theGuiSlotselement. -
setHighlightColour
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 theSlotGroup -
setHighlightColourI
Allows you to set per-slot highlight colours, The integer passed to the function is the index of the slot within theSlotGroupSimilar to
setHighlightColour(Function)except you are given the index of the slot within theGuiSlotselement. -
setEmptyIcon
Applies a single empty slot icon to all slots. Recommended texture size is 16x16 -
setEmptyIcon
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 theSlotGroup, and should return a material or null.
-
setEmptyIconI
Allows you to provide a texture to be rendered in each slot when the slot is empty. Recommended texture size is 16x16Similar to
setEmptyIcon(Function)except you are given the index of the slot within theGuiSlotselement.- Parameters:
slotIcons- A function that is given the slot index within theSlotGroup, 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 theGuiSlotselement.- Parameters:
slotOverlay- Render callback providing the slot, screen position of the slot (top-left corner) and the active GuiRender.
-
setXSlotSpacing
-
setYSlotSpacing
-
setSlotSpacing
-
getBackgroundDepth
public double getBackgroundDepth()Description copied from interface:BackgroundRenderSpecifies the z depth of the background content. AfterBackgroundRender.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:
getBackgroundDepthin interfaceBackgroundRender- Returns:
- the z height of the background content.
-
tick
public void tick(double mouseX, double mouseY) Description copied from class:GuiElementCalled every tick to update the element. Note this is called regardless of weather or not the element is actually enabled.- Overrides:
tickin classGuiElement<GuiSlots>- Parameters:
mouseX- Current mouse X positionmouseY- Current mouse Y position
-
renderBackground
Description copied from interface:BackgroundRenderUsed to render content behind this elements child elements. When rendering element content, always use thePoseStackavailable via the providedGuiRenderWhere applicable, always use push/pop to ensure the stack is returned to its original state after your rendering is complete.- Specified by:
renderBackgroundin interfaceBackgroundRender- Parameters:
render- Contains gui context information as well as essential render methods/utils including the PoseStack.
-