ServerData.java

net.minecraft.client.multiplayer.ServerData

信息

  • 全限定名:net.minecraft.client.multiplayer.ServerData
  • 类型:public class
  • 包:net.minecraft.client.multiplayer
  • 源码路径:src/main/java/net/minecraft/client/multiplayer/ServerData.java
  • 起始行号:L22
  • 职责:

    TODO

字段/常量

  • LOGGER

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

      TODO

  • MAX_ICON_SIZE

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

      TODO

  • name

    • 类型: String
    • 修饰符: public
    • 源码定位: L25
    • 说明:

      TODO

  • ip

    • 类型: String
    • 修饰符: public
    • 源码定位: L26
    • 说明:

      TODO

  • status

    • 类型: Component
    • 修饰符: public
    • 源码定位: L27
    • 说明:

      TODO

  • motd

    • 类型: Component
    • 修饰符: public
    • 源码定位: L28
    • 说明:

      TODO

  • players

    • 类型: ServerStatus.Players
    • 修饰符: public
    • 源码定位: L29
    • 说明:

      TODO

  • ping

    • 类型: long
    • 修饰符: public
    • 源码定位: L30
    • 说明:

      TODO

  • protocol

    • 类型: int
    • 修饰符: public
    • 源码定位: L31
    • 说明:

      TODO

  • version

    • 类型: Component
    • 修饰符: public
    • 源码定位: L32
    • 说明:

      TODO

  • playerList

    • 类型: List<Component>
    • 修饰符: public
    • 源码定位: L33
    • 说明:

      TODO

  • packStatus

    • 类型: ServerData.ServerPackStatus
    • 修饰符: private
    • 源码定位: L34
    • 说明:

      TODO

  • iconBytes

    • 类型: byte[]
    • 修饰符: private
    • 源码定位: L35
    • 说明:

      TODO

  • type

    • 类型: ServerData.Type
    • 修饰符: private
    • 源码定位: L36
    • 说明:

      TODO

  • acceptedCodeOfConduct

    • 类型: int
    • 修饰符: private
    • 源码定位: L37
    • 说明:

      TODO

  • state

    • 类型: ServerData.State
    • 修饰符: private
    • 源码定位: L38
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.multiplayer.ServerData.ServerPackStatus

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L143
    • 说明:

      TODO

  • net.minecraft.client.multiplayer.ServerData.State

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L169
    • 说明:

      TODO

  • net.minecraft.client.multiplayer.ServerData.Type

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L178
    • 说明:

      TODO

构造器

public ServerData(String name, String ip, ServerData.Type type) @ L40

  • 构造器名:ServerData
  • 源码定位:L40
  • 修饰符:public

参数:

  • name: String
  • ip: String
  • type: ServerData.Type

说明:

TODO

方法

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

public CompoundTag write() @ L46

  • 方法名:write
  • 源码定位:L46
  • 返回类型:CompoundTag
  • 修饰符:public

参数:

说明:

TODO

public ServerData.ServerPackStatus getResourcePackStatus() @ L59

  • 方法名:getResourcePackStatus
  • 源码定位:L59
  • 返回类型:ServerData.ServerPackStatus
  • 修饰符:public

参数:

说明:

TODO

public void setResourcePackStatus(ServerData.ServerPackStatus packStatus) @ L63

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

参数:

  • packStatus: ServerData.ServerPackStatus

说明:

TODO

public static ServerData read(CompoundTag tag) @ L67

  • 方法名:read
  • 源码定位:L67
  • 返回类型:ServerData
  • 修饰符:public static

参数:

  • tag: CompoundTag

说明:

TODO

public byte[] getIconBytes() @ L75

  • 方法名:getIconBytes
  • 源码定位:L75
  • 返回类型:byte[]
  • 修饰符:public

参数:

说明:

TODO

public void setIconBytes(byte[] iconBytes) @ L79

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

参数:

  • iconBytes: byte[]

说明:

TODO

public boolean isLan() @ L83

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

参数:

说明:

TODO

public boolean isRealm() @ L87

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

参数:

说明:

TODO

public ServerData.Type type() @ L91

  • 方法名:type
  • 源码定位:L91
  • 返回类型:ServerData.Type
  • 修饰符:public

参数:

说明:

TODO

public boolean hasAcceptedCodeOfConduct(String codeOfConduct) @ L95

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

参数:

  • codeOfConduct: String

说明:

TODO

public void acceptCodeOfConduct(String codeOfConduct) @ L99

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

参数:

  • codeOfConduct: String

说明:

TODO

public void clearCodeOfConduct() @ L103

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

参数:

说明:

TODO

public void copyNameIconFrom(ServerData other) @ L107

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

参数:

  • other: ServerData

说明:

TODO

public void copyFrom(ServerData other) @ L113

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

参数:

  • other: ServerData

说明:

TODO

public ServerData.State state() @ L119

  • 方法名:state
  • 源码定位:L119
  • 返回类型:ServerData.State
  • 修饰符:public

参数:

说明:

TODO

public void setState(ServerData.State state) @ L123

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

参数:

  • state: ServerData.State

说明:

TODO

public static byte[] validateIcon(byte[] bytes) @ L127

  • 方法名:validateIcon
  • 源码定位:L127
  • 返回类型:byte[]
  • 修饰符:public static

参数:

  • bytes: byte[]

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ServerData {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final int MAX_ICON_SIZE = 1024;
    public String name;
    public String ip;
    public Component status;
    public Component motd;
    public ServerStatus.@Nullable Players players;
    public long ping;
    public int protocol = SharedConstants.getCurrentVersion().protocolVersion();
    public Component version = Component.literal(SharedConstants.getCurrentVersion().name());
    public List<Component> playerList = Collections.emptyList();
    private ServerData.ServerPackStatus packStatus = ServerData.ServerPackStatus.PROMPT;
    private byte @Nullable [] iconBytes;
    private ServerData.Type type;
    private int acceptedCodeOfConduct;
    private ServerData.State state = ServerData.State.INITIAL;
 
    public ServerData(String name, String ip, ServerData.Type type) {
        this.name = name;
        this.ip = ip;
        this.type = type;
    }
 
    public CompoundTag write() {
        CompoundTag tag = new CompoundTag();
        tag.putString("name", this.name);
        tag.putString("ip", this.ip);
        tag.storeNullable("icon", ExtraCodecs.BASE64_STRING, this.iconBytes);
        tag.store(ServerData.ServerPackStatus.FIELD_CODEC, this.packStatus);
        if (this.acceptedCodeOfConduct != 0) {
            tag.putInt("acceptedCodeOfConduct", this.acceptedCodeOfConduct);
        }
 
        return tag;
    }
 
    public ServerData.ServerPackStatus getResourcePackStatus() {
        return this.packStatus;
    }
 
    public void setResourcePackStatus(ServerData.ServerPackStatus packStatus) {
        this.packStatus = packStatus;
    }
 
    public static ServerData read(CompoundTag tag) {
        ServerData server = new ServerData(tag.getStringOr("name", ""), tag.getStringOr("ip", ""), ServerData.Type.OTHER);
        server.setIconBytes(tag.read("icon", ExtraCodecs.BASE64_STRING).orElse(null));
        server.setResourcePackStatus(tag.read(ServerData.ServerPackStatus.FIELD_CODEC).orElse(ServerData.ServerPackStatus.PROMPT));
        server.acceptedCodeOfConduct = tag.getIntOr("acceptedCodeOfConduct", 0);
        return server;
    }
 
    public byte @Nullable [] getIconBytes() {
        return this.iconBytes;
    }
 
    public void setIconBytes(byte @Nullable [] iconBytes) {
        this.iconBytes = iconBytes;
    }
 
    public boolean isLan() {
        return this.type == ServerData.Type.LAN;
    }
 
    public boolean isRealm() {
        return this.type == ServerData.Type.REALM;
    }
 
    public ServerData.Type type() {
        return this.type;
    }
 
    public boolean hasAcceptedCodeOfConduct(String codeOfConduct) {
        return this.acceptedCodeOfConduct == codeOfConduct.hashCode();
    }
 
    public void acceptCodeOfConduct(String codeOfConduct) {
        this.acceptedCodeOfConduct = codeOfConduct.hashCode();
    }
 
    public void clearCodeOfConduct() {
        this.acceptedCodeOfConduct = 0;
    }
 
    public void copyNameIconFrom(ServerData other) {
        this.ip = other.ip;
        this.name = other.name;
        this.iconBytes = other.iconBytes;
    }
 
    public void copyFrom(ServerData other) {
        this.copyNameIconFrom(other);
        this.setResourcePackStatus(other.getResourcePackStatus());
        this.type = other.type;
    }
 
    public ServerData.State state() {
        return this.state;
    }
 
    public void setState(ServerData.State state) {
        this.state = state;
    }
 
    public static byte @Nullable [] validateIcon(byte @Nullable [] bytes) {
        if (bytes != null) {
            try {
                PngInfo iconInfo = PngInfo.fromBytes(bytes);
                if (iconInfo.width() <= 1024 && iconInfo.height() <= 1024) {
                    return bytes;
                }
            } catch (IOException var2) {
                LOGGER.warn("Failed to decode server icon", (Throwable)var2);
            }
        }
 
        return null;
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum ServerPackStatus {
        ENABLED("enabled"),
        DISABLED("disabled"),
        PROMPT("prompt");
 
        public static final MapCodec<ServerData.ServerPackStatus> FIELD_CODEC = Codec.BOOL
            .optionalFieldOf("acceptTextures")
            .xmap(acceptTextures -> acceptTextures.<ServerData.ServerPackStatus>map(b -> b ? ENABLED : DISABLED).orElse(PROMPT), status -> {
                return switch (status) {
                    case ENABLED -> Optional.of(true);
                    case DISABLED -> Optional.of(false);
                    case PROMPT -> Optional.empty();
                };
            });
        private final Component name;
 
        private ServerPackStatus(String name) {
            this.name = Component.translatable("manageServer.resourcePack." + name);
        }
 
        public Component getName() {
            return this.name;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum State {
        INITIAL,
        PINGING,
        UNREACHABLE,
        INCOMPATIBLE,
        SUCCESSFUL;
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum Type {
        LAN,
        REALM,
        OTHER;
    }
}

引用的其他类

  • SharedConstants

    • 引用位置: 方法调用
    • 关联成员: SharedConstants.getCurrentVersion()
  • CompoundTag

    • 引用位置: 参数/构造调用/返回值
    • 关联成员: CompoundTag()
  • Component

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

    • 引用位置: 字段
  • PngInfo

    • 引用位置: 方法调用
    • 关联成员: PngInfo.fromBytes()