JukeboxPlayablePredicate.java

net.minecraft.core.component.predicates.JukeboxPlayablePredicate

信息

  • 全限定名:net.minecraft.core.component.predicates.JukeboxPlayablePredicate
  • 类型:public record
  • 包:net.minecraft.core.component.predicates
  • 源码路径:src/main/java/net/minecraft/core/component/predicates/JukeboxPlayablePredicate.java
  • 起始行号:L17
  • 实现:SingleComponentItemPredicate
  • 职责:

    TODO

字段/常量

  • CODEC
    • 类型: Codec<JukeboxPlayablePredicate>
    • 修饰符: public static final
    • 源码定位: L18
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public DataComponentType<JukeboxPlayable> componentType() @ L23

  • 方法名:componentType
  • 源码定位:L23
  • 返回类型:DataComponentType
  • 修饰符:public

参数:

说明:

TODO

public boolean matches(JukeboxPlayable value) @ L28

  • 方法名:matches
  • 源码定位:L28
  • 返回类型:boolean
  • 修饰符:public

参数:

  • value: JukeboxPlayable

说明:

TODO

public static JukeboxPlayablePredicate any() @ L46

  • 方法名:any
  • 源码定位:L46
  • 返回类型:JukeboxPlayablePredicate
  • 修饰符:public static

参数:

说明:

TODO

代码

public record JukeboxPlayablePredicate(Optional<HolderSet<JukeboxSong>> song) implements SingleComponentItemPredicate<JukeboxPlayable> {
    public static final Codec<JukeboxPlayablePredicate> CODEC = RecordCodecBuilder.create(
        i -> i.group(RegistryCodecs.homogeneousList(Registries.JUKEBOX_SONG).optionalFieldOf("song").forGetter(JukeboxPlayablePredicate::song))
            .apply(i, JukeboxPlayablePredicate::new)
    );
 
    @Override
    public DataComponentType<JukeboxPlayable> componentType() {
        return DataComponents.JUKEBOX_PLAYABLE;
    }
 
    public boolean matches(JukeboxPlayable value) {
        if (!this.song.isPresent()) {
            return true;
        } else {
            boolean songIsPresent = false;
 
            for (Holder<JukeboxSong> maybeSong : this.song.get()) {
                Optional<ResourceKey<JukeboxSong>> songId = maybeSong.unwrapKey();
                if (!songId.isEmpty() && songId.equals(value.song().unwrapKey())) {
                    songIsPresent = true;
                    break;
                }
            }
 
            return songIsPresent;
        }
    }
 
    public static JukeboxPlayablePredicate any() {
        return new JukeboxPlayablePredicate(Optional.empty());
    }
}

引用的其他类