| 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.core.BlockPos;
|
| 7 | import net.minecraft.util.random.WeightedList;
|
| 8 | import net.minecraft.util.valueproviders.ConstantInt;
|
| 9 | import net.minecraft.util.valueproviders.UniformInt;
|
| 10 | import net.minecraft.world.entity.EntityTypes;
|
| 11 | import net.minecraft.world.level.ChunkPos;
|
| 12 | import net.minecraft.world.level.biome.MobSpawnSettings;
|
| 13 | import net.minecraft.world.level.levelgen.structure.Structure;
|
| 14 | import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
| 15 | import net.minecraft.world.level.levelgen.structure.StructureType;
|
| 16 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
| 17 |
|
| 18 | public class NetherFortressStructure extends Structure {
|
| 19 | public static final WeightedList<MobSpawnSettings.SpawnerData> FORTRESS_ENEMIES = WeightedList.<MobSpawnSettings.SpawnerData>builder()
|
| 20 | .add(new MobSpawnSettings.SpawnerData(EntityTypes.BLAZE, new UniformInt(2, 3)), 10)
|
| 21 | .add(new MobSpawnSettings.SpawnerData(EntityTypes.ZOMBIFIED_PIGLIN, new ConstantInt(4)), 5)
|
| 22 | .add(new MobSpawnSettings.SpawnerData(EntityTypes.WITHER_SKELETON, new ConstantInt(5)), 8)
|
| 23 | .add(new MobSpawnSettings.SpawnerData(EntityTypes.SKELETON, new ConstantInt(5)), 2)
|
| 24 | .add(new MobSpawnSettings.SpawnerData(EntityTypes.MAGMA_CUBE, new ConstantInt(4)), 3)
|
| 25 | .build();
|
| 26 | public static final MapCodec<NetherFortressStructure> CODEC = simpleCodec(NetherFortressStructure::new);
|
| 27 |
|
| 28 | public NetherFortressStructure(final Structure.StructureSettings settings) {
|
| 29 | super(settings);
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | public Optional<Structure.GenerationStub> findGenerationPoint(final Structure.GenerationContext context) {
|
| 34 | ChunkPos chunkPos = context.chunkPos();
|
| 35 | BlockPos startPos = new BlockPos(chunkPos.getMinBlockX(), 64, chunkPos.getMinBlockZ());
|
| 36 | return Optional.of(new Structure.GenerationStub(startPos, builder -> generatePieces(builder, context)));
|
| 37 | }
|
| 38 |
|
| 39 | private static void generatePieces(final StructurePiecesBuilder builder, final Structure.GenerationContext context) {
|
| 40 | NetherFortressPieces.StartPiece start = new NetherFortressPieces.StartPiece(
|
| 41 | context.random(), context.chunkPos().getBlockX(2), context.chunkPos().getBlockZ(2)
|
| 42 | );
|
| 43 | builder.addPiece(start);
|
| 44 | start.addChildren(start, builder, context.random());
|
| 45 | List<StructurePiece> pendingChildren = start.pendingChildren;
|
| 46 |
|
| 47 | while (!pendingChildren.isEmpty()) {
|
| 48 | int pos = context.random().nextInt(pendingChildren.size());
|
| 49 | StructurePiece structurePiece = pendingChildren.remove(pos);
|
| 50 | structurePiece.addChildren(start, builder, context.random());
|
| 51 | }
|
| 52 |
|
| 53 | builder.moveInsideHeights(context.random(), 48, 70);
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public StructureType<?> type() {
|
| 58 | return StructureType.FORTRESS;
|
| 59 | }
|
| 60 | }
|
| 61 |
|