32 lines
1.3 KiB
Java
32 lines
1.3 KiB
Java
|
package net.minecraft.advancements.critereon;
|
||
|
|
||
|
import com.mojang.serialization.Codec;
|
||
|
import com.mojang.serialization.MapCodec;
|
||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||
|
import com.mojang.serialization.codecs.RecordCodecBuilder.Instance;
|
||
|
import java.util.Optional;
|
||
|
import javax.annotation.Nullable;
|
||
|
import net.minecraft.server.level.ServerLevel;
|
||
|
import net.minecraft.world.entity.Entity;
|
||
|
import net.minecraft.world.entity.animal.sheep.Sheep;
|
||
|
import net.minecraft.world.phys.Vec3;
|
||
|
|
||
|
public record SheepPredicate(Optional<Boolean> sheared) implements EntitySubPredicate {
|
||
|
public static final MapCodec<SheepPredicate> CODEC = RecordCodecBuilder.mapCodec(
|
||
|
p_389124_ -> p_389124_.group(Codec.BOOL.optionalFieldOf("sheared").forGetter(SheepPredicate::sheared)).apply(p_389124_, SheepPredicate::new)
|
||
|
);
|
||
|
|
||
|
@Override
|
||
|
public MapCodec<SheepPredicate> codec() {
|
||
|
return EntitySubPredicates.SHEEP;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean matches(Entity p_365747_, ServerLevel p_366681_, @Nullable Vec3 p_363108_) {
|
||
|
return p_365747_ instanceof Sheep sheep ? !this.sheared.isPresent() || sheep.isSheared() == this.sheared.get() : false;
|
||
|
}
|
||
|
|
||
|
public static SheepPredicate hasWool() {
|
||
|
return new SheepPredicate(Optional.of(false));
|
||
|
}
|
||
|
}
|