StoneDepthCondition .java

net.minecraft.world.level.levelgen.material.condition.StoneDepthCondition (record, 42 lines): members: offset, addSurfaceDepth, secondaryDepthRange, codec.

net.minecraft.world.level.levelgen.material.conditionrecord42 linescommon1.9 KB

Implements

API Surface (3)

MapCodec<StoneDepthCondition> codec()
ConditionEvaluator compile(final MaterialRuleContext ruleContext)
boolean compute()

Fields & Constants (1)

CODEC

String literals (4)

"offset"
"add_surface_depth"
"secondary_depth_range"
"surface_type"

Code Graph: Dependencies (5)

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

Full Source

StoneDepthCondition.java42 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 net.minecraft.util.Mth;
7
import net.minecraft.world.level.levelgen.material.MaterialRuleContext;
8
import net.minecraft.world.level.levelgen.placement.CaveSurface;
9
10
public record StoneDepthCondition(int offset, boolean addSurfaceDepth, int secondaryDepthRange, CaveSurface surfaceType) implements MaterialCondition {
11
	public static final MapCodec<StoneDepthCondition> CODEC = RecordCodecBuilder.mapCodec(
12
		i -> i.group(
13
				Codec.INT.fieldOf("offset").forGetter(StoneDepthCondition::offset),
14
				Codec.BOOL.fieldOf("add_surface_depth").forGetter(StoneDepthCondition::addSurfaceDepth),
15
				Codec.INT.fieldOf("secondary_depth_range").forGetter(StoneDepthCondition::secondaryDepthRange),
16
				CaveSurface.CODEC.fieldOf("surface_type").forGetter(StoneDepthCondition::surfaceType)
17
			)
18
			.apply(i, StoneDepthCondition::new)
19
	);
20
21
	@Override
22
	public MapCodec<StoneDepthCondition> codec() {
23
		return CODEC;
24
	}
25
26
	@Override
27
	public ConditionEvaluator compile(final MaterialRuleContext ruleContext) {
28
		final boolean ceiling = this.surfaceType == CaveSurface.CEILING;
29
		return new MaterialRuleContext.LazyYCondition(ruleContext) {
30
			@Override
31
			protected boolean compute() {
32
				int stoneDepth = ceiling ? this.context.stoneDepthBelow() : this.context.stoneDepthAbove();
33
				int surfaceDepth = StoneDepthCondition.this.addSurfaceDepth ? this.context.surfaceDepth() : 0;
34
				int secondarySurfaceDepth = StoneDepthCondition.this.secondaryDepthRange == 0
35
					? 0
36
					: (int)Mth.map(this.context.getSurfaceSecondary(), -1.0, 1.0, 0.0, StoneDepthCondition.this.secondaryDepthRange);
37
				return stoneDepth <= 1 + StoneDepthCondition.this.offset + surfaceDepth + secondarySurfaceDepth;
38
			}
39
		};
40
	}
41
}
42

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