Class TGuiGraphics
java.lang.Object
com.thecsdev.commonmc.api.client.gui.render.TGuiGraphics
An extension of the game's
Serves as an abstraction layer over the game's native
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
ConstructorsModifierConstructorDescriptionprotectedTGuiGraphics(net.minecraft.client.gui.GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float deltaTicks) -
Method Summary
Modifier and TypeMethodDescriptionstatic final TGuiGraphicscreateInstance(@NotNull net.minecraft.client.gui.GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float deltaTicks) Creates aTGuiGraphicsinstance that will be used for GUI rendering and drawing.final voiddraw9SlicedTexture(@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 theRenderPipelineof your choosing.final voiddraw9SlicedTexture(@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 voiddrawButton(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted) Draws a button.abstract voiddrawCheckbox(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted, boolean checked) Draws a checkbox.abstract voiddrawGuiSprite(@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 theRenderPipelineof your choosing.final voiddrawGuiSprite(@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.voiddrawMissingNo(int x, int y, int width, int height, int color) Draws the "missing texture" sprite that looks like a magenta-&-black grid.voiddrawOutlineIn(int x, int y, int width, int height, int color) Draws a simple 1-unit thick outline (inwards facing).voiddrawOutlineOut(int x, int y, int width, int height, int color) Draws a simple 1-unit thick outline (outwards facing).final voiddrawRepeatingTexture(@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 theRenderPipelineof your choosing.final voiddrawRepeatingTexture(@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.voiddrawShadow(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 voiddrawTexture(@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 theRenderPipelineof your choosing.final voiddrawTexture(@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 theRenderPipelineof your choosing.final voiddrawTexture(@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 voiddrawTexture(@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 voiddrawToggleButton(int x, int y, int width, int height, int color, boolean enabled, boolean highlighted, boolean toggled) Draws a togglable button.abstract voidfillColor(int x, int y, int width, int height, int color) Fills the given region with a solid rectangular color.final @Nullable TElementReturns theTElementthat is currently being rendered.final floatReturns the "delta-time" for this frame, but in ticks.final intReturns the mouse's X position on the screen, in the game's scaled screen-space coordinates.final intReturns the mouse's Y position on the screen, in the game's scaled screen-space coordinates.final net.minecraft.client.gui.GuiGraphicsExtractorReturns the game's nativeGuiGraphicsExtractor.final net.minecraft.client.MinecraftReturns the game'sMinecraftinstance.final org.joml.Matrix3x2fStackReturns the nativeGuiRenderer'sMatrix3x2fStack.final intReturns the (gui-scaled) height of the game window.final intReturns the (gui-scaled) width of the game window.final voidPops a "scissor" from the game's "scissor stack", effectively disabling the previously pushed scissors.final voidpushScissors(int x, int y, int width, int height) Pushes a "scissor" onto the game's "scissor stack".voidrenderEntity(@NotNull net.minecraft.world.entity.Entity entity, int x, int y, int width, int height, double scale, boolean followsCursor) Renders an entity.voidrenderItem(@NotNull net.minecraft.world.item.ItemStack item, int x, int y, int width, int height) Renders an item.final voidrenderTScreen(@NotNull TScreen screen) Renders aTScreenand all of its children recursively, as well as some additional screen-related stuff like tooltips.
-
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 aTGuiGraphicsinstance that will be used for GUI rendering and drawing.- Parameters:
drawContext- The nativeGuiGraphicsExtractorobject thisTGuiGraphicsis 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 nativeGuiGraphicsExtractor.- 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'sMinecraftinstance. -
getNativeMatrices
@Experimental public final org.joml.Matrix3x2fStack getNativeMatrices()Returns the nativeGuiRenderer'sMatrix3x2fStack. -
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:
-
getCurrentElement
-
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
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
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
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
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'sIdentifier.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'sIdentifier.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 theRenderPipelineof your choosing.- Parameters:
renderPipeline- TheRenderPipelineto use.id- The texture'sIdentifier.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 theRenderPipelineof your choosing.- Parameters:
renderPipeline- TheRenderPipelineto use.id- The texture'sIdentifier.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'sIdentifier.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:
-
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 theRenderPipelineof your choosing.- Parameters:
renderPipeline- TheRenderPipelineto use.id- The sprite'sIdentifier.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:
-
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'sIdentifier.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'sIdentifier.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 theRenderPipelineof your choosing.- Parameters:
renderPipeline- TheRenderPipelineto use.id- The texture'sIdentifier.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 theRenderPipelineof your choosing.- Parameters:
id- The texture'sIdentifier.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- TheItemStackto 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- TheEntityto render.x- The X coordinate.y- The Y coordinate.width- The width.height- The height.scale- The on-screen scale of theEntity.followsCursor- Whether theEntity'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 maythrowwhen attempting to render them. Should this happen, you are to CEASE attempting to render saidEntity. The type ofThrowablesuch entities canthrowcan be literally anything.
-
renderTScreen
Renders aTScreenand all of its children recursively, as well as some additional screen-related stuff like tooltips.- Parameters:
screen- TheTScreento draw.- API Note:
- Not necessary for you to use this. Primarily used by
TScreenWrapperwhen renderingTScreens.
-