RandomSpreadFoliagePlacer .java

net.minecraft.world.level.levelgen.feature.foliageplacers.RandomSpreadFoliagePlacer (class): members: leafPlacementAttempts, shouldSkipLocation, tree.

net.minecraft.world.level.levelgen.feature.foliageplacersclass74 linescommonextends FoliagePlacer2.5 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
foliageHeight
leafPlacementAttempts
level
foliageSetter
random
tree
treeHeight
foliageAttachment
leafRadius

String literals (2)

"foliage_height"
"leaf_placement_attempts"

Full Source

RandomSpreadFoliagePlacer.java74 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature.foliageplacers;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import net.minecraft.core.BlockPos;
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 RandomSpreadFoliagePlacer extends FoliagePlacer {
14
	public static final MapCodec<RandomSpreadFoliagePlacer> CODEC = RecordCodecBuilder.mapCodec(
15
		i -> foliagePlacerParts(i)
16
			.and(
17
				i.group(
18
					IntProviders.codec(1, 512).fieldOf("foliage_height").forGetter(c -> c.foliageHeight),
19
					Codec.intRange(0, 256).fieldOf("leaf_placement_attempts").forGetter(c -> c.leafPlacementAttempts)
20
				)
21
			)
22
			.apply(i, RandomSpreadFoliagePlacer::new)
23
	);
24
	private final IntProvider foliageHeight;
25
	private final int leafPlacementAttempts;
26
27
	public RandomSpreadFoliagePlacer(final IntProvider radius, final IntProvider offset, final IntProvider foliageHeight, final int leafPlacementAttempts) {
28
		super(radius, offset);
29
		this.foliageHeight = foliageHeight;
30
		this.leafPlacementAttempts = leafPlacementAttempts;
31
	}
32
33
	@Override
34
	protected FoliagePlacerType<?> type() {
35
		return FoliagePlacerType.RANDOM_SPREAD_FOLIAGE_PLACER;
36
	}
37
38
	@Override
39
	protected void createFoliage(
40
		final WorldGenLevel level,
41
		final FoliagePlacer.FoliageSetter foliageSetter,
42
		final RandomSource random,
43
		final TreeFeature tree,
44
		final int treeHeight,
45
		final FoliagePlacer.FoliageAttachment foliageAttachment,
46
		final int foliageHeight,
47
		final int leafRadius,
48
		final int offset
49
	) {
50
		BlockPos origin = foliageAttachment.pos();
51
		BlockPos.MutableBlockPos pos = origin.mutable();
52
53
		for (int i = 0; i < this.leafPlacementAttempts; i++) {
54
			pos.setWithOffset(
55
				origin,
56
				random.nextInt(leafRadius) - random.nextInt(leafRadius),
57
				random.nextInt(foliageHeight) - random.nextInt(foliageHeight),
58
				random.nextInt(leafRadius) - random.nextInt(leafRadius)
59
			);
60
			tryPlaceLeaf(level, foliageSetter, random, tree, pos);
61
		}
62
	}
63
64
	@Override
65
	public int foliageHeight(final RandomSource random, final int treeHeight, final TreeFeature tree) {
66
		return this.foliageHeight.sample(random);
67
	}
68
69
	@Override
70
	protected boolean shouldSkipLocation(final RandomSource random, final int dx, final int y, final int dz, final int currentRadius, final boolean doubleTrunk) {
71
		return false;
72
	}
73
}
74

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