FoodPredicate .java

net.minecraft.advancements.predicates.FoodPredicate (record): members: saturation, ANY, matches, Builder, level, CODEC. strings: "saturation", "level".

net.minecraft.advancements.predicatesrecord44 linescommon1.5 KB

API Surface (6)

record FoodPredicate(MinMaxBounds.Ints level, MinMaxBounds.Doubles saturation)
boolean matches(final FoodData food)
FoodPredicate.Builder withLevel(final MinMaxBounds.Ints level)
FoodPredicate.Builder withSaturation(final MinMaxBounds.Doubles saturation)
FoodPredicate.Builder food()
FoodPredicate build()

Fields & Constants (2)

ANY
CODEC

String literals (2)

"level"
"saturation"

Code Graph: Dependencies (2)

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

Full Source

FoodPredicate.java44 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.world.food.FoodData;
6
7
public record FoodPredicate(MinMaxBounds.Ints level, MinMaxBounds.Doubles saturation) {
8
	public static final FoodPredicate ANY = new FoodPredicate(MinMaxBounds.Ints.ANY, MinMaxBounds.Doubles.ANY);
9
	public static final Codec<FoodPredicate> CODEC = RecordCodecBuilder.create(
10
		i -> i.group(
11
				MinMaxBounds.Ints.CODEC.optionalFieldOf("level", MinMaxBounds.Ints.ANY).forGetter(FoodPredicate::level),
12
				MinMaxBounds.Doubles.CODEC.optionalFieldOf("saturation", MinMaxBounds.Doubles.ANY).forGetter(FoodPredicate::saturation)
13
			)
14
			.apply(i, FoodPredicate::new)
15
	);
16
17
	public boolean matches(final FoodData food) {
18
		return !this.level.matches(food.getFoodLevel()) ? false : this.saturation.matches(food.getSaturationLevel());
19
	}
20
21
	public static class Builder {
22
		private MinMaxBounds.Ints level = MinMaxBounds.Ints.ANY;
23
		private MinMaxBounds.Doubles saturation = MinMaxBounds.Doubles.ANY;
24
25
		public FoodPredicate.Builder withLevel(final MinMaxBounds.Ints level) {
26
			this.level = level;
27
			return this;
28
		}
29
30
		public FoodPredicate.Builder withSaturation(final MinMaxBounds.Doubles saturation) {
31
			this.saturation = saturation;
32
			return this;
33
		}
34
35
		public static FoodPredicate.Builder food() {
36
			return new FoodPredicate.Builder();
37
		}
38
39
		public FoodPredicate build() {
40
			return new FoodPredicate(this.level, this.saturation);
41
		}
42
	}
43
}
44

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