DebugScreenEntryList.java

net.minecraft.client.gui.components.debug.DebugScreenEntryList

信息

  • 全限定名:net.minecraft.client.gui.components.debug.DebugScreenEntryList
  • 类型:public class
  • 包:net.minecraft.client.gui.components.debug
  • 源码路径:src/main/java/net/minecraft/client/gui/components/debug/DebugScreenEntryList.java
  • 起始行号:L32
  • 职责:

    TODO

字段/常量

  • LOGGER

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

      TODO

  • DEFAULT_DEBUG_PROFILE_VERSION

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

      TODO

  • allStatuses

    • 类型: Map<Identifier,DebugScreenEntryStatus>
    • 修饰符: private final
    • 源码定位: L35
    • 说明:

      TODO

  • currentlyEnabled

    • 类型: List<Identifier>
    • 修饰符: private final
    • 源码定位: L36
    • 说明:

      TODO

  • isOverlayVisible

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

      TODO

  • profile

    • 类型: DebugScreenProfile
    • 修饰符: private
    • 源码定位: L38
    • 说明:

      TODO

  • debugProfileFile

    • 类型: File
    • 修饰符: private final
    • 源码定位: L39
    • 说明:

      TODO

  • currentlyEnabledVersion

    • 类型: long
    • 修饰符: private
    • 源码定位: L40
    • 说明:

      TODO

  • codec

    • 类型: Codec<DebugScreenEntryList.SerializedOptions>
    • 修饰符: private final
    • 源码定位: L41
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.components.debug.DebugScreenEntryList.SerializedOptions
    • 类型: record
    • 修饰符: package-private
    • 源码定位: L193
    • 说明:

      TODO

构造器

public DebugScreenEntryList(File workingDirectory, DataFixer dataFixer) @ L43

  • 构造器名:DebugScreenEntryList
  • 源码定位:L43
  • 修饰符:public

参数:

  • workingDirectory: File
  • dataFixer: DataFixer

说明:

TODO

方法

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

public void load() @ L49

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

参数:

说明:

TODO

private void resetStatuses(Map<Identifier,DebugScreenEntryStatus> newEntries) @ L78

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

参数:

  • newEntries: Map<Identifier,DebugScreenEntryStatus>

说明:

TODO

private void resetToProfile(DebugScreenProfile profile) @ L83

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

参数:

  • profile: DebugScreenProfile

说明:

TODO

public void loadProfile(DebugScreenProfile profile) @ L88

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

参数:

  • profile: DebugScreenProfile

说明:

TODO

public DebugScreenEntryStatus getStatus(Identifier location) @ L93

  • 方法名:getStatus
  • 源码定位:L93
  • 返回类型:DebugScreenEntryStatus
  • 修饰符:public

参数:

  • location: Identifier

说明:

TODO

public boolean isCurrentlyEnabled(Identifier location) @ L97

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

参数:

  • location: Identifier

说明:

TODO

public void setStatus(Identifier location, DebugScreenEntryStatus status) @ L101

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

参数:

  • location: Identifier
  • status: DebugScreenEntryStatus

说明:

TODO

public boolean toggleStatus(Identifier location) @ L108

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

参数:

  • location: Identifier

说明:

TODO

public Collection<Identifier> getCurrentlyEnabled() @ L136

  • 方法名:getCurrentlyEnabled
  • 源码定位:L136
  • 返回类型:Collection
  • 修饰符:public

参数:

说明:

TODO

public void toggleDebugOverlay() @ L140

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

参数:

说明:

TODO

public void setOverlayVisible(boolean visible) @ L144

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

参数:

  • visible: boolean

说明:

TODO

public boolean isOverlayVisible() @ L151

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

参数:

说明:

TODO

public void rebuildCurrentList() @ L155

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

参数:

说明:

TODO

public long getCurrentlyEnabledVersion() @ L170

  • 方法名:getCurrentlyEnabledVersion
  • 源码定位:L170
  • 返回类型:long
  • 修饰符:public

参数:

说明:

TODO

public boolean isUsingProfile(DebugScreenProfile profile) @ L174

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

参数:

  • profile: DebugScreenProfile

说明:

TODO

public void save() @ L178

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class DebugScreenEntryList {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final int DEFAULT_DEBUG_PROFILE_VERSION = 4649;
    private final Map<Identifier, DebugScreenEntryStatus> allStatuses = new HashMap<>();
    private final List<Identifier> currentlyEnabled = new ArrayList<>();
    private boolean isOverlayVisible = false;
    private @Nullable DebugScreenProfile profile;
    private final File debugProfileFile;
    private long currentlyEnabledVersion;
    private final Codec<DebugScreenEntryList.SerializedOptions> codec;
 
    public DebugScreenEntryList(File workingDirectory, DataFixer dataFixer) {
        this.debugProfileFile = new File(workingDirectory, "debug-profile.json");
        this.codec = DataFixTypes.DEBUG_PROFILE.wrapCodec(DebugScreenEntryList.SerializedOptions.CODEC, dataFixer, 4649);
        this.load();
    }
 
    public void load() {
        try {
            if (!this.debugProfileFile.isFile()) {
                this.resetToProfile(DebugScreenProfile.DEFAULT);
                this.rebuildCurrentList();
                return;
            }
 
            Dynamic<JsonElement> data = new Dynamic<>(
                JsonOps.INSTANCE, StrictJsonParser.parse(FileUtils.readFileToString(this.debugProfileFile, StandardCharsets.UTF_8))
            );
            DebugScreenEntryList.SerializedOptions serializedOptions = this.codec
                .parse(data)
                .getOrThrow(error -> new IOException("Could not parse debug profile JSON: " + error));
            if (serializedOptions.profile().isPresent()) {
                this.resetToProfile(serializedOptions.profile().get());
            } else {
                this.resetStatuses(serializedOptions.custom().orElse(Map.of()));
                this.profile = null;
            }
        } catch (JsonSyntaxException | IOException var3) {
            LOGGER.error("Couldn't read debug profile file {}, resetting to default", this.debugProfileFile, var3);
            this.resetToProfile(DebugScreenProfile.DEFAULT);
            this.save();
        }
 
        this.rebuildCurrentList();
    }
 
    private void resetStatuses(Map<Identifier, DebugScreenEntryStatus> newEntries) {
        this.allStatuses.clear();
        this.allStatuses.putAll(newEntries);
    }
 
    private void resetToProfile(DebugScreenProfile profile) {
        this.profile = profile;
        this.resetStatuses(DebugScreenEntries.PROFILES.get(profile));
    }
 
    public void loadProfile(DebugScreenProfile profile) {
        this.resetToProfile(profile);
        this.rebuildCurrentList();
    }
 
    public DebugScreenEntryStatus getStatus(Identifier location) {
        return this.allStatuses.getOrDefault(location, DebugScreenEntryStatus.NEVER);
    }
 
    public boolean isCurrentlyEnabled(Identifier location) {
        return this.currentlyEnabled.contains(location);
    }
 
    public void setStatus(Identifier location, DebugScreenEntryStatus status) {
        this.profile = null;
        this.allStatuses.put(location, status);
        this.rebuildCurrentList();
        this.save();
    }
 
    public boolean toggleStatus(Identifier location) {
        switch ((DebugScreenEntryStatus)this.allStatuses.get(location)) {
            case ALWAYS_ON:
                this.setStatus(location, DebugScreenEntryStatus.NEVER);
                return false;
            case IN_OVERLAY:
                if (this.isOverlayVisible) {
                    this.setStatus(location, DebugScreenEntryStatus.NEVER);
                    return false;
                }
 
                this.setStatus(location, DebugScreenEntryStatus.ALWAYS_ON);
                return true;
            case NEVER:
                if (this.isOverlayVisible) {
                    this.setStatus(location, DebugScreenEntryStatus.IN_OVERLAY);
                } else {
                    this.setStatus(location, DebugScreenEntryStatus.ALWAYS_ON);
                }
 
                return true;
            case null:
            default:
                this.setStatus(location, DebugScreenEntryStatus.ALWAYS_ON);
                return true;
        }
    }
 
    public Collection<Identifier> getCurrentlyEnabled() {
        return this.currentlyEnabled;
    }
 
    public void toggleDebugOverlay() {
        this.setOverlayVisible(!this.isOverlayVisible);
    }
 
    public void setOverlayVisible(boolean visible) {
        if (this.isOverlayVisible != visible) {
            this.isOverlayVisible = visible;
            this.rebuildCurrentList();
        }
    }
 
    public boolean isOverlayVisible() {
        return this.isOverlayVisible;
    }
 
    public void rebuildCurrentList() {
        this.currentlyEnabled.clear();
        boolean isReducedDebugInfo = Minecraft.getInstance().showOnlyReducedInfo();
        this.allStatuses.forEach((key, value) -> {
            if (value == DebugScreenEntryStatus.ALWAYS_ON || this.isOverlayVisible && value == DebugScreenEntryStatus.IN_OVERLAY) {
                DebugScreenEntry debug = DebugScreenEntries.getEntry(key);
                if (debug != null && debug.isAllowed(isReducedDebugInfo)) {
                    this.currentlyEnabled.add(key);
                }
            }
        });
        this.currentlyEnabled.sort(Comparator.naturalOrder());
        this.currentlyEnabledVersion++;
    }
 
    public long getCurrentlyEnabledVersion() {
        return this.currentlyEnabledVersion;
    }
 
    public boolean isUsingProfile(DebugScreenProfile profile) {
        return this.profile == profile;
    }
 
    public void save() {
        DebugScreenEntryList.SerializedOptions serializedOptions = new DebugScreenEntryList.SerializedOptions(
            Optional.ofNullable(this.profile), this.profile == null ? Optional.of(this.allStatuses) : Optional.empty()
        );
 
        try {
            FileUtils.writeStringToFile(
                this.debugProfileFile, this.codec.encodeStart(JsonOps.INSTANCE, serializedOptions).getOrThrow().toString(), StandardCharsets.UTF_8
            );
        } catch (IOException var3) {
            LOGGER.error("Failed to save debug profile file {}", this.debugProfileFile, var3);
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    record SerializedOptions(Optional<DebugScreenProfile> profile, Optional<Map<Identifier, DebugScreenEntryStatus>> custom) {
        private static final Codec<Map<Identifier, DebugScreenEntryStatus>> CUSTOM_ENTRIES_CODEC = Codec.unboundedMap(
            Identifier.CODEC, DebugScreenEntryStatus.CODEC
        );
        public static final Codec<DebugScreenEntryList.SerializedOptions> CODEC = RecordCodecBuilder.create(
            i -> i.group(
                    DebugScreenProfile.CODEC.optionalFieldOf("profile").forGetter(DebugScreenEntryList.SerializedOptions::profile),
                    CUSTOM_ENTRIES_CODEC.optionalFieldOf("custom").forGetter(DebugScreenEntryList.SerializedOptions::custom)
                )
                .apply(i, DebugScreenEntryList.SerializedOptions::new)
        );
    }
}

引用的其他类