BiasedToBottomHeight .java

net.minecraft.world.level.levelgen.heightproviders.BiasedToBottomHeight (class): members: inner, maxInclusive, minInclusive, sample, getType, LOGGER.

net.minecraft.world.level.levelgen.heightprovidersclass59 linescommonextends HeightProvider2.1 KB

API Surface (4)

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

Fields & Constants (5)

CODEC
LOGGER
minInclusive
maxInclusive
inner

String literals (5)

"min_inclusive"
"max_inclusive"
"inner"
"biased["
" inner: "

Code Graph: Dependencies (5)

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

Full Source

BiasedToBottomHeight.java59 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.Codec;
5
import com.mojang.serialization.MapCodec;
6
import com.mojang.serialization.codecs.RecordCodecBuilder;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.level.levelgen.VerticalAnchor;
9
import net.minecraft.world.level.levelgen.WorldGenerationContext;
10
import org.slf4j.Logger;
11
12
public class BiasedToBottomHeight extends HeightProvider {
13
	public static final MapCodec<BiasedToBottomHeight> CODEC = RecordCodecBuilder.mapCodec(
14
		i -> i.group(
15
				VerticalAnchor.CODEC.fieldOf("min_inclusive").forGetter(u -> u.minInclusive),
16
				VerticalAnchor.CODEC.fieldOf("max_inclusive").forGetter(u -> u.maxInclusive),
17
				Codec.intRange(1, Integer.MAX_VALUE).optionalFieldOf("inner", 1).forGetter(u -> u.inner)
18
			)
19
			.apply(i, BiasedToBottomHeight::new)
20
	);
21
	private static final Logger LOGGER = LogUtils.getLogger();
22
	private final VerticalAnchor minInclusive;
23
	private final VerticalAnchor maxInclusive;
24
	private final int inner;
25
26
	private BiasedToBottomHeight(final VerticalAnchor minInclusive, final VerticalAnchor maxInclusive, final int inner) {
27
		this.minInclusive = minInclusive;
28
		this.maxInclusive = maxInclusive;
29
		this.inner = inner;
30
	}
31
32
	public static BiasedToBottomHeight of(final VerticalAnchor minInclusive, final VerticalAnchor maxInclusive, final int offset) {
33
		return new BiasedToBottomHeight(minInclusive, maxInclusive, offset);
34
	}
35
36
	@Override
37
	public int sample(final RandomSource random, final WorldGenerationContext context) {
38
		int min = this.minInclusive.resolveY(context);
39
		int max = this.maxInclusive.resolveY(context);
40
		if (max - min - this.inner + 1 <= 0) {
41
			LOGGER.warn("Empty height range: {}", this);
42
			return min;
43
		} else {
44
			int limit = random.nextInt(max - min - this.inner + 1);
45
			return random.nextInt(limit + this.inner) + min;
46
		}
47
	}
48
49
	@Override
50
	public HeightProviderType<?> getType() {
51
		return HeightProviderType.BIASED_TO_BOTTOM;
52
	}
53
54
	@Override
55
	public String toString() {
56
		return "biased[" + this.minInclusive + "-" + this.maxInclusive + " inner: " + this.inner + "]";
57
	}
58
}
59

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