Interface InlineRenderer<D extends InlineData<D>>
- All Known Implementing Classes:
InlineEntityRenderer
,InlineErrorRenderer
,InlineItemRenderer
,InlineSpriteRenderer
,PlayerHeadRenderer
public interface InlineRenderer<D extends InlineData<D>>
Renders in place of text based on the InlineData attached to the text.
You can either directly implement this interface or build off of an existing
renderer either by inheritance or composition. If you make a new renderer, you'll
want to register it with InlineClientAPI.addRenderer(com.samsthenerd.inline.api.client.InlineRenderer<?>)
.
Inline comes with the following built-in core renderers:
-
InlineSpriteRenderer
: renders a texture, can be a local resource or from a url -
InlineItemRenderer
: renders an itemstack -
InlineEntityRenderer
: renders an entity
Check out PlayerHeadRenderer
for an example of extending by composition and
ModIconData
for an example of re-using an existing renderer by extending the data class.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
A collection of values taken from the text renderer. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionint
Gets the width of the render without doing the rendering.default GlowHandling
getGlowPreference
(D forData) Indicates preferences for how the render system should handle glow effects with this renderer.net.minecraft.util.Identifier
getId()
Gets this renderer's ID.default boolean
handleOwnSizing
(D forData) Indicates if this renderer wants to handle size modifiers on its own.default boolean
handleOwnTransparency
(D forData) Indicates if this renderer will handle transparency/alpha.static boolean
isChatty()
A small helper for checking if this renderer is being called from a chat renderer.static boolean
isFlat
(net.minecraft.client.util.math.MatrixStack matrices, net.minecraft.client.font.TextRenderer.TextLayerType layerType) A helper method for checking if a given rendering environment is for a flat UI, such as in chat, a tooltip, inventory title, or other similar cases.int
render
(D data, net.minecraft.client.gui.DrawContext context, int index, net.minecraft.text.Style style, int codepoint, InlineRenderer.TextRenderingContext trContext) Renders in place of a single codepoint/character based on the data given.
-
Field Details
-
DEFAULT_FONT_COLOR
static final int DEFAULT_FONT_COLOR- See Also:
-
DEFAULT_SHADOW_COLOR
static final int DEFAULT_SHADOW_COLOR- See Also:
-
-
Method Details
-
getId
net.minecraft.util.Identifier getId()Gets this renderer's ID. Used primarily by the InlineData to specify which renderer to use for it.- Returns:
- the id
-
render
int render(D data, net.minecraft.client.gui.DrawContext context, int index, net.minecraft.text.Style style, int codepoint, InlineRenderer.TextRenderingContext trContext) Renders in place of a single codepoint/character based on the data given.- Parameters:
data
- the data to render.context
- aDrawContext
with aMatrixStack
set to the correct position for this character and with aVertexConsumerProvider
for rendering to.index
- the index of this character in the overall string.style
- the style attached to the text.codepoint
- the unicode codepoint for this character.trContext
- a collection of values taken from the text renderer.- Returns:
- the width that this render takes up. more or less corresponds to pixels in the default font.
-
charWidth
Gets the width of the render without doing the rendering.- Parameters:
data
- the data to render.style
- the style attached to the text.codepoint
- the unicode codepoint for this character.- Returns:
- the width that this render takes up. more or less corresponds to pixels in the default font.
-
getGlowPreference
Indicates preferences for how the render system should handle glow effects with this renderer. Glow effects happen when a sign is clicked with a glow ink sac. Vanilla text handles this by rendering text in 8 offsets, doing this with inline renders tends to create a busy z-fighting mess. Instead, the render system can flatten the rendering to create an outline. SeeGlowHandling
for more details.- Parameters:
forData
- incase the handling changes based on data. This should really only be used for returning a cache id in the GlowHandling.- Returns:
- a GlowHandling for if this renderer needs glow help.
-
handleOwnSizing
Indicates if this renderer wants to handle size modifiers on its own. The default handling should be fine for most cases as it simply scales the matrix stack before passing to the renderer.- Parameters:
forData
- incase the handling changes based on data. In the vast majority of cases it shouldn't.
-
handleOwnTransparency
Indicates if this renderer will handle transparency/alpha. Note that the default handling is done withRenderSystem.setShaderColor(float, float, float, float)
.- Parameters:
forData
- incase the handling changes based on data. In the vast majority of cases it shouldn't.
-
isFlat
static boolean isFlat(net.minecraft.client.util.math.MatrixStack matrices, net.minecraft.client.font.TextRenderer.TextLayerType layerType) A helper method for checking if a given rendering environment is for a flat UI, such as in chat, a tooltip, inventory title, or other similar cases.- Parameters:
matrices
- the matrix stack given by the rendering env.layerType
- text layer type for the given env. Can be found withInlineRenderer.TextRenderingContext.layerType()
- Returns:
- if the render context, with the given matrix stack, is flat or not.
-
isChatty
static boolean isChatty()A small helper for checking if this renderer is being called from a chat renderer.NOTE: since this has to check the call stack, it's maybe not the most efficient thing in the world. Try to limit calls to it. Using
isFlat(net.minecraft.client.util.math.MatrixStack, net.minecraft.client.font.TextRenderer.TextLayerType)
can- Returns:
- if this renderer is being called from a chat renderer.
-