StructurePiece .java

net.minecraft.world.level.levelgen.structure.StructurePiece (class, 562 lines): members: getRandomHorizontalDirection, isReplaceableByStructures, boxBB.

net.minecraft.world.level.levelgen.structureclass562 linescommon17.3 KB

API Surface (38)

BoundingBox makeBoundingBox(final int x, final int y, final int z, final Direction direction, final int width, final int height, final int depth)
Direction getRandomHorizontalDirection(final RandomSource random)
CompoundTag createTag(final StructurePieceSerializationContext context)
void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random)
BoundingBox getBoundingBox()
int getGenDepth()
void setGenDepth(final int genDepth)
boolean isCloseToChunk(final ChunkPos pos, final int distance)
BlockPos getLocatorPosition()
BlockPos.MutableBlockPos getWorldPos(final int x, final int y, final int z)
int getWorldX(final int x, final int z)
int getWorldY(final int y)
int getWorldZ(final int x, final int z)
void placeBlock(final WorldGenLevel level, BlockState blockState, final int x, final int y, final int z, final BoundingBox chunkBB)
boolean canBeReplaced(final LevelReader level, final int x, final int y, final int z, final BoundingBox chunkBB)
BlockState getBlock(final BlockGetter level, final int x, final int y, final int z, final BoundingBox chunkBB)
boolean isInterior(final LevelReader level, final int x, final int y, final int z, final BoundingBox chunkBB)
void generateAirBox(final WorldGenLevel level, final BoundingBox chunkBB, final int x0, final int y0, final int z0, final int x1, final int y1, final int z1)
void generateBox(final WorldGenLevel level, final BoundingBox chunkBB, final int x0, final int y0, final int z0, final int x1, final int y1, final int z1, final BlockState edgeBlock, final BlockState fillBlock, final boolean skipAir)
void generateBox(final WorldGenLevel level, final BoundingBox chunkBB, final BoundingBox boxBB, final BlockState edgeBlock, final BlockState fillBlock, final boolean skipAir)
void generateBox(final WorldGenLevel level, final BoundingBox chunkBB, final int x0, final int y0, final int z0, final int x1, final int y1, final int z1, final boolean skipAir, final RandomSource random, final StructurePiece.BlockSelector selector)
void generateBox(final WorldGenLevel level, final BoundingBox chunkBB, final BoundingBox boxBB, final boolean skipAir, final RandomSource random, final StructurePiece.BlockSelector selector)
void generateMaybeBox(final WorldGenLevel level, final BoundingBox chunkBB, final RandomSource random, final float probability, final int x0, final int y0, final int z0, final int x1, final int y1, final int z1, final BlockState edgeBlock, final BlockState fillBlock, final boolean skipAir, final boolean hasToBeInside)
void maybeGenerateBlock(final WorldGenLevel level, final BoundingBox chunkBB, final RandomSource random, final float probability, final int x, final int y, final int z, final BlockState blockState)
void generateUpperHalfSphere(final WorldGenLevel level, final BoundingBox chunkBB, final int x0, final int y0, final int z0, final int x1, final int y1, final int z1, final BlockState fillBlock, final boolean skipAir)
void fillColumnDown(final WorldGenLevel level, final BlockState blockState, final int x, final int startY, final int z, final BoundingBox chunkBB)
boolean isReplaceableByStructures(final BlockState state)
boolean createChest(final WorldGenLevel level, final BoundingBox chunkBB, final RandomSource random, final int x, final int y, final int z, final ResourceKey<LootTable> lootTable)
BlockState reorient(final BlockGetter level, final BlockPos blockPos, final BlockState blockState)
boolean createChest(final ServerLevelAccessor level, final BoundingBox chunkBB, final RandomSource random, final BlockPos pos, final ResourceKey<LootTable> lootTable, @Nullable BlockState blockState)
boolean createDispenser(final WorldGenLevel level, final BoundingBox chunkBB, final RandomSource random, final int x, final int y, final int z, final Direction facing, final ResourceKey<LootTable> lootTable)
void move(final int dx, final int dy, final int dz)
BoundingBox createBoundingBox(final Stream<StructurePiece> pieces)
void setOrientation(final @Nullable Direction orientation)
Rotation getRotation()
Mirror getMirror()
StructurePieceType getType()
BlockState getNext()

Fields & Constants (32)

CAVE_AIR
SHAPE_CHECK_BLOCKS
boundingBox
orientation
mirror
rotation
genDepth
type
height
level
structureManager
generator
random
chunkBB
chunkPos
y1
x0
y0
z0
x1
z1
edgeBlock
fillBlock
skipAir
boxBB
probability

…and 6 more (see full source).

String literals (1)

"Unable to calculate boundingbox without pieces"

Full Source

StructurePiece.java562 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure;
2
3
import com.google.common.collect.ImmutableSet;
4
import java.util.List;
5
import java.util.Set;
6
import java.util.stream.Stream;
7
import net.minecraft.core.BlockPos;
8
import net.minecraft.core.Direction;
9
import net.minecraft.core.registries.BuiltInRegistries;
10
import net.minecraft.nbt.CompoundTag;
11
import net.minecraft.resources.ResourceKey;
12
import net.minecraft.util.RandomSource;
13
import net.minecraft.world.level.BlockGetter;
14
import net.minecraft.world.level.ChunkPos;
15
import net.minecraft.world.level.LevelReader;
16
import net.minecraft.world.level.ServerLevelAccessor;
17
import net.minecraft.world.level.StructureManager;
18
import net.minecraft.world.level.WorldGenLevel;
19
import net.minecraft.world.level.block.Block;
20
import net.minecraft.world.level.block.Blocks;
21
import net.minecraft.world.level.block.DispenserBlock;
22
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
23
import net.minecraft.world.level.block.Mirror;
24
import net.minecraft.world.level.block.Rotation;
25
import net.minecraft.world.level.block.entity.ChestBlockEntity;
26
import net.minecraft.world.level.block.entity.DispenserBlockEntity;
27
import net.minecraft.world.level.block.state.BlockState;
28
import net.minecraft.world.level.chunk.ChunkGenerator;
29
import net.minecraft.world.level.levelgen.Heightmap;
30
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
31
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
32
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
33
import net.minecraft.world.level.material.FluidState;
34
import net.minecraft.world.level.storage.loot.LootTable;
35
import org.jspecify.annotations.Nullable;
36
37
public abstract class StructurePiece {
38
	protected static final BlockState CAVE_AIR = Blocks.CAVE_AIR.defaultBlockState();
39
	protected BoundingBox boundingBox;
40
	private @Nullable Direction orientation;
41
	private Mirror mirror;
42
	private Rotation rotation;
43
	protected int genDepth;
44
	private final StructurePieceType type;
45
	private static final Set<Block> SHAPE_CHECK_BLOCKS = ImmutableSet.<Block>builder()
46
		.add(Blocks.NETHER_BRICK_FENCE)
47
		.add(Blocks.TORCH)
48
		.add(Blocks.WALL_TORCH)
49
		.add(Blocks.OAK_FENCE)
50
		.add(Blocks.SPRUCE_FENCE)
51
		.add(Blocks.DARK_OAK_FENCE)
52
		.add(Blocks.PALE_OAK_FENCE)
53
		.add(Blocks.ACACIA_FENCE)
54
		.add(Blocks.BIRCH_FENCE)
55
		.add(Blocks.JUNGLE_FENCE)
56
		.add(Blocks.LADDER)
57
		.add(Blocks.IRON_BARS)
58
		.build();
59
60
	protected StructurePiece(final StructurePieceType type, final int genDepth, final BoundingBox boundingBox) {
61
		this.type = type;
62
		this.genDepth = genDepth;
63
		this.boundingBox = boundingBox;
64
	}
65
66
	public StructurePiece(final StructurePieceType type, final CompoundTag tag) {
67
		this(type, tag.getIntOr("GD", 0), tag.read("BB", BoundingBox.CODEC).orElseThrow());
68
		int orientation = tag.getIntOr("O", 0);
69
		this.setOrientation(orientation == -1 ? null : Direction.from2DDataValue(orientation));
70
	}
71
72
	protected static BoundingBox makeBoundingBox(
73
		final int x, final int y, final int z, final Direction direction, final int width, final int height, final int depth
74
	) {
75
		return direction.getAxis() == Direction.Axis.Z
76
			? new BoundingBox(x, y, z, x + width - 1, y + height - 1, z + depth - 1)
77
			: new BoundingBox(x, y, z, x + depth - 1, y + height - 1, z + width - 1);
78
	}
79
80
	protected static Direction getRandomHorizontalDirection(final RandomSource random) {
81
		return Direction.Plane.HORIZONTAL.getRandomDirection(random);
82
	}
83
84
	public final CompoundTag createTag(final StructurePieceSerializationContext context) {
85
		CompoundTag tag = new CompoundTag();
86
		tag.putString("id", BuiltInRegistries.STRUCTURE_PIECE.getKey(this.getType()).toString());
87
		tag.store("BB", BoundingBox.CODEC, this.boundingBox);
88
		Direction orientation = this.getOrientation();
89
		tag.putInt("O", orientation == null ? -1 : orientation.get2DDataValue());
90
		tag.putInt("GD", this.genDepth);
91
		this.addAdditionalSaveData(context, tag);
92
		return tag;
93
	}
94
95
	protected abstract void addAdditionalSaveData(StructurePieceSerializationContext context, CompoundTag tag);
96
97
	public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
98
	}
99
100
	public abstract void postProcess(
101
		final WorldGenLevel level,
102
		final StructureManager structureManager,
103
		final ChunkGenerator generator,
104
		final RandomSource random,
105
		final BoundingBox chunkBB,
106
		final ChunkPos chunkPos,
107
		final BlockPos referencePos
108
	);
109
110
	public BoundingBox getBoundingBox() {
111
		return this.boundingBox;
112
	}
113
114
	public int getGenDepth() {
115
		return this.genDepth;
116
	}
117
118
	public void setGenDepth(final int genDepth) {
119
		this.genDepth = genDepth;
120
	}
121
122
	public boolean isCloseToChunk(final ChunkPos pos, final int distance) {
123
		int cx = pos.getMinBlockX();
124
		int cz = pos.getMinBlockZ();
125
		return this.boundingBox.intersects(cx - distance, cz - distance, cx + 15 + distance, cz + 15 + distance);
126
	}
127
128
	public BlockPos getLocatorPosition() {
129
		return this.boundingBox.getCenter();
130
	}
131
132
	protected BlockPos.MutableBlockPos getWorldPos(final int x, final int y, final int z) {
133
		return new BlockPos.MutableBlockPos(this.getWorldX(x, z), this.getWorldY(y), this.getWorldZ(x, z));
134
	}
135
136
	protected int getWorldX(final int x, final int z) {
137
		Direction orientation = this.getOrientation();
138
		if (orientation == null) {
139
			return x;
140
		}
141
142
		return switch (orientation) {
143
			case NORTH, SOUTH -> this.boundingBox.minX() + x;
144
			case WEST -> this.boundingBox.maxX() - z;
145
			case EAST -> this.boundingBox.minX() + z;
146
			default -> x;
147
		};
148
	}
149
150
	protected int getWorldY(final int y) {
151
		return this.getOrientation() == null ? y : y + this.boundingBox.minY();
152
	}
153
154
	protected int getWorldZ(final int x, final int z) {
155
		Direction orientation = this.getOrientation();
156
		if (orientation == null) {
157
			return z;
158
		}
159
160
		return switch (orientation) {
161
			case NORTH -> this.boundingBox.maxZ() - z;
162
			case SOUTH -> this.boundingBox.minZ() + z;
163
			case WEST, EAST -> this.boundingBox.minZ() + x;
164
			default -> z;
165
		};
166
	}
167
168
	protected void placeBlock(final WorldGenLevel level, BlockState blockState, final int x, final int y, final int z, final BoundingBox chunkBB) {
169
		BlockPos pos = this.getWorldPos(x, y, z);
170
		if (chunkBB.isInside(pos)) {
171
			if (this.canBeReplaced(level, x, y, z, chunkBB)) {
172
				if (this.mirror != Mirror.NONE) {
173
					blockState = blockState.mirror(this.mirror);
174
				}
175
176
				if (this.rotation != Rotation.NONE) {
177
					blockState = blockState.rotate(this.rotation);
178
				}
179
180
				level.setBlock(pos, blockState, 2);
181
				FluidState fluidState = level.getFluidState(pos);
182
				if (!fluidState.isEmpty()) {
183
					level.scheduleTick(pos, fluidState.getType(), 0);
184
				}
185
186
				if (SHAPE_CHECK_BLOCKS.contains(blockState.getBlock())) {
187
					level.getChunk(pos).markPosForPostProcessing(pos);
188
				}
189
			}
190
		}
191
	}
192
193
	protected boolean canBeReplaced(final LevelReader level, final int x, final int y, final int z, final BoundingBox chunkBB) {
194
		return true;
195
	}
196
197
	protected BlockState getBlock(final BlockGetter level, final int x, final int y, final int z, final BoundingBox chunkBB) {
198
		BlockPos blockPos = this.getWorldPos(x, y, z);
199
		return !chunkBB.isInside(blockPos) ? Blocks.AIR.defaultBlockState() : level.getBlockState(blockPos);
200
	}
201
202
	protected boolean isInterior(final LevelReader level, final int x, final int y, final int z, final BoundingBox chunkBB) {
203
		BlockPos pos = this.getWorldPos(x, y + 1, z);
204
		return !chunkBB.isInside(pos) ? false : pos.getY() < level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX(), pos.getZ());
205
	}
206
207
	protected void generateAirBox(
208
		final WorldGenLevel level, final BoundingBox chunkBB, final int x0, final int y0, final int z0, final int x1, final int y1, final int z1
209
	) {
210
		for (int y = y0; y <= y1; y++) {
211
			for (int x = x0; x <= x1; x++) {
212
				for (int z = z0; z <= z1; z++) {
213
					this.placeBlock(level, Blocks.AIR.defaultBlockState(), x, y, z, chunkBB);
214
				}
215
			}
216
		}
217
	}
218
219
	protected void generateBox(
220
		final WorldGenLevel level,
221
		final BoundingBox chunkBB,
222
		final int x0,
223
		final int y0,
224
		final int z0,
225
		final int x1,
226
		final int y1,
227
		final int z1,
228
		final BlockState edgeBlock,
229
		final BlockState fillBlock,
230
		final boolean skipAir
231
	) {
232
		for (int y = y0; y <= y1; y++) {
233
			for (int x = x0; x <= x1; x++) {
234
				for (int z = z0; z <= z1; z++) {
235
					if (!skipAir || !this.getBlock(level, x, y, z, chunkBB).isAir()) {
236
						if (y != y0 && y != y1 && x != x0 && x != x1 && z != z0 && z != z1) {
237
							this.placeBlock(level, fillBlock, x, y, z, chunkBB);
238
						} else {
239
							this.placeBlock(level, edgeBlock, x, y, z, chunkBB);
240
						}
241
					}
242
				}
243
			}
244
		}
245
	}
246
247
	protected void generateBox(
248
		final WorldGenLevel level, final BoundingBox chunkBB, final BoundingBox boxBB, final BlockState edgeBlock, final BlockState fillBlock, final boolean skipAir
249
	) {
250
		this.generateBox(level, chunkBB, boxBB.minX(), boxBB.minY(), boxBB.minZ(), boxBB.maxX(), boxBB.maxY(), boxBB.maxZ(), edgeBlock, fillBlock, skipAir);
251
	}
252
253
	protected void generateBox(
254
		final WorldGenLevel level,
255
		final BoundingBox chunkBB,
256
		final int x0,
257
		final int y0,
258
		final int z0,
259
		final int x1,
260
		final int y1,
261
		final int z1,
262
		final boolean skipAir,
263
		final RandomSource random,
264
		final StructurePiece.BlockSelector selector
265
	) {
266
		for (int y = y0; y <= y1; y++) {
267
			for (int x = x0; x <= x1; x++) {
268
				for (int z = z0; z <= z1; z++) {
269
					if (!skipAir || !this.getBlock(level, x, y, z, chunkBB).isAir()) {
270
						selector.next(random, x, y, z, y == y0 || y == y1 || x == x0 || x == x1 || z == z0 || z == z1);
271
						this.placeBlock(level, selector.getNext(), x, y, z, chunkBB);
272
					}
273
				}
274
			}
275
		}
276
	}
277
278
	protected void generateBox(
279
		final WorldGenLevel level,
280
		final BoundingBox chunkBB,
281
		final BoundingBox boxBB,
282
		final boolean skipAir,
283
		final RandomSource random,
284
		final StructurePiece.BlockSelector selector
285
	) {
286
		this.generateBox(level, chunkBB, boxBB.minX(), boxBB.minY(), boxBB.minZ(), boxBB.maxX(), boxBB.maxY(), boxBB.maxZ(), skipAir, random, selector);
287
	}
288
289
	protected void generateMaybeBox(
290
		final WorldGenLevel level,
291
		final BoundingBox chunkBB,
292
		final RandomSource random,
293
		final float probability,
294
		final int x0,
295
		final int y0,
296
		final int z0,
297
		final int x1,
298
		final int y1,
299
		final int z1,
300
		final BlockState edgeBlock,
301
		final BlockState fillBlock,
302
		final boolean skipAir,
303
		final boolean hasToBeInside
304
	) {
305
		for (int y = y0; y <= y1; y++) {
306
			for (int x = x0; x <= x1; x++) {
307
				for (int z = z0; z <= z1; z++) {
308
					if (!(random.nextFloat() > probability)
309
						&& (!skipAir || !this.getBlock(level, x, y, z, chunkBB).isAir())
310
						&& (!hasToBeInside || this.isInterior(level, x, y, z, chunkBB))) {
311
						if (y != y0 && y != y1 && x != x0 && x != x1 && z != z0 && z != z1) {
312
							this.placeBlock(level, fillBlock, x, y, z, chunkBB);
313
						} else {
314
							this.placeBlock(level, edgeBlock, x, y, z, chunkBB);
315
						}
316
					}
317
				}
318
			}
319
		}
320
	}
321
322
	protected void maybeGenerateBlock(
323
		final WorldGenLevel level,
324
		final BoundingBox chunkBB,
325
		final RandomSource random,
326
		final float probability,
327
		final int x,
328
		final int y,
329
		final int z,
330
		final BlockState blockState
331
	) {
332
		if (random.nextFloat() < probability) {
333
			this.placeBlock(level, blockState, x, y, z, chunkBB);
334
		}
335
	}
336
337
	protected void generateUpperHalfSphere(
338
		final WorldGenLevel level,
339
		final BoundingBox chunkBB,
340
		final int x0,
341
		final int y0,
342
		final int z0,
343
		final int x1,
344
		final int y1,
345
		final int z1,
346
		final BlockState fillBlock,
347
		final boolean skipAir
348
	) {
349
		float diagX = x1 - x0 + 1;
350
		float diagY = y1 - y0 + 1;
351
		float diagZ = z1 - z0 + 1;
352
		float cx = x0 + diagX / 2.0F;
353
		float cz = z0 + diagZ / 2.0F;
354
355
		for (int y = y0; y <= y1; y++) {
356
			float normalizedYDistance = (y - y0) / diagY;
357
358
			for (int x = x0; x <= x1; x++) {
359
				float normalizedXDistance = (x - cx) / (diagX * 0.5F);
360
361
				for (int z = z0; z <= z1; z++) {
362
					float normalizedZDistance = (z - cz) / (diagZ * 0.5F);
363
					if (!skipAir || !this.getBlock(level, x, y, z, chunkBB).isAir()) {
364
						float dist = normalizedXDistance * normalizedXDistance + normalizedYDistance * normalizedYDistance + normalizedZDistance * normalizedZDistance;
365
						if (dist <= 1.05F) {
366
							this.placeBlock(level, fillBlock, x, y, z, chunkBB);
367
						}
368
					}
369
				}
370
			}
371
		}
372
	}
373
374
	protected void fillColumnDown(final WorldGenLevel level, final BlockState blockState, final int x, final int startY, final int z, final BoundingBox chunkBB) {
375
		BlockPos.MutableBlockPos pos = this.getWorldPos(x, startY, z);
376
		if (chunkBB.isInside(pos)) {
377
			while (this.isReplaceableByStructures(level.getBlockState(pos)) && pos.getY() > level.getMinY() + 1) {
378
				level.setBlock(pos, blockState, 2);
379
				pos.move(Direction.DOWN);
380
			}
381
		}
382
	}
383
384
	protected boolean isReplaceableByStructures(final BlockState state) {
385
		return state.isAir() || state.liquid() || state.is(Blocks.GLOW_LICHEN) || state.is(Blocks.SEAGRASS) || state.is(Blocks.TALL_SEAGRASS);
386
	}
387
388
	protected boolean createChest(
389
		final WorldGenLevel level,
390
		final BoundingBox chunkBB,
391
		final RandomSource random,
392
		final int x,
393
		final int y,
394
		final int z,
395
		final ResourceKey<LootTable> lootTable
396
	) {
397
		return this.createChest(level, chunkBB, random, this.getWorldPos(x, y, z), lootTable, null);
398
	}
399
400
	public static BlockState reorient(final BlockGetter level, final BlockPos blockPos, final BlockState blockState) {
401
		Direction solidNeighbor = null;
402
403
		for (Direction direction : Direction.Plane.HORIZONTAL) {
404
			BlockPos relativePos = blockPos.relative(direction);
405
			BlockState state = level.getBlockState(relativePos);
406
			if (state.is(Blocks.CHEST)) {
407
				return blockState;
408
			}
409
410
			if (state.isSolidRender()) {
411
				if (solidNeighbor != null) {
412
					solidNeighbor = null;
413
					break;
414
				}
415
416
				solidNeighbor = direction;
417
			}
418
		}
419
420
		if (solidNeighbor != null) {
421
			return blockState.setValue(HorizontalDirectionalBlock.FACING, solidNeighbor.getOpposite());
422
		}
423
424
		Direction lockDir = blockState.getValue(HorizontalDirectionalBlock.FACING);
425
		BlockPos relativePos = blockPos.relative(lockDir);
426
		if (level.getBlockState(relativePos).isSolidRender()) {
427
			lockDir = lockDir.getOpposite();
428
			relativePos = blockPos.relative(lockDir);
429
		}
430
431
		if (level.getBlockState(relativePos).isSolidRender()) {
432
			lockDir = lockDir.getClockWise();
433
			relativePos = blockPos.relative(lockDir);
434
		}
435
436
		if (level.getBlockState(relativePos).isSolidRender()) {
437
			lockDir = lockDir.getOpposite();
438
			relativePos = blockPos.relative(lockDir);
439
		}
440
441
		return blockState.setValue(HorizontalDirectionalBlock.FACING, lockDir);
442
	}
443
444
	protected boolean createChest(
445
		final ServerLevelAccessor level,
446
		final BoundingBox chunkBB,
447
		final RandomSource random,
448
		final BlockPos pos,
449
		final ResourceKey<LootTable> lootTable,
450
		@Nullable BlockState blockState
451
	) {
452
		if (chunkBB.isInside(pos) && !level.getBlockState(pos).is(Blocks.CHEST)) {
453
			if (blockState == null) {
454
				blockState = reorient(level, pos, Blocks.CHEST.defaultBlockState());
455
			}
456
457
			level.setBlock(pos, blockState, 2);
458
			if (level.getBlockEntity(pos) instanceof ChestBlockEntity chestBlockEntity) {
459
				chestBlockEntity.setLootTable(lootTable, random.nextLong());
460
			}
461
462
			return true;
463
		} else {
464
			return false;
465
		}
466
	}
467
468
	protected boolean createDispenser(
469
		final WorldGenLevel level,
470
		final BoundingBox chunkBB,
471
		final RandomSource random,
472
		final int x,
473
		final int y,
474
		final int z,
475
		final Direction facing,
476
		final ResourceKey<LootTable> lootTable
477
	) {
478
		BlockPos pos = this.getWorldPos(x, y, z);
479
		if (chunkBB.isInside(pos) && !level.getBlockState(pos).is(Blocks.DISPENSER)) {
480
			this.placeBlock(level, Blocks.DISPENSER.defaultBlockState().setValue(DispenserBlock.FACING, facing), x, y, z, chunkBB);
481
			if (level.getBlockEntity(pos) instanceof DispenserBlockEntity dispenserBlockEntity) {
482
				dispenserBlockEntity.setLootTable(lootTable, random.nextLong());
483
			}
484
485
			return true;
486
		} else {
487
			return false;
488
		}
489
	}
490
491
	public void move(final int dx, final int dy, final int dz) {
492
		this.boundingBox.move(dx, dy, dz);
493
	}
494
495
	public static BoundingBox createBoundingBox(final Stream<StructurePiece> pieces) {
496
		return BoundingBox.encapsulatingBoxes(pieces.map(StructurePiece::getBoundingBox)::iterator)
497
			.orElseThrow(() -> new IllegalStateException("Unable to calculate boundingbox without pieces"));
498
	}
499
500
	public static @Nullable StructurePiece findCollisionPiece(final List<StructurePiece> pieces, final BoundingBox box) {
501
		for (StructurePiece piece : pieces) {
502
			if (piece.getBoundingBox().intersects(box)) {
503
				return piece;
504
			}
505
		}
506
507
		return null;
508
	}
509
510
	public @Nullable Direction getOrientation() {
511
		return this.orientation;
512
	}
513
514
	public void setOrientation(final @Nullable Direction orientation) {
515
		this.orientation = orientation;
516
		if (orientation == null) {
517
			this.rotation = Rotation.NONE;
518
			this.mirror = Mirror.NONE;
519
		} else {
520
			switch (orientation) {
521
				case SOUTH:
522
					this.mirror = Mirror.LEFT_RIGHT;
523
					this.rotation = Rotation.NONE;
524
					break;
525
				case WEST:
526
					this.mirror = Mirror.LEFT_RIGHT;
527
					this.rotation = Rotation.CLOCKWISE_90;
528
					break;
529
				case EAST:
530
					this.mirror = Mirror.NONE;
531
					this.rotation = Rotation.CLOCKWISE_90;
532
					break;
533
				default:
534
					this.mirror = Mirror.NONE;
535
					this.rotation = Rotation.NONE;
536
			}
537
		}
538
	}
539
540
	public Rotation getRotation() {
541
		return this.rotation;
542
	}
543
544
	public Mirror getMirror() {
545
		return this.mirror;
546
	}
547
548
	public StructurePieceType getType() {
549
		return this.type;
550
	}
551
552
	public abstract static class BlockSelector {
553
		protected BlockState next = Blocks.AIR.defaultBlockState();
554
555
		public abstract void next(RandomSource random, int worldX, int worldY, int worldZ, boolean isEdge);
556
557
		public BlockState getNext() {
558
			return this.next;
559
		}
560
	}
561
}
562

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