InBedChatScreen.java

net.minecraft.client.gui.screens.InBedChatScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.InBedChatScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/InBedChatScreen.java
  • 起始行号:L11
  • 继承:ChatScreen
  • 职责:

    TODO

字段/常量

  • leaveBedButton
    • 类型: Button
    • 修饰符: private
    • 源码定位: L12
    • 说明:

      TODO

内部类/嵌套类型

构造器

public InBedChatScreen(String initial, boolean isDraft) @ L14

  • 构造器名:InBedChatScreen
  • 源码定位:L14
  • 修饰符:public

参数:

  • initial: String
  • isDraft: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected void init() @ L18

  • 方法名:init
  • 源码定位:L18
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public void onClose() @ L27

  • 方法名:onClose
  • 源码定位:L27
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private void sendWakeUp() @ L32

  • 方法名:sendWakeUp
  • 源码定位:L32
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public void onPlayerWokeUp() @ L37

  • 方法名:onPlayerWokeUp
  • 源码定位:L37
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class InBedChatScreen extends ChatScreen {
    private Button leaveBedButton;
 
    public InBedChatScreen(String initial, boolean isDraft) {
        super(initial, isDraft, false);
    }
 
    @Override
    protected void init() {
        super.init();
        this.leaveBedButton = Button.builder(Component.translatable("multiplayer.stopSleeping"), button -> this.sendWakeUp())
            .bounds(this.width / 2 - 100, this.height - 40, 200, 20)
            .build();
        this.addRenderableWidget(this.leaveBedButton);
    }
 
    @Override
    public void onClose() {
        this.sendWakeUp();
    }
 
    private void sendWakeUp() {
        ClientPacketListener connection = this.minecraft.player.connection;
        connection.send(new ServerboundPlayerCommandPacket(this.minecraft.player, ServerboundPlayerCommandPacket.Action.STOP_SLEEPING));
    }
 
    public void onPlayerWokeUp() {
        String text = this.input.getValue();
        if (!this.isDraft && !text.isEmpty()) {
            this.exitReason = ChatScreen.ExitReason.DONE;
            this.minecraft.setScreen(new ChatScreen(text, false));
        } else {
            this.exitReason = ChatScreen.ExitReason.INTERRUPTED;
            this.minecraft.setScreen(null);
        }
    }
}

引用的其他类

  • Button

    • 引用位置: 字段/方法调用
    • 关联成员: Button.builder()
  • ChatScreen

    • 引用位置: 构造调用/继承
    • 关联成员: ChatScreen()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.translatable()
  • ServerboundPlayerCommandPacket

    • 引用位置: 构造调用
    • 关联成员: ServerboundPlayerCommandPacket()