WeighedSoundEvents.java
net.minecraft.client.sounds.WeighedSoundEvents
信息
- 全限定名:net.minecraft.client.sounds.WeighedSoundEvents
- 类型:public class
- 包:net.minecraft.client.sounds
- 源码路径:src/main/java/net/minecraft/client/sounds/WeighedSoundEvents.java
- 起始行号:L17
- 实现:Weighted
- 职责:
TODO
字段/常量
-
list- 类型:
List<Weighted<Sound>> - 修饰符:
private final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
subtitle- 类型:
Component - 修饰符:
private final - 源码定位:
L19 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public WeighedSoundEvents(Identifier location, String subtitle) @ L21
- 构造器名:WeighedSoundEvents
- 源码定位:L21
- 修饰符:public
参数:
- location: Identifier
- subtitle: String
说明:
TODO
方法
下面的方法块按源码顺序生成。
public int getWeight() @ L34
- 方法名:getWeight
- 源码定位:L34
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public Sound getSound(RandomSource random) @ L45
- 方法名:getSound
- 源码定位:L45
- 返回类型:Sound
- 修饰符:public
参数:
- random: RandomSource
说明:
TODO
public void addSound(Weighted<Sound> sound) @ L63
- 方法名:addSound
- 源码定位:L63
- 返回类型:void
- 修饰符:public
参数:
- sound: Weighted
说明:
TODO
public Component getSubtitle() @ L67
- 方法名:getSubtitle
- 源码定位:L67
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
public void preloadIfRequired(SoundEngine soundEngine) @ L71
- 方法名:preloadIfRequired
- 源码定位:L71
- 返回类型:void
- 修饰符:public
参数:
- soundEngine: SoundEngine
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class WeighedSoundEvents implements Weighted<Sound> {
private final List<Weighted<Sound>> list = Lists.newArrayList();
private final @Nullable Component subtitle;
public WeighedSoundEvents(Identifier location, @Nullable String subtitle) {
if (SharedConstants.DEBUG_SUBTITLES) {
MutableComponent components = Component.literal(location.getPath());
if ("FOR THE DEBUG!".equals(subtitle)) {
components = components.append(Component.literal(" missing").withStyle(ChatFormatting.RED));
}
this.subtitle = components;
} else {
this.subtitle = subtitle == null ? null : Component.translatable(subtitle);
}
}
@Override
public int getWeight() {
int sum = 0;
for (Weighted<Sound> sound : this.list) {
sum += sound.getWeight();
}
return sum;
}
public Sound getSound(RandomSource random) {
int weight = this.getWeight();
if (!this.list.isEmpty() && weight != 0) {
int index = random.nextInt(weight);
for (Weighted<Sound> weighted : this.list) {
index -= weighted.getWeight();
if (index < 0) {
return weighted.getSound(random);
}
}
return SoundManager.EMPTY_SOUND;
} else {
return SoundManager.EMPTY_SOUND;
}
}
public void addSound(Weighted<Sound> sound) {
this.list.add(sound);
}
public @Nullable Component getSubtitle() {
return this.subtitle;
}
@Override
public void preloadIfRequired(SoundEngine soundEngine) {
for (Weighted<Sound> weighted : this.list) {
weighted.preloadIfRequired(soundEngine);
}
}
}引用的其他类
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/实现
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: