EntityTypePredicate .java

net.minecraft.advancements.predicates.entity.EntityTypePredicate (record, 37 lines): members: types, matches, CODEC. imports: TagKey.

net.minecraft.advancements.predicates.entityrecord37 linescommon1.4 KB

Implements

API Surface (4)

EntityTypePredicate of(final HolderGetter<EntityType<?>> lookup, final EntityType<?> type)
EntityTypePredicate of(final HolderGetter<EntityType<?>> lookup, final TagKey<EntityType<?>> type)
boolean matches(final Holder<EntityType<?>> type)
boolean matches(final Entity entity, final ServerLevel level, final @Nullable Vec3 position)

Fields & Constants (1)

CODEC

Full Source

EntityTypePredicate.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.advancements.predicates.entity;
2
3
import com.mojang.serialization.Codec;
4
import net.minecraft.core.Holder;
5
import net.minecraft.core.HolderGetter;
6
import net.minecraft.core.HolderSet;
7
import net.minecraft.core.registries.Registries;
8
import net.minecraft.core.registries.codec.RegistryCodecs;
9
import net.minecraft.server.level.ServerLevel;
10
import net.minecraft.tags.TagKey;
11
import net.minecraft.world.entity.Entity;
12
import net.minecraft.world.entity.EntityType;
13
import net.minecraft.world.phys.Vec3;
14
import org.jspecify.annotations.Nullable;
15
16
public record EntityTypePredicate(HolderSet<EntityType<?>> types) implements EntitySubPredicate {
17
	public static final Codec<EntityTypePredicate> CODEC = RegistryCodecs.holderSet(Registries.ENTITY_TYPE)
18
		.xmap(EntityTypePredicate::new, EntityTypePredicate::types);
19
20
	public static EntityTypePredicate of(final HolderGetter<EntityType<?>> lookup, final EntityType<?> type) {
21
		return new EntityTypePredicate(HolderSet.direct(type.builtInRegistryHolder()));
22
	}
23
24
	public static EntityTypePredicate of(final HolderGetter<EntityType<?>> lookup, final TagKey<EntityType<?>> type) {
25
		return new EntityTypePredicate(lookup.getOrThrow(type));
26
	}
27
28
	public boolean matches(final Holder<EntityType<?>> type) {
29
		return this.types.contains(type);
30
	}
31
32
	@Override
33
	public boolean matches(final Entity entity, final ServerLevel level, final @Nullable Vec3 position) {
34
		return this.matches(entity.typeHolder());
35
	}
36
}
37

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