NetherFossilStructure .java

net.minecraft.world.level.levelgen.structure.structures.NetherFossilStructure (class, 63 lines): members: findGenerationPoint, height, type, CODEC.

net.minecraft.world.level.levelgen.structure.structuresclass63 linescommonextends Structure2.6 KB

API Surface (2)

Optional<Structure.GenerationStub> findGenerationPoint(final Structure.GenerationContext context)
StructureType<?> type()

Fields & Constants (2)

CODEC
height

String literals (1)

"height"

Full Source

NetherFossilStructure.java63 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.structures;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.core.Direction;
8
import net.minecraft.world.level.EmptyBlockGetter;
9
import net.minecraft.world.level.NoiseColumn;
10
import net.minecraft.world.level.block.Blocks;
11
import net.minecraft.world.level.block.state.BlockState;
12
import net.minecraft.world.level.levelgen.WorldGenerationContext;
13
import net.minecraft.world.level.levelgen.WorldgenRandom;
14
import net.minecraft.world.level.levelgen.heightproviders.HeightProvider;
15
import net.minecraft.world.level.levelgen.structure.Structure;
16
import net.minecraft.world.level.levelgen.structure.StructureType;
17
18
public class NetherFossilStructure extends Structure {
19
	public static final MapCodec<NetherFossilStructure> CODEC = RecordCodecBuilder.mapCodec(
20
		i -> i.group(settingsCodec(i), HeightProvider.CODEC.fieldOf("height").forGetter(c -> c.height)).apply(i, NetherFossilStructure::new)
21
	);
22
	public final HeightProvider height;
23
24
	public NetherFossilStructure(final Structure.StructureSettings settings, final HeightProvider height) {
25
		super(settings);
26
		this.height = height;
27
	}
28
29
	@Override
30
	public Optional<Structure.GenerationStub> findGenerationPoint(final Structure.GenerationContext context) {
31
		WorldgenRandom random = context.random();
32
		int blockX = context.chunkPos().getMinBlockX() + random.nextInt(16);
33
		int blockZ = context.chunkPos().getMinBlockZ() + random.nextInt(16);
34
		int seaLevel = context.chunkGenerator().getSeaLevel();
35
		WorldGenerationContext generationContext = new WorldGenerationContext(context.chunkGenerator(), context.heightAccessor());
36
		int y = this.height.sample(random, generationContext);
37
		NoiseColumn column = context.chunkGenerator().getBaseColumn(blockX, blockZ, context.heightAccessor(), context.randomState());
38
		BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(blockX, y, blockZ);
39
40
		while (y > seaLevel) {
41
			BlockState current = column.getBlock(y);
42
			BlockState below = column.getBlock(--y);
43
			if (current.isAir() && (below.is(Blocks.SOUL_SAND) || below.isFaceSturdy(EmptyBlockGetter.INSTANCE, pos.setY(y), Direction.UP))) {
44
				break;
45
			}
46
		}
47
48
		if (y <= seaLevel) {
49
			return Optional.empty();
50
		}
51
52
		BlockPos position = new BlockPos(blockX, y, blockZ);
53
		return Optional.of(
54
			new Structure.GenerationStub(position, builder -> NetherFossilPieces.addPieces(context.structureTemplateManager(), builder, random, position))
55
		);
56
	}
57
58
	@Override
59
	public StructureType<?> type() {
60
		return StructureType.NETHER_FOSSIL;
61
	}
62
}
63

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