Item tooltips v1
本页目录
本文对应 1.21.10 现代框架。文档中的接口与配置按当前文档快照核对;完整框架仍在开发验收。接口可编译、配置可解析与游戏内效果验证分别记录。
ADR-046(源码配套资料). Declare item_tooltips_v1 in PresentationProfile.requires and a tooltip domain:
{
"schemaVersion": 1,
"styles": [{
"id": "sample",
"priority": 10,
"match": {"item": "minecraft:stick"},
"titleFormat": "&6{line}",
"lineFormat": "{line}",
"hide": {"prefix": "private:"},
"backgroundColor": "#F0182330",
"borderStartColor": "#FFFFCC55",
"borderEndColor": "#FF446688"
}]
}
Public operations are owner.ui().replaceTooltips(context, domain), upsertTooltip(context, style), removeTooltip(context, id) and clearTooltips(context). They share the existing UI queue and status receipt. Configuration scripts use tooltip:replace / tooltip:upsert with value, tooltip:remove with id, and tooltip:clear. Mutations replace whole style declarations. Existing typed ref/expr bindings may supply configuration values; changing data preserves the behavior runtime.
Rules select by descending explicit priority (−10000 to 10000), then declaration order. match uses the existing item conditions; {} is an explicit fallback matching any nonempty hovered item. A predicate evaluation error stops selection and reports a diagnostic, rather than selecting a fallback. There are at most 64 rules and 64 KiB per resolved domain.
Text fields: stripColors, titleFormat, lineFormat, and hide with prefix, suffix, contains, paired start/end. Hiding runs before visible line numbering. Patterns support {line}, {index}, {name}, {id} and {damage}. Label patterns additionally support {line:0} etc. and {lores}. Inserted native/server text remains literal: placeholders inside item names or lore are never expanded again. & color codes in authored patterns become legacy color sequences; modern rendering converts legacy and RGB sequences into Components. Unchanged native rich text retains its original style.
Hidden patterns match the formatted native text before stripColors is applied, as in V1. For default purple italic lore, a prefix such as &5&oprivate: includes those native styles; stripColors affects the resulting displayed text and does not change matching.
Visual fields:
backgroundColor,borderStartColor,borderEndColor:#RRGGBBor#AARRGGBB.padding:left/top/right/bottom, defaults 3/4/3/4, range 0–256.canvasX/canvasY: optional absolute origins; otherwise the text origin minus padding.background:image,x/y/width/height, optionalsplitU/splitVfor a stretched nine-slice.replaceBackgrounddefaults true when an image is provided.overlays: up to 16 layers using the same texture shape, relative to the canvas.labels: up to 32 entries withx/y/scale/align/texts. Alignment is left/center/right.customTextdefaults true when labels are present and replaces native text drawing; native non-text item components remain.slot:x/y/size/itemSize, optionalfill/emptytexture layers. It draws the hovered item without changing inventory state.
Each image uses exactly one namespaced PNG texture, GIF texture (optional gif:true), or PNG frames array. Animated images accept frameTicks (or per-frame ticks) and loop. Up to 128 images and 32 animations share the existing decoded-pixel/resource budgets. Image clocks survive data-only updates when their identity is unchanged. Nine-slice borders must fit every source frame.
Layout numbers may be literal or {"metric":"tipW"} or {"calc":"add","args":[{"metric":"tipW"},12]}. Metrics: tipX/tipY/tipW/tipH/tipS/tipRealS, canvasW/canvasH, slotW, screenW/screenH. Operations: add/sub/mul/div/min/max, gt/ge/lt/le/eq/ne (0 or 1), and lazy three-argument if. Expressions are limited to depth 8, 128 nodes, finite intermediate results within ±32768; drawing dimensions are 0–4096 and text scale .01–16. This is arithmetic over read-only render metrics, with no Java objects or executable strings. Native positioners and wrapping remain authoritative.
Preparation failures retain the active configuration. Invalid data or unavailable resources suspend stale rendering; successful rebinding restores the current template. Owner close, clear, disconnect and new sessions release the surface and image resources. Frame payloads fence owner and version changes. Original V1 rank/metadata/layout aliases and old Java API calls require R5 conversion; this new schema does not claim direct legacy compatibility. Current verification status is recorded only in delivery-tasks.json.