ChatLog.java
net.minecraft.client.multiplayer.chat.ChatLog
信息
- 全限定名:net.minecraft.client.multiplayer.chat.ChatLog
- 类型:public class
- 包:net.minecraft.client.multiplayer.chat
- 源码路径:src/main/java/net/minecraft/client/multiplayer/chat/ChatLog.java
- 起始行号:L12
- 职责:
TODO
字段/常量
-
buffer- 类型:
LoggedChatEvent[] - 修饰符:
private final - 源码定位:
L13 - 说明:
TODO
- 类型:
-
nextId- 类型:
int - 修饰符:
private - 源码定位:
L14 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ChatLog(int capacity) @ L31
- 构造器名:ChatLog
- 源码定位:L31
- 修饰符:public
参数:
- capacity: int
说明:
TODO
private ChatLog(int capacity, List<LoggedChatEvent> buffer) @ L35
- 构造器名:ChatLog
- 源码定位:L35
- 修饰符:private
参数:
- capacity: int
- buffer: List
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static Codec<ChatLog> codec(int capacity) @ L16
- 方法名:codec
- 源码定位:L16
- 返回类型:Codec
- 修饰符:public static
参数:
- capacity: int
说明:
TODO
private List<LoggedChatEvent> loggedChatEvents() @ L40
- 方法名:loggedChatEvents
- 源码定位:L40
- 返回类型:List
- 修饰符:private
参数:
- 无
说明:
TODO
public void push(LoggedChatEvent event) @ L50
- 方法名:push
- 源码定位:L50
- 返回类型:void
- 修饰符:public
参数:
- event: LoggedChatEvent
说明:
TODO
public LoggedChatEvent lookup(int id) @ L54
- 方法名:lookup
- 源码定位:L54
- 返回类型:LoggedChatEvent
- 修饰符:public
参数:
- id: int
说明:
TODO
private int index(int id) @ L58
- 方法名:index
- 源码定位:L58
- 返回类型:int
- 修饰符:private
参数:
- id: int
说明:
TODO
public int start() @ L62
- 方法名:start
- 源码定位:L62
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int end() @ L66
- 方法名:end
- 源码定位:L66
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
private int size() @ L70
- 方法名:size
- 源码定位:L70
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ChatLog {
private final LoggedChatEvent[] buffer;
private int nextId;
public static Codec<ChatLog> codec(int capacity) {
return Codec.list(LoggedChatEvent.CODEC)
.comapFlatMap(
loggedChatEvents -> {
int parsedSize = loggedChatEvents.size();
return parsedSize > capacity
? DataResult.error(
() -> "Expected: a buffer of size less than or equal to " + capacity + " but: " + parsedSize + " is greater than " + capacity
)
: DataResult.success(new ChatLog(capacity, (List<LoggedChatEvent>)loggedChatEvents));
},
ChatLog::loggedChatEvents
);
}
public ChatLog(int capacity) {
this.buffer = new LoggedChatEvent[capacity];
}
private ChatLog(int capacity, List<LoggedChatEvent> buffer) {
this.buffer = buffer.toArray(LoggedChatEvent[]::new);
this.nextId = buffer.size();
}
private List<LoggedChatEvent> loggedChatEvents() {
List<LoggedChatEvent> loggedChatEvents = new ArrayList<>(this.size());
for (int i = this.start(); i <= this.end(); i++) {
loggedChatEvents.add(this.lookup(i));
}
return loggedChatEvents;
}
public void push(LoggedChatEvent event) {
this.buffer[this.index(this.nextId++)] = event;
}
public @Nullable LoggedChatEvent lookup(int id) {
return id >= this.start() && id <= this.end() ? this.buffer[this.index(id)] : null;
}
private int index(int id) {
return id % this.buffer.length;
}
public int start() {
return Math.max(this.nextId - this.buffer.length, 0);
}
public int end() {
return this.nextId - 1;
}
private int size() {
return this.end() - this.start() + 1;
}
}引用的其他类
- LoggedChatEvent
- 引用位置:
参数/字段/返回值
- 引用位置: