MegaPineFoliagePlacer .java

net.minecraft.world.level.levelgen.feature.foliageplacers.MegaPineFoliagePlacer (class): members: crownHeight, shouldSkipLocation, foliageAttachment, tree.

net.minecraft.world.level.levelgen.feature.foliageplacersclass72 linescommonextends FoliagePlacer2.6 KB

API Surface (4)

FoliagePlacerType<?> type()
void createFoliage(final WorldGenLevel level, final FoliagePlacer.FoliageSetter foliageSetter, final RandomSource random, final TreeFeature tree, final int treeHeight, final FoliagePlacer.FoliageAttachment foliageAttachment, final int foliageHeight, final int leafRadius, final int offset)
int foliageHeight(final RandomSource random, final int treeHeight, final TreeFeature tree)
boolean shouldSkipLocation(final RandomSource random, final int dx, final int y, final int dz, final int currentRadius, final boolean doubleTrunk)

Fields & Constants (10)

CODEC
crownHeight
level
foliageSetter
random
tree
treeHeight
foliageAttachment
foliageHeight
leafRadius

String literals (1)

"crown_height"

Full Source

MegaPineFoliagePlacer.java72 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature.foliageplacers;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.util.Mth;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.util.valueproviders.IntProvider;
9
import net.minecraft.util.valueproviders.IntProviders;
10
import net.minecraft.world.level.WorldGenLevel;
11
import net.minecraft.world.level.levelgen.feature.TreeFeature;
12
13
public class MegaPineFoliagePlacer extends FoliagePlacer {
14
	public static final MapCodec<MegaPineFoliagePlacer> CODEC = RecordCodecBuilder.mapCodec(
15
		i -> foliagePlacerParts(i).and(IntProviders.codec(0, 24).fieldOf("crown_height").forGetter(p -> p.crownHeight)).apply(i, MegaPineFoliagePlacer::new)
16
	);
17
	private final IntProvider crownHeight;
18
19
	public MegaPineFoliagePlacer(final IntProvider radius, final IntProvider offset, final IntProvider crownHeight) {
20
		super(radius, offset);
21
		this.crownHeight = crownHeight;
22
	}
23
24
	@Override
25
	protected FoliagePlacerType<?> type() {
26
		return FoliagePlacerType.MEGA_PINE_FOLIAGE_PLACER;
27
	}
28
29
	@Override
30
	protected void createFoliage(
31
		final WorldGenLevel level,
32
		final FoliagePlacer.FoliageSetter foliageSetter,
33
		final RandomSource random,
34
		final TreeFeature tree,
35
		final int treeHeight,
36
		final FoliagePlacer.FoliageAttachment foliageAttachment,
37
		final int foliageHeight,
38
		final int leafRadius,
39
		final int offset
40
	) {
41
		BlockPos foliagePos = foliageAttachment.pos();
42
		int prevRadius = 0;
43
		int foliageHeightWithOffset = foliageHeight + foliageAttachment.foliageHeightOffset();
44
45
		for (int yy = foliagePos.getY() - foliageHeightWithOffset + offset; yy <= foliagePos.getY() + offset; yy++) {
46
			int yo = foliagePos.getY() - yy;
47
			int smoothRadius = leafRadius + foliageAttachment.radiusOffsetXZ() + Mth.floor((float)yo / foliageHeightWithOffset * 3.5F);
48
			int jaggedRadius;
49
			if (yo > 0 && smoothRadius == prevRadius && (yy & 1) == 0) {
50
				jaggedRadius = smoothRadius + 1;
51
			} else {
52
				jaggedRadius = smoothRadius;
53
			}
54
55
			this.placeLeavesRow(
56
				level, foliageSetter, random, tree, new BlockPos(foliagePos.getX(), yy, foliagePos.getZ()), jaggedRadius, 0, foliageAttachment.doubleTrunk()
57
			);
58
			prevRadius = smoothRadius;
59
		}
60
	}
61
62
	@Override
63
	public int foliageHeight(final RandomSource random, final int treeHeight, final TreeFeature tree) {
64
		return this.crownHeight.sample(random);
65
	}
66
67
	@Override
68
	protected boolean shouldSkipLocation(final RandomSource random, final int dx, final int y, final int dz, final int currentRadius, final boolean doubleTrunk) {
69
		return dx + dz >= 7 ? true : dx * dx + dz * dz > currentRadius * currentRadius;
70
	}
71
}
72

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