InBedChatScreen .java

net.minecraft.client.gui.screens.InBedChatScreen (class, 49 lines): members: leaveBedButton, onPlayerWokeUp, onClose, init. imports: ClientPacketListener.

net.minecraft.client.gui.screensclass49 linesclientextends ChatScreen1.5 KB

API Surface (3)

void init()
void onClose()
void onPlayerWokeUp()

Fields & Constants (1)

leaveBedButton

String literals (1)

"multiplayer.stopSleeping"

Full Source

InBedChatScreen.java49 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.gui.components.Button;
6
import net.minecraft.client.multiplayer.ClientPacketListener;
7
import net.minecraft.network.chat.Component;
8
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
9
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket.Action;
10
11
@Environment(EnvType.CLIENT)
12
public class InBedChatScreen extends ChatScreen {
13
	private Button leaveBedButton;
14
15
	public InBedChatScreen(final String initial, final boolean isDraft) {
16
		super(initial, isDraft, false);
17
	}
18
19
	@Override
20
	protected void init() {
21
		super.init();
22
		this.leaveBedButton = Button.builder(Component.translatable("multiplayer.stopSleeping"), button -> this.sendWakeUp())
23
			.bounds(this.width / 2 - 100, this.height - 40, 200, 20)
24
			.build();
25
		this.addRenderableWidget(this.leaveBedButton);
26
	}
27
28
	@Override
29
	public void onClose() {
30
		this.sendWakeUp();
31
	}
32
33
	private void sendWakeUp() {
34
		ClientPacketListener connection = this.minecraft.player.connection;
35
		connection.send(new ServerboundPlayerCommandPacket(this.minecraft.player, Action.STOP_SLEEPING));
36
	}
37
38
	public void onPlayerWokeUp() {
39
		String text = this.input.getValue();
40
		if (!this.isDraft && !text.isEmpty()) {
41
			this.exitReason = ChatScreen.ExitReason.DONE;
42
			this.minecraft.gui.setScreen(new ChatScreen(text, false));
43
		} else {
44
			this.exitReason = ChatScreen.ExitReason.INTERRUPTED;
45
			this.minecraft.gui.setScreen(null);
46
		}
47
	}
48
}
49

Decompiled Minecraft 26.3 source of InBedChatScreen (net/minecraft/client/gui/screens/InBedChatScreen.java) with Mojang official mappings, stored verbatim on the site.