QuickPlayLog.java
net.minecraft.client.quickplay.QuickPlayLog
信息
- 全限定名:net.minecraft.client.quickplay.QuickPlayLog
- 类型:public class
- 包:net.minecraft.client.quickplay
- 源码路径:src/main/java/net/minecraft/client/quickplay/QuickPlayLog.java
- 起始行号:L26
- 职责:
TODO
字段/常量
-
INACTIVE- 类型:
QuickPlayLog - 修饰符:
private static final public public - 源码定位:
L27 - 说明:
TODO
- 类型:
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
GSON- 类型:
Gson - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
path- 类型:
Path - 修饰符:
private final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
worldData- 类型:
QuickPlayLog.QuickPlayWorld - 修饰符:
private - 源码定位:
L39 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.quickplay.QuickPlayLog.QuickPlayEntry- 类型:
record - 修饰符:
private - 源码定位:
L86 - 说明:
TODO
- 类型:
-
net.minecraft.client.quickplay.QuickPlayLog.QuickPlayWorld- 类型:
record - 修饰符:
private - 源码定位:
L98 - 说明:
TODO
- 类型:
-
net.minecraft.client.quickplay.QuickPlayLog.Type- 类型:
enum - 修饰符:
public static - 源码定位:
L110 - 说明:
TODO
- 类型:
构造器
private QuickPlayLog(String quickPlayPath) @ L41
- 构造器名:QuickPlayLog
- 源码定位:L41
- 修饰符:private
参数:
- quickPlayPath: String
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static QuickPlayLog of(String path) @ L45
- 方法名:of
- 源码定位:L45
- 返回类型:QuickPlayLog
- 修饰符:public static
参数:
- path: String
说明:
TODO
public void setWorldData(QuickPlayLog.Type type, String id, String name) @ L49
- 方法名:setWorldData
- 源码定位:L49
- 返回类型:void
- 修饰符:public
参数:
- type: QuickPlayLog.Type
- id: String
- name: String
说明:
TODO
public void log(Minecraft minecraft) @ L53
- 方法名:log
- 源码定位:L53
- 返回类型:void
- 修饰符:public
参数:
- minecraft: Minecraft
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class QuickPlayLog {
private static final QuickPlayLog INACTIVE = new QuickPlayLog("") {
@Override
public void log(Minecraft minecraft) {
}
@Override
public void setWorldData(QuickPlayLog.Type type, String id, String name) {
}
};
private static final Logger LOGGER = LogUtils.getLogger();
private static final Gson GSON = new GsonBuilder().create();
private final Path path;
private QuickPlayLog.@Nullable QuickPlayWorld worldData;
private QuickPlayLog(String quickPlayPath) {
this.path = Minecraft.getInstance().gameDirectory.toPath().resolve(quickPlayPath);
}
public static QuickPlayLog of(@Nullable String path) {
return path == null ? INACTIVE : new QuickPlayLog(path);
}
public void setWorldData(QuickPlayLog.Type type, String id, String name) {
this.worldData = new QuickPlayLog.QuickPlayWorld(type, id, name);
}
public void log(Minecraft minecraft) {
if (minecraft.gameMode != null && this.worldData != null) {
Util.ioPool()
.execute(
() -> {
try {
Files.deleteIfExists(this.path);
} catch (IOException var3) {
LOGGER.error("Failed to delete quickplay log file {}", this.path, var3);
}
QuickPlayLog.QuickPlayEntry quickPlayEntry = new QuickPlayLog.QuickPlayEntry(
this.worldData, Instant.now(), minecraft.gameMode.getPlayerMode()
);
Codec.list(QuickPlayLog.QuickPlayEntry.CODEC)
.encodeStart(JsonOps.INSTANCE, List.of(quickPlayEntry))
.resultOrPartial(Util.prefix("Quick Play: ", LOGGER::error))
.ifPresent(json -> {
try {
Files.createDirectories(this.path.getParent());
Files.writeString(this.path, GSON.toJson(json));
} catch (IOException var3x) {
LOGGER.error("Failed to write to quickplay log file {}", this.path, var3x);
}
});
}
);
} else {
LOGGER.error("Failed to log session for quickplay. Missing world data or gamemode");
}
}
@OnlyIn(Dist.CLIENT)
private record QuickPlayEntry(QuickPlayLog.QuickPlayWorld quickPlayWorld, Instant lastPlayedTime, GameType gamemode) {
public static final Codec<QuickPlayLog.QuickPlayEntry> CODEC = RecordCodecBuilder.create(
i -> i.group(
QuickPlayLog.QuickPlayWorld.MAP_CODEC.forGetter(QuickPlayLog.QuickPlayEntry::quickPlayWorld),
ExtraCodecs.INSTANT_ISO8601.fieldOf("lastPlayedTime").forGetter(QuickPlayLog.QuickPlayEntry::lastPlayedTime),
GameType.CODEC.fieldOf("gamemode").forGetter(QuickPlayLog.QuickPlayEntry::gamemode)
)
.apply(i, QuickPlayLog.QuickPlayEntry::new)
);
}
@OnlyIn(Dist.CLIENT)
private record QuickPlayWorld(QuickPlayLog.Type type, String id, String name) {
public static final MapCodec<QuickPlayLog.QuickPlayWorld> MAP_CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(
QuickPlayLog.Type.CODEC.fieldOf("type").forGetter(QuickPlayLog.QuickPlayWorld::type),
ExtraCodecs.ESCAPED_STRING.fieldOf("id").forGetter(QuickPlayLog.QuickPlayWorld::id),
Codec.STRING.fieldOf("name").forGetter(QuickPlayLog.QuickPlayWorld::name)
)
.apply(i, QuickPlayLog.QuickPlayWorld::new)
);
}
@OnlyIn(Dist.CLIENT)
public static enum Type implements StringRepresentable {
SINGLEPLAYER("singleplayer"),
MULTIPLAYER("multiplayer"),
REALMS("realms");
private static final Codec<QuickPlayLog.Type> CODEC = StringRepresentable.fromEnum(QuickPlayLog.Type::values);
private final String name;
private Type(String name) {
this.name = name;
}
@Override
public String getSerializedName() {
return this.name;
}
}
}引用的其他类
-
- 引用位置:
参数/方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StringRepresentable.fromEnum()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.ioPool(), Util.prefix()
- 引用位置: