CodeOfConductScreen.java

net.minecraft.client.gui.screens.multiplayer.CodeOfConductScreen

信息

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

    TODO

字段/常量

  • TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L20
    • 说明:

      TODO

  • CHECK

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L21
    • 说明:

      TODO

  • serverData

    • 类型: ServerData
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

  • codeOfConductText

    • 类型: String
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • resultConsumer

    • 类型: BooleanConsumer
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • parent

    • 类型: Screen
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

内部类/嵌套类型

构造器

private CodeOfConductScreen(ServerData serverData, Screen parent, Component contents, String codeOfConductText, BooleanConsumer resultConsumer) @ L27

  • 构造器名:CodeOfConductScreen
  • 源码定位:L27
  • 修饰符:private

参数:

  • serverData: ServerData
  • parent: Screen
  • contents: Component
  • codeOfConductText: String
  • resultConsumer: BooleanConsumer

说明:

TODO

public CodeOfConductScreen(ServerData serverData, Screen parent, String codeOfConductText, BooleanConsumer resultConsumer) @ L35

  • 构造器名:CodeOfConductScreen
  • 源码定位:L35
  • 修饰符:public

参数:

  • serverData: ServerData
  • parent: Screen
  • codeOfConductText: String
  • resultConsumer: BooleanConsumer

说明:

TODO

方法

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

protected Layout addFooterButtons() @ L39

  • 方法名:addFooterButtons
  • 源码定位:L39
  • 返回类型:Layout
  • 修饰符:protected

参数:

说明:

TODO

private void onResult(boolean accepted) @ L47

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

参数:

  • accepted: boolean

说明:

TODO

public boolean shouldCloseOnEsc() @ L60

  • 方法名:shouldCloseOnEsc
  • 源码定位:L60
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public void tick() @ L65

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CodeOfConductScreen extends WarningScreen {
    private static final Component TITLE = Component.translatable("multiplayer.codeOfConduct.title").withStyle(ChatFormatting.BOLD);
    private static final Component CHECK = Component.translatable("multiplayer.codeOfConduct.check");
    private final @Nullable ServerData serverData;
    private final String codeOfConductText;
    private final BooleanConsumer resultConsumer;
    private final Screen parent;
 
    private CodeOfConductScreen(@Nullable ServerData serverData, Screen parent, Component contents, String codeOfConductText, BooleanConsumer resultConsumer) {
        super(TITLE, contents, CHECK, TITLE.copy().append("\n").append(contents));
        this.serverData = serverData;
        this.parent = parent;
        this.codeOfConductText = codeOfConductText;
        this.resultConsumer = resultConsumer;
    }
 
    public CodeOfConductScreen(@Nullable ServerData serverData, Screen parent, String codeOfConductText, BooleanConsumer resultConsumer) {
        this(serverData, parent, Component.literal(codeOfConductText), codeOfConductText, resultConsumer);
    }
 
    @Override
    protected Layout addFooterButtons() {
        LinearLayout footer = LinearLayout.horizontal().spacing(8);
        footer.addChild(Button.builder(CommonComponents.GUI_ACKNOWLEDGE, button -> this.onResult(true)).build());
        footer.addChild(Button.builder(CommonComponents.GUI_DISCONNECT, button -> this.onResult(false)).build());
        return footer;
    }
 
    private void onResult(boolean accepted) {
        this.resultConsumer.accept(accepted);
        if (this.serverData != null) {
            if (accepted && this.stopShowing.selected()) {
                this.serverData.acceptCodeOfConduct(this.codeOfConductText);
            } else {
                this.serverData.clearCodeOfConduct();
            }
 
            ServerList.saveSingleServer(this.serverData);
        }
    }
 
    @Override
    public boolean shouldCloseOnEsc() {
        return false;
    }
 
    @Override
    public void tick() {
        super.tick();
        if (this.parent instanceof ConnectScreen || this.parent instanceof ServerReconfigScreen) {
            this.parent.tick();
        }
    }
}

引用的其他类

  • Button

    • 引用位置: 方法调用
    • 关联成员: Button.builder()
  • Layout

    • 引用位置: 返回值
  • LinearLayout

    • 引用位置: 方法调用
    • 关联成员: LinearLayout.horizontal()
  • Screen

    • 引用位置: 参数/字段
  • WarningScreen

    • 引用位置: 继承
  • ServerData

    • 引用位置: 参数/字段
  • ServerList

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

    • 引用位置: 参数/字段/方法调用
    • 关联成员: Component.literal(), Component.translatable()