JukeboxPlayablePredicate .java

net.minecraft.core.component.predicates.JukeboxPlayablePredicate (record, 50 lines): members: song, any, componentType, matches, CODEC. strings: "song".

net.minecraft.core.component.predicatesrecord50 linescommon1.7 KB

Implements

API Surface (3)

DataComponentType<JukeboxPlayable> componentType()
boolean matches(final JukeboxPlayable value)
JukeboxPlayablePredicate any()

Fields & Constants (1)

CODEC

String literals (1)

"song"

Full Source

JukeboxPlayablePredicate.java50 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.core.component.predicates;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import net.minecraft.advancements.predicates.SingleComponentItemPredicate;
7
import net.minecraft.core.Holder;
8
import net.minecraft.core.HolderSet;
9
import net.minecraft.core.component.DataComponentType;
10
import net.minecraft.core.component.DataComponents;
11
import net.minecraft.core.registries.Registries;
12
import net.minecraft.core.registries.codec.RegistryCodecs;
13
import net.minecraft.resources.ResourceKey;
14
import net.minecraft.world.item.JukeboxPlayable;
15
import net.minecraft.world.item.JukeboxSong;
16
17
public record JukeboxPlayablePredicate(Optional<HolderSet<JukeboxSong>> song) implements SingleComponentItemPredicate<JukeboxPlayable> {
18
	public static final Codec<JukeboxPlayablePredicate> CODEC = RecordCodecBuilder.create(
19
		i -> i.group(RegistryCodecs.holderSet(Registries.JUKEBOX_SONG).optionalFieldOf("song").forGetter(JukeboxPlayablePredicate::song))
20
			.apply(i, JukeboxPlayablePredicate::new)
21
	);
22
23
	@Override
24
	public DataComponentType<JukeboxPlayable> componentType() {
25
		return DataComponents.JUKEBOX_PLAYABLE;
26
	}
27
28
	public boolean matches(final JukeboxPlayable value) {
29
		if (!this.song.isPresent()) {
30
			return true;
31
		}
32
33
		boolean songIsPresent = false;
34
35
		for (Holder<JukeboxSong> maybeSong : this.song.get()) {
36
			Optional<ResourceKey<JukeboxSong>> songId = maybeSong.unwrapKey();
37
			if (!songId.isEmpty() && songId.equals(value.song().unwrapKey())) {
38
				songIsPresent = true;
39
				break;
40
			}
41
		}
42
43
		return songIsPresent;
44
	}
45
46
	public static JukeboxPlayablePredicate any() {
47
		return new JukeboxPlayablePredicate(Optional.empty());
48
	}
49
}
50

Decompiled Minecraft 26.3 source of JukeboxPlayablePredicate (net/minecraft/core/component/predicates/JukeboxPlayablePredicate.java) with Mojang official mappings, stored verbatim on the site.