ChannelAccess.java
net.minecraft.client.sounds.ChannelAccess
信息
- 全限定名:net.minecraft.client.sounds.ChannelAccess
- 类型:public class
- 包:net.minecraft.client.sounds
- 源码路径:src/main/java/net/minecraft/client/sounds/ChannelAccess.java
- 起始行号:L18
- 职责:
TODO
字段/常量
-
channels- 类型:
Set<ChannelAccess.ChannelHandle> - 修饰符:
private final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
library- 类型:
Library - 修饰符:
private final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
executor- 类型:
Executor - 修饰符:
private final - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.sounds.ChannelAccess.ChannelHandle- 类型:
class - 修饰符:
public - 源码定位:
L68 - 说明:
TODO
- 类型:
构造器
public ChannelAccess(Library library, Executor executor) @ L23
- 构造器名:ChannelAccess
- 源码定位:L23
- 修饰符:public
参数:
- library: Library
- executor: Executor
说明:
TODO
方法
下面的方法块按源码顺序生成。
public CompletableFuture<ChannelAccess.ChannelHandle> createHandle(Library.Pool pool) @ L28
- 方法名:createHandle
- 源码定位:L28
- 返回类型:CompletableFuture<ChannelAccess.ChannelHandle>
- 修饰符:public
参数:
- pool: Library.Pool
说明:
TODO
public void executeOnChannels(Consumer<Stream<Channel>> action) @ L43
- 方法名:executeOnChannels
- 源码定位:L43
- 返回类型:void
- 修饰符:public
参数:
- action: Consumer<Stream
>
说明:
TODO
public void scheduleTick() @ L47
- 方法名:scheduleTick
- 源码定位:L47
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void clear() @ L62
- 方法名:clear
- 源码定位:L62
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ChannelAccess {
private final Set<ChannelAccess.ChannelHandle> channels = Sets.newIdentityHashSet();
private final Library library;
private final Executor executor;
public ChannelAccess(Library library, Executor executor) {
this.library = library;
this.executor = executor;
}
public CompletableFuture<ChannelAccess.ChannelHandle> createHandle(Library.Pool pool) {
CompletableFuture<ChannelAccess.ChannelHandle> result = new CompletableFuture<>();
this.executor.execute(() -> {
Channel channel = this.library.acquireChannel(pool);
if (channel != null) {
ChannelAccess.ChannelHandle handle = new ChannelAccess.ChannelHandle(channel);
this.channels.add(handle);
result.complete(handle);
} else {
result.complete(null);
}
});
return result;
}
public void executeOnChannels(Consumer<Stream<Channel>> action) {
this.executor.execute(() -> action.accept(this.channels.stream().map(channelHandle -> channelHandle.channel).filter(Objects::nonNull)));
}
public void scheduleTick() {
this.executor.execute(() -> {
Iterator<ChannelAccess.ChannelHandle> it = this.channels.iterator();
while (it.hasNext()) {
ChannelAccess.ChannelHandle handle = it.next();
handle.channel.updateStream();
if (handle.channel.stopped()) {
handle.release();
it.remove();
}
}
});
}
public void clear() {
this.channels.forEach(ChannelAccess.ChannelHandle::release);
this.channels.clear();
}
@OnlyIn(Dist.CLIENT)
public class ChannelHandle {
private @Nullable Channel channel;
private boolean stopped;
public boolean isStopped() {
return this.stopped;
}
public ChannelHandle(Channel channel) {
Objects.requireNonNull(ChannelAccess.this);
super();
this.channel = channel;
}
public void execute(Consumer<Channel> action) {
ChannelAccess.this.executor.execute(() -> {
if (this.channel != null) {
action.accept(this.channel);
}
});
}
public void release() {
this.stopped = true;
ChannelAccess.this.library.releaseChannel(this.channel);
this.channel = null;
}
}
}