UniformHeight .java

net.minecraft.world.level.levelgen.heightproviders.UniformHeight (class): members: warnedFor, maxInclusive, minInclusive, sample, getType, LOGGER, CODEC.

net.minecraft.world.level.levelgen.heightprovidersclass60 linescommonextends HeightProvider2.0 KB

API Surface (4)

UniformHeight of(final VerticalAnchor minInclusive, final VerticalAnchor maxInclusive)
int sample(final RandomSource random, final WorldGenerationContext context)
HeightProviderType<?> getType()
String toString()

Fields & Constants (5)

CODEC
LOGGER
minInclusive
maxInclusive
warnedFor

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

UniformHeight.java60 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.heightproviders;
2
3
import com.mojang.logging.LogUtils;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
7
import it.unimi.dsi.fastutil.longs.LongSet;
8
import net.minecraft.util.Mth;
9
import net.minecraft.util.RandomSource;
10
import net.minecraft.world.level.levelgen.VerticalAnchor;
11
import net.minecraft.world.level.levelgen.WorldGenerationContext;
12
import org.slf4j.Logger;
13
14
public class UniformHeight extends HeightProvider {
15
	public static final MapCodec<UniformHeight> CODEC = RecordCodecBuilder.mapCodec(
16
		i -> i.group(
17
				VerticalAnchor.CODEC.fieldOf("min_inclusive").forGetter(u -> u.minInclusive), VerticalAnchor.CODEC.fieldOf("max_inclusive").forGetter(u -> u.maxInclusive)
18
			)
19
			.apply(i, UniformHeight::new)
20
	);
21
	private static final Logger LOGGER = LogUtils.getLogger();
22
	private final VerticalAnchor minInclusive;
23
	private final VerticalAnchor maxInclusive;
24
	private final LongSet warnedFor = new LongOpenHashSet();
25
26
	private UniformHeight(final VerticalAnchor minInclusive, final VerticalAnchor maxInclusive) {
27
		this.minInclusive = minInclusive;
28
		this.maxInclusive = maxInclusive;
29
	}
30
31
	public static UniformHeight of(final VerticalAnchor minInclusive, final VerticalAnchor maxInclusive) {
32
		return new UniformHeight(minInclusive, maxInclusive);
33
	}
34
35
	@Override
36
	public int sample(final RandomSource random, final WorldGenerationContext context) {
37
		int min = this.minInclusive.resolveY(context);
38
		int max = this.maxInclusive.resolveY(context);
39
		if (min > max) {
40
			if (this.warnedFor.add((long)min << 32 | max)) {
41
				LOGGER.warn("Empty height range: {}", this);
42
			}
43
44
			return min;
45
		} else {
46
			return Mth.randomBetweenInclusive(random, min, max);
47
		}
48
	}
49
50
	@Override
51
	public HeightProviderType<?> getType() {
52
		return HeightProviderType.UNIFORM;
53
	}
54
55
	@Override
56
	public String toString() {
57
		return "[" + this.minInclusive + "-" + this.maxInclusive + "]";
58
	}
59
}
60

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