🛡️ 聊天可見性與輸入攔截
| 參數 | 技術規格 |
|---|---|
| Target Screen Class | net.minecraft.client.gui.screens.ChatScreen |
| Mixin Handler | ChatScreenMixin.java |
| In-Memory State | BedChatHiderClient.hideChat (boolean) |
| Interception Targets | extractRenderState, keyPressed, mouseClicked, mouseScrolled |
| Focus Gatekeeper | bedchathider$updateChatState() |
🔄 狀態機生命週期演進
[ User Clicks 'Hide Chat' ]
│
▼
BedChatHiderClient.hideChat = true
│
▼
this.rebuildWidgets()
│
┌────────────────────┴────────────────────┐
▼ ▼
[ EditBox Input State ] [ Input Interception ]
• input.visible = false • extractRenderState -> cancel
• input.active = false • keyPressed -> super.keyPressed
• input.setFocused(false) • mouseClicked -> super.mouseClicked
• screen.setFocused(null) • mouseScrolled -> super.mouseScrolled🛡️ 四點輸入攔截機制詳解
當聊天框隱藏時,ChatScreenMixin 攔截 4 個關鍵輸入路徑,以防止後台幽靈輸入或誤觸連結:
| 攔截方法 | 原版行為 | 隱藏時的模組操作 | 結果 |
|---|---|---|---|
extractRenderState | 渲染聊天背景、歷史記錄文字與指令建議。 | 調用 super.extractRenderState 並執行 ci.cancel()。 | 聊天文字與背景框完全不可見。 |
keyPressed | 向 input 輸入字符、自動補全指令、輪換歷史。 | 返回 cir.setReturnValue(super.keyPressed(event))。 | 禁用文字輸入與方向鍵歷史輪換;Escape 正常關閉介面。 |
mouseClicked | 點擊聊天文字中的 URL、建議選項或選取文字。 | 返回 cir.setReturnValue(super.mouseClicked(event, doubleClick))。 | 禁用聊天互動;介面原生按鈕(離開床、顯示聊天)正常運作。 |
mouseScrolled | 上下滾動聊天歷史記錄。 | 返回 cir.setReturnValue(super.mouseScrolled(x, y, scrollX, scrollY))。 | 禁用日誌滾動;介面保持靜止。 |
💻 原始碼審查與驗證
java
// Sourced from ChatScreenMixin.java
@Inject(method = "extractRenderState", at = @At("HEAD"), cancellable = true)
private void onExtractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a, CallbackInfo ci) {
if ((Object) this instanceof InBedChatScreen && BedChatHiderClient.hideChat) {
super.extractRenderState(graphics, mouseX, mouseY, a);
ci.cancel();
}
}
@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
private void onKeyPressed(KeyEvent event, CallbackInfoReturnable<Boolean> cir) {
if ((Object) this instanceof InBedChatScreen && BedChatHiderClient.hideChat) {
cir.setReturnValue(super.keyPressed(event));
}
}相關頁面: 首頁面板 | 睡眠界面佈局與座標計算 | 程式碼架構與 Mixin 注入剖析
