86 lines
2.8 KiB
Java
86 lines
2.8 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package net.minecraft.client.gui.screens;
|
|
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.gui.components.Button;
|
|
import net.minecraft.client.gui.screens.ChatScreen;
|
|
import net.minecraft.client.input.CharacterEvent;
|
|
import net.minecraft.client.input.KeyEvent;
|
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
|
|
|
|
public class InBedChatScreen
|
|
extends ChatScreen {
|
|
private Button leaveBedButton;
|
|
|
|
public InBedChatScreen(String initial, boolean isDraft) {
|
|
super(initial, isDraft);
|
|
}
|
|
|
|
@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 render(GuiGraphics graphics, int mouseX, int mouseY, float a) {
|
|
if (!this.minecraft.getChatStatus().isChatAllowed(this.minecraft.isLocalServer())) {
|
|
this.leaveBedButton.render(graphics, mouseX, mouseY, a);
|
|
return;
|
|
}
|
|
super.render(graphics, mouseX, mouseY, a);
|
|
}
|
|
|
|
@Override
|
|
public void onClose() {
|
|
this.sendWakeUp();
|
|
}
|
|
|
|
@Override
|
|
public boolean charTyped(CharacterEvent event) {
|
|
if (!this.minecraft.getChatStatus().isChatAllowed(this.minecraft.isLocalServer())) {
|
|
return true;
|
|
}
|
|
return super.charTyped(event);
|
|
}
|
|
|
|
@Override
|
|
public boolean keyPressed(KeyEvent event) {
|
|
if (event.isEscape()) {
|
|
this.sendWakeUp();
|
|
}
|
|
if (!this.minecraft.getChatStatus().isChatAllowed(this.minecraft.isLocalServer())) {
|
|
return true;
|
|
}
|
|
if (event.isConfirmation()) {
|
|
this.handleChatInput(this.input.getValue(), true);
|
|
this.input.setValue("");
|
|
this.minecraft.gui.getChat().resetChatScroll();
|
|
return true;
|
|
}
|
|
return super.keyPressed(event);
|
|
}
|
|
|
|
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.INTERRUPTED;
|
|
this.minecraft.setScreen(null);
|
|
} else {
|
|
this.exitReason = ChatScreen.ExitReason.DONE;
|
|
this.minecraft.setScreen(new ChatScreen(text, false));
|
|
}
|
|
}
|
|
}
|
|
|