NoiseThresholdCondition .java

net.minecraft.world.level.levelgen.material.condition.NoiseThresholdCondition (record): members: noise, minThreshold, maxThreshold, is3d, compile, codec.

net.minecraft.world.level.levelgen.material.conditionrecord37 linescommon1.5 KB

Implements

API Surface (2)

MapCodec<NoiseThresholdCondition> codec()
ConditionEvaluator compile(final MaterialRuleContext ruleContext)

Fields & Constants (1)

CODEC

String literals (3)

"noise"
"min_threshold"
"max_threshold"

Code Graph: Dependencies (6)

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

Full Source

NoiseThresholdCondition.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.material.condition;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.function.DoubleSupplier;
7
import net.minecraft.core.registries.Registries;
8
import net.minecraft.resources.ResourceKey;
9
import net.minecraft.world.level.levelgen.material.MaterialRuleContext;
10
import net.minecraft.world.level.levelgen.synth.NormalNoise;
11
12
public record NoiseThresholdCondition(ResourceKey<NormalNoise> noise, double minThreshold, double maxThreshold, boolean is3d) implements MaterialCondition {
13
	public static final MapCodec<NoiseThresholdCondition> CODEC = RecordCodecBuilder.mapCodec(
14
		i -> i.group(
15
				ResourceKey.codec(Registries.NOISE).fieldOf("noise").forGetter(NoiseThresholdCondition::noise),
16
				Codec.DOUBLE.fieldOf("min_threshold").forGetter(NoiseThresholdCondition::minThreshold),
17
				Codec.DOUBLE.fieldOf("max_threshold").forGetter(NoiseThresholdCondition::maxThreshold),
18
				Codec.BOOL.optionalFieldOf("is_3d", false).forGetter(NoiseThresholdCondition::is3d)
19
			)
20
			.apply(i, NoiseThresholdCondition::new)
21
	);
22
23
	@Override
24
	public MapCodec<NoiseThresholdCondition> codec() {
25
		return CODEC;
26
	}
27
28
	@Override
29
	public ConditionEvaluator compile(final MaterialRuleContext ruleContext) {
30
		DoubleSupplier noise = ruleContext.getNoiseSampler(this.noise, this.is3d);
31
		return () -> {
32
			double value = noise.getAsDouble();
33
			return value >= this.minThreshold && value <= this.maxThreshold;
34
		};
35
	}
36
}
37

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