SheepPredicate .java

net.minecraft.advancements.predicates.entity.SheepPredicate (record): members: sheared, hasWool, matches, CODEC. strings: "sheared". imports: Sheep, Vec3.

net.minecraft.advancements.predicates.entityrecord26 linescommon1.0 KB

Implements

API Surface (2)

boolean matches(final Entity entity, final ServerLevel level, final @Nullable Vec3 position)
SheepPredicate hasWool()

Fields & Constants (1)

CODEC

String literals (1)

"sheared"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SheepPredicate.java26 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.advancements.predicates.entity;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import net.minecraft.server.level.ServerLevel;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.entity.animal.sheep.Sheep;
9
import net.minecraft.world.phys.Vec3;
10
import org.jspecify.annotations.Nullable;
11
12
public record SheepPredicate(Optional<Boolean> sheared) implements EntitySubPredicate {
13
	public static final Codec<SheepPredicate> CODEC = RecordCodecBuilder.create(
14
		i -> i.group(Codec.BOOL.optionalFieldOf("sheared").forGetter(SheepPredicate::sheared)).apply(i, SheepPredicate::new)
15
	);
16
17
	@Override
18
	public boolean matches(final Entity entity, final ServerLevel level, final @Nullable Vec3 position) {
19
		return entity instanceof Sheep sheep ? !this.sheared.isPresent() || sheep.isSheared() == this.sheared.get() : false;
20
	}
21
22
	public static SheepPredicate hasWool() {
23
		return new SheepPredicate(Optional.of(false));
24
	}
25
}
26

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