| 1 | package net.minecraft.world.level.levelgen.structure.structures;
|
| 2 |
|
| 3 | import com.mojang.serialization.MapCodec;
|
| 4 | import java.util.List;
|
| 5 | import java.util.Optional;
|
| 6 | import net.minecraft.world.level.levelgen.structure.Structure;
|
| 7 | import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
| 8 | import net.minecraft.world.level.levelgen.structure.StructureType;
|
| 9 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
| 10 |
|
| 11 | public class StrongholdStructure extends Structure {
|
| 12 | public static final MapCodec<StrongholdStructure> CODEC = simpleCodec(StrongholdStructure::new);
|
| 13 |
|
| 14 | public StrongholdStructure(final Structure.StructureSettings settings) {
|
| 15 | super(settings);
|
| 16 | }
|
| 17 |
|
| 18 | @Override
|
| 19 | public Optional<Structure.GenerationStub> findGenerationPoint(final Structure.GenerationContext context) {
|
| 20 | return Optional.of(new Structure.GenerationStub(context.chunkPos().getWorldPosition(), builder -> generatePieces(builder, context)));
|
| 21 | }
|
| 22 |
|
| 23 | private static void generatePieces(final StructurePiecesBuilder builder, final Structure.GenerationContext context) {
|
| 24 | int tries = 0;
|
| 25 |
|
| 26 | StrongholdPieces.StartPiece startRoom;
|
| 27 | do {
|
| 28 | builder.clear();
|
| 29 | context.random().setLargeFeatureSeed(context.seed() + tries++, context.chunkPos().x(), context.chunkPos().z());
|
| 30 | StrongholdPieces.resetPieces();
|
| 31 | startRoom = new StrongholdPieces.StartPiece(context.random(), context.chunkPos().getBlockX(2), context.chunkPos().getBlockZ(2));
|
| 32 | builder.addPiece(startRoom);
|
| 33 | startRoom.addChildren(startRoom, builder, context.random());
|
| 34 | List<StructurePiece> pendingChildren = startRoom.pendingChildren;
|
| 35 |
|
| 36 | while (!pendingChildren.isEmpty()) {
|
| 37 | int pos = context.random().nextInt(pendingChildren.size());
|
| 38 | StructurePiece structurePiece = pendingChildren.remove(pos);
|
| 39 | structurePiece.addChildren(startRoom, builder, context.random());
|
| 40 | }
|
| 41 |
|
| 42 | builder.moveBelowSeaLevel(context.chunkGenerator().getSeaLevel(), context.chunkGenerator().getMinY(), context.random(), 10);
|
| 43 | } while (builder.isEmpty() || startRoom.portalRoomPiece == null);
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | public StructureType<?> type() {
|
| 48 | return StructureType.STRONGHOLD;
|
| 49 | }
|
| 50 | }
|
| 51 |
|