| 1 | package net.minecraft.world.level.levelgen.structure.structures;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Optional;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.world.level.ChunkPos;
|
| 9 | import net.minecraft.world.level.block.Rotation;
|
| 10 | import net.minecraft.world.level.levelgen.structure.Structure;
|
| 11 | import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
| 12 | import net.minecraft.world.level.levelgen.structure.StructureType;
|
| 13 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
| 14 |
|
| 15 | public class EndCityStructure extends Structure {
|
| 16 | public static final MapCodec<EndCityStructure> CODEC = simpleCodec(EndCityStructure::new);
|
| 17 | private static final int START_OFFSET_IN_CHUNK = 7;
|
| 18 |
|
| 19 | public EndCityStructure(final Structure.StructureSettings settings) {
|
| 20 | super(settings);
|
| 21 | }
|
| 22 |
|
| 23 | @Override
|
| 24 | public Optional<Structure.GenerationStub> findGenerationPoint(final Structure.GenerationContext context) {
|
| 25 | ChunkPos chunkPos = context.chunkPos();
|
| 26 | int blockX = chunkPos.getBlockX(7);
|
| 27 | int blockZ = chunkPos.getBlockZ(7);
|
| 28 | if (!context.couldValidBiomeExistInTerrainColumn(blockX, blockZ)) {
|
| 29 | return Optional.empty();
|
| 30 | }
|
| 31 |
|
| 32 | Rotation rotation = Rotation.getRandom(context.random());
|
| 33 | BlockPos startPos = this.getLowestYIn5by5Box(context, blockX, blockZ, rotation);
|
| 34 | return startPos.getY() < 60
|
| 35 | ? Optional.empty()
|
| 36 | : Optional.of(new Structure.GenerationStub(startPos, builder -> this.generatePieces(builder, startPos, rotation, context)));
|
| 37 | }
|
| 38 |
|
| 39 | private void generatePieces(final StructurePiecesBuilder builder, final BlockPos startPos, final Rotation rotation, final Structure.GenerationContext context) {
|
| 40 | List<StructurePiece> pieces = Lists.newArrayList();
|
| 41 | EndCityPieces.startHouseTower(context.structureTemplateManager(), startPos, rotation, pieces, context.random());
|
| 42 | pieces.forEach(builder::addPiece);
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public StructureType<?> type() {
|
| 47 | return StructureType.END_CITY;
|
| 48 | }
|
| 49 | }
|
| 50 |
|