AbstractHugeMushroomFeature .java

net.minecraft.world.level.levelgen.feature.AbstractHugeMushroomFeature (interface, 98 lines): members: MIN_MUSHROOM_HEIGHT, placeMushroomBlock, makeCap.

net.minecraft.world.level.levelgen.featureinterface98 linescommonextends Feature3.3 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Fields & Constants (2)

MIN_MUSHROOM_HEIGHT
treeHeight

Full Source

AbstractHugeMushroomFeature.java98 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature;
2
3
import com.mojang.serialization.MapCodec;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.core.Holder;
7
import net.minecraft.tags.BlockTags;
8
import net.minecraft.util.RandomSource;
9
import net.minecraft.world.level.LevelAccessor;
10
import net.minecraft.world.level.WorldGenLevel;
11
import net.minecraft.world.level.block.state.BlockState;
12
import net.minecraft.world.level.chunk.ChunkGenerator;
13
import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
14
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
15
16
public interface AbstractHugeMushroomFeature extends Feature {
17
	int MIN_MUSHROOM_HEIGHT = 4;
18
19
	Holder<BlockStateProvider> capProvider();
20
21
	Holder<BlockStateProvider> stemProvider();
22
23
	int foliageRadius();
24
25
	BlockPredicate canPlaceOn();
26
27
	@Override
28
	MapCodec<? extends AbstractHugeMushroomFeature> codec();
29
30
	default void placeTrunk(
31
		final WorldGenLevel level, final RandomSource random, final BlockPos origin, final int treeHeight, final BlockPos.MutableBlockPos blockPos
32
	) {
33
		for (int dy = 0; dy < treeHeight; dy++) {
34
			blockPos.set(origin).move(Direction.UP, dy);
35
			this.placeMushroomBlock(level, blockPos, this.stemProvider().value().getState(level, random, origin));
36
		}
37
	}
38
39
	default void placeMushroomBlock(final LevelAccessor level, final BlockPos.MutableBlockPos blockPos, final BlockState newState) {
40
		BlockState currentState = level.getBlockState(blockPos);
41
		if (currentState.isAir() || currentState.is(BlockTags.REPLACEABLE_BY_MUSHROOMS)) {
42
			this.setBlock(level, blockPos, newState);
43
		}
44
	}
45
46
	default int getTreeHeight(final RandomSource random) {
47
		int treeHeight = random.nextInt(3) + 4;
48
		if (random.nextInt(12) == 0) {
49
			treeHeight *= 2;
50
		}
51
52
		return treeHeight;
53
	}
54
55
	default boolean isValidPosition(final WorldGenLevel level, final BlockPos origin, final int treeHeight, final BlockPos.MutableBlockPos blockPos) {
56
		int y = origin.getY();
57
		if (y >= level.getMinY() + 1 && y + treeHeight + 1 <= level.getMaxY()) {
58
			if (!this.canPlaceOn().test(level, origin.below())) {
59
				return false;
60
			}
61
62
			for (int dy = 0; dy <= treeHeight; dy++) {
63
				int radius = this.getTreeRadiusForHeight(-1, -1, this.foliageRadius(), dy);
64
65
				for (int dx = -radius; dx <= radius; dx++) {
66
					for (int dz = -radius; dz <= radius; dz++) {
67
						BlockState state = level.getBlockState(blockPos.setWithOffset(origin, dx, dy, dz));
68
						if (!state.isAir() && !state.is(BlockTags.LEAVES)) {
69
							return false;
70
						}
71
					}
72
				}
73
			}
74
75
			return true;
76
		} else {
77
			return false;
78
		}
79
	}
80
81
	@Override
82
	default boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
83
		int treeHeight = this.getTreeHeight(random);
84
		BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
85
		if (!this.isValidPosition(level, origin, treeHeight, blockPos)) {
86
			return false;
87
		}
88
89
		this.makeCap(level, random, origin, treeHeight, blockPos);
90
		this.placeTrunk(level, random, origin, treeHeight, blockPos);
91
		return true;
92
	}
93
94
	int getTreeRadiusForHeight(final int trunkHeight, final int treeHeight, final int leafRadius, final int yo);
95
96
	void makeCap(final WorldGenLevel level, final RandomSource random, final BlockPos origin, final int treeHeight, final BlockPos.MutableBlockPos blockPos);
97
}
98

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