SoundEvent.java
net.minecraft.sounds.SoundEvent
信息
- 全限定名:net.minecraft.sounds.SoundEvent
- 类型:public record
- 包:net.minecraft.sounds
- 源码路径:src/main/java/net/minecraft/sounds/SoundEvent.java
- 起始行号:L15
- 职责:
TODO
字段/常量
-
DIRECT_CODEC- 类型:
Codec<SoundEvent> - 修饰符:
public static final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
CODEC- 类型:
Codec<Holder<SoundEvent>> - 修饰符:
public static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
DIRECT_STREAM_CODEC- 类型:
StreamCodec<ByteBuf,SoundEvent> - 修饰符:
public static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
STREAM_CODEC- 类型:
StreamCodec<RegistryFriendlyByteBuf,Holder<SoundEvent>> - 修饰符:
public static final - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
private static SoundEvent create(Identifier location, Optional<Float> range) @ L31
- 方法名:create
- 源码定位:L31
- 返回类型:SoundEvent
- 修饰符:private static
参数:
- location: Identifier
- range: Optional
说明:
TODO
public static SoundEvent createVariableRangeEvent(Identifier location) @ L35
- 方法名:createVariableRangeEvent
- 源码定位:L35
- 返回类型:SoundEvent
- 修饰符:public static
参数:
- location: Identifier
说明:
TODO
public static SoundEvent createFixedRangeEvent(Identifier location, float range) @ L39
- 方法名:createFixedRangeEvent
- 源码定位:L39
- 返回类型:SoundEvent
- 修饰符:public static
参数:
- location: Identifier
- range: float
说明:
TODO
public float getRange(float volume) @ L43
- 方法名:getRange
- 源码定位:L43
- 返回类型:float
- 修饰符:public
参数:
- volume: float
说明:
TODO
代码
public record SoundEvent(Identifier location, Optional<Float> fixedRange) {
public static final Codec<SoundEvent> DIRECT_CODEC = RecordCodecBuilder.create(
i -> i.group(
Identifier.CODEC.fieldOf("sound_id").forGetter(SoundEvent::location),
Codec.FLOAT.lenientOptionalFieldOf("range").forGetter(SoundEvent::fixedRange)
)
.apply(i, SoundEvent::create)
);
public static final Codec<Holder<SoundEvent>> CODEC = RegistryFileCodec.create(Registries.SOUND_EVENT, DIRECT_CODEC);
public static final StreamCodec<ByteBuf, SoundEvent> DIRECT_STREAM_CODEC = StreamCodec.composite(
Identifier.STREAM_CODEC, SoundEvent::location, ByteBufCodecs.FLOAT.apply(ByteBufCodecs::optional), SoundEvent::fixedRange, SoundEvent::create
);
public static final StreamCodec<RegistryFriendlyByteBuf, Holder<SoundEvent>> STREAM_CODEC = ByteBufCodecs.holder(
Registries.SOUND_EVENT, DIRECT_STREAM_CODEC
);
private static SoundEvent create(Identifier location, Optional<Float> range) {
return range.<SoundEvent>map(r -> createFixedRangeEvent(location, r)).orElseGet(() -> createVariableRangeEvent(location));
}
public static SoundEvent createVariableRangeEvent(Identifier location) {
return new SoundEvent(location, Optional.empty());
}
public static SoundEvent createFixedRangeEvent(Identifier location, float range) {
return new SoundEvent(location, Optional.of(range));
}
public float getRange(float volume) {
return this.fixedRange.orElse(volume > 1.0F ? 16.0F * volume : 16.0F);
}
}引用的其他类
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ByteBufCodecs.holder()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
StreamCodec.composite()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RegistryFileCodec.create()
- 引用位置: