77 lines
2.4 KiB
Java
77 lines
2.4 KiB
Java
package net.minecraft.client.gui.screens;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.gui.components.Button;
|
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class InBedChatScreen extends ChatScreen {
|
|
private Button leaveBedButton;
|
|
|
|
public InBedChatScreen() {
|
|
super("");
|
|
}
|
|
|
|
@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 guiGraphics, int mouseX, int mouseY, float partialTick) {
|
|
if (!this.minecraft.getChatStatus().isChatAllowed(this.minecraft.isLocalServer())) {
|
|
this.leaveBedButton.render(guiGraphics, mouseX, mouseY, partialTick);
|
|
} else {
|
|
super.render(guiGraphics, mouseX, mouseY, partialTick);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onClose() {
|
|
this.sendWakeUp();
|
|
}
|
|
|
|
@Override
|
|
public boolean charTyped(char codePoint, int modifiers) {
|
|
return !this.minecraft.getChatStatus().isChatAllowed(this.minecraft.isLocalServer()) ? true : super.charTyped(codePoint, modifiers);
|
|
}
|
|
|
|
@Override
|
|
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
|
if (keyCode == 256) {
|
|
this.sendWakeUp();
|
|
}
|
|
|
|
if (!this.minecraft.getChatStatus().isChatAllowed(this.minecraft.isLocalServer())) {
|
|
return true;
|
|
} else if (keyCode != 257 && keyCode != 335) {
|
|
return super.keyPressed(keyCode, scanCode, modifiers);
|
|
} else {
|
|
this.handleChatInput(this.input.getValue(), true);
|
|
this.input.setValue("");
|
|
this.minecraft.gui.getChat().resetChatScroll();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private void sendWakeUp() {
|
|
ClientPacketListener clientPacketListener = this.minecraft.player.connection;
|
|
clientPacketListener.send(new ServerboundPlayerCommandPacket(this.minecraft.player, ServerboundPlayerCommandPacket.Action.STOP_SLEEPING));
|
|
}
|
|
|
|
public void onPlayerWokeUp() {
|
|
if (this.input.getValue().isEmpty()) {
|
|
this.minecraft.setScreen(null);
|
|
} else {
|
|
this.minecraft.setScreen(new ChatScreen(this.input.getValue()));
|
|
}
|
|
}
|
|
}
|