Class RenderTooltipEvent.GatherComponents
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.client.event.RenderTooltipEvent.GatherComponents
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
- Enclosing class:
RenderTooltipEvent
public static class RenderTooltipEvent.GatherComponents
extends net.neoforged.bus.api.Event
implements net.neoforged.bus.api.ICancellableEvent
Fired when a tooltip gathers the
TooltipComponent
s to be rendered, before any text wrapping or processing.
The list of components and the maximum width of the tooltip can be modified through this event.
This event is cancellable, and does not
.
If this event is cancelled, then the list of components will be empty, causing the tooltip to not be rendered and
the corresponding invalid reference
have a result
RenderTooltipEvent.Pre
and RenderTooltipEvent.Texture
to not be fired.
This event is fired on the main Forge event bus, only on the logical client.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final net.minecraft.world.item.ItemStack
private int
private final int
private final int
private final List
<com.mojang.datafixers.util.Either<net.minecraft.network.chat.FormattedText, net.minecraft.world.inventory.tooltip.TooltipComponent>> -
Constructor Summary
ConstructorsConstructorDescriptionGatherComponents
(net.minecraft.world.item.ItemStack itemStack, int screenWidth, int screenHeight, List<com.mojang.datafixers.util.Either<net.minecraft.network.chat.FormattedText, net.minecraft.world.inventory.tooltip.TooltipComponent>> tooltipElements, int maxWidth) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.item.ItemStack
Returns the item stack which the tooltip is being rendered for, or an empty item stack if there is no associated item stack.int
Returns the maximum width of the tooltip when being rendered.int
Returns the height of the screen.int
Returns the width of the screen.List
<com.mojang.datafixers.util.Either<net.minecraft.network.chat.FormattedText, net.minecraft.world.inventory.tooltip.TooltipComponent>> Returns the modifiable list of elements to be rendered on the tooltip.void
setMaxWidth
(int maxWidth) Sets the maximum width of the tooltip.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled, setCanceled
-
Field Details
-
itemStack
private final net.minecraft.world.item.ItemStack itemStack -
screenWidth
private final int screenWidth -
screenHeight
private final int screenHeight -
tooltipElements
private final List<com.mojang.datafixers.util.Either<net.minecraft.network.chat.FormattedText,net.minecraft.world.inventory.tooltip.TooltipComponent>> tooltipElements -
maxWidth
private int maxWidth
-
-
Constructor Details
-
GatherComponents
@Internal public GatherComponents(net.minecraft.world.item.ItemStack itemStack, int screenWidth, int screenHeight, List<com.mojang.datafixers.util.Either<net.minecraft.network.chat.FormattedText, net.minecraft.world.inventory.tooltip.TooltipComponent>> tooltipElements, int maxWidth)
-
-
Method Details
-
getItemStack
public net.minecraft.world.item.ItemStack getItemStack()Returns the item stack which the tooltip is being rendered for, or an empty item stack if there is no associated item stack.- Returns:
- the item stack which the tooltip is being rendered for, or an empty item stack if there is no associated item stack
-
getScreenWidth
public int getScreenWidth()Returns the width of the screen.. The lines of text within the tooltip are wrapped to be within the screen width, and the tooltip box itself is moved to be within the screen width.- Returns:
- the width of the screen
-
getScreenHeight
public int getScreenHeight()Returns the height of the screen. The tooltip box is moved to be within the screen height.- Returns:
- the height of the screen
-
getTooltipElements
public List<com.mojang.datafixers.util.Either<net.minecraft.network.chat.FormattedText,net.minecraft.world.inventory.tooltip.TooltipComponent>> getTooltipElements()Returns the modifiable list of elements to be rendered on the tooltip. These elements can be either formatted text or custom tooltip components.- Returns:
- the modifiable list of elements to be rendered on the tooltip
-
getMaxWidth
public int getMaxWidth()Returns the maximum width of the tooltip when being rendered.A value of
-1
means an unlimited maximum width. However, an unlimited maximum width will still be wrapped to be within the screen bounds.- Returns:
- the maximum width of the tooltip when being rendered
-
setMaxWidth
public void setMaxWidth(int maxWidth) Sets the maximum width of the tooltip. Use-1
for unlimited maximum width.- Parameters:
maxWidth
- the new maximum width
-