MineshaftPieces .java

net.minecraft.world.level.levelgen.structure.structures.MineshaftPieces (class, 1186 lines): members: DEFAULT_SHAFT_HEIGHT, DEFAULT_SHAFT_LENGTH, genDepth.

net.minecraft.world.level.levelgen.structure.structuresclass1,186 linescommon41.8 KB

API Surface (20)

void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag)
void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random)
boolean createChest(final WorldGenLevel level, final BoundingBox chunkBB, final RandomSource random, final int x, final int y, final int z, final ResourceKey<LootTable> lootTable)
void postProcess(final WorldGenLevel level, final StructureManager structureManager, final ChunkGenerator generator, final RandomSource random, final BoundingBox chunkBB, final ChunkPos chunkPos, final BlockPos referencePos)
void fillColumnDown(final WorldGenLevel level, final BlockState columnState, final int x, final int startY, final int z, final BoundingBox chunkBB)
void fillPillarDownOrChainUp(final WorldGenLevel level, final BlockState pillarState, final int x, final int y, final int z, final BoundingBox chunkBB)
void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag)
void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random)
void postProcess(final WorldGenLevel level, final StructureManager structureManager, final ChunkGenerator generator, final RandomSource random, final BoundingBox chunkBB, final ChunkPos chunkPos, final BlockPos referencePos)
boolean canBeReplaced(final LevelReader level, final int x, final int y, final int z, final BoundingBox chunkBB)
void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag)
boolean isSupportingBox(final BlockGetter level, final BoundingBox chunkBB, final int x0, final int x1, final int y1, final int z0)
boolean isInInvalidLocation(final LevelAccessor level, final BoundingBox chunkBB)
void setPlanksBlock(final WorldGenLevel level, final BoundingBox chunkBB, final BlockState planksBlock, final int x, final int y, final int z)
void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random)
void postProcess(final WorldGenLevel level, final StructureManager structureManager, final ChunkGenerator generator, final RandomSource random, final BoundingBox chunkBB, final ChunkPos chunkPos, final BlockPos referencePos)
void move(final int dx, final int dy, final int dz)
void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag)
void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random)
void postProcess(final WorldGenLevel level, final StructureManager structureManager, final ChunkGenerator generator, final RandomSource random, final BoundingBox chunkBB, final ChunkPos chunkPos, final BlockPos referencePos)

Fields & Constants (15)

DEFAULT_SHAFT_WIDTH
DEFAULT_SHAFT_HEIGHT
DEFAULT_SHAFT_LENGTH
MAX_PILLAR_HEIGHT
MAX_CHAIN_HEIGHT
MAX_DEPTH
MAGIC_START_Y
builder
random
footX
footY
footZ
direction
genDepth
startPiece

String literals (1)

"Entrances"

Full Source

MineshaftPieces.java1186 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.structures;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.core.Direction;
7
import net.minecraft.nbt.CompoundTag;
8
import net.minecraft.resources.ResourceKey;
9
import net.minecraft.tags.BiomeTags;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.entity.EntitySpawnReason;
12
import net.minecraft.world.entity.EntityTypes;
13
import net.minecraft.world.entity.vehicle.minecart.MinecartChest;
14
import net.minecraft.world.level.BlockGetter;
15
import net.minecraft.world.level.ChunkPos;
16
import net.minecraft.world.level.LevelAccessor;
17
import net.minecraft.world.level.LevelReader;
18
import net.minecraft.world.level.StructureManager;
19
import net.minecraft.world.level.WorldGenLevel;
20
import net.minecraft.world.level.block.Block;
21
import net.minecraft.world.level.block.Blocks;
22
import net.minecraft.world.level.block.FallingBlock;
23
import net.minecraft.world.level.block.FenceBlock;
24
import net.minecraft.world.level.block.RailBlock;
25
import net.minecraft.world.level.block.WallTorchBlock;
26
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
27
import net.minecraft.world.level.block.state.BlockState;
28
import net.minecraft.world.level.block.state.properties.RailShape;
29
import net.minecraft.world.level.chunk.ChunkGenerator;
30
import net.minecraft.world.level.levelgen.structure.BoundingBox;
31
import net.minecraft.world.level.levelgen.structure.StructurePiece;
32
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
33
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
34
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
35
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
36
import net.minecraft.world.level.storage.loot.LootTable;
37
import org.jspecify.annotations.Nullable;
38
39
public class MineshaftPieces {
40
	private static final int DEFAULT_SHAFT_WIDTH = 3;
41
	private static final int DEFAULT_SHAFT_HEIGHT = 3;
42
	private static final int DEFAULT_SHAFT_LENGTH = 5;
43
	private static final int MAX_PILLAR_HEIGHT = 20;
44
	private static final int MAX_CHAIN_HEIGHT = 50;
45
	private static final int MAX_DEPTH = 8;
46
	public static final int MAGIC_START_Y = 50;
47
48
	private static MineshaftPieces.@Nullable MineShaftPiece createRandomShaftPiece(
49
		final StructurePiecesBuilder builder,
50
		final RandomSource random,
51
		final int footX,
52
		final int footY,
53
		final int footZ,
54
		final Direction direction,
55
		final int genDepth,
56
		final MineshaftStructure.Type type
57
	) {
58
		int randomSelection = random.nextInt(100);
59
		if (randomSelection >= 80) {
60
			BoundingBox crossingBox = MineshaftPieces.MineShaftCrossing.findCrossing(builder, random, footX, footY, footZ, direction);
61
			if (crossingBox != null) {
62
				return new MineshaftPieces.MineShaftCrossing(genDepth, crossingBox, direction, type);
63
			}
64
		} else if (randomSelection >= 70) {
65
			BoundingBox stairsBox = MineshaftPieces.MineShaftStairs.findStairs(builder, random, footX, footY, footZ, direction);
66
			if (stairsBox != null) {
67
				return new MineshaftPieces.MineShaftStairs(genDepth, stairsBox, direction, type);
68
			}
69
		} else {
70
			BoundingBox corridorBox = MineshaftPieces.MineShaftCorridor.findCorridorSize(builder, random, footX, footY, footZ, direction);
71
			if (corridorBox != null) {
72
				return new MineshaftPieces.MineShaftCorridor(genDepth, random, corridorBox, direction, type);
73
			}
74
		}
75
76
		return null;
77
	}
78
79
	private static MineshaftPieces.@Nullable MineShaftPiece generateAndAddPiece(
80
		final StructurePiece startPiece,
81
		final StructurePiecesBuilder builder,
82
		final RandomSource random,
83
		final int footX,
84
		final int footY,
85
		final int footZ,
86
		final Direction direction,
87
		final int depth
88
	) {
89
		if (depth > 8) {
90
			return null;
91
		}
92
93
		if (Math.abs(footX - startPiece.getBoundingBox().minX()) <= 80 && Math.abs(footZ - startPiece.getBoundingBox().minZ()) <= 80) {
94
			MineshaftStructure.Type type = ((MineshaftPieces.MineShaftPiece)startPiece).type;
95
			MineshaftPieces.MineShaftPiece newPiece = createRandomShaftPiece(builder, random, footX, footY, footZ, direction, depth + 1, type);
96
			if (newPiece != null) {
97
				builder.addPiece(newPiece);
98
				newPiece.addChildren(startPiece, builder, random);
99
			}
100
101
			return newPiece;
102
		} else {
103
			return null;
104
		}
105
	}
106
107
	public static class MineShaftCorridor extends MineshaftPieces.MineShaftPiece {
108
		private final boolean hasRails;
109
		private final boolean spiderCorridor;
110
		private boolean hasPlacedSpider;
111
		private final int numSections;
112
113
		public MineShaftCorridor(final CompoundTag tag) {
114
			super(StructurePieceType.MINE_SHAFT_CORRIDOR, tag);
115
			this.hasRails = tag.getBooleanOr("hr", false);
116
			this.spiderCorridor = tag.getBooleanOr("sc", false);
117
			this.hasPlacedSpider = tag.getBooleanOr("hps", false);
118
			this.numSections = tag.getIntOr("Num", 0);
119
		}
120
121
		@Override
122
		protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
123
			super.addAdditionalSaveData(context, tag);
124
			tag.putBoolean("hr", this.hasRails);
125
			tag.putBoolean("sc", this.spiderCorridor);
126
			tag.putBoolean("hps", this.hasPlacedSpider);
127
			tag.putInt("Num", this.numSections);
128
		}
129
130
		public MineShaftCorridor(
131
			final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction, final MineshaftStructure.Type type
132
		) {
133
			super(StructurePieceType.MINE_SHAFT_CORRIDOR, genDepth, type, boundingBox);
134
			this.setOrientation(direction);
135
			this.hasRails = random.nextInt(3) == 0;
136
			this.spiderCorridor = !this.hasRails && random.nextInt(23) == 0;
137
			if (this.getOrientation().getAxis() == Direction.Axis.Z) {
138
				this.numSections = boundingBox.getZSpan() / 5;
139
			} else {
140
				this.numSections = boundingBox.getXSpan() / 5;
141
			}
142
		}
143
144
		public static @Nullable BoundingBox findCorridorSize(
145
			final StructurePiecesBuilder builder, final RandomSource random, final int footX, final int footY, final int footZ, final Direction direction
146
		) {
147
			for (int corridorLength = random.nextInt(3) + 2; corridorLength > 0; corridorLength--) {
148
				int blockLength = corridorLength * 5;
149
150
				BoundingBox box = switch (direction) {
151
					default -> new BoundingBox(0, 0, -(blockLength - 1), 2, 2, 0);
152
					case SOUTH -> new BoundingBox(0, 0, 0, 2, 2, blockLength - 1);
153
					case WEST -> new BoundingBox(-(blockLength - 1), 0, 0, 0, 2, 2);
154
					case EAST -> new BoundingBox(0, 0, 0, blockLength - 1, 2, 2);
155
				};
156
				box.move(footX, footY, footZ);
157
				if (builder.findCollisionPiece(box) == null) {
158
					return box;
159
				}
160
			}
161
162
			return null;
163
		}
164
165
		@Override
166
		public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
167
			int depth = this.getGenDepth();
168
			int endSelection = random.nextInt(4);
169
			Direction orientation = this.getOrientation();
170
			if (orientation != null) {
171
				switch (orientation) {
172
					case NORTH:
173
					default:
174
						if (endSelection <= 1) {
175
							MineshaftPieces.generateAndAddPiece(
176
								startPiece, builder, random, this.boundingBox.minX(), this.boundingBox.minY() - 1 + random.nextInt(3), this.boundingBox.minZ() - 1, orientation, depth
177
							);
178
						} else if (endSelection == 2) {
179
							MineshaftPieces.generateAndAddPiece(
180
								startPiece,
181
								builder,
182
								random,
183
								this.boundingBox.minX() - 1,
184
								this.boundingBox.minY() - 1 + random.nextInt(3),
185
								this.boundingBox.minZ(),
186
								Direction.WEST,
187
								depth
188
							);
189
						} else {
190
							MineshaftPieces.generateAndAddPiece(
191
								startPiece,
192
								builder,
193
								random,
194
								this.boundingBox.maxX() + 1,
195
								this.boundingBox.minY() - 1 + random.nextInt(3),
196
								this.boundingBox.minZ(),
197
								Direction.EAST,
198
								depth
199
							);
200
						}
201
						break;
202
					case SOUTH:
203
						if (endSelection <= 1) {
204
							MineshaftPieces.generateAndAddPiece(
205
								startPiece, builder, random, this.boundingBox.minX(), this.boundingBox.minY() - 1 + random.nextInt(3), this.boundingBox.maxZ() + 1, orientation, depth
206
							);
207
						} else if (endSelection == 2) {
208
							MineshaftPieces.generateAndAddPiece(
209
								startPiece,
210
								builder,
211
								random,
212
								this.boundingBox.minX() - 1,
213
								this.boundingBox.minY() - 1 + random.nextInt(3),
214
								this.boundingBox.maxZ() - 3,
215
								Direction.WEST,
216
								depth
217
							);
218
						} else {
219
							MineshaftPieces.generateAndAddPiece(
220
								startPiece,
221
								builder,
222
								random,
223
								this.boundingBox.maxX() + 1,
224
								this.boundingBox.minY() - 1 + random.nextInt(3),
225
								this.boundingBox.maxZ() - 3,
226
								Direction.EAST,
227
								depth
228
							);
229
						}
230
						break;
231
					case WEST:
232
						if (endSelection <= 1) {
233
							MineshaftPieces.generateAndAddPiece(
234
								startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY() - 1 + random.nextInt(3), this.boundingBox.minZ(), orientation, depth
235
							);
236
						} else if (endSelection == 2) {
237
							MineshaftPieces.generateAndAddPiece(
238
								startPiece,
239
								builder,
240
								random,
241
								this.boundingBox.minX(),
242
								this.boundingBox.minY() - 1 + random.nextInt(3),
243
								this.boundingBox.minZ() - 1,
244
								Direction.NORTH,
245
								depth
246
							);
247
						} else {
248
							MineshaftPieces.generateAndAddPiece(
249
								startPiece,
250
								builder,
251
								random,
252
								this.boundingBox.minX(),
253
								this.boundingBox.minY() - 1 + random.nextInt(3),
254
								this.boundingBox.maxZ() + 1,
255
								Direction.SOUTH,
256
								depth
257
							);
258
						}
259
						break;
260
					case EAST:
261
						if (endSelection <= 1) {
262
							MineshaftPieces.generateAndAddPiece(
263
								startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY() - 1 + random.nextInt(3), this.boundingBox.minZ(), orientation, depth
264
							);
265
						} else if (endSelection == 2) {
266
							MineshaftPieces.generateAndAddPiece(
267
								startPiece,
268
								builder,
269
								random,
270
								this.boundingBox.maxX() - 3,
271
								this.boundingBox.minY() - 1 + random.nextInt(3),
272
								this.boundingBox.minZ() - 1,
273
								Direction.NORTH,
274
								depth
275
							);
276
						} else {
277
							MineshaftPieces.generateAndAddPiece(
278
								startPiece,
279
								builder,
280
								random,
281
								this.boundingBox.maxX() - 3,
282
								this.boundingBox.minY() - 1 + random.nextInt(3),
283
								this.boundingBox.maxZ() + 1,
284
								Direction.SOUTH,
285
								depth
286
							);
287
						}
288
				}
289
			}
290
291
			if (depth < 8) {
292
				if (orientation != Direction.NORTH && orientation != Direction.SOUTH) {
293
					for (int x = this.boundingBox.minX() + 3; x + 3 <= this.boundingBox.maxX(); x += 5) {
294
						int selection = random.nextInt(5);
295
						if (selection == 0) {
296
							MineshaftPieces.generateAndAddPiece(startPiece, builder, random, x, this.boundingBox.minY(), this.boundingBox.minZ() - 1, Direction.NORTH, depth + 1);
297
						} else if (selection == 1) {
298
							MineshaftPieces.generateAndAddPiece(startPiece, builder, random, x, this.boundingBox.minY(), this.boundingBox.maxZ() + 1, Direction.SOUTH, depth + 1);
299
						}
300
					}
301
				} else {
302
					for (int z = this.boundingBox.minZ() + 3; z + 3 <= this.boundingBox.maxZ(); z += 5) {
303
						int selection = random.nextInt(5);
304
						if (selection == 0) {
305
							MineshaftPieces.generateAndAddPiece(startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY(), z, Direction.WEST, depth + 1);
306
						} else if (selection == 1) {
307
							MineshaftPieces.generateAndAddPiece(startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY(), z, Direction.EAST, depth + 1);
308
						}
309
					}
310
				}
311
			}
312
		}
313
314
		@Override
315
		protected boolean createChest(
316
			final WorldGenLevel level,
317
			final BoundingBox chunkBB,
318
			final RandomSource random,
319
			final int x,
320
			final int y,
321
			final int z,
322
			final ResourceKey<LootTable> lootTable
323
		) {
324
			BlockPos pos = this.getWorldPos(x, y, z);
325
			if (chunkBB.isInside(pos) && level.getBlockState(pos).isAir() && !level.getBlockState(pos.below()).isAir()) {
326
				BlockState state = Blocks.RAIL.defaultBlockState().setValue(RailBlock.SHAPE, random.nextBoolean() ? RailShape.NORTH_SOUTH : RailShape.EAST_WEST);
327
				this.placeBlock(level, state, x, y, z, chunkBB);
328
				MinecartChest chest = EntityTypes.CHEST_MINECART.create(level.getLevel(), EntitySpawnReason.CHUNK_GENERATION);
329
				if (chest != null) {
330
					chest.setInitialPos(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
331
					chest.setLootTable(lootTable, random.nextLong());
332
					level.addFreshEntity(chest);
333
				}
334
335
				return true;
336
			} else {
337
				return false;
338
			}
339
		}
340
341
		@Override
342
		public void postProcess(
343
			final WorldGenLevel level,
344
			final StructureManager structureManager,
345
			final ChunkGenerator generator,
346
			final RandomSource random,
347
			final BoundingBox chunkBB,
348
			final ChunkPos chunkPos,
349
			final BlockPos referencePos
350
		) {
351
			if (!this.isInInvalidLocation(level, chunkBB)) {
352
				int x0 = 0;
353
				int x1 = 2;
354
				int y0 = 0;
355
				int y1 = 2;
356
				int length = this.numSections * 5 - 1;
357
				BlockState planks = this.type.getPlanksState();
358
				this.generateBox(level, chunkBB, 0, 0, 0, 2, 1, length, CAVE_AIR, CAVE_AIR, false);
359
				this.generateMaybeBox(level, chunkBB, random, 0.8F, 0, 2, 0, 2, 2, length, CAVE_AIR, CAVE_AIR, false, false);
360
				if (this.spiderCorridor) {
361
					this.generateMaybeBox(level, chunkBB, random, 0.6F, 0, 0, 0, 2, 1, length, Blocks.COBWEB.defaultBlockState(), CAVE_AIR, false, true);
362
				}
363
364
				for (int section = 0; section < this.numSections; section++) {
365
					int z = 2 + section * 5;
366
					this.placeSupport(level, chunkBB, 0, 0, z, 2, 2, random);
367
					this.maybePlaceCobWeb(level, chunkBB, random, 0.1F, 0, 2, z - 1);
368
					this.maybePlaceCobWeb(level, chunkBB, random, 0.1F, 2, 2, z - 1);
369
					this.maybePlaceCobWeb(level, chunkBB, random, 0.1F, 0, 2, z + 1);
370
					this.maybePlaceCobWeb(level, chunkBB, random, 0.1F, 2, 2, z + 1);
371
					this.maybePlaceCobWeb(level, chunkBB, random, 0.05F, 0, 2, z - 2);
372
					this.maybePlaceCobWeb(level, chunkBB, random, 0.05F, 2, 2, z - 2);
373
					this.maybePlaceCobWeb(level, chunkBB, random, 0.05F, 0, 2, z + 2);
374
					this.maybePlaceCobWeb(level, chunkBB, random, 0.05F, 2, 2, z + 2);
375
					if (random.nextInt(100) == 0) {
376
						this.createChest(level, chunkBB, random, 2, 0, z - 1, BuiltInLootTables.ABANDONED_MINESHAFT);
377
					}
378
379
					if (random.nextInt(100) == 0) {
380
						this.createChest(level, chunkBB, random, 0, 0, z + 1, BuiltInLootTables.ABANDONED_MINESHAFT);
381
					}
382
383
					if (this.spiderCorridor && !this.hasPlacedSpider) {
384
						int newX = 1;
385
						int newZ = z - 1 + random.nextInt(3);
386
						BlockPos pos = this.getWorldPos(1, 0, newZ);
387
						if (chunkBB.isInside(pos) && this.isInterior(level, 1, 0, newZ, chunkBB)) {
388
							this.hasPlacedSpider = true;
389
							level.setBlock(pos, Blocks.SPAWNER.defaultBlockState(), 2);
390
							if (level.getBlockEntity(pos) instanceof SpawnerBlockEntity spawner) {
391
								spawner.setEntityId(EntityTypes.CAVE_SPIDER, random);
392
							}
393
						}
394
					}
395
				}
396
397
				for (int x = 0; x <= 2; x++) {
398
					for (int z = 0; z <= length; z++) {
399
						this.setPlanksBlock(level, chunkBB, planks, x, -1, z);
400
					}
401
				}
402
403
				int supportPillarIndent = 2;
404
				this.placeDoubleLowerOrUpperSupport(level, chunkBB, 0, -1, 2);
405
				if (this.numSections > 1) {
406
					int lastSupportPillar = length - 2;
407
					this.placeDoubleLowerOrUpperSupport(level, chunkBB, 0, -1, lastSupportPillar);
408
				}
409
410
				if (this.hasRails) {
411
					BlockState state = Blocks.RAIL.defaultBlockState().setValue(RailBlock.SHAPE, RailShape.NORTH_SOUTH);
412
413
					for (int z = 0; z <= length; z++) {
414
						BlockState floor = this.getBlock(level, 1, -1, z, chunkBB);
415
						if (!floor.isAir() && floor.isSolidRender()) {
416
							float probability = this.isInterior(level, 1, 0, z, chunkBB) ? 0.7F : 0.9F;
417
							this.maybeGenerateBlock(level, chunkBB, random, probability, 1, 0, z, state);
418
						}
419
					}
420
				}
421
			}
422
		}
423
424
		private void placeDoubleLowerOrUpperSupport(final WorldGenLevel level, final BoundingBox chunkBB, final int x, final int y, final int z) {
425
			BlockState woodBlock = this.type.getWoodState();
426
			BlockState plankBlock = this.type.getPlanksState();
427
			if (this.getBlock(level, x, y, z, chunkBB).is(plankBlock.getBlock())) {
428
				this.fillPillarDownOrChainUp(level, woodBlock, x, y, z, chunkBB);
429
			}
430
431
			if (this.getBlock(level, x + 2, y, z, chunkBB).is(plankBlock.getBlock())) {
432
				this.fillPillarDownOrChainUp(level, woodBlock, x + 2, y, z, chunkBB);
433
			}
434
		}
435
436
		@Override
437
		protected void fillColumnDown(final WorldGenLevel level, final BlockState columnState, final int x, final int startY, final int z, final BoundingBox chunkBB) {
438
			BlockPos.MutableBlockPos pos = this.getWorldPos(x, startY, z);
439
			if (chunkBB.isInside(pos)) {
440
				int worldY = pos.getY();
441
442
				while (this.isReplaceableByStructures(level.getBlockState(pos)) && pos.getY() > level.getMinY() + 1) {
443
					pos.move(Direction.DOWN);
444
				}
445
446
				if (this.canPlaceColumnOnTopOf(level, pos, level.getBlockState(pos))) {
447
					while (pos.getY() < worldY) {
448
						pos.move(Direction.UP);
449
						level.setBlock(pos, columnState, 2);
450
					}
451
				}
452
			}
453
		}
454
455
		protected void fillPillarDownOrChainUp(
456
			final WorldGenLevel level, final BlockState pillarState, final int x, final int y, final int z, final BoundingBox chunkBB
457
		) {
458
			BlockPos.MutableBlockPos pos = this.getWorldPos(x, y, z);
459
			if (chunkBB.isInside(pos)) {
460
				int worldY = pos.getY();
461
				int distanceFromWorldY = 1;
462
				boolean checkBelow = true;
463
464
				for (boolean checkAbove = true; checkBelow || checkAbove; distanceFromWorldY++) {
465
					if (checkBelow) {
466
						pos.setY(worldY - distanceFromWorldY);
467
						BlockState belowState = level.getBlockState(pos);
468
						boolean emptyBelow = this.isReplaceableByStructures(belowState) && !belowState.is(Blocks.LAVA);
469
						if (!emptyBelow && this.canPlaceColumnOnTopOf(level, pos, belowState)) {
470
							fillColumnBetween(level, pillarState, pos, worldY - distanceFromWorldY + 1, worldY);
471
							return;
472
						}
473
474
						checkBelow = distanceFromWorldY <= 20 && emptyBelow && pos.getY() > level.getMinY() + 1;
475
					}
476
477
					if (checkAbove) {
478
						pos.setY(worldY + distanceFromWorldY);
479
						BlockState aboveState = level.getBlockState(pos);
480
						boolean emptyAbove = this.isReplaceableByStructures(aboveState);
481
						if (!emptyAbove && this.canHangChainBelow(level, pos, aboveState)) {
482
							level.setBlock(pos.setY(worldY + 1), this.type.getFenceState(), 2);
483
							fillColumnBetween(level, Blocks.IRON_CHAIN.defaultBlockState(), pos, worldY + 2, worldY + distanceFromWorldY);
484
							return;
485
						}
486
487
						checkAbove = distanceFromWorldY <= 50 && emptyAbove && pos.getY() < level.getMaxY();
488
					}
489
				}
490
			}
491
		}
492
493
		private static void fillColumnBetween(
494
			final WorldGenLevel level, final BlockState pillarState, final BlockPos.MutableBlockPos pos, final int bottomInclusive, final int topExclusive
495
		) {
496
			for (int pillarY = bottomInclusive; pillarY < topExclusive; pillarY++) {
497
				level.setBlock(pos.setY(pillarY), pillarState, 2);
498
			}
499
		}
500
501
		private boolean canPlaceColumnOnTopOf(final LevelReader level, final BlockPos posBelow, final BlockState stateBelow) {
502
			return stateBelow.isFaceSturdy(level, posBelow, Direction.UP);
503
		}
504
505
		private boolean canHangChainBelow(final LevelReader level, final BlockPos posAbove, final BlockState stateAbove) {
506
			return Block.canSupportCenter(level, posAbove, Direction.DOWN) && !(stateAbove.getBlock() instanceof FallingBlock);
507
		}
508
509
		private void placeSupport(
510
			final WorldGenLevel level, final BoundingBox chunkBB, final int x0, final int y0, final int z, final int y1, final int x1, final RandomSource random
511
		) {
512
			if (this.isSupportingBox(level, chunkBB, x0, x1, y1, z)) {
513
				BlockState planksBlock = this.type.getPlanksState();
514
				BlockState fenceBlock = this.type.getFenceState();
515
				this.generateBox(level, chunkBB, x0, y0, z, x0, y1 - 1, z, fenceBlock.setValue(FenceBlock.WEST, true), CAVE_AIR, false);
516
				this.generateBox(level, chunkBB, x1, y0, z, x1, y1 - 1, z, fenceBlock.setValue(FenceBlock.EAST, true), CAVE_AIR, false);
517
				if (random.nextInt(4) == 0) {
518
					this.generateBox(level, chunkBB, x0, y1, z, x0, y1, z, planksBlock, CAVE_AIR, false);
519
					this.generateBox(level, chunkBB, x1, y1, z, x1, y1, z, planksBlock, CAVE_AIR, false);
520
				} else {
521
					this.generateBox(level, chunkBB, x0, y1, z, x1, y1, z, planksBlock, CAVE_AIR, false);
522
					this.maybeGenerateBlock(
523
						level, chunkBB, random, 0.05F, x0 + 1, y1, z - 1, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.SOUTH)
524
					);
525
					this.maybeGenerateBlock(
526
						level, chunkBB, random, 0.05F, x0 + 1, y1, z + 1, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.NORTH)
527
					);
528
				}
529
			}
530
		}
531
532
		private void maybePlaceCobWeb(
533
			final WorldGenLevel level, final BoundingBox chunkBB, final RandomSource random, final float probability, final int x, final int y, final int z
534
		) {
535
			if (this.isInterior(level, x, y, z, chunkBB) && random.nextFloat() < probability && this.hasSturdyNeighbours(level, chunkBB, x, y, z, 2)) {
536
				this.placeBlock(level, Blocks.COBWEB.defaultBlockState(), x, y, z, chunkBB);
537
			}
538
		}
539
540
		private boolean hasSturdyNeighbours(final WorldGenLevel level, final BoundingBox chunkBB, final int x, final int y, final int z, final int count) {
541
			BlockPos.MutableBlockPos worldPos = this.getWorldPos(x, y, z);
542
			int sturdyNeighbours = 0;
543
544
			for (Direction direction : Direction.values()) {
545
				worldPos.move(direction);
546
				if (chunkBB.isInside(worldPos) && level.getBlockState(worldPos).isFaceSturdy(level, worldPos, direction.getOpposite())) {
547
					if (++sturdyNeighbours >= count) {
548
						return true;
549
					}
550
				}
551
552
				worldPos.move(direction.getOpposite());
553
			}
554
555
			return false;
556
		}
557
	}
558
559
	public static class MineShaftCrossing extends MineshaftPieces.MineShaftPiece {
560
		private final Direction direction;
561
		private final boolean isTwoFloored;
562
563
		public MineShaftCrossing(final CompoundTag tag) {
564
			super(StructurePieceType.MINE_SHAFT_CROSSING, tag);
565
			this.isTwoFloored = tag.getBooleanOr("tf", false);
566
			this.direction = tag.read("D", Direction.LEGACY_ID_CODEC_2D).orElse(Direction.SOUTH);
567
		}
568
569
		@Override
570
		protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
571
			super.addAdditionalSaveData(context, tag);
572
			tag.putBoolean("tf", this.isTwoFloored);
573
			tag.store("D", Direction.LEGACY_ID_CODEC_2D, this.direction);
574
		}
575
576
		public MineShaftCrossing(final int genDepth, final BoundingBox boundingBox, final @Nullable Direction direction, final MineshaftStructure.Type type) {
577
			super(StructurePieceType.MINE_SHAFT_CROSSING, genDepth, type, boundingBox);
578
			this.direction = direction;
579
			this.isTwoFloored = boundingBox.getYSpan() > 3;
580
		}
581
582
		public static @Nullable BoundingBox findCrossing(
583
			final StructurePiecesBuilder builder, final RandomSource random, final int footX, final int footY, final int footZ, final Direction direction
584
		) {
585
			int y1;
586
			if (random.nextInt(4) == 0) {
587
				y1 = 6;
588
			} else {
589
				y1 = 2;
590
			}
591
			BoundingBox box = switch (direction) {
592
				default -> new BoundingBox(-1, 0, -4, 3, y1, 0);
593
				case SOUTH -> new BoundingBox(-1, 0, 0, 3, y1, 4);
594
				case WEST -> new BoundingBox(-4, 0, -1, 0, y1, 3);
595
				case EAST -> new BoundingBox(0, 0, -1, 4, y1, 3);
596
			};
597
			box.move(footX, footY, footZ);
598
			return builder.findCollisionPiece(box) != null ? null : box;
599
		}
600
601
		@Override
602
		public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
603
			int depth = this.getGenDepth();
604
			switch (this.direction) {
605
				case NORTH:
606
				default:
607
					MineshaftPieces.generateAndAddPiece(
608
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() - 1, Direction.NORTH, depth
609
					);
610
					MineshaftPieces.generateAndAddPiece(
611
						startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, Direction.WEST, depth
612
					);
613
					MineshaftPieces.generateAndAddPiece(
614
						startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, Direction.EAST, depth
615
					);
616
					break;
617
				case SOUTH:
618
					MineshaftPieces.generateAndAddPiece(
619
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.maxZ() + 1, Direction.SOUTH, depth
620
					);
621
					MineshaftPieces.generateAndAddPiece(
622
						startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, Direction.WEST, depth
623
					);
624
					MineshaftPieces.generateAndAddPiece(
625
						startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, Direction.EAST, depth
626
					);
627
					break;
628
				case WEST:
629
					MineshaftPieces.generateAndAddPiece(
630
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() - 1, Direction.NORTH, depth
631
					);
632
					MineshaftPieces.generateAndAddPiece(
633
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.maxZ() + 1, Direction.SOUTH, depth
634
					);
635
					MineshaftPieces.generateAndAddPiece(
636
						startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, Direction.WEST, depth
637
					);
638
					break;
639
				case EAST:
640
					MineshaftPieces.generateAndAddPiece(
641
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() - 1, Direction.NORTH, depth
642
					);
643
					MineshaftPieces.generateAndAddPiece(
644
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.maxZ() + 1, Direction.SOUTH, depth
645
					);
646
					MineshaftPieces.generateAndAddPiece(
647
						startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, Direction.EAST, depth
648
					);
649
			}
650
651
			if (this.isTwoFloored) {
652
				if (random.nextBoolean()) {
653
					MineshaftPieces.generateAndAddPiece(
654
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY() + 3 + 1, this.boundingBox.minZ() - 1, Direction.NORTH, depth
655
					);
656
				}
657
658
				if (random.nextBoolean()) {
659
					MineshaftPieces.generateAndAddPiece(
660
						startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY() + 3 + 1, this.boundingBox.minZ() + 1, Direction.WEST, depth
661
					);
662
				}
663
664
				if (random.nextBoolean()) {
665
					MineshaftPieces.generateAndAddPiece(
666
						startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY() + 3 + 1, this.boundingBox.minZ() + 1, Direction.EAST, depth
667
					);
668
				}
669
670
				if (random.nextBoolean()) {
671
					MineshaftPieces.generateAndAddPiece(
672
						startPiece, builder, random, this.boundingBox.minX() + 1, this.boundingBox.minY() + 3 + 1, this.boundingBox.maxZ() + 1, Direction.SOUTH, depth
673
					);
674
				}
675
			}
676
		}
677
678
		@Override
679
		public void postProcess(
680
			final WorldGenLevel level,
681
			final StructureManager structureManager,
682
			final ChunkGenerator generator,
683
			final RandomSource random,
684
			final BoundingBox chunkBB,
685
			final ChunkPos chunkPos,
686
			final BlockPos referencePos
687
		) {
688
			if (!this.isInInvalidLocation(level, chunkBB)) {
689
				BlockState planks = this.type.getPlanksState();
690
				if (this.isTwoFloored) {
691
					this.generateBox(
692
						level,
693
						chunkBB,
694
						this.boundingBox.minX() + 1,
695
						this.boundingBox.minY(),
696
						this.boundingBox.minZ(),
697
						this.boundingBox.maxX() - 1,
698
						this.boundingBox.minY() + 3 - 1,
699
						this.boundingBox.maxZ(),
700
						CAVE_AIR,
701
						CAVE_AIR,
702
						false
703
					);
704
					this.generateBox(
705
						level,
706
						chunkBB,
707
						this.boundingBox.minX(),
708
						this.boundingBox.minY(),
709
						this.boundingBox.minZ() + 1,
710
						this.boundingBox.maxX(),
711
						this.boundingBox.minY() + 3 - 1,
712
						this.boundingBox.maxZ() - 1,
713
						CAVE_AIR,
714
						CAVE_AIR,
715
						false
716
					);
717
					this.generateBox(
718
						level,
719
						chunkBB,
720
						this.boundingBox.minX() + 1,
721
						this.boundingBox.maxY() - 2,
722
						this.boundingBox.minZ(),
723
						this.boundingBox.maxX() - 1,
724
						this.boundingBox.maxY(),
725
						this.boundingBox.maxZ(),
726
						CAVE_AIR,
727
						CAVE_AIR,
728
						false
729
					);
730
					this.generateBox(
731
						level,
732
						chunkBB,
733
						this.boundingBox.minX(),
734
						this.boundingBox.maxY() - 2,
735
						this.boundingBox.minZ() + 1,
736
						this.boundingBox.maxX(),
737
						this.boundingBox.maxY(),
738
						this.boundingBox.maxZ() - 1,
739
						CAVE_AIR,
740
						CAVE_AIR,
741
						false
742
					);
743
					this.generateBox(
744
						level,
745
						chunkBB,
746
						this.boundingBox.minX() + 1,
747
						this.boundingBox.minY() + 3,
748
						this.boundingBox.minZ() + 1,
749
						this.boundingBox.maxX() - 1,
750
						this.boundingBox.minY() + 3,
751
						this.boundingBox.maxZ() - 1,
752
						CAVE_AIR,
753
						CAVE_AIR,
754
						false
755
					);
756
				} else {
757
					this.generateBox(
758
						level,
759
						chunkBB,
760
						this.boundingBox.minX() + 1,
761
						this.boundingBox.minY(),
762
						this.boundingBox.minZ(),
763
						this.boundingBox.maxX() - 1,
764
						this.boundingBox.maxY(),
765
						this.boundingBox.maxZ(),
766
						CAVE_AIR,
767
						CAVE_AIR,
768
						false
769
					);
770
					this.generateBox(
771
						level,
772
						chunkBB,
773
						this.boundingBox.minX(),
774
						this.boundingBox.minY(),
775
						this.boundingBox.minZ() + 1,
776
						this.boundingBox.maxX(),
777
						this.boundingBox.maxY(),
778
						this.boundingBox.maxZ() - 1,
779
						CAVE_AIR,
780
						CAVE_AIR,
781
						false
782
					);
783
				}
784
785
				this.placeSupportPillar(level, chunkBB, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, this.boundingBox.maxY());
786
				this.placeSupportPillar(level, chunkBB, this.boundingBox.minX() + 1, this.boundingBox.minY(), this.boundingBox.maxZ() - 1, this.boundingBox.maxY());
787
				this.placeSupportPillar(level, chunkBB, this.boundingBox.maxX() - 1, this.boundingBox.minY(), this.boundingBox.minZ() + 1, this.boundingBox.maxY());
788
				this.placeSupportPillar(level, chunkBB, this.boundingBox.maxX() - 1, this.boundingBox.minY(), this.boundingBox.maxZ() - 1, this.boundingBox.maxY());
789
				int y = this.boundingBox.minY() - 1;
790
791
				for (int x = this.boundingBox.minX(); x <= this.boundingBox.maxX(); x++) {
792
					for (int z = this.boundingBox.minZ(); z <= this.boundingBox.maxZ(); z++) {
793
						this.setPlanksBlock(level, chunkBB, planks, x, y, z);
794
					}
795
				}
796
			}
797
		}
798
799
		private void placeSupportPillar(final WorldGenLevel level, final BoundingBox chunkBB, final int x, final int y0, final int z, final int y1) {
800
			if (!this.getBlock(level, x, y1 + 1, z, chunkBB).isAir()) {
801
				this.generateBox(level, chunkBB, x, y0, z, x, y1, z, this.type.getPlanksState(), CAVE_AIR, false);
802
			}
803
		}
804
	}
805
806
	private abstract static class MineShaftPiece extends StructurePiece {
807
		protected MineshaftStructure.Type type;
808
809
		public MineShaftPiece(final StructurePieceType pieceType, final int genDepth, final MineshaftStructure.Type type, final BoundingBox boundingBox) {
810
			super(pieceType, genDepth, boundingBox);
811
			this.type = type;
812
		}
813
814
		public MineShaftPiece(final StructurePieceType type, final CompoundTag tag) {
815
			super(type, tag);
816
			this.type = MineshaftStructure.Type.byId(tag.getIntOr("MST", 0));
817
		}
818
819
		@Override
820
		protected boolean canBeReplaced(final LevelReader level, final int x, final int y, final int z, final BoundingBox chunkBB) {
821
			BlockState state = this.getBlock(level, x, y, z, chunkBB);
822
			return !state.is(this.type.getPlanksState().getBlock())
823
				&& !state.is(this.type.getWoodState().getBlock())
824
				&& !state.is(this.type.getFenceState().getBlock())
825
				&& !state.is(Blocks.IRON_CHAIN);
826
		}
827
828
		@Override
829
		protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
830
			tag.putInt("MST", this.type.ordinal());
831
		}
832
833
		protected boolean isSupportingBox(final BlockGetter level, final BoundingBox chunkBB, final int x0, final int x1, final int y1, final int z0) {
834
			for (int x = x0; x <= x1; x++) {
835
				if (this.getBlock(level, x, y1 + 1, z0, chunkBB).isAir()) {
836
					return false;
837
				}
838
			}
839
840
			return true;
841
		}
842
843
		protected boolean isInInvalidLocation(final LevelAccessor level, final BoundingBox chunkBB) {
844
			int x0 = Math.max(this.boundingBox.minX() - 1, chunkBB.minX());
845
			int y0 = Math.max(this.boundingBox.minY() - 1, chunkBB.minY());
846
			int z0 = Math.max(this.boundingBox.minZ() - 1, chunkBB.minZ());
847
			int x1 = Math.min(this.boundingBox.maxX() + 1, chunkBB.maxX());
848
			int y1 = Math.min(this.boundingBox.maxY() + 1, chunkBB.maxY());
849
			int z1 = Math.min(this.boundingBox.maxZ() + 1, chunkBB.maxZ());
850
			BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos((x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2);
851
			if (level.getBiome(blockPos).is(BiomeTags.MINESHAFT_BLOCKING)) {
852
				return true;
853
			}
854
855
			for (int x = x0; x <= x1; x++) {
856
				for (int z = z0; z <= z1; z++) {
857
					if (level.getBlockState(blockPos.set(x, y0, z)).liquid()) {
858
						return true;
859
					}
860
861
					if (level.getBlockState(blockPos.set(x, y1, z)).liquid()) {
862
						return true;
863
					}
864
				}
865
			}
866
867
			for (int x = x0; x <= x1; x++) {
868
				for (int y = y0; y <= y1; y++) {
869
					if (level.getBlockState(blockPos.set(x, y, z0)).liquid()) {
870
						return true;
871
					}
872
873
					if (level.getBlockState(blockPos.set(x, y, z1)).liquid()) {
874
						return true;
875
					}
876
				}
877
			}
878
879
			for (int z = z0; z <= z1; z++) {
880
				for (int y = y0; y <= y1; y++) {
881
					if (level.getBlockState(blockPos.set(x0, y, z)).liquid()) {
882
						return true;
883
					}
884
885
					if (level.getBlockState(blockPos.set(x1, y, z)).liquid()) {
886
						return true;
887
					}
888
				}
889
			}
890
891
			return false;
892
		}
893
894
		protected void setPlanksBlock(final WorldGenLevel level, final BoundingBox chunkBB, final BlockState planksBlock, final int x, final int y, final int z) {
895
			if (this.isInterior(level, x, y, z, chunkBB)) {
896
				BlockPos pos = this.getWorldPos(x, y, z);
897
				BlockState existingState = level.getBlockState(pos);
898
				if (!existingState.isFaceSturdy(level, pos, Direction.UP)) {
899
					level.setBlock(pos, planksBlock, 2);
900
				}
901
			}
902
		}
903
	}
904
905
	public static class MineShaftRoom extends MineshaftPieces.MineShaftPiece {
906
		private final List<BoundingBox> childEntranceBoxes = Lists.newLinkedList();
907
908
		public MineShaftRoom(final int genDepth, final RandomSource random, final int west, final int north, final MineshaftStructure.Type type) {
909
			super(
910
				StructurePieceType.MINE_SHAFT_ROOM,
911
				genDepth,
912
				type,
913
				new BoundingBox(west, 50, north, west + 7 + random.nextInt(6), 54 + random.nextInt(6), north + 7 + random.nextInt(6))
914
			);
915
			this.type = type;
916
		}
917
918
		public MineShaftRoom(final CompoundTag tag) {
919
			super(StructurePieceType.MINE_SHAFT_ROOM, tag);
920
			this.childEntranceBoxes.addAll(tag.read("Entrances", BoundingBox.CODEC.listOf()).orElse(List.of()));
921
		}
922
923
		@Override
924
		public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
925
			int depth = this.getGenDepth();
926
			int heightSpace = this.boundingBox.getYSpan() - 3 - 1;
927
			if (heightSpace <= 0) {
928
				heightSpace = 1;
929
			}
930
931
			int pos = 0;
932
933
			while (pos < this.boundingBox.getXSpan()) {
934
				pos += random.nextInt(this.boundingBox.getXSpan());
935
				if (pos + 3 > this.boundingBox.getXSpan()) {
936
					break;
937
				}
938
939
				MineshaftPieces.MineShaftPiece child = MineshaftPieces.generateAndAddPiece(
940
					startPiece,
941
					builder,
942
					random,
943
					this.boundingBox.minX() + pos,
944
					this.boundingBox.minY() + random.nextInt(heightSpace) + 1,
945
					this.boundingBox.minZ() - 1,
946
					Direction.NORTH,
947
					depth
948
				);
949
				if (child != null) {
950
					BoundingBox childBox = child.getBoundingBox();
951
					this.childEntranceBoxes
952
						.add(new BoundingBox(childBox.minX(), childBox.minY(), this.boundingBox.minZ(), childBox.maxX(), childBox.maxY(), this.boundingBox.minZ() + 1));
953
				}
954
955
				pos += 4;
956
			}
957
958
			pos = 0;
959
960
			while (pos < this.boundingBox.getXSpan()) {
961
				pos += random.nextInt(this.boundingBox.getXSpan());
962
				if (pos + 3 > this.boundingBox.getXSpan()) {
963
					break;
964
				}
965
966
				MineshaftPieces.MineShaftPiece child = MineshaftPieces.generateAndAddPiece(
967
					startPiece,
968
					builder,
969
					random,
970
					this.boundingBox.minX() + pos,
971
					this.boundingBox.minY() + random.nextInt(heightSpace) + 1,
972
					this.boundingBox.maxZ() + 1,
973
					Direction.SOUTH,
974
					depth
975
				);
976
				if (child != null) {
977
					BoundingBox childBox = child.getBoundingBox();
978
					this.childEntranceBoxes
979
						.add(new BoundingBox(childBox.minX(), childBox.minY(), this.boundingBox.maxZ() - 1, childBox.maxX(), childBox.maxY(), this.boundingBox.maxZ()));
980
				}
981
982
				pos += 4;
983
			}
984
985
			pos = 0;
986
987
			while (pos < this.boundingBox.getZSpan()) {
988
				pos += random.nextInt(this.boundingBox.getZSpan());
989
				if (pos + 3 > this.boundingBox.getZSpan()) {
990
					break;
991
				}
992
993
				MineshaftPieces.MineShaftPiece child = MineshaftPieces.generateAndAddPiece(
994
					startPiece,
995
					builder,
996
					random,
997
					this.boundingBox.minX() - 1,
998
					this.boundingBox.minY() + random.nextInt(heightSpace) + 1,
999
					this.boundingBox.minZ() + pos,
1000
					Direction.WEST,
1001
					depth
1002
				);
1003
				if (child != null) {
1004
					BoundingBox childBox = child.getBoundingBox();
1005
					this.childEntranceBoxes
1006
						.add(new BoundingBox(this.boundingBox.minX(), childBox.minY(), childBox.minZ(), this.boundingBox.minX() + 1, childBox.maxY(), childBox.maxZ()));
1007
				}
1008
1009
				pos += 4;
1010
			}
1011
1012
			pos = 0;
1013
1014
			while (pos < this.boundingBox.getZSpan()) {
1015
				pos += random.nextInt(this.boundingBox.getZSpan());
1016
				if (pos + 3 > this.boundingBox.getZSpan()) {
1017
					break;
1018
				}
1019
1020
				StructurePiece child = MineshaftPieces.generateAndAddPiece(
1021
					startPiece,
1022
					builder,
1023
					random,
1024
					this.boundingBox.maxX() + 1,
1025
					this.boundingBox.minY() + random.nextInt(heightSpace) + 1,
1026
					this.boundingBox.minZ() + pos,
1027
					Direction.EAST,
1028
					depth
1029
				);
1030
				if (child != null) {
1031
					BoundingBox childBox = child.getBoundingBox();
1032
					this.childEntranceBoxes
1033
						.add(new BoundingBox(this.boundingBox.maxX() - 1, childBox.minY(), childBox.minZ(), this.boundingBox.maxX(), childBox.maxY(), childBox.maxZ()));
1034
				}
1035
1036
				pos += 4;
1037
			}
1038
		}
1039
1040
		@Override
1041
		public void postProcess(
1042
			final WorldGenLevel level,
1043
			final StructureManager structureManager,
1044
			final ChunkGenerator generator,
1045
			final RandomSource random,
1046
			final BoundingBox chunkBB,
1047
			final ChunkPos chunkPos,
1048
			final BlockPos referencePos
1049
		) {
1050
			if (!this.isInInvalidLocation(level, chunkBB)) {
1051
				this.generateBox(
1052
					level,
1053
					chunkBB,
1054
					this.boundingBox.minX(),
1055
					this.boundingBox.minY() + 1,
1056
					this.boundingBox.minZ(),
1057
					this.boundingBox.maxX(),
1058
					Math.min(this.boundingBox.minY() + 3, this.boundingBox.maxY()),
1059
					this.boundingBox.maxZ(),
1060
					CAVE_AIR,
1061
					CAVE_AIR,
1062
					false
1063
				);
1064
1065
				for (BoundingBox entranceBox : this.childEntranceBoxes) {
1066
					this.generateBox(
1067
						level,
1068
						chunkBB,
1069
						entranceBox.minX(),
1070
						entranceBox.maxY() - 2,
1071
						entranceBox.minZ(),
1072
						entranceBox.maxX(),
1073
						entranceBox.maxY(),
1074
						entranceBox.maxZ(),
1075
						CAVE_AIR,
1076
						CAVE_AIR,
1077
						false
1078
					);
1079
				}
1080
1081
				this.generateUpperHalfSphere(
1082
					level,
1083
					chunkBB,
1084
					this.boundingBox.minX(),
1085
					this.boundingBox.minY() + 4,
1086
					this.boundingBox.minZ(),
1087
					this.boundingBox.maxX(),
1088
					this.boundingBox.maxY(),
1089
					this.boundingBox.maxZ(),
1090
					CAVE_AIR,
1091
					false
1092
				);
1093
			}
1094
		}
1095
1096
		@Override
1097
		public void move(final int dx, final int dy, final int dz) {
1098
			super.move(dx, dy, dz);
1099
1100
			for (BoundingBox bb : this.childEntranceBoxes) {
1101
				bb.move(dx, dy, dz);
1102
			}
1103
		}
1104
1105
		@Override
1106
		protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
1107
			super.addAdditionalSaveData(context, tag);
1108
			tag.store("Entrances", BoundingBox.CODEC.listOf(), this.childEntranceBoxes);
1109
		}
1110
	}
1111
1112
	public static class MineShaftStairs extends MineshaftPieces.MineShaftPiece {
1113
		public MineShaftStairs(final int genDepth, final BoundingBox boundingBox, final Direction direction, final MineshaftStructure.Type type) {
1114
			super(StructurePieceType.MINE_SHAFT_STAIRS, genDepth, type, boundingBox);
1115
			this.setOrientation(direction);
1116
		}
1117
1118
		public MineShaftStairs(final CompoundTag tag) {
1119
			super(StructurePieceType.MINE_SHAFT_STAIRS, tag);
1120
		}
1121
1122
		public static @Nullable BoundingBox findStairs(
1123
			final StructurePiecesBuilder builder, final RandomSource random, final int footX, final int footY, final int footZ, final Direction direction
1124
		) {
1125
			BoundingBox box = switch (direction) {
1126
				default -> new BoundingBox(0, -5, -8, 2, 2, 0);
1127
				case SOUTH -> new BoundingBox(0, -5, 0, 2, 2, 8);
1128
				case WEST -> new BoundingBox(-8, -5, 0, 0, 2, 2);
1129
				case EAST -> new BoundingBox(0, -5, 0, 8, 2, 2);
1130
			};
1131
			box.move(footX, footY, footZ);
1132
			return builder.findCollisionPiece(box) != null ? null : box;
1133
		}
1134
1135
		@Override
1136
		public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
1137
			int depth = this.getGenDepth();
1138
			Direction orientation = this.getOrientation();
1139
			if (orientation != null) {
1140
				switch (orientation) {
1141
					case NORTH:
1142
					default:
1143
						MineshaftPieces.generateAndAddPiece(
1144
							startPiece, builder, random, this.boundingBox.minX(), this.boundingBox.minY(), this.boundingBox.minZ() - 1, Direction.NORTH, depth
1145
						);
1146
						break;
1147
					case SOUTH:
1148
						MineshaftPieces.generateAndAddPiece(
1149
							startPiece, builder, random, this.boundingBox.minX(), this.boundingBox.minY(), this.boundingBox.maxZ() + 1, Direction.SOUTH, depth
1150
						);
1151
						break;
1152
					case WEST:
1153
						MineshaftPieces.generateAndAddPiece(
1154
							startPiece, builder, random, this.boundingBox.minX() - 1, this.boundingBox.minY(), this.boundingBox.minZ(), Direction.WEST, depth
1155
						);
1156
						break;
1157
					case EAST:
1158
						MineshaftPieces.generateAndAddPiece(
1159
							startPiece, builder, random, this.boundingBox.maxX() + 1, this.boundingBox.minY(), this.boundingBox.minZ(), Direction.EAST, depth
1160
						);
1161
				}
1162
			}
1163
		}
1164
1165
		@Override
1166
		public void postProcess(
1167
			final WorldGenLevel level,
1168
			final StructureManager structureManager,
1169
			final ChunkGenerator generator,
1170
			final RandomSource random,
1171
			final BoundingBox chunkBB,
1172
			final ChunkPos chunkPos,
1173
			final BlockPos referencePos
1174
		) {
1175
			if (!this.isInInvalidLocation(level, chunkBB)) {
1176
				this.generateBox(level, chunkBB, 0, 5, 0, 2, 7, 1, CAVE_AIR, CAVE_AIR, false);
1177
				this.generateBox(level, chunkBB, 0, 0, 7, 2, 2, 8, CAVE_AIR, CAVE_AIR, false);
1178
1179
				for (int i = 0; i < 5; i++) {
1180
					this.generateBox(level, chunkBB, 0, 5 - i - (i < 4 ? 1 : 0), 2 + i, 2, 7 - i, 2 + i, CAVE_AIR, CAVE_AIR, false);
1181
				}
1182
			}
1183
		}
1184
	}
1185
}
1186

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