| 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 |
|