SculkPatchFeature .java

net.minecraft.world.level.levelgen.feature.SculkPatchFeature (record): members: chargeCount, amountPerCharge, spreadAttempts, growthRounds, spreadRounds.

net.minecraft.world.level.levelgen.featurerecord71 linescommon2.6 KB

Implements

API Surface (2)

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

Fields & Constants (1)

CODEC

String literals (5)

"charge_count"
"amount_per_charge"
"spread_attempts"
"growth_rounds"
"spread_rounds"

Full Source

SculkPatchFeature.java71 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.util.RandomSource;
9
import net.minecraft.world.level.LevelAccessor;
10
import net.minecraft.world.level.WorldGenLevel;
11
import net.minecraft.world.level.block.Blocks;
12
import net.minecraft.world.level.block.SculkBehaviour;
13
import net.minecraft.world.level.block.SculkSpreader;
14
import net.minecraft.world.level.block.state.BlockState;
15
import net.minecraft.world.level.chunk.ChunkGenerator;
16
17
public record SculkPatchFeature(int chargeCount, int amountPerCharge, int spreadAttempts, int growthRounds, int spreadRounds) implements Feature {
18
	public static final MapCodec<SculkPatchFeature> CODEC = RecordCodecBuilder.mapCodec(
19
		i -> i.group(
20
				Codec.intRange(1, 32).fieldOf("charge_count").forGetter(SculkPatchFeature::chargeCount),
21
				Codec.intRange(1, 500).fieldOf("amount_per_charge").forGetter(SculkPatchFeature::amountPerCharge),
22
				Codec.intRange(1, 64).fieldOf("spread_attempts").forGetter(SculkPatchFeature::spreadAttempts),
23
				Codec.intRange(0, 8).fieldOf("growth_rounds").forGetter(SculkPatchFeature::growthRounds),
24
				Codec.intRange(0, 8).fieldOf("spread_rounds").forGetter(SculkPatchFeature::spreadRounds)
25
			)
26
			.apply(i, SculkPatchFeature::new)
27
	);
28
29
	@Override
30
	public MapCodec<SculkPatchFeature> codec() {
31
		return CODEC;
32
	}
33
34
	@Override
35
	public boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
36
		if (!this.canSpreadFrom(level, origin)) {
37
			return false;
38
		}
39
40
		SculkSpreader spreader = SculkSpreader.createWorldGenSpreader();
41
		int totalRounds = this.spreadRounds + this.growthRounds;
42
43
		for (int round = 0; round < totalRounds; round++) {
44
			for (int i = 0; i < this.chargeCount; i++) {
45
				spreader.addCursors(origin, this.amountPerCharge);
46
			}
47
48
			boolean spreadVeins = round < this.spreadRounds;
49
50
			for (int i = 0; i < this.spreadAttempts; i++) {
51
				spreader.updateCursors(level, origin, random, spreadVeins);
52
			}
53
54
			spreader.clear();
55
		}
56
57
		return true;
58
	}
59
60
	private boolean canSpreadFrom(final LevelAccessor level, final BlockPos origin) {
61
		BlockState start = level.getBlockState(origin);
62
		if (start.getBlock() instanceof SculkBehaviour) {
63
			return true;
64
		} else {
65
			return !start.isAir() && (!start.is(Blocks.WATER) || !start.getFluidState().isSource())
66
				? false
67
				: Direction.stream().map(origin::relative).anyMatch(pos -> level.getBlockState(pos).isCollisionShapeFullBlock(level, pos));
68
		}
69
	}
70
}
71

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