StructurePiecesBuilder .java

net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder (class, 72 lines): members: offsetPiecesVertically, moveBelowSeaLevel, addPiece.

net.minecraft.world.level.levelgen.structure.piecesclass72 linescommon1.9 KB

API Surface (8)

void addPiece(final StructurePiece piece)
void offsetPiecesVertically(final int dy)
int moveBelowSeaLevel(final int seaLevel, final int minY, final RandomSource random, final int offset)
void moveInsideHeights(final RandomSource random, final int lowestAllowed, final int highestAllowed)
PiecesContainer build()
void clear()
boolean isEmpty()
BoundingBox getBoundingBox()

Fields & Constants (1)

pieces

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

StructurePiecesBuilder.java72 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.pieces;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.util.RandomSource;
6
import net.minecraft.world.level.levelgen.structure.BoundingBox;
7
import net.minecraft.world.level.levelgen.structure.StructurePiece;
8
import org.jspecify.annotations.Nullable;
9
10
public class StructurePiecesBuilder {
11
	private final List<StructurePiece> pieces = Lists.newArrayList();
12
13
	public void addPiece(final StructurePiece piece) {
14
		this.pieces.add(piece);
15
	}
16
17
	public @Nullable StructurePiece findCollisionPiece(final BoundingBox box) {
18
		return StructurePiece.findCollisionPiece(this.pieces, box);
19
	}
20
21
	@Deprecated
22
	public void offsetPiecesVertically(final int dy) {
23
		for (StructurePiece piece : this.pieces) {
24
			piece.move(0, dy, 0);
25
		}
26
	}
27
28
	@Deprecated
29
	public int moveBelowSeaLevel(final int seaLevel, final int minY, final RandomSource random, final int offset) {
30
		int maxY = seaLevel - offset;
31
		BoundingBox boundingBox = this.getBoundingBox();
32
		int y1Pos = boundingBox.getYSpan() + minY + 1;
33
		if (y1Pos < maxY) {
34
			y1Pos += random.nextInt(maxY - y1Pos);
35
		}
36
37
		int dy = y1Pos - boundingBox.maxY();
38
		this.offsetPiecesVertically(dy);
39
		return dy;
40
	}
41
42
	public void moveInsideHeights(final RandomSource random, final int lowestAllowed, final int highestAllowed) {
43
		BoundingBox boundingBox = this.getBoundingBox();
44
		int heightSpan = highestAllowed - lowestAllowed + 1 - boundingBox.getYSpan();
45
		int y0Pos;
46
		if (heightSpan > 1) {
47
			y0Pos = lowestAllowed + random.nextInt(heightSpan);
48
		} else {
49
			y0Pos = lowestAllowed;
50
		}
51
52
		int dy = y0Pos - boundingBox.minY();
53
		this.offsetPiecesVertically(dy);
54
	}
55
56
	public PiecesContainer build() {
57
		return new PiecesContainer(this.pieces);
58
	}
59
60
	public void clear() {
61
		this.pieces.clear();
62
	}
63
64
	public boolean isEmpty() {
65
		return this.pieces.isEmpty();
66
	}
67
68
	public BoundingBox getBoundingBox() {
69
		return StructurePiece.createBoundingBox(this.pieces.stream());
70
	}
71
}
72

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