VolumeMatchPredicate .java

net.minecraft.world.level.levelgen.blockpredicates.VolumeMatchPredicate (record, 46 lines): members: min, max, match, UNVALIDATED_CODEC, test, type, CODEC.

net.minecraft.world.level.levelgen.blockpredicatesrecord46 linescommon1.7 KB

Implements

API Surface (2)

BlockPredicateType<VolumeMatchPredicate> type()
boolean test(final LevelAccessor level, final BlockPos blockPos)

Fields & Constants (2)

UNVALIDATED_CODEC
CODEC

String literals (2)

"match"
"min bound cannot be larger than max bound"

Code Graph: Dependencies (5)

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

Full Source

VolumeMatchPredicate.java46 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.blockpredicates;
2
3
import com.mojang.serialization.DataResult;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.core.Vec3i;
8
import net.minecraft.world.level.LevelAccessor;
9
10
public record VolumeMatchPredicate(Vec3i min, Vec3i max, BlockPredicate match) implements BlockPredicate {
11
	private static final MapCodec<VolumeMatchPredicate> UNVALIDATED_CODEC = RecordCodecBuilder.mapCodec(
12
		i -> i.group(
13
				Vec3i.offsetCodec(16).fieldOf("min").forGetter(VolumeMatchPredicate::min),
14
				Vec3i.offsetCodec(16).fieldOf("max").forGetter(VolumeMatchPredicate::max),
15
				BlockPredicate.CODEC.fieldOf("match").forGetter(VolumeMatchPredicate::match)
16
			)
17
			.apply(i, VolumeMatchPredicate::new)
18
	);
19
	public static final MapCodec<VolumeMatchPredicate> CODEC = UNVALIDATED_CODEC.validate(
20
		p -> p.min.getX() <= p.max.getX() && p.min.getY() <= p.max.getY() && p.min.getZ() <= p.max.getZ()
21
			? DataResult.success(p)
22
			: DataResult.error(() -> "min bound cannot be larger than max bound")
23
	);
24
25
	@Override
26
	public BlockPredicateType<VolumeMatchPredicate> type() {
27
		return BlockPredicateType.VOLUME_MATCH;
28
	}
29
30
	public boolean test(final LevelAccessor level, final BlockPos blockPos) {
31
		BlockPos.MutableBlockPos pos = blockPos.mutable();
32
33
		for (int ox = this.min.getX(); ox <= this.max.getX(); ox++) {
34
			for (int oz = this.min.getZ(); oz <= this.max.getZ(); oz++) {
35
				for (int oy = this.min.getY(); oy <= this.max.getY(); oy++) {
36
					if (!this.match.test(level, pos.setWithOffset(blockPos, ox, oy, oz))) {
37
						return false;
38
					}
39
				}
40
			}
41
		}
42
43
		return true;
44
	}
45
}
46

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