StructurePoolElement .java

net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement (class): members: projectionCodec, getProjection, dataMarker, legacy, processors.

net.minecraft.world.level.levelgen.structure.poolsclass138 linescommon5.8 KB

API Surface (14)

<E extends StructurePoolElement> RecordCodecBuilder<E, StructureTemplatePool.Projection> projectionCodec()
void handleDataMarker(final LevelAccessor level, final StructureTemplate.StructureBlockInfo dataMarker, final BlockPos position, final Rotation rotation, final RandomSource random, final BoundingBox chunkBB)
StructurePoolElement setProjection(final StructureTemplatePool.Projection projection)
StructureTemplatePool.Projection getProjection()
int getGroundLevelDelta()
Function<StructureTemplatePool.Projection, EmptyPoolElement> empty()
Function<StructureTemplatePool.Projection, LegacySinglePoolElement> legacy(final String location)
Function<StructureTemplatePool.Projection, LegacySinglePoolElement> legacy(final String location, final Holder<StructureProcessorList> processors)
Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location)
Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location, final Holder<StructureProcessorList> processors)
Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location, final LiquidSettings overrideLiquidSettings)
Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location, final Holder<StructureProcessorList> processors, final LiquidSettings overrideLiquidSettings)
Function<StructureTemplatePool.Projection, FeaturePoolElement> feature(final Holder<PlacedFeature> feature)
Function<StructureTemplatePool.Projection, ListPoolElement> list(final List<Function<StructureTemplatePool.Projection, ? extends StructurePoolElement>> elements)

Fields & Constants (16)

CODEC
EMPTY
projection
rotation
structureTemplateManager
level
structureManager
generator
position
referencePos
chunkBB
random
liquidSettings
dataMarker
location
processors

String literals (2)

"element_type"
"projection"

Full Source

StructurePoolElement.java138 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.pools;
2
3
import com.mojang.datafixers.util.Either;
4
import com.mojang.serialization.Codec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.List;
7
import java.util.Optional;
8
import java.util.function.Function;
9
import java.util.stream.Collectors;
10
import net.minecraft.core.BlockPos;
11
import net.minecraft.core.Holder;
12
import net.minecraft.core.Vec3i;
13
import net.minecraft.core.registries.BuiltInRegistries;
14
import net.minecraft.resources.Identifier;
15
import net.minecraft.util.RandomSource;
16
import net.minecraft.world.level.LevelAccessor;
17
import net.minecraft.world.level.StructureManager;
18
import net.minecraft.world.level.WorldGenLevel;
19
import net.minecraft.world.level.block.Rotation;
20
import net.minecraft.world.level.chunk.ChunkGenerator;
21
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
22
import net.minecraft.world.level.levelgen.structure.BoundingBox;
23
import net.minecraft.world.level.levelgen.structure.templatesystem.LiquidSettings;
24
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList;
25
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
26
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
27
import org.jspecify.annotations.Nullable;
28
29
public abstract class StructurePoolElement {
30
	public static final Codec<StructurePoolElement> CODEC = BuiltInRegistries.STRUCTURE_POOL_ELEMENT
31
		.byNameCodec()
32
		.dispatch("element_type", StructurePoolElement::getType, StructurePoolElementType::codec);
33
	private static final Holder<StructureProcessorList> EMPTY = Holder.direct(new StructureProcessorList(List.of()));
34
	private volatile StructureTemplatePool.@Nullable Projection projection;
35
36
	protected static <E extends StructurePoolElement> RecordCodecBuilder<E, StructureTemplatePool.Projection> projectionCodec() {
37
		return StructureTemplatePool.Projection.CODEC.fieldOf("projection").forGetter(StructurePoolElement::getProjection);
38
	}
39
40
	protected StructurePoolElement(final StructureTemplatePool.Projection projection) {
41
		this.projection = projection;
42
	}
43
44
	public abstract Vec3i getSize(StructureTemplateManager structureTemplateManager, Rotation rotation);
45
46
	public abstract List<StructureTemplate.JigsawBlockInfo> getShuffledJigsawBlocks(
47
		StructureTemplateManager structureTemplateManager, BlockPos position, Rotation rotation, RandomSource random
48
	);
49
50
	public abstract BoundingBox getBoundingBox(StructureTemplateManager structureTemplateManager, BlockPos position, Rotation rotation);
51
52
	public abstract boolean place(
53
		final StructureTemplateManager structureTemplateManager,
54
		final WorldGenLevel level,
55
		final StructureManager structureManager,
56
		final ChunkGenerator generator,
57
		final BlockPos position,
58
		final BlockPos referencePos,
59
		final Rotation rotation,
60
		final BoundingBox chunkBB,
61
		final RandomSource random,
62
		final LiquidSettings liquidSettings,
63
		final boolean keepJigsaws
64
	);
65
66
	public abstract StructurePoolElementType<?> getType();
67
68
	public void handleDataMarker(
69
		final LevelAccessor level,
70
		final StructureTemplate.StructureBlockInfo dataMarker,
71
		final BlockPos position,
72
		final Rotation rotation,
73
		final RandomSource random,
74
		final BoundingBox chunkBB
75
	) {
76
	}
77
78
	public StructurePoolElement setProjection(final StructureTemplatePool.Projection projection) {
79
		this.projection = projection;
80
		return this;
81
	}
82
83
	public StructureTemplatePool.Projection getProjection() {
84
		StructureTemplatePool.Projection projection = this.projection;
85
		if (projection == null) {
86
			throw new IllegalStateException();
87
		} else {
88
			return projection;
89
		}
90
	}
91
92
	public int getGroundLevelDelta() {
93
		return 1;
94
	}
95
96
	public static Function<StructureTemplatePool.Projection, EmptyPoolElement> empty() {
97
		return p -> EmptyPoolElement.INSTANCE;
98
	}
99
100
	public static Function<StructureTemplatePool.Projection, LegacySinglePoolElement> legacy(final String location) {
101
		return p -> new LegacySinglePoolElement(Either.left(Identifier.parse(location)), EMPTY, p, Optional.empty());
102
	}
103
104
	public static Function<StructureTemplatePool.Projection, LegacySinglePoolElement> legacy(
105
		final String location, final Holder<StructureProcessorList> processors
106
	) {
107
		return p -> new LegacySinglePoolElement(Either.left(Identifier.parse(location)), processors, p, Optional.empty());
108
	}
109
110
	public static Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location) {
111
		return p -> new SinglePoolElement(Either.left(Identifier.parse(location)), EMPTY, p, Optional.empty());
112
	}
113
114
	public static Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location, final Holder<StructureProcessorList> processors) {
115
		return p -> new SinglePoolElement(Either.left(Identifier.parse(location)), processors, p, Optional.empty());
116
	}
117
118
	public static Function<StructureTemplatePool.Projection, SinglePoolElement> single(final String location, final LiquidSettings overrideLiquidSettings) {
119
		return p -> new SinglePoolElement(Either.left(Identifier.parse(location)), EMPTY, p, Optional.of(overrideLiquidSettings));
120
	}
121
122
	public static Function<StructureTemplatePool.Projection, SinglePoolElement> single(
123
		final String location, final Holder<StructureProcessorList> processors, final LiquidSettings overrideLiquidSettings
124
	) {
125
		return p -> new SinglePoolElement(Either.left(Identifier.parse(location)), processors, p, Optional.of(overrideLiquidSettings));
126
	}
127
128
	public static Function<StructureTemplatePool.Projection, FeaturePoolElement> feature(final Holder<PlacedFeature> feature) {
129
		return p -> new FeaturePoolElement(feature, p);
130
	}
131
132
	public static Function<StructureTemplatePool.Projection, ListPoolElement> list(
133
		final List<Function<StructureTemplatePool.Projection, ? extends StructurePoolElement>> elements
134
	) {
135
		return p -> new ListPoolElement(elements.stream().map(e -> e.apply(p)).collect(Collectors.toList()), p);
136
	}
137
}
138

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