BackgroundMusic.java

net.minecraft.world.attribute.BackgroundMusic

信息

  • 全限定名:net.minecraft.world.attribute.BackgroundMusic
  • 类型:public record
  • 包:net.minecraft.world.attribute
  • 源码路径:src/main/java/net/minecraft/world/attribute/BackgroundMusic.java
  • 起始行号:L11
  • 职责:

    TODO

字段/常量

  • EMPTY

    • 类型: BackgroundMusic
    • 修饰符: public static final
    • 源码定位: L12
    • 说明:

      TODO

  • OVERWORLD

    • 类型: BackgroundMusic
    • 修饰符: public static final
    • 源码定位: L13
    • 说明:

      TODO

  • CODEC

    • 类型: Codec<BackgroundMusic>
    • 修饰符: public static final
    • 源码定位: L14
    • 说明:

      TODO

内部类/嵌套类型

构造器

public BackgroundMusic(Music music) @ L23

  • 构造器名:BackgroundMusic
  • 源码定位:L23
  • 修饰符:public

参数:

  • music: Music

说明:

TODO

public BackgroundMusic(Holder<SoundEvent> sound) @ L27

  • 构造器名:BackgroundMusic
  • 源码定位:L27
  • 修饰符:public

参数:

  • sound: Holder

说明:

TODO

方法

下面的方法块按源码顺序生成。

public BackgroundMusic withUnderwater(Music underwaterMusic) @ L31

  • 方法名:withUnderwater
  • 源码定位:L31
  • 返回类型:BackgroundMusic
  • 修饰符:public

参数:

  • underwaterMusic: Music

说明:

TODO

public Optional<Music> select(boolean isCreative, boolean isUnderwater) @ L35

  • 方法名:select
  • 源码定位:L35
  • 返回类型:Optional
  • 修饰符:public

参数:

  • isCreative: boolean
  • isUnderwater: boolean

说明:

TODO

代码

public record BackgroundMusic(Optional<Music> defaultMusic, Optional<Music> creativeMusic, Optional<Music> underwaterMusic) {
    public static final BackgroundMusic EMPTY = new BackgroundMusic(Optional.empty(), Optional.empty(), Optional.empty());
    public static final BackgroundMusic OVERWORLD = new BackgroundMusic(Optional.of(Musics.GAME), Optional.of(Musics.CREATIVE), Optional.empty());
    public static final Codec<BackgroundMusic> CODEC = RecordCodecBuilder.create(
        i -> i.group(
                Music.CODEC.optionalFieldOf("default").forGetter(BackgroundMusic::defaultMusic),
                Music.CODEC.optionalFieldOf("creative").forGetter(BackgroundMusic::creativeMusic),
                Music.CODEC.optionalFieldOf("underwater").forGetter(BackgroundMusic::underwaterMusic)
            )
            .apply(i, BackgroundMusic::new)
    );
 
    public BackgroundMusic(Music music) {
        this(Optional.of(music), Optional.empty(), Optional.empty());
    }
 
    public BackgroundMusic(Holder<SoundEvent> sound) {
        this(Musics.createGameMusic(sound));
    }
 
    public BackgroundMusic withUnderwater(Music underwaterMusic) {
        return new BackgroundMusic(this.defaultMusic, this.creativeMusic, Optional.of(underwaterMusic));
    }
 
    public Optional<Music> select(boolean isCreative, boolean isUnderwater) {
        if (isUnderwater && this.underwaterMusic.isPresent()) {
            return this.underwaterMusic;
        } else {
            return isCreative && this.creativeMusic.isPresent() ? this.creativeMusic : this.defaultMusic;
        }
    }
}

引用的其他类

  • Holder

    • 引用位置: 参数
  • Music

    • 引用位置: 参数/返回值
  • Musics

    • 引用位置: 方法调用
    • 关联成员: Musics.createGameMusic()
  • SoundEvent

    • 引用位置: 参数