Archived Legacy DynamicHUD
  • Dynamic HUD
  • Import using Gradle
  • Widgets
    • Adding Widgets
      • TextWidget
      • ItemWidget
      • ArmorWidget
    • Creating your own Widget class
    • Widget class
    • WidgetManager
    • WidgetBox
  • Saving and Loading
    • Saving and Loading
    • Changing save file name and directory
  • Moveable Screen
    • AbstractMoveableScreen
    • Default Moveable Screen
    • Using the default Moveable Screen
    • Creating and using your own MoveableScreen class
  • ContextMenu
    • ContextMenu class
    • ContextMenuOptionsProvider interface
    • DoubleInputScreen
    • DataInputScreen
  • Slider Widget
    • Slider
  • SliderWidgetBuilder
  • ColorPicker
    • ColorGradientPicker
      • ColorPickerButton
      • GradientBox
      • GradientSlider
  • Helpers
    • ColorHelper
    • DrawHelper
    • TextureHelper
Powered by GitBook
On this page
  • TextureHelper
  • Methods:
  • Position
  1. Helpers

TextureHelper

Talks about TextureHelper

TextureHelper

TextureHelper This class extends the DrawContext class and provides several static methods for drawing textures in Minecraft using Fabric.

Methods:

  • drawItemTexture(DrawContext drawContext, ItemStack itemStack, int x, int y)

Draws the texture of an item at the specified coordinates.

Parameter
Description

drawContext

The DrawContext instance used for rendering.

itemStack

The item stack to draw the texture of.

x

The x position to draw at.

y

The y position to draw at.

  • drawMainHandTexture(DrawContext drawContext, MinecraftClient client, int x, int y)

Draws the texture of the item in the player's main hand at the specified coordinates.

Parameter
Description

drawContext

The DrawContext instance used for rendering.

client

The Minecraft client instance.

x

The x position to draw at.

y

The y position to draw at.

  • drawTexture(DrawContext drawContext, Identifier texture, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight)

Draws a texture at the specified coordinates with the specified dimensions.

Parameter
Description

drawContext

The DrawContext instance used for rendering.

texture

The identifier of the texture to draw.

x

The x position to draw at.

y

The y position to draw at.

u

The x coordinate of the top left corner of the region to draw from the texture.

v

The y coordinate of the top left corner of the region to draw from the texture.

width

The width of the region to draw from the texture.

height

The height of the region to draw from the texture.

textureWidth

The width of the entire texture.

textureHeight

The height of the entire texture.

  • drawTexturedRect(DrawContext drawContext, Identifier texture, int x, int y, int u, int v, int width, int height, int color)

Draws a textured rectangle at the specified coordinates with the specified dimensions and color.

Parameter
Description

drawContext

The DrawContext instance used for rendering.

texture

The identifier of the texture to draw.

x

The x position to draw at.

y

The y position to draw at.

u

The x coordinate of the top left corner of the region to draw from the texture.

v

The y coordinate of the top left corner of

  • drawTexturedRect(DrawContext drawContext, Identifier texture, int x, int y, int u, int v, int width, int height, int color)

Draws a textured rectangle at the specified coordinates with the specified dimensions and color.

Parameter
Description

drawContext

The DrawContext instance used for rendering.

texture

The identifier of the texture to draw.

x

The x position to draw at.

y

The y position to draw at.

u

The x coordinate of the top left corner of the region to draw from the texture.

v

The y coordinate of the top left corner of the region to draw from the texture.

width

The width of the region to draw from the texture.

height

The height of the region to draw from the texture.

color

The color to apply to the texture.

  • drawItemTextureWithText(MatrixStack matrices, DrawContext drawContext, ItemRenderer itemRenderer, TextRenderer textRenderer, ItemStack itemStack, int x, int y, String text, int color, Position position,float scale, boolean textBackground)

Draws an item texture with text at the specified coordinates. The text is positioned relative to the item texture according to the specified Position enum value. The text can be scaled and can have a semi-opaque black background if desired.

Parameter
Description

matrices

The matrix stack used for rendering.

drawContext

The DrawContext instance used for rendering.

itemRenderer

The item renderer instance used for rendering.

textRenderer

The text renderer instance used for rendering.

itemStack

The item stack to draw the texture of.

x

The x position to draw at.

y

The y position to draw at.

text

The text to draw.

color

The color to draw the text with.

position

The position of the text relative to the item texture (above, below, left or right).

scale

The scale factor for the text.

textBackground

Whether or not to draw a semi-opaque black background behind the text.

The Position enum is an inner enum of the TextureHelper class. It defines four possible positions for the text relative to the item texture when using the drawItemTextureWithText method: above (ABOVE), below (BELOW), to the left (LEFT), or to the right (RIGHT). The getByUpperCaseName(String name) method can be used to get a Position enum value from its upper case name.

Position

This enum defines four possible positions for the text relative to the item texture when using the drawItemTextureWithText method of the TextureHelper class.

Enum Values:

  • ABOVE: The text is positioned above the item texture.

  • BELOW: The text is positioned below the item texture.

  • LEFT: The text is positioned to the left of the item texture.

  • RIGHT: The text is positioned to the right of the item texture.

Methods:

  • getByUpperCaseName(String name): Returns a Position enum value from its upper case name.

Parameter
Description

name

The upper case name of the enum value.

Returns: The corresponding Position enum value, or null if no matching value is found.

PreviousDrawHelper