HeightRangePredicate .java

net.minecraft.world.level.levelgen.blockpredicates.HeightRangePredicate (record, 31 lines): members: minInclusive, maxInclusive, test, type, CODEC.

net.minecraft.world.level.levelgen.blockpredicatesrecord31 linescommon1.2 KB

Implements

API Surface (2)

BlockPredicateType<?> type()
boolean test(final LevelAccessor level, final BlockPos pos)

Fields & Constants (1)

CODEC

String literals (2)

"min_inclusive"
"max_inclusive"

Code Graph: Dependencies (6)

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

Full Source

HeightRangePredicate.java31 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.blockpredicates;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.world.level.LevelAccessor;
7
import net.minecraft.world.level.levelgen.VerticalAnchor;
8
import net.minecraft.world.level.levelgen.WorldGenerationContext;
9
10
public record HeightRangePredicate(VerticalAnchor minInclusive, VerticalAnchor maxInclusive) implements BlockPredicate {
11
	public static final MapCodec<HeightRangePredicate> CODEC = RecordCodecBuilder.mapCodec(
12
		i -> i.group(
13
				VerticalAnchor.CODEC.fieldOf("min_inclusive").forGetter(HeightRangePredicate::minInclusive),
14
				VerticalAnchor.CODEC.fieldOf("max_inclusive").forGetter(HeightRangePredicate::maxInclusive)
15
			)
16
			.apply(i, HeightRangePredicate::new)
17
	);
18
19
	@Override
20
	public BlockPredicateType<?> type() {
21
		return BlockPredicateType.HEIGHT_RANGE;
22
	}
23
24
	public boolean test(final LevelAccessor level, final BlockPos pos) {
25
		WorldGenerationContext context = WorldGenerationContext.of(level);
26
		int min = this.minInclusive.resolveY(context);
27
		int max = this.maxInclusive.resolveY(context);
28
		return pos.getY() >= min && pos.getY() <= max;
29
	}
30
}
31

Decompiled Minecraft 26.3 source of HeightRangePredicate (net/minecraft/world/level/levelgen/blockpredicates/HeightRangePredicate.java) with Mojang official mappings, stored verbatim on the site.