ForkingTrunkPlacer .java

net.minecraft.world.level.levelgen.feature.trunkplacers.ForkingTrunkPlacer (class): members: trunkSetter, placeTrunk, treeHeight, origin, random, level.

net.minecraft.world.level.levelgen.feature.trunkplacersclass94 linescommonextends TrunkPlacer3.1 KB

API Surface (2)

TrunkPlacerType<?> type()
List<FoliagePlacer.FoliageAttachment> placeTrunk(final WorldGenLevel level, final BiConsumer<BlockPos, BlockState> trunkSetter, final RandomSource random, final int treeHeight, final BlockPos origin, final TreeFeature tree)

Fields & Constants (6)

CODEC
level
trunkSetter
random
treeHeight
origin

Full Source

ForkingTrunkPlacer.java94 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature.trunkplacers;
2
3
import com.google.common.collect.Lists;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.List;
7
import java.util.OptionalInt;
8
import java.util.function.BiConsumer;
9
import net.minecraft.core.BlockPos;
10
import net.minecraft.core.Direction;
11
import net.minecraft.util.RandomSource;
12
import net.minecraft.world.level.WorldGenLevel;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.level.levelgen.feature.TreeFeature;
15
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;
16
17
public class ForkingTrunkPlacer extends TrunkPlacer {
18
	public static final MapCodec<ForkingTrunkPlacer> CODEC = RecordCodecBuilder.mapCodec(i -> trunkPlacerParts(i).apply(i, ForkingTrunkPlacer::new));
19
20
	public ForkingTrunkPlacer(final int baseHeight, final int heightRandA, final int heightRandB) {
21
		super(baseHeight, heightRandA, heightRandB);
22
	}
23
24
	@Override
25
	protected TrunkPlacerType<?> type() {
26
		return TrunkPlacerType.FORKING_TRUNK_PLACER;
27
	}
28
29
	@Override
30
	public List<FoliagePlacer.FoliageAttachment> placeTrunk(
31
		final WorldGenLevel level,
32
		final BiConsumer<BlockPos, BlockState> trunkSetter,
33
		final RandomSource random,
34
		final int treeHeight,
35
		final BlockPos origin,
36
		final TreeFeature tree
37
	) {
38
		placeBelowTrunkBlock(level, trunkSetter, random, origin.below(), tree);
39
		List<FoliagePlacer.FoliageAttachment> attachments = Lists.newArrayList();
40
		Direction leanDirection = Direction.Plane.HORIZONTAL.getRandomDirection(random);
41
		int leanHeight = treeHeight - random.nextInt(4) - 1;
42
		int leanSteps = 3 - random.nextInt(3);
43
		BlockPos.MutableBlockPos logPos = new BlockPos.MutableBlockPos();
44
		int tx = origin.getX();
45
		int tz = origin.getZ();
46
		OptionalInt ey = OptionalInt.empty();
47
48
		for (int yo = 0; yo < treeHeight; yo++) {
49
			int yy = origin.getY() + yo;
50
			if (yo >= leanHeight && leanSteps > 0) {
51
				tx += leanDirection.getStepX();
52
				tz += leanDirection.getStepZ();
53
				leanSteps--;
54
			}
55
56
			if (this.placeLog(level, trunkSetter, random, logPos.set(tx, yy, tz), tree)) {
57
				ey = OptionalInt.of(yy + 1);
58
			}
59
		}
60
61
		if (ey.isPresent()) {
62
			attachments.add(new FoliagePlacer.FoliageAttachment(new BlockPos(tx, ey.getAsInt(), tz), 1, false));
63
		}
64
65
		tx = origin.getX();
66
		tz = origin.getZ();
67
		Direction branchDirection = Direction.Plane.HORIZONTAL.getRandomDirection(random);
68
		if (branchDirection != leanDirection) {
69
			int branchPos = leanHeight - random.nextInt(2) - 1;
70
			int branchSteps = 1 + random.nextInt(3);
71
			ey = OptionalInt.empty();
72
73
			for (int yo = branchPos; yo < treeHeight && branchSteps > 0; branchSteps--) {
74
				if (yo >= 1) {
75
					int yy = origin.getY() + yo;
76
					tx += branchDirection.getStepX();
77
					tz += branchDirection.getStepZ();
78
					if (this.placeLog(level, trunkSetter, random, logPos.set(tx, yy, tz), tree)) {
79
						ey = OptionalInt.of(yy + 1);
80
					}
81
				}
82
83
				yo++;
84
			}
85
86
			if (ey.isPresent()) {
87
				attachments.add(new FoliagePlacer.FoliageAttachment(new BlockPos(tx, ey.getAsInt(), tz), 0, false));
88
			}
89
		}
90
91
		return attachments;
92
	}
93
}
94

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