feat(tooltip): 实现 Shift 键条件展开工具提示
本提交引入了一个新的客户端用户体验优化功能,用于修改游戏中物品工具提示的显示方式。当玩家查看物品的工具提示时,默认会显示占位符消息“按住 Shift 查看详情...”。按下并 hold 住 Shift 键可揭示完整、详尽的工具提示内容,从而提供整洁有序的物品栏浏览体验。
背景 / 问题:
- Minecraft 中的工具提示可能会变得过于冗长,尤其是在模组环境中,物品通常带有详细描述、附魔信息和模组特定的元数据。
- 杂乱的工具提示会遮挡玩家的视野,使物品栏管理变得繁琐,因为无论是否需要,关键信息始终可见。
- 目前原版或标准 Forge API 中没有切换工具提示或将其隐藏在修饰键后的方法。
实现细节:
- 创建了一个新的事件处理器,监听
ItemTooltipEvent(Forge 用于构建工具提示的 API 事件)。
- 当事件触发时,处理器使用
Screen.hasShiftDown()(客户端侧)检查 Shift 键的状态,以确定玩家在悬停于物品上方时是否按住了该键。
- 如果按键被按下,则将原始未修改的工具提示文本列表(List<Component>)添加到工具提示中,显示所有行的信息。
- 如果按键未被按下,则清除默认工具提示,并将其替换为单行组件:“按住 Shift 查看详情...”。
- 每当玩家在悬停于物品上时按键状态发生变化,工具提示会自动更新并重新渲染。
行为变更:
- 玩家现在可以快速瞥一眼物品而不会被长篇大论的文字淹没。
- 在需要时,完整的工具提示会立即显示,无需额外的按键绑定或配置菜单。
- 占位符文本已本地化,并且可以在未来的更新中进行适配或国际化。
- 此功能适用于所有物品,包括来自其他模组的物品,因为它在通用层面拦截了工具提示事件。
执行的测试:
- 在 Forge 1.20.1 环境下验证,测试对象包括原版物品和模组物品(例如带有附魔的物品、模组装备)。
- 确认 Shift 键检测在所有游戏界面(物品栏、创造模式菜单、容器)中均可靠工作。
- 测试了在鼠标保持在同一物品上时,按下、释放以及再次按下按键时工具提示的响应速度。
- 确保与其他通过调整事件优先级来修改
ItemTooltipEvent 的模组兼容。
附加说明:
- 本模组完全为客户端侧运行,不需要任何服务端安装。
- 使用
Screen.hasShiftDown() 而非 keyBindSneak,以准确反映与 GUI 相关的按键操作,同时不干扰移动控制。
- 未来考虑:添加可配置的按键绑定以切换此行为或自定义占位符消息。
解决:#ISSUE-42(如适用,请替换为实际的问题工单号)
feat(tooltip): Implement conditional tooltip expansion with Shift key
This commit introduces a new client-side quality-of-life feature that
modifies how item tooltips are displayed in the game. When a player is
viewing an item's tooltip, a placeholder message "Hold Shift for
details..." is shown by default. Pressing and holding the Shift key
reveals the full, complete tooltip, providing an organized and clean
inventory browsing experience.
Background / Problem:
- Tooltips in Minecraft can become excessively long, especially in
modded environments where items often carry detailed descriptions,
enchantment information, and mod-specific metadata.
- A cluttered tooltip obstructs the player's view and makes inventory
management cumbersome, as crucial information is always visible
whether needed or not.
- There is currently no vanilla or standard Forge method to toggle
tooltips or hide them behind a modifier key.
Implementation Details:
- Created a new event handler that listens to the
ItemTooltipEvent
(Forge's API event for tooltip construction).
- When the event is triggered, the handler checks the state of the
Shift key using
Screen.hasShiftDown() (client-side) to determine
if the player is holding the key while hovering over the item.
- If the key is pressed, the original, unmodified tooltip text list
(List<Component>) is added to the tooltip, showing every line of
information.
- If the key is not pressed, the default tooltip is cleared and
replaced with a single-line component: "Hold Shift for details...".
- The tooltip is automatically updated and re-rendered each time the
player's key state changes while the item is hovered over.
Changes in Behavior:
- Players can now quickly glance at an item without being overwhelmed
by lengthy text.
- The full tooltip is instantly revealed when needed, without any
additional keybinds or configuration menus.
- The placeholder text is localized and can be adapted or
internationalized by future updates.
- This feature works on all items, including those from other mods,
because it intercepts the tooltip event at a generic level.
Testing Performed:
- Verified on Forge 1.20.1 with both vanilla and modded items (e.g.,
items with enchantments, modded equipment).
- Confirmed that the Shift key detection works reliably in all game
screens (inventory, creative menu, containers).
- Tested the responsiveness of the tooltip when the key is pressed,
released, and pressed again while the mouse remains on the same
item.
- Ensured compatibility with other mods that also modify
ItemTooltipEvent through event priority adjustments.
Additional Notes:
- This mod is fully client-side and does not require any server-side
installation.
- The
Screen.hasShiftDown() method is used over keyBindSneak to
accurately reflect GUI-related key presses without interfering
with movement controls.
- Future consideration: Adding a configurable keybind to toggle this
behavior or customize the placeholder message.
Resolves: #ISSUE-42 (Replace with actual issue ticket number if applicable)
评论 0
登录后参与评分
还没有评论,来抢沙发吧