Skip to content

🎛️ 睡眠界面布局与坐标计算

参数技术规格
Target Screen Classnet.minecraft.client.gui.screens.InBedChatScreen
Superclassnet.minecraft.client.gui.screens.ChatScreen
Mixin HandlerInBedChatScreenMixin.java
注入位置@Inject(method = "init", at = @At("TAIL"))
按钮宽度$98\text{ px}$ (左侧:离开床,右侧:切换聊天)
Button Height$20\text{ px}$
Button Gap$4\text{ px}$
Vertical Anchor$Y = H - 40\text{ px}$
Translation Keysvanilla-outsider-bed-chat-hider.hideChat, ...showChat

🎮 玩家交互工作流程

当玩家躺在床上时:

  1. Minecraft 打开 InBedChatScreen 界面。
  2. 原版默认在屏幕底部显示一个单独且较宽的 离开床 按钮(宽度 $200\text{px}$)。
  3. Bed Chat Hider 动态将 离开床 按钮调整为 $98\text{px}$,并在其旁边添加匹配的 $98\text{px}$ 隐藏聊天 / 显示聊天 切换按钮。
  4. 点击切换按钮会翻转内存状态,立即刷新所有组件,无需关闭界面或唤醒玩家。

📐 坐标几何与分割数学公式

原版 Minecraft 单一按钮位置计算公式如下: $$X_{\text{vanilla}} = \frac{W}{2} - 100, \quad \text{Width} = 200, \quad Y = H - 40$$

Bed Chat Hider 将此 $200\text{px}$ 跨度分解为带有 $4\text{px}$ 居中间隙的对称双按钮组:

$$\text{Leave Bed Button: } X_1 = \frac{W}{2} - 100, \quad \text{Width}_1 = 98, \quad Y_1 = H - 40$$ $$\text{Center Gap: } \Delta X = 4\text{ px}$$ $$\text{Toggle Chat Button: } X_2 = \frac{W}{2} + 2, \quad \text{Width}_2 = 98, \quad Y_2 = H - 40$$

$$\text{Total Span: } W_1 + \Delta X + W_2 = 98 + 4 + 98 = 200\text{ px}$$


🖼️ 屏幕布局 ASCII 示意图

原版睡眠屏幕:

+-------------------------------------------------------------+
| [Chat Log Overlay Area]                                     |
| <Player1> Good night everyone!                              |
|                                                             |
| [Chat Input EditBox] ______________________________________ |
|                                                             |
|                 [      Leave Bed (200px)      ]             |
+-------------------------------------------------------------+

Bed Chat Hider 睡眠屏幕 (聊天框可见):

+-------------------------------------------------------------+
| [Chat Log Overlay Area]                                     |
| <Player1> Good night everyone!                              |
|                                                             |
| [Chat Input EditBox] ______________________________________ |
|                                                             |
|           [ Leave Bed (98px) ]  [ Hide Chat (98px) ]         |
+-------------------------------------------------------------+

Bed Chat Hider 睡眠屏幕 (聊天框隐藏):

+-------------------------------------------------------------+
|                                                             |
|              (Clean, Unobstructed Sleep View)               |
|                                                             |
|                                                             |
|           [ Leave Bed (98px) ]  [ Show Chat (98px) ]         |
+-------------------------------------------------------------+

💻 核心技术代码实现

java
// Sourced from InBedChatScreenMixin.java
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo ci) {
    if (this.leaveBedButton != null) {
        this.leaveBedButton.setX(this.width / 2 - 100);
        this.leaveBedButton.setWidth(98);
    }

    Button toggleButton = Button.builder(
        bedchathider$getButtonMessage(),
        button -> {
            BedChatHiderClient.hideChat = !BedChatHiderClient.hideChat;
            this.rebuildWidgets();
        }
    ).bounds(this.width / 2 + 2, this.height - 40, 98, 20).build();

    this.addRenderableWidget(toggleButton);
    bedchathider$updateChatState();
}

相关页面: 首页面板 | 聊天可见性与输入拦截 | 代码架构与 Mixin 注入剖析

Official documentation & web portal for Dasik Igaijinn mods.