Package com.samsthenerd.inline.tooltips
Class CustomTooltipManager
java.lang.Object
com.samsthenerd.inline.tooltips.CustomTooltipManager
An item-less custom tooltip system.
By default Minecraft only supports 3 types of HoverEvent
s:
Text, Item, and Entity (which is kinda just text again). But, Item tooltips
have a pretty good tooltip system with TooltipData
and TooltipComponent
s.
Unfortunately, using those requires adding a new item, which is rather inconvenient, so
instead we hijack an arbitrary vanilla item to throw our tooltip system on.
You can use these tooltips in hover events by making an item based hover event
out of the dummy itemstack from getForTooltip(CustomTooltipProvider, Object)
.
Note that this isn't necessarily a part of the core Inline API, just a useful system used for the built in player facing features.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Makes a tooltip out of some arbitrary data of type T. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> net.minecraft.item.ItemStack
getForTooltip
(CustomTooltipManager.CustomTooltipProvider<T> provider, T content) Gets a dummy itemstack hijacked with the data to display the tooltip provided by the provider for the given content.getProvider
(net.minecraft.item.ItemStack stack) static <T> Optional<net.minecraft.client.item.TooltipData>
getTooltipData
(net.minecraft.item.ItemStack stack) static <T> List<net.minecraft.text.Text>
getTooltipText
(net.minecraft.item.ItemStack stack) static <T> CustomTooltipManager.CustomTooltipProvider<T>
Registers a provider.
-
Field Details
-
HIJACKED_ITEM
public static final net.minecraft.item.Item HIJACKED_ITEM
-
-
Constructor Details
-
CustomTooltipManager
public CustomTooltipManager()
-
-
Method Details
-
getForTooltip
public static <T> net.minecraft.item.ItemStack getForTooltip(CustomTooltipManager.CustomTooltipProvider<T> provider, T content) Gets a dummy itemstack hijacked with the data to display the tooltip provided by the provider for the given content.- Type Parameters:
T
- Type of the content that the provider handles- Parameters:
provider
- A tooltip provider that can handle the given content.content
- Arbitrary data to be handled by the provider.- Returns:
- an itemstack that will have a tooltip given by our provider and content.
-
getProvider
@Nullable public static CustomTooltipManager.CustomTooltipProvider<?> getProvider(net.minecraft.item.ItemStack stack) -
getTooltipText
@Nullable public static <T> List<net.minecraft.text.Text> getTooltipText(net.minecraft.item.ItemStack stack) -
getTooltipData
@Nullable public static <T> Optional<net.minecraft.client.item.TooltipData> getTooltipData(net.minecraft.item.ItemStack stack) -
registerProvider
public static <T> CustomTooltipManager.CustomTooltipProvider<T> registerProvider(CustomTooltipManager.CustomTooltipProvider<T> provider) Registers a provider.- Type Parameters:
T
- type that the provider handles- Parameters:
provider
-- Returns:
- the same provider.
-