Tooltip Library
This mod adds a remote interface for adding custom tooltips and statuses to entities at runtime. Tooltip Library works by using LuaEntity.custom_status, and setting custom entity statuses using this mod will improve comaptibility; however, Tooltip Library automatically adapts to custom statuses set by other mods.
Set Status
To set the custom status of an entity, call the remote interface:
remote.call("tooltip-lib", "set_status", entity, custom_status)
Where:
entityis theLuaEntityfor which to set the custom status.custom_statusis aCustomEntityStatus, ornilto unset the custom status.
Set Tooltip
To add a custom tooltip to an entity, call the remote interface:
remote.call("tooltip-lib", "set_tooltip", entity, name, value)
Where:
entityis theLuaEntityfor which to set the custom status.nameis astring, usually aLocalisedStringkey (e.g."mod-tooltip-name.my-tooltip"), that is the unique identifier for the tooltip. Unlessnameis registered as "value only," the localised value of this string will be displayed as the tooltip key.valueis aLocalisedStringthat is the value displayed for this tooltip, ornilto remove the tooltip.
By default, the localised text of name and value will be formatted and displayed in the standard way for tooltips (i.e. "name: value"), including with the standard font and text color. To display only the value, and without formatting, register the tooltip's name as "value only" (see next section). Note that you can add formatting, icons, and everything else supported by LocalisedString in tooltip text yourself.
Set Value Only Tooltip Name
To register a tooltip name as "value only," call the remote interface:
remote.call("tooltip-lib", "set_value_only_toolip_name", name, is_value_only)
Where:
nameis thestringtooltip name to set (or unset) as "value only."is_value_onlyis abooleanthat determines whether to set or unset thisnameas "value only."
Note that his interface only needs to be called once per name, and not once per entity.
More Information
Implementation
Tooltip Library uses LuaEntity.custom_status under the hood for displaying all custom statuses and custom tooltips. There is almost no performance overhead in this mod; it is mostly event-driven, and at worst, it checks up to two entities per player each tick for entity status changes. Most of the complexity in the implementation comes from the compatibility logic required to work gracefully with other mods that set custom status but that do not use Tooltip Library.
Issues
This is a brand new mod, and should still be considered experimental. Use at your own risk.