PineFoliagePlacer .java

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

net.minecraft.world.level.levelgen.feature.foliageplacersclass67 linescommonextends FoliagePlacer2.4 KB

API Surface (5)

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 foliageRadius(final RandomSource random, final int trunkHeight)
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
height
level
foliageSetter
random
tree
treeHeight
foliageAttachment
foliageHeight
leafRadius

String literals (1)

"height"

Full Source

PineFoliagePlacer.java67 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.util.RandomSource;
6
import net.minecraft.util.valueproviders.IntProvider;
7
import net.minecraft.util.valueproviders.IntProviders;
8
import net.minecraft.world.level.WorldGenLevel;
9
import net.minecraft.world.level.levelgen.feature.TreeFeature;
10
11
public class PineFoliagePlacer extends FoliagePlacer {
12
	public static final MapCodec<PineFoliagePlacer> CODEC = RecordCodecBuilder.mapCodec(
13
		i -> foliagePlacerParts(i).and(IntProviders.codec(0, 24).fieldOf("height").forGetter(p -> p.height)).apply(i, PineFoliagePlacer::new)
14
	);
15
	private final IntProvider height;
16
17
	public PineFoliagePlacer(final IntProvider radius, final IntProvider offset, final IntProvider height) {
18
		super(radius, offset);
19
		this.height = height;
20
	}
21
22
	@Override
23
	protected FoliagePlacerType<?> type() {
24
		return FoliagePlacerType.PINE_FOLIAGE_PLACER;
25
	}
26
27
	@Override
28
	protected void createFoliage(
29
		final WorldGenLevel level,
30
		final FoliagePlacer.FoliageSetter foliageSetter,
31
		final RandomSource random,
32
		final TreeFeature tree,
33
		final int treeHeight,
34
		final FoliagePlacer.FoliageAttachment foliageAttachment,
35
		final int foliageHeight,
36
		final int leafRadius,
37
		final int offset
38
	) {
39
		int currentRadius = 0;
40
		int foliageHeightWithOffset = foliageHeight + foliageAttachment.foliageHeightOffset();
41
42
		for (int yo = offset; yo >= offset - foliageHeightWithOffset; yo--) {
43
			this.placeLeavesRow(level, foliageSetter, random, tree, foliageAttachment.pos(), currentRadius, yo, foliageAttachment.doubleTrunk());
44
			if (currentRadius >= 1 && yo == offset - foliageHeightWithOffset + 1) {
45
				currentRadius--;
46
			} else if (currentRadius < leafRadius + foliageAttachment.radiusOffsetXZ()) {
47
				currentRadius++;
48
			}
49
		}
50
	}
51
52
	@Override
53
	public int foliageRadius(final RandomSource random, final int trunkHeight) {
54
		return super.foliageRadius(random, trunkHeight) + random.nextInt(Math.max(trunkHeight + 1, 1));
55
	}
56
57
	@Override
58
	public int foliageHeight(final RandomSource random, final int treeHeight, final TreeFeature tree) {
59
		return this.height.sample(random);
60
	}
61
62
	@Override
63
	protected boolean shouldSkipLocation(final RandomSource random, final int dx, final int y, final int dz, final int currentRadius, final boolean doubleTrunk) {
64
		return dx == currentRadius && dz == currentRadius && currentRadius > 0;
65
	}
66
}
67

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