TagPredicate .java

net.minecraft.advancements.predicates.TagPredicate (record, 43 lines): members: tag, expected, isNot, matches, codec. strings: "expected". imports: TagKey.

net.minecraft.advancements.predicatesrecord43 linescommon1.4 KB

API Surface (6)

<T> Codec<TagPredicate<T>> codec(final ResourceKey<? extends Registry<T>> registryKey)
<T> TagPredicate<T> is(final HolderGetter<T> lookup, final TagKey<T> tag)
<T> TagPredicate<T> is(final HolderSet<T> tag)
<T> TagPredicate<T> isNot(final HolderGetter<T> lookup, final TagKey<T> tag)
<T> TagPredicate<T> isNot(final HolderSet<T> tag)
boolean matches(final Holder<T> holder)

String literals (1)

"expected"

Full Source

TagPredicate.java43 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.advancements.predicates;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.minecraft.core.Holder;
6
import net.minecraft.core.HolderGetter;
7
import net.minecraft.core.HolderSet;
8
import net.minecraft.core.Registry;
9
import net.minecraft.core.registries.codec.RegistryCodecs;
10
import net.minecraft.resources.ResourceKey;
11
import net.minecraft.tags.TagKey;
12
13
public record TagPredicate<T>(HolderSet<T> tag, boolean expected) {
14
	public static <T> Codec<TagPredicate<T>> codec(final ResourceKey<? extends Registry<T>> registryKey) {
15
		return RecordCodecBuilder.create(
16
			i -> i.group(
17
					RegistryCodecs.holderSet(registryKey).fieldOf("id").forGetter(TagPredicate::tag), Codec.BOOL.fieldOf("expected").forGetter(TagPredicate::expected)
18
				)
19
				.apply(i, TagPredicate::new)
20
		);
21
	}
22
23
	public static <T> TagPredicate<T> is(final HolderGetter<T> lookup, final TagKey<T> tag) {
24
		return is(lookup.getOrThrow(tag));
25
	}
26
27
	public static <T> TagPredicate<T> is(final HolderSet<T> tag) {
28
		return new TagPredicate<>(tag, true);
29
	}
30
31
	public static <T> TagPredicate<T> isNot(final HolderGetter<T> lookup, final TagKey<T> tag) {
32
		return isNot(lookup.getOrThrow(tag));
33
	}
34
35
	public static <T> TagPredicate<T> isNot(final HolderSet<T> tag) {
36
		return new TagPredicate<>(tag, false);
37
	}
38
39
	public boolean matches(final Holder<T> holder) {
40
		return this.tag.contains(holder) == this.expected;
41
	}
42
}
43

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