ShareToLanScreen.java
net.minecraft.client.gui.screens.ShareToLanScreen
信息
- 全限定名:net.minecraft.client.gui.screens.ShareToLanScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens
- 源码路径:src/main/java/net/minecraft/client/gui/screens/ShareToLanScreen.java
- 起始行号:L19
- 继承:Screen
- 职责:
TODO
字段/常量
-
PORT_LOWER_BOUND- 类型:
int - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
PORT_HIGHER_BOUND- 类型:
int - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
ALLOW_COMMANDS_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
GAME_MODE_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
INFO_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
PORT_INFO_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
PORT_UNAVAILABLE- 类型:
Component - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
INVALID_PORT- 类型:
Component - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
lastScreen- 类型:
Screen - 修饰符:
private final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
gameMode- 类型:
GameType - 修饰符:
private - 源码定位:
L29 - 说明:
TODO
- 类型:
-
commands- 类型:
boolean - 修饰符:
private - 源码定位:
L30 - 说明:
TODO
- 类型:
-
port- 类型:
int - 修饰符:
private - 源码定位:
L31 - 说明:
TODO
- 类型:
-
portEdit- 类型:
EditBox - 修饰符:
private - 源码定位:
L32 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ShareToLanScreen(Screen lastScreen) @ L34
- 构造器名:ShareToLanScreen
- 源码定位:L34
- 修饰符:public
参数:
- lastScreen: Screen
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void init() @ L39
- 方法名:init
- 源码定位:L39
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public void onClose() @ L87
- 方法名:onClose
- 源码定位:L87
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private Component tryParsePort(String value) @ L92
- 方法名:tryParsePort
- 源码定位:L92
- 返回类型:Component
- 修饰符:private
参数:
- value: String
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L111
- 方法名:extractRenderState
- 源码定位:L111
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ShareToLanScreen extends Screen {
private static final int PORT_LOWER_BOUND = 1024;
private static final int PORT_HIGHER_BOUND = 65535;
private static final Component ALLOW_COMMANDS_LABEL = Component.translatable("selectWorld.allowCommands");
private static final Component GAME_MODE_LABEL = Component.translatable("selectWorld.gameMode");
private static final Component INFO_TEXT = Component.translatable("lanServer.otherPlayers");
private static final Component PORT_INFO_TEXT = Component.translatable("lanServer.port");
private static final Component PORT_UNAVAILABLE = Component.translatable("lanServer.port.unavailable", 1024, 65535);
private static final Component INVALID_PORT = Component.translatable("lanServer.port.invalid", 1024, 65535);
private final Screen lastScreen;
private GameType gameMode = GameType.SURVIVAL;
private boolean commands;
private int port = HttpUtil.getAvailablePort();
private @Nullable EditBox portEdit;
public ShareToLanScreen(Screen lastScreen) {
super(Component.translatable("lanServer.title"));
this.lastScreen = lastScreen;
}
@Override
protected void init() {
IntegratedServer singleplayerServer = this.minecraft.getSingleplayerServer();
this.gameMode = singleplayerServer.getDefaultGameType();
this.commands = singleplayerServer.getWorldData().isAllowCommands();
this.addRenderableWidget(
CycleButton.builder(GameType::getShortDisplayName, this.gameMode)
.withValues(GameType.SURVIVAL, GameType.SPECTATOR, GameType.CREATIVE, GameType.ADVENTURE)
.create(this.width / 2 - 155, 100, 150, 20, GAME_MODE_LABEL, (button, value) -> this.gameMode = value)
);
this.addRenderableWidget(
CycleButton.onOffBuilder(this.commands).create(this.width / 2 + 5, 100, 150, 20, ALLOW_COMMANDS_LABEL, (button, value) -> this.commands = value)
);
Button startButton = Button.builder(Component.translatable("lanServer.start"), button -> {
this.minecraft.setScreen(null);
Component message;
if (singleplayerServer.publishServer(this.gameMode, this.commands, this.port)) {
message = PublishCommand.getSuccessMessage(this.port);
} else {
message = Component.translatable("commands.publish.failed");
}
this.minecraft.gui.getChat().addClientSystemMessage(message);
this.minecraft.getNarrator().saySystemQueued(message);
this.minecraft.updateTitle();
}).bounds(this.width / 2 - 155, this.height - 28, 150, 20).build();
this.portEdit = new EditBox(this.font, this.width / 2 - 75, 160, 150, 20, Component.translatable("lanServer.port"));
this.portEdit.setResponder(value -> {
Component errorMessage = this.tryParsePort(value);
this.portEdit.setHint(Component.literal(this.port + ""));
if (errorMessage == null) {
this.portEdit.setTextColor(-2039584);
this.portEdit.setTooltip(null);
startButton.active = true;
} else {
this.portEdit.setTextColor(-2142128);
this.portEdit.setTooltip(Tooltip.create(errorMessage));
startButton.active = false;
}
});
this.portEdit.setHint(Component.literal(this.port + ""));
this.addRenderableWidget(this.portEdit);
this.addRenderableWidget(startButton);
this.addRenderableWidget(
Button.builder(CommonComponents.GUI_CANCEL, button -> this.onClose()).bounds(this.width / 2 + 5, this.height - 28, 150, 20).build()
);
}
@Override
public void onClose() {
this.minecraft.setScreen(this.lastScreen);
}
private @Nullable Component tryParsePort(String value) {
if (value.isBlank()) {
this.port = HttpUtil.getAvailablePort();
return null;
} else {
try {
this.port = Integer.parseInt(value);
if (this.port < 1024 || this.port > 65535) {
return INVALID_PORT;
} else {
return !HttpUtil.isPortAvailable(this.port) ? PORT_UNAVAILABLE : null;
}
} catch (NumberFormatException var3) {
this.port = HttpUtil.getAvailablePort();
return INVALID_PORT;
}
}
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractRenderState(graphics, mouseX, mouseY, a);
graphics.centeredText(this.font, this.title, this.width / 2, 50, -1);
graphics.centeredText(this.font, INFO_TEXT, this.width / 2, 82, -1);
graphics.centeredText(this.font, PORT_INFO_TEXT, this.width / 2, 142, -1);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CycleButton.builder(), CycleButton.onOffBuilder()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
EditBox()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Tooltip.create()
- 引用位置:
-
- 引用位置:
参数/字段/继承
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
PublishCommand.getSuccessMessage()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
HttpUtil.getAvailablePort(), HttpUtil.isPortAvailable()
- 引用位置:
-
- 引用位置:
字段
- 引用位置: