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.
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.
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.
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.
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.
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.
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 aPosition
enum value from its upper case name.
name
The upper case name of the enum value.
Returns: The corresponding Position
enum value, or null
if no matching value is found.