BambooFeature .java

net.minecraft.world.level.levelgen.feature.BambooFeature (record): members: probability, BAMBOO_FINAL_LARGE, BAMBOO_TOP_LARGE, BAMBOO_TOP_SMALL, place.

net.minecraft.world.level.levelgen.featurerecord79 linescommon3.2 KB

Implements

API Surface (2)

MapCodec<BambooFeature> codec()
boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin)

Fields & Constants (5)

BAMBOO_TRUNK
BAMBOO_FINAL_LARGE
BAMBOO_TOP_LARGE
BAMBOO_TOP_SMALL
CODEC

String literals (1)

"probability"

Full Source

BambooFeature.java79 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature;
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.core.Direction;
8
import net.minecraft.tags.BlockTags;
9
import net.minecraft.util.RandomSource;
10
import net.minecraft.world.level.WorldGenLevel;
11
import net.minecraft.world.level.block.BambooStalkBlock;
12
import net.minecraft.world.level.block.Blocks;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.level.block.state.properties.BambooLeaves;
15
import net.minecraft.world.level.chunk.ChunkGenerator;
16
import net.minecraft.world.level.levelgen.Heightmap;
17
18
public record BambooFeature(float probability) implements Feature {
19
	private static final BlockState BAMBOO_TRUNK = Blocks.BAMBOO
20
		.defaultBlockState()
21
		.setValue(BambooStalkBlock.AGE, 1)
22
		.setValue(BambooStalkBlock.LEAVES, BambooLeaves.NONE)
23
		.setValue(BambooStalkBlock.STAGE, 0);
24
	private static final BlockState BAMBOO_FINAL_LARGE = BAMBOO_TRUNK.setValue(BambooStalkBlock.LEAVES, BambooLeaves.LARGE).setValue(BambooStalkBlock.STAGE, 1);
25
	private static final BlockState BAMBOO_TOP_LARGE = BAMBOO_TRUNK.setValue(BambooStalkBlock.LEAVES, BambooLeaves.LARGE);
26
	private static final BlockState BAMBOO_TOP_SMALL = BAMBOO_TRUNK.setValue(BambooStalkBlock.LEAVES, BambooLeaves.SMALL);
27
	public static final MapCodec<BambooFeature> CODEC = RecordCodecBuilder.mapCodec(
28
		i -> i.group(Codec.floatRange(0.0F, 1.0F).fieldOf("probability").forGetter(BambooFeature::probability)).apply(i, BambooFeature::new)
29
	);
30
31
	@Override
32
	public MapCodec<BambooFeature> codec() {
33
		return CODEC;
34
	}
35
36
	@Override
37
	public boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
38
		int placed = 0;
39
		BlockPos.MutableBlockPos bambooPos = origin.mutable();
40
		BlockPos.MutableBlockPos podzolPos = origin.mutable();
41
		if (level.isEmptyBlock(bambooPos)) {
42
			if (Blocks.BAMBOO.defaultBlockState().canSurvive(level, bambooPos)) {
43
				int height = random.nextInt(12) + 5;
44
				if (random.nextFloat() < this.probability) {
45
					int r = random.nextInt(4) + 1;
46
47
					for (int xx = origin.getX() - r; xx <= origin.getX() + r; xx++) {
48
						for (int zz = origin.getZ() - r; zz <= origin.getZ() + r; zz++) {
49
							int xd = xx - origin.getX();
50
							int zd = zz - origin.getZ();
51
							if (xd * xd + zd * zd <= r * r) {
52
								podzolPos.set(xx, level.getHeight(Heightmap.Types.WORLD_SURFACE, xx, zz) - 1, zz);
53
								if (level.getBlockState(podzolPos).is(BlockTags.BENEATH_BAMBOO_PODZOL_REPLACEABLE)) {
54
									level.setBlock(podzolPos, Blocks.PODZOL.defaultBlockState(), 2);
55
								}
56
							}
57
						}
58
					}
59
				}
60
61
				for (int i = 0; i < height && level.isEmptyBlock(bambooPos); i++) {
62
					level.setBlock(bambooPos, BAMBOO_TRUNK, 2);
63
					bambooPos.move(Direction.UP, 1);
64
				}
65
66
				if (bambooPos.getY() - origin.getY() >= 3) {
67
					level.setBlock(bambooPos, BAMBOO_FINAL_LARGE, 2);
68
					level.setBlock(bambooPos.move(Direction.DOWN, 1), BAMBOO_TOP_LARGE, 2);
69
					level.setBlock(bambooPos.move(Direction.DOWN, 1), BAMBOO_TOP_SMALL, 2);
70
				}
71
			}
72
73
			placed++;
74
		}
75
76
		return placed > 0;
77
	}
78
}
79

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