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.