Package codechicken.lib.gui.modular
Class ModularGui
java.lang.Object
codechicken.lib.gui.modular.ModularGui
- All Implemented Interfaces:
GuiParent<ModularGui>
The modular gui system is built around "Gui Elements" but those elements need to be rendered by a base parent element. That's what this class is.
This class is essentially just a container for the root gui element.
Created by brandon3055 on 18/08/2023
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionModularGui(GuiProvider provider) ModularGui(GuiProvider provider, net.minecraft.client.gui.screens.Screen parentScreen) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(GuiElement<?> child) Adds a new child element to this parent.addChild(Consumer<ModularGui> createChild) This meant to be a convenience method that allows builder style addition of a child element.voidadoptChild(GuiElement<?> child) This method can be used to transfer an already initialized child to this parent element.booleancharTyped(char character, int modifiers) Pass through for the charTyped event.booleandoubledoublecreateRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource buffers) Deprecated.booleannet.minecraft.client.gui.Fontfont()List<GuiElement<?>>GuiElement<?>@NotNull net.minecraft.network.chat.ComponentList<GuiElement<?>>List<GuiElement<?>>int@Nullable net.minecraft.client.gui.screens.ScreenGuiElement<?>getRoot()net.minecraft.client.gui.screens.ScreenReturns the Screen housing thisModularGuiWith custom ModularGui implementations this may be null.GuiElement<?>getSlotHandler(net.minecraft.world.inventory.Slot slot) Returns the gui element responsible for managing a gui slot.Sets up this gui to render as a full screen gui.initStandardGui(int guiWidth, int guiHeight) Sets up this gui to render like any other standards gui with the specified width and height.booleanbooleankeyPressed(int key, int scancode, int modifiers) Pass through for the keyPressed event.booleankeyReleased(int key, int scancode, int modifiers) Pass through for the keyReleased event.net.minecraft.client.Minecraftmc()booleanmouseClicked(double mouseX, double mouseY, int button) Pass through for the mouseClicked event.voidmouseMoved(double mouseX, double mouseY) Pass through for the mouseMoved event.booleanmouseReleased(double mouseX, double mouseY, int button) Pass through for the mouseReleased event.booleanmouseScrolled(double mouseX, double mouseY, double scroll) Pass through for the mouseScrolled event.voidvoidMust be called by the screen when this gui is closed.voidonKeyPressPost(org.apache.logging.log4j.util.TriConsumer<Integer, Integer, Integer> postKeyPress) Allows you to attach a callback that will be fired on key press, after it has been handled by the rest of the gui.voidonKeyPressPre(org.apache.logging.log4j.util.TriConsumer<Integer, Integer, Integer> preKeyPress) Allows you to attach a callback that will be fired on key press, before the is handled by the rest of the gui.voidonMouseClickPost(org.apache.logging.log4j.util.TriConsumer<Double, Double, Integer> onClick) Allows you to attach a callback that will be fired on mouse click, after the click has been handled by the rest of the gui.voidonMouseClickPre(org.apache.logging.log4j.util.TriConsumer<Double, Double, Integer> onClick) Allows you to attach a callback that will be fired on mouse click, before the click is handled by the rest of the gui.voidAllows you to attach a callback that will be fired when the parent screen is resized.voidonScreenInit(net.minecraft.client.Minecraft mc, net.minecraft.client.gui.Font font, int screenWidth, int screenHeight) Called when the minecraft Screen is initialised or resized.voidAllows you to attach a callback that will be fired at the start of each gui tick.voidremoveChild(GuiElement<?> child) Allows the removal of a child element.voidPrimary render method for ModularGui.booleanbooleanrenderOverlay(GuiRender render, float partialTicks) Handles gui overlay rendering.voidrenderScreenBackground(boolean renderBackground) Enable / disable the default screen background.intintvoidsetCloseOnEscape(boolean closeOnEscape) voidsetCursor(net.minecraft.resources.ResourceLocation cursor) Sets the current mouse cursor.voidsetFloatingItemDisablesToolTips(boolean floatingItemDisablesToolTips) By default, tool tips are disabled while where is a floating item on screen.voidsetGuiTitle(@NotNull net.minecraft.network.chat.Component guiTitle) voidsetJeiHighlightTime(int jeiHighlightTime) voidsetPauseScreen(boolean pauseScreen) voidsetScreen(net.minecraft.client.gui.screens.Screen screen) voidsetSlotHandler(net.minecraft.world.inventory.Slot slot, GuiElement<?> handler) Provides a way to later retrieve the gui element responsible for positioning and rendering a slot.voidsetVanillaSlotRendering(boolean vanillaSlotRendering) By default, modular gui completely overrides vanillas default slot rendering.voidtick()Primary update / tick method.protected voidupdateScreenData(net.minecraft.client.Minecraft mc, net.minecraft.client.gui.Font font, int screenWidth, int screenHeight) booleandoublexMax()doublexMin()doublexSize()doubleyMax()doubleyMin()doubleySize()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface codechicken.lib.gui.modular.lib.geometry.GuiParent
blockMouseOver, get, getValue, isDescendantOf
-
Constructor Details
-
ModularGui
- Parameters:
provider- The gui builder that will be used to construct this modular gui when the screen is initialized.
-
ModularGui
-
-
Method Details
-
setScreen
public void setScreen(net.minecraft.client.gui.screens.Screen screen) -
getProvider
-
setGuiTitle
public void setGuiTitle(@NotNull @NotNull net.minecraft.network.chat.Component guiTitle) -
getGuiTitle
@NotNull public @NotNull net.minecraft.network.chat.Component getGuiTitle() -
setPauseScreen
public void setPauseScreen(boolean pauseScreen) - Parameters:
pauseScreen- Should a single-player game pause while this screen is open?
-
isPauseScreen
public boolean isPauseScreen() -
setCloseOnEscape
public void setCloseOnEscape(boolean closeOnEscape) -
closeOnEscape
public boolean closeOnEscape() -
renderScreenBackground
public void renderScreenBackground(boolean renderBackground) Enable / disable the default screen background. (Default Enabled) This will be the usual darkened background when in-game, or the dirt background when not in game. -
renderBackground
public boolean renderBackground() -
getRoot
- Returns:
- the root element to which content elements should be added.
-
getDirectRoot
-
initStandardGui
Sets up this gui to render like any other standards gui with the specified width and height. Meaning, the root element (usually the gui background image) will be centered on the screen, and will have the specified width and height.- Parameters:
guiWidth- Gui WidthguiHeight- Gui Height- See Also:
-
initFullscreenGui
Sets up this gui to render as a full screen gui. Meaning the root element's geometry will match that of the underlying minecraft screen.- See Also:
-
setVanillaSlotRendering
public void setVanillaSlotRendering(boolean vanillaSlotRendering) By default, modular gui completely overrides vanillas default slot rendering. This ensures slots render within the depth constraint of the slot element and avoids situations where stacks in slots render on top of other parts of the gui. Meaning you can do things like hide slots by disabling the slot element, Or render elements on top of the slots.This method allow you to return full rendering control to vanilla if you need to for whatever reason.
-
vanillaSlotRendering
public boolean vanillaSlotRendering() -
createRender
@Deprecated public GuiRender createRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource buffers) Deprecated.Create a newGuiRenderfor the current render call.- Parameters:
buffers- BufferSource can be retried fromGuiGraphics- Returns:
- A new
GuiRenderfor the current render call.
-
render
Primary render method for ModularGui. The screen implementing ModularGui must call this in its render method. Followed by therenderOverlay(GuiRender, float)method to handle overlay rendering.- Parameters:
render- GuiRender instance converted from Minecraft'sGuiGraphicsviaGuiRender.convert(GuiGraphics)
-
renderOverlay
Handles gui overlay rendering. This is where things like tool tips are rendered. This should be called immediately afterrender(GuiRender, float)The reason this is split out from
render(GuiRender, float)is to allow stack tool tips to override gui overlay rendering inModularGuiContainer- Parameters:
render- This should be the same render instance that was passed to the previousrender(GuiRender, float)call.- Returns:
- true if an overlay such as a tooltip is currently being drawn.
-
tick
public void tick()Primary update / tick method. Must be called from the tick method of the implementing screen. -
mouseMoved
public void mouseMoved(double mouseX, double mouseY) Pass through for the mouseMoved event. Any screen implementingModularGuimust pass through this event.- Parameters:
mouseX- new mouse X positionmouseY- new mouse Y position
-
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button) Pass through for the mouseClicked event. Any screen implementingModularGuimust pass through this event.- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Button- Returns:
- true if this event has been consumed.
-
mouseReleased
public boolean mouseReleased(double mouseX, double mouseY, int button) Pass through for the mouseReleased event. Any screen implementingModularGuimust pass through this event.- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Button- Returns:
- true if this event has been consumed.
-
keyPressed
public boolean keyPressed(int key, int scancode, int modifiers) Pass through for the keyPressed event. Any screen implementingModularGuimust pass through this event.- Parameters:
key- the keyboard key that was pressed.scancode- the system-specific scancode of the keymodifiers- bitfield describing which modifier keys were held down.- Returns:
- true if this event has been consumed.
-
keyReleased
public boolean keyReleased(int key, int scancode, int modifiers) Pass through for the keyReleased event. Any screen implementingModularGuimust pass through this event.- Parameters:
key- the keyboard key that was released.scancode- the system-specific scancode of the keymodifiers- bitfield describing which modifier keys were held down.- Returns:
- true if this event has been consumed.
-
charTyped
public boolean charTyped(char character, int modifiers) Pass through for the charTyped event. Any screen implementingModularGuimust pass through this event.- Parameters:
character- The character typed.modifiers- bitfield describing which modifier keys were held down.- Returns:
- true if this event has been consumed.
-
mouseScrolled
public boolean mouseScrolled(double mouseX, double mouseY, double scroll) Pass through for the mouseScrolled event. Any screen implementingModularGuimust pass through this event.- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionscroll- Scroll direction and amount- Returns:
- true if this event has been consumed.
-
onGuiClose
public void onGuiClose()Must be called by the screen when this gui is closed. -
updateScreenData
protected void updateScreenData(net.minecraft.client.Minecraft mc, net.minecraft.client.gui.Font font, int screenWidth, int screenHeight) -
onScreenInit
public void onScreenInit(net.minecraft.client.Minecraft mc, net.minecraft.client.gui.Font font, int screenWidth, int screenHeight) Description copied from interface:GuiParentCalled when the minecraft Screen is initialised or resized.- Specified by:
onScreenInitin interfaceGuiParent<ModularGui>- Parameters:
mc- The Minecraft instance.font- The active font.screenWidth- The current guiScaledWidth.screenHeight- The current guiScaledHeight.
-
mc
public net.minecraft.client.Minecraft mc()- Specified by:
mcin interfaceGuiParent<ModularGui>- Returns:
- The minecraft instance.
-
font
public net.minecraft.client.gui.Font font()- Specified by:
fontin interfaceGuiParent<ModularGui>- Returns:
- The active font instance.
-
scaledScreenWidth
public int scaledScreenWidth()- Specified by:
scaledScreenWidthin interfaceGuiParent<ModularGui>- Returns:
- The current gui screen width, As returned by mc.getWindow().getGuiScaledWidth()
-
scaledScreenHeight
public int scaledScreenHeight()- Specified by:
scaledScreenHeightin interfaceGuiParent<ModularGui>- Returns:
- The current gui screen height, As returned by mc.getWindow().getGuiScaledHeight()
-
getModularGui
- Specified by:
getModularGuiin interfaceGuiParent<ModularGui>- Returns:
- the parent ModularGui instance.
-
getScreen
public net.minecraft.client.gui.screens.Screen getScreen()Returns the Screen housing thisModularGuiWith custom ModularGui implementations this may be null. -
getParentScreen
@Nullable public @Nullable net.minecraft.client.gui.screens.Screen getParentScreen() -
getChildren
- Specified by:
getChildrenin interfaceGuiParent<ModularGui>- Returns:
- An unmodifiable list of all assigned child elements assigned to this parent. The list should be sorted in the order they were added.
-
addChild
Description copied from interface:GuiParentAdds a new child element to this parent. You should almost never need to use this because this is handled automatically when an element is created.Note: Due to the way relative coordinates work with the new geometry system, Transferring an element to a different parent can have unpredictable results. Therefor, to help avoid confusion it is not possible to transfer a child to a new parent using this method.
- Specified by:
addChildin interfaceGuiParent<ModularGui>- Parameters:
child- The child element to be added.- See Also:
-
addChild
Description copied from interface:GuiParentThis meant to be a convenience method that allows builder style addition of a child element. I'm not sure how useful it will be yet, so it may or may not stay.- Specified by:
addChildin interfaceGuiParent<ModularGui>- Parameters:
createChild- A consumer that is given this element to be used in the construction of the child element.- Returns:
- The parent element
-
adoptChild
Description copied from interface:GuiParentThis method can be used to transfer an already initialized child to this parent element. This automatically handles removing the element from its previous parent, adds it to this element. Note: This will most likely break any relative constraints on the child's geometry. To fix this you will need to re-apply geometry constraints after the transfer.- Specified by:
adoptChildin interfaceGuiParent<ModularGui>- Parameters:
child- The child element to be adopted.
-
removeChild
Description copied from interface:GuiParentAllows the removal of a child element. Child removal is not instantaneous, Instead all removals occur at the end of the current screen thick. This is to avoid any possible concurrency issues.- Specified by:
removeChildin interfaceGuiParent<ModularGui>- Parameters:
child- The child element to be removed.
-
xMin
public double xMin()- Specified by:
xMinin interfaceGuiParent<ModularGui>- Returns:
- The position of the Left edge of this element.
-
xMax
public double xMax()- Specified by:
xMaxin interfaceGuiParent<ModularGui>- Returns:
- The position of the Right edge of this element.
-
xSize
public double xSize()- Specified by:
xSizein interfaceGuiParent<ModularGui>- Returns:
- The Width of this element.
-
yMin
public double yMin()- Specified by:
yMinin interfaceGuiParent<ModularGui>- Returns:
- The position of the Top edge of this element.
-
yMax
public double yMax()- Specified by:
yMaxin interfaceGuiParent<ModularGui>- Returns:
- The position of the Bottom edge of this element.
-
ySize
public double ySize()- Specified by:
ySizein interfaceGuiParent<ModularGui>- Returns:
- The Height of this element.
-
computeMouseX
public double computeMouseX() -
computeMouseY
public double computeMouseY() -
setSlotHandler
Provides a way to later retrieve the gui element responsible for positioning and rendering a slot. -
getSlotHandler
Returns the gui element responsible for managing a gui slot. -
setCursor
public void setCursor(net.minecraft.resources.ResourceLocation cursor) Sets the current mouse cursor. The cursor is reset at the end of each UI tick so this must be set every tick for as long as you want your custom cursor to be active. -
setFloatingItemDisablesToolTips
public void setFloatingItemDisablesToolTips(boolean floatingItemDisablesToolTips) By default, tool tips are disabled while where is a floating item on screen. This can be used to re-enable them. -
doesFloatingItemDisableToolTips
public boolean doesFloatingItemDisableToolTips() -
getJeiExclusions
-
getJeiDropTargets
-
setJeiHighlightTime
public void setJeiHighlightTime(int jeiHighlightTime) -
getJeiHighlightTime
public int getJeiHighlightTime() -
onTick
Allows you to attach a callback that will be fired at the start of each gui tick. -
onResize
Allows you to attach a callback that will be fired when the parent screen is resized. -
onClose
-
onMouseClickPre
public void onMouseClickPre(org.apache.logging.log4j.util.TriConsumer<Double, Double, Integer> onClick) Allows you to attach a callback that will be fired on mouse click, before the click is handled by the rest of the gui. -
onMouseClickPost
public void onMouseClickPost(org.apache.logging.log4j.util.TriConsumer<Double, Double, Integer> onClick) Allows you to attach a callback that will be fired on mouse click, after the click has been handled by the rest of the gui. Will only be fired if the event was not consumed by an element. -
onKeyPressPre
public void onKeyPressPre(org.apache.logging.log4j.util.TriConsumer<Integer, Integer, Integer> preKeyPress) Allows you to attach a callback that will be fired on key press, before the is handled by the rest of the gui. -
onKeyPressPost
public void onKeyPressPost(org.apache.logging.log4j.util.TriConsumer<Integer, Integer, Integer> postKeyPress) Allows you to attach a callback that will be fired on key press, after it has been handled by the rest of the gui. Will only be fired if the event was not consumed by an element.
-