Class TGuiGraphics

java.lang.Object
com.thecsdev.commonmc.api.client.gui.render.TGuiGraphics

@Environment(CLIENT) public abstract class TGuiGraphics extends Object
An extension of the game's GuiGraphicsExtractor, featuring additional rendering-related tools and utilities.
Serves as an abstraction layer over the game's native GuiGraphicsExtractor.
API Note:
Screen coordinates use in-game units and not native LWJGL/GLFW raw pixels.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    TGuiGraphics(net.minecraft.client.gui.GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float deltaTicks)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final TGuiGraphics
    createInstance(@NotNull net.minecraft.client.gui.GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float deltaTicks)
    Creates a TGuiGraphics instance that will be used for GUI rendering and drawing.
    final void
    draw9SlicedTexture(@NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color, int sliceSize)
    Draws a rectangular 9-slided texture from the loaded resource-packs, using the RenderPipeline of your choosing.
    final void
    draw9SlicedTexture(@NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color, int sliceSize)
    Draws a rectangular 9-slided texture from the loaded resource-packs.
    abstract void
    drawButton(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted)
    Draws a button.
    abstract void
    drawCheckbox(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted, boolean checked)
    Draws a checkbox.
    abstract void
    drawGuiSprite(@NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
    Draws a rectangular sprite using the game's GUI sprite system, using the RenderPipeline of your choosing.
    final void
    drawGuiSprite(@NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
    Draws a rectangular sprite using the game's GUI sprite system.
    void
    drawMissingNo(int x, int y, int width, int height, int color)
    Draws the "missing texture" sprite that looks like a magenta-&-black grid.
    void
    drawOutlineIn(int x, int y, int width, int height, int color)
    Draws a simple 1-unit thick outline (inwards facing).
    void
    drawOutlineOut(int x, int y, int width, int height, int color)
    Draws a simple 1-unit thick outline (outwards facing).
    final void
    drawRepeatingTexture(@NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
    Draws a repeating texture in a given rectangular area, using the RenderPipeline of your choosing.
    final void
    drawRepeatingTexture(@NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
    Draws a repeating texture in a given rectangular area.
    void
    drawShadow(int x, int y, int width, int height, int offsetX, int offsetY, int blurRadius, int spreadRadius, int color, boolean inset)
    Draws a simple shadow effect around the given rectangle.
    abstract void
    drawTexture(@NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float uvX, float uvY, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
    Draws a rectangular texture from the loaded resource-packs, using the RenderPipeline of your choosing.
    final void
    drawTexture(@NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
    Draws a rectangular texture from the loaded resource-packs, using the RenderPipeline of your choosing.
    final void
    drawTexture(@NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float uvX, float uvY, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
    Draws a rectangular texture from the loaded resource-packs.
    final void
    drawTexture(@NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
    Draws a rectangular texture from the loaded resource-packs.
    abstract void
    drawToggleButton(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted, boolean toggled)
    Draws a togglable button.
    abstract void
    fillColor(int x, int y, int width, int height, int color)
    Fills the given region with a solid rectangular color.
    final @Nullable TElement
    Returns the TElement that is currently being rendered.
    final float
    Returns the "delta-time" for this frame, but in ticks.
    final int
    Returns the mouse's X position on the screen, in the game's scaled screen-space coordinates.
    final int
    Returns the mouse's Y position on the screen, in the game's scaled screen-space coordinates.
    final net.minecraft.client.gui.GuiGraphicsExtractor
    Returns the game's native GuiGraphicsExtractor.
    final net.minecraft.client.Minecraft
    Returns the game's Minecraft instance.
    final org.joml.Matrix3x2fStack
    Returns the native GuiRenderer's Matrix3x2fStack.
    final int
    Returns the (gui-scaled) height of the game window.
    final int
    Returns the (gui-scaled) width of the game window.
    final void
    Pops a "scissor" from the game's "scissor stack", effectively disabling the previously pushed scissors.
    final void
    pushScissors(int x, int y, int width, int height)
    Pushes a "scissor" onto the game's "scissor stack".
    void
    renderEntity(@NotNull net.minecraft.world.entity.Entity entity, int x, int y, int width, int height, double scale, boolean followsCursor)
    Renders an entity.
    void
    renderItem(@NotNull net.minecraft.world.item.ItemStack item, int x, int y, int width, int height)
    Renders an item.
    final void
    renderTScreen(@NotNull TScreen screen)
    Renders a TScreen and all of its children recursively, as well as some additional screen-related stuff like tooltips.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TGuiGraphics

      protected TGuiGraphics(net.minecraft.client.gui.GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float deltaTicks)
  • Method Details

    • createInstance

      @Internal public static final TGuiGraphics createInstance(@NotNull @NotNull net.minecraft.client.gui.GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float deltaTicks)
      Creates a TGuiGraphics instance that will be used for GUI rendering and drawing.
      Parameters:
      drawContext - The native GuiGraphicsExtractor object this TGuiGraphics is based on.
      mouseX - The mouse X position. In-game coordinates.
      mouseY - The mouse Y position. In-game coordinates.
      deltaTicks - The rendering delta-time in game ticks.
    • getNative

      @Experimental public final net.minecraft.client.gui.GuiGraphicsExtractor getNative()
      Returns the game's native GuiGraphicsExtractor.
      API Note:
      May be unsafe and unstable to make draw calls directly to the game.
    • getNativeClient

      @Experimental public final net.minecraft.client.Minecraft getNativeClient()
      Returns the game's Minecraft instance.
    • getNativeMatrices

      @Experimental public final org.joml.Matrix3x2fStack getNativeMatrices()
      Returns the native GuiRenderer's Matrix3x2fStack.
    • getMouseX

      public final int getMouseX()
      Returns the mouse's X position on the screen, in the game's scaled screen-space coordinates.
    • getMouseY

      public final int getMouseY()
      Returns the mouse's Y position on the screen, in the game's scaled screen-space coordinates.
    • getDeltaTicks

      public final float getDeltaTicks()
      Returns the "delta-time" for this frame, but in ticks.
    • getScreenWidth

      public final int getScreenWidth()
      Returns the (gui-scaled) width of the game window.
    • getScreenHeight

      public final int getScreenHeight()
      Returns the (gui-scaled) height of the game window.
      See Also:
      • Window.getGuiScaledWidth()
    • getCurrentElement

      @Nullable public final @Nullable TElement getCurrentElement()
      Returns the TElement that is currently being rendered.
      See Also:
      • Window.getGuiScaledHeight()
    • pushScissors

      public final void pushScissors(int x, int y, int width, int height)
      Pushes a "scissor" onto the game's "scissor stack". Scissors allow you to define regions on the screen where rendering will take place. Any draw calls that take place outside the scissor bounds get cut off.
      See Also:
      API Note:
      You must call popScissors() once you're done!
    • popScissors

      public final void popScissors() throws IllegalStateException
      Pops a "scissor" from the game's "scissor stack", effectively disabling the previously pushed scissors.
      Throws:
      IllegalStateException - If the scissor stack is already empty.
      See Also:
    • drawMissingNo

      @Virtual public void drawMissingNo(int x, int y, int width, int height, int color)
      Draws the "missing texture" sprite that looks like a magenta-&-black grid.
      Parameters:
      x - The sprite's X coordinate.
      y - The sprite's Y coordinate.
      width - The sprite's width.
      height - The sprite's height.
      color - The sprite's ARGB color.
    • drawShadow

      @Virtual public void drawShadow(int x, int y, int width, int height, int offsetX, int offsetY, int blurRadius, int spreadRadius, int color, boolean inset)
      Draws a simple shadow effect around the given rectangle.
      Parameters:
      x - Rectangle X coordinate.
      y - Rectangle Y coordinate.
      width - Rectangle width.
      height - Rectangle height.
      color - Shadow ARGB color.
    • fillColor

      public abstract void fillColor(int x, int y, int width, int height, int color)
      Fills the given region with a solid rectangular color.
      Parameters:
      x - The rectangle's start X coordinate.
      y - The rectangle's start Y coordinate.
      width - The rectangle's width.
      height - The rectangle's height.
      color - The rectangle's ARGB color.
    • drawOutlineIn

      @Virtual public void drawOutlineIn(int x, int y, int width, int height, int color)
      Draws a simple 1-unit thick outline (inwards facing).
      Parameters:
      x - Outline X coordinate.
      y - Outline Y coordinate.
      width - Outline width.
      height - Outline height.
      color - Outline ARGB color.
    • drawOutlineOut

      @Virtual public void drawOutlineOut(int x, int y, int width, int height, int color)
      Draws a simple 1-unit thick outline (outwards facing).
      Parameters:
      x - Outline X coordinate.
      y - Outline Y coordinate.
      width - Outline width.
      height - Outline height.
      color - Outline ARGB color.
    • drawTexture

      public final void drawTexture(@NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
      Draws a rectangular texture from the loaded resource-packs.
      Parameters:
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      color - Texture ARGB color. It is recommended to use white (aka -1).
    • drawTexture

      public final void drawTexture(@NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float uvX, float uvY, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
      Draws a rectangular texture from the loaded resource-packs.
      Parameters:
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      uvX - X coordinate on the texture UV coordinates.
      uvY - Y coordinate on the texture UV coordinates.
      uvWidth - Width on the UV coordinates.
      uvHeight - Height on the UV coordinates.
      textureWidth - Texture image width.
      textureHeight - Texture image height.
      color - Texture ARGB color. It is recommended to use white (aka -1).
    • drawTexture

      public final void drawTexture(@NotNull @NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
      Draws a rectangular texture from the loaded resource-packs, using the RenderPipeline of your choosing.
      Parameters:
      renderPipeline - The RenderPipeline to use.
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      color - Texture ARGB color. It is recommended to use white (aka -1).
    • drawTexture

      public abstract void drawTexture(@NotNull @NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float uvX, float uvY, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
      Draws a rectangular texture from the loaded resource-packs, using the RenderPipeline of your choosing.
      Parameters:
      renderPipeline - The RenderPipeline to use.
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      uvX - X coordinate on the texture UV coordinates.
      uvY - Y coordinate on the texture UV coordinates.
      uvWidth - Width on the UV coordinates.
      uvHeight - Height on the UV coordinates.
      textureWidth - Texture image width.
      textureHeight - Texture image height.
      color - Texture ARGB color. It is recommended to use white (aka -1).
    • drawGuiSprite

      public final void drawGuiSprite(@NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
      Draws a rectangular sprite using the game's GUI sprite system.
      Parameters:
      id - The sprite's Identifier.
      x - Sprite X coordinate.
      y - Sprite Y coordinate.
      width - Sprite width.
      height - Sprite height.
      color - Sprite ARGB color. It is recommended to use white (aka -1).
      See Also:
      • AtlasIds.GUI
    • drawGuiSprite

      public abstract void drawGuiSprite(@NotNull @NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, int color)
      Draws a rectangular sprite using the game's GUI sprite system, using the RenderPipeline of your choosing.
      Parameters:
      renderPipeline - The RenderPipeline to use.
      id - The sprite's Identifier.
      x - Sprite X coordinate.
      y - Sprite Y coordinate.
      width - Sprite width.
      height - Sprite height.
      color - Sprite ARGB color. It is recommended to use white (aka -1).
      See Also:
      • AtlasIds.GUI
    • draw9SlicedTexture

      public final void draw9SlicedTexture(@NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color, int sliceSize)
      Draws a rectangular 9-slided texture from the loaded resource-packs.
      Parameters:
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      u - X coordinate on the texture UV coordinates.
      v - Y coordinate on the texture UV coordinates.
      uvWidth - Width on the UV coordinates.
      uvHeight - Height on the UV coordinates.
      textureWidth - Texture image width.
      textureHeight - Texture image height.
      color - Texture ARGB color. It is recommended to use white (aka -1).
      sliceSize - The size of the sliced pieces around the centerpiece.
    • drawRepeatingTexture

      public final void drawRepeatingTexture(@NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
      Draws a repeating texture in a given rectangular area.
      Parameters:
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      u - X coordinate on the texture UV coordinates.
      v - Y coordinate on the texture UV coordinates.
      uvWidth - Width on the UV coordinates.
      uvHeight - Height on the UV coordinates.
      textureWidth - Texture image width.
      textureHeight - Texture image height.
      color - Texture ARGB color. It is recommended to use white (aka -1).
    • draw9SlicedTexture

      public final void draw9SlicedTexture(@NotNull @NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color, int sliceSize)
      Draws a rectangular 9-slided texture from the loaded resource-packs, using the RenderPipeline of your choosing.
      Parameters:
      renderPipeline - The RenderPipeline to use.
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      u - X coordinate on the texture UV coordinates.
      v - Y coordinate on the texture UV coordinates.
      uvWidth - Width on the UV coordinates.
      uvHeight - Height on the UV coordinates.
      textureWidth - Texture image width.
      textureHeight - Texture image height.
      color - Texture ARGB color. It is recommended to use white (aka -1).
      sliceSize - The size of the sliced pieces around the centerpiece.
    • drawRepeatingTexture

      public final void drawRepeatingTexture(@NotNull @NotNull com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline, @NotNull @NotNull net.minecraft.resources.Identifier id, int x, int y, int width, int height, float u, float v, int uvWidth, int uvHeight, int textureWidth, int textureHeight, int color)
      Draws a repeating texture in a given rectangular area, using the RenderPipeline of your choosing.
      Parameters:
      id - The texture's Identifier.
      x - X coordinate on the screen.
      y - Y coordinate on the screen.
      width - Width on the screen.
      height - Height on the screen.
      u - X coordinate on the texture UV coordinates.
      v - Y coordinate on the texture UV coordinates.
      uvWidth - Width on the UV coordinates.
      uvHeight - Height on the UV coordinates.
      textureWidth - Texture image width.
      textureHeight - Texture image height.
      color - Texture ARGB color. It is recommended to use white (aka -1).
    • drawButton

      public abstract void drawButton(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted)
      Draws a button.
      Parameters:
      x - The X coordinate.
      y - The Y coordinate.
      width - The width.
      height - The height.
      color - The texture color. It is recommended to use white (aka -1).
      enabled - Is the button enabled and clickable?
      highlighted - Is the button hovered or selected?
    • drawCheckbox

      public abstract void drawCheckbox(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted, boolean checked)
      Draws a checkbox.
      Parameters:
      x - The X coordinate.
      y - The Y coordinate.
      width - The width.
      height - The height.
      color - The texture color. It is recommended to use white (aka -1).
      enabled - Is the checkbox enabled and clickable?
      highlighted - Is the checkbox hovered or selected?
      checked - Is the checkbox checked?
    • drawToggleButton

      public abstract void drawToggleButton(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted, boolean toggled)
      Draws a togglable button.
      Parameters:
      x - The X coordinate.
      y - The Y coordinate.
      width - The width.
      height - The height.
      color - The texture color. It is recommended to use white (aka -1).
      enabled - Is the checkbox enabled and clickable?
      highlighted - Is the checkbox hovered or selected?
      toggled - Is the button toggled?
    • renderItem

      @Virtual public void renderItem(@NotNull @NotNull net.minecraft.world.item.ItemStack item, int x, int y, int width, int height)
      Renders an item.
      Parameters:
      item - The ItemStack to render.
      x - The X coordinate.
      y - The Y coordinate.
      width - The width.
      height - The height.
    • renderEntity

      @Virtual public void renderEntity(@NotNull @NotNull net.minecraft.world.entity.Entity entity, int x, int y, int width, int height, double scale, boolean followsCursor) throws Exception
      Renders an entity.
      Parameters:
      entity - The Entity to render.
      x - The X coordinate.
      y - The Y coordinate.
      width - The width.
      height - The height.
      scale - The on-screen scale of the Entity.
      followsCursor - Whether the Entity's on-screen rotation follows the mouse cursor.
      Throws:
      Exception - Some entities are incompatible with the idea of being rendered on a GUI screen. Such entities may throw when attempting to render them. Should this happen, you are to CEASE attempting to render said Entity. The type of Throwable such entities can throw can be literally anything.
    • renderTScreen

      @Internal public final void renderTScreen(@NotNull @NotNull TScreen screen)
      Renders a TScreen and all of its children recursively, as well as some additional screen-related stuff like tooltips.
      Parameters:
      screen - The TScreen to draw.
      API Note:
      Not necessary for you to use this. Primarily used by TScreenWrapper when rendering TScreens.