| 1 | package net.minecraft.world.level.levelgen.structure.structures;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.mojang.serialization.Codec;
|
| 5 | import java.util.List;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.Direction;
|
| 8 | import net.minecraft.nbt.CompoundTag;
|
| 9 | import net.minecraft.util.ExtraCodecs;
|
| 10 | import net.minecraft.util.RandomSource;
|
| 11 | import net.minecraft.world.entity.EntityTypes;
|
| 12 | import net.minecraft.world.level.ChunkPos;
|
| 13 | import net.minecraft.world.level.StructureManager;
|
| 14 | import net.minecraft.world.level.WorldGenLevel;
|
| 15 | import net.minecraft.world.level.block.Blocks;
|
| 16 | import net.minecraft.world.level.block.ButtonBlock;
|
| 17 | import net.minecraft.world.level.block.DoorBlock;
|
| 18 | import net.minecraft.world.level.block.EndPortalFrameBlock;
|
| 19 | import net.minecraft.world.level.block.FenceBlock;
|
| 20 | import net.minecraft.world.level.block.IronBarsBlock;
|
| 21 | import net.minecraft.world.level.block.LadderBlock;
|
| 22 | import net.minecraft.world.level.block.SlabBlock;
|
| 23 | import net.minecraft.world.level.block.StairBlock;
|
| 24 | import net.minecraft.world.level.block.WallTorchBlock;
|
| 25 | import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
|
| 26 | import net.minecraft.world.level.block.state.BlockState;
|
| 27 | import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
|
| 28 | import net.minecraft.world.level.block.state.properties.SlabType;
|
| 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 org.jspecify.annotations.Nullable;
|
| 37 |
|
| 38 | public class StrongholdPieces {
|
| 39 | private static final int SMALL_DOOR_WIDTH = 3;
|
| 40 | private static final int SMALL_DOOR_HEIGHT = 3;
|
| 41 | private static final int MAX_DEPTH = 50;
|
| 42 | private static final int LOWEST_Y_POSITION = 10;
|
| 43 | private static final boolean CHECK_AIR = true;
|
| 44 | public static final int MAGIC_START_Y = 64;
|
| 45 | private static final StrongholdPieces.PieceWeight[] STRONGHOLD_PIECE_WEIGHTS = new StrongholdPieces.PieceWeight[]{
|
| 46 | new StrongholdPieces.PieceWeight(StrongholdPieces.Straight.class, 40, 0),
|
| 47 | new StrongholdPieces.PieceWeight(StrongholdPieces.PrisonHall.class, 5, 5),
|
| 48 | new StrongholdPieces.PieceWeight(StrongholdPieces.LeftTurn.class, 20, 0),
|
| 49 | new StrongholdPieces.PieceWeight(StrongholdPieces.RightTurn.class, 20, 0),
|
| 50 | new StrongholdPieces.PieceWeight(StrongholdPieces.RoomCrossing.class, 10, 6),
|
| 51 | new StrongholdPieces.PieceWeight(StrongholdPieces.StraightStairsDown.class, 5, 5),
|
| 52 | new StrongholdPieces.PieceWeight(StrongholdPieces.StairsDown.class, 5, 5),
|
| 53 | new StrongholdPieces.PieceWeight(StrongholdPieces.FiveCrossing.class, 5, 4),
|
| 54 | new StrongholdPieces.PieceWeight(StrongholdPieces.ChestCorridor.class, 5, 4),
|
| 55 | new StrongholdPieces.PieceWeight(StrongholdPieces.Library.class, 10, 2) {
|
| 56 | @Override
|
| 57 | public boolean doPlace(final int depth) {
|
| 58 | return super.doPlace(depth) && depth > 4;
|
| 59 | }
|
| 60 | },
|
| 61 | new StrongholdPieces.PieceWeight(StrongholdPieces.PortalRoom.class, 20, 1) {
|
| 62 | @Override
|
| 63 | public boolean doPlace(final int depth) {
|
| 64 | return super.doPlace(depth) && depth > 5;
|
| 65 | }
|
| 66 | }
|
| 67 | };
|
| 68 | private static List<StrongholdPieces.PieceWeight> currentPieces;
|
| 69 | private static @Nullable Class<? extends StrongholdPieces.StrongholdPiece> imposedPiece;
|
| 70 | private static int totalWeight;
|
| 71 | private static final StrongholdPieces.SmoothStoneSelector SMOOTH_STONE_SELECTOR = new StrongholdPieces.SmoothStoneSelector();
|
| 72 |
|
| 73 | public static void resetPieces() {
|
| 74 | currentPieces = Lists.newArrayList();
|
| 75 |
|
| 76 | for (StrongholdPieces.PieceWeight piece : STRONGHOLD_PIECE_WEIGHTS) {
|
| 77 | piece.placeCount = 0;
|
| 78 | currentPieces.add(piece);
|
| 79 | }
|
| 80 |
|
| 81 | imposedPiece = null;
|
| 82 | }
|
| 83 |
|
| 84 | private static boolean updatePieceWeight() {
|
| 85 | boolean hasAnyPieces = false;
|
| 86 | totalWeight = 0;
|
| 87 |
|
| 88 | for (StrongholdPieces.PieceWeight piece : currentPieces) {
|
| 89 | if (piece.maxPlaceCount > 0 && piece.placeCount < piece.maxPlaceCount) {
|
| 90 | hasAnyPieces = true;
|
| 91 | }
|
| 92 |
|
| 93 | totalWeight = totalWeight + piece.weight;
|
| 94 | }
|
| 95 |
|
| 96 | return hasAnyPieces;
|
| 97 | }
|
| 98 |
|
| 99 | private static StrongholdPieces.@Nullable StrongholdPiece findAndCreatePieceFactory(
|
| 100 | final Class<? extends StrongholdPieces.StrongholdPiece> pieceClass,
|
| 101 | final StructurePiecesBuilder builder,
|
| 102 | final RandomSource random,
|
| 103 | final int footX,
|
| 104 | final int footY,
|
| 105 | final int footZ,
|
| 106 | final Direction direction,
|
| 107 | final int depth
|
| 108 | ) {
|
| 109 | StrongholdPieces.StrongholdPiece strongholdPiece = null;
|
| 110 | if (pieceClass == StrongholdPieces.Straight.class) {
|
| 111 | strongholdPiece = StrongholdPieces.Straight.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 112 | } else if (pieceClass == StrongholdPieces.PrisonHall.class) {
|
| 113 | strongholdPiece = StrongholdPieces.PrisonHall.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 114 | } else if (pieceClass == StrongholdPieces.LeftTurn.class) {
|
| 115 | strongholdPiece = StrongholdPieces.LeftTurn.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 116 | } else if (pieceClass == StrongholdPieces.RightTurn.class) {
|
| 117 | strongholdPiece = StrongholdPieces.RightTurn.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 118 | } else if (pieceClass == StrongholdPieces.RoomCrossing.class) {
|
| 119 | strongholdPiece = StrongholdPieces.RoomCrossing.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 120 | } else if (pieceClass == StrongholdPieces.StraightStairsDown.class) {
|
| 121 | strongholdPiece = StrongholdPieces.StraightStairsDown.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 122 | } else if (pieceClass == StrongholdPieces.StairsDown.class) {
|
| 123 | strongholdPiece = StrongholdPieces.StairsDown.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 124 | } else if (pieceClass == StrongholdPieces.FiveCrossing.class) {
|
| 125 | strongholdPiece = StrongholdPieces.FiveCrossing.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 126 | } else if (pieceClass == StrongholdPieces.ChestCorridor.class) {
|
| 127 | strongholdPiece = StrongholdPieces.ChestCorridor.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 128 | } else if (pieceClass == StrongholdPieces.Library.class) {
|
| 129 | strongholdPiece = StrongholdPieces.Library.createPiece(builder, random, footX, footY, footZ, direction, depth);
|
| 130 | } else if (pieceClass == StrongholdPieces.PortalRoom.class) {
|
| 131 | strongholdPiece = StrongholdPieces.PortalRoom.createPiece(builder, footX, footY, footZ, direction, depth);
|
| 132 | }
|
| 133 |
|
| 134 | return strongholdPiece;
|
| 135 | }
|
| 136 |
|
| 137 | private static StrongholdPieces.@Nullable StrongholdPiece generatePieceFromSmallDoor(
|
| 138 | final StrongholdPieces.StartPiece startPiece,
|
| 139 | final StructurePiecesBuilder builder,
|
| 140 | final RandomSource random,
|
| 141 | final int footX,
|
| 142 | final int footY,
|
| 143 | final int footZ,
|
| 144 | final Direction direction,
|
| 145 | final int depth
|
| 146 | ) {
|
| 147 | if (!updatePieceWeight()) {
|
| 148 | return null;
|
| 149 | }
|
| 150 |
|
| 151 | if (imposedPiece != null) {
|
| 152 | StrongholdPieces.StrongholdPiece strongholdPiece = findAndCreatePieceFactory(imposedPiece, builder, random, footX, footY, footZ, direction, depth);
|
| 153 | imposedPiece = null;
|
| 154 | if (strongholdPiece != null) {
|
| 155 | return strongholdPiece;
|
| 156 | }
|
| 157 | }
|
| 158 |
|
| 159 | int numAttempts = 0;
|
| 160 |
|
| 161 | while (numAttempts < 5) {
|
| 162 | numAttempts++;
|
| 163 | int weightSelection = random.nextInt(totalWeight);
|
| 164 |
|
| 165 | for (StrongholdPieces.PieceWeight piece : currentPieces) {
|
| 166 | weightSelection -= piece.weight;
|
| 167 | if (weightSelection < 0) {
|
| 168 | if (!piece.doPlace(depth) || piece == startPiece.previousPiece) {
|
| 169 | break;
|
| 170 | }
|
| 171 |
|
| 172 | StrongholdPieces.StrongholdPiece strongholdPiece = findAndCreatePieceFactory(piece.pieceClass, builder, random, footX, footY, footZ, direction, depth);
|
| 173 | if (strongholdPiece != null) {
|
| 174 | piece.placeCount++;
|
| 175 | startPiece.previousPiece = piece;
|
| 176 | if (!piece.isValid()) {
|
| 177 | currentPieces.remove(piece);
|
| 178 | }
|
| 179 |
|
| 180 | return strongholdPiece;
|
| 181 | }
|
| 182 | }
|
| 183 | }
|
| 184 | }
|
| 185 |
|
| 186 | BoundingBox box = StrongholdPieces.FillerCorridor.findPieceBox(builder, random, footX, footY, footZ, direction);
|
| 187 | return box != null && box.minY() > 1 ? new StrongholdPieces.FillerCorridor(depth, box, direction) : null;
|
| 188 | }
|
| 189 |
|
| 190 | private static @Nullable StructurePiece generateAndAddPiece(
|
| 191 | final StrongholdPieces.StartPiece startPiece,
|
| 192 | final StructurePiecesBuilder builder,
|
| 193 | final RandomSource random,
|
| 194 | final int footX,
|
| 195 | final int footY,
|
| 196 | final int footZ,
|
| 197 | final Direction direction,
|
| 198 | final int depth
|
| 199 | ) {
|
| 200 | if (depth > 50) {
|
| 201 | return null;
|
| 202 | }
|
| 203 |
|
| 204 | if (Math.abs(footX - startPiece.getBoundingBox().minX()) <= 112 && Math.abs(footZ - startPiece.getBoundingBox().minZ()) <= 112) {
|
| 205 | StructurePiece newPiece = generatePieceFromSmallDoor(startPiece, builder, random, footX, footY, footZ, direction, depth + 1);
|
| 206 | if (newPiece != null) {
|
| 207 | builder.addPiece(newPiece);
|
| 208 | startPiece.pendingChildren.add(newPiece);
|
| 209 | }
|
| 210 |
|
| 211 | return newPiece;
|
| 212 | } else {
|
| 213 | return null;
|
| 214 | }
|
| 215 | }
|
| 216 |
|
| 217 | public static class ChestCorridor extends StrongholdPieces.StrongholdPiece {
|
| 218 | private static final int WIDTH = 5;
|
| 219 | private static final int HEIGHT = 5;
|
| 220 | private static final int DEPTH = 7;
|
| 221 | private boolean hasPlacedChest;
|
| 222 |
|
| 223 | public ChestCorridor(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 224 | super(StructurePieceType.STRONGHOLD_CHEST_CORRIDOR, genDepth, boundingBox);
|
| 225 | this.setOrientation(direction);
|
| 226 | this.entryDoor = this.randomSmallDoor(random);
|
| 227 | }
|
| 228 |
|
| 229 | public ChestCorridor(final CompoundTag tag) {
|
| 230 | super(StructurePieceType.STRONGHOLD_CHEST_CORRIDOR, tag);
|
| 231 | this.hasPlacedChest = tag.getBooleanOr("Chest", false);
|
| 232 | }
|
| 233 |
|
| 234 | @Override
|
| 235 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 236 | super.addAdditionalSaveData(context, tag);
|
| 237 | tag.putBoolean("Chest", this.hasPlacedChest);
|
| 238 | }
|
| 239 |
|
| 240 | @Override
|
| 241 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 242 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 243 | }
|
| 244 |
|
| 245 | public static StrongholdPieces.@Nullable ChestCorridor createPiece(
|
| 246 | final StructurePiecesBuilder builder,
|
| 247 | final RandomSource random,
|
| 248 | final int footX,
|
| 249 | final int footY,
|
| 250 | final int footZ,
|
| 251 | final Direction direction,
|
| 252 | final int genDepth
|
| 253 | ) {
|
| 254 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, 7, direction);
|
| 255 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.ChestCorridor(genDepth, random, box, direction) : null;
|
| 256 | }
|
| 257 |
|
| 258 | @Override
|
| 259 | public void postProcess(
|
| 260 | final WorldGenLevel level,
|
| 261 | final StructureManager structureManager,
|
| 262 | final ChunkGenerator generator,
|
| 263 | final RandomSource random,
|
| 264 | final BoundingBox chunkBB,
|
| 265 | final ChunkPos chunkPos,
|
| 266 | final BlockPos referencePos
|
| 267 | ) {
|
| 268 | this.generateBox(level, chunkBB, 0, 0, 0, 4, 4, 6, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 269 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 1, 0);
|
| 270 | this.generateSmallDoor(level, random, chunkBB, StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING, 1, 1, 6);
|
| 271 | this.generateBox(level, chunkBB, 3, 1, 2, 3, 1, 4, Blocks.STONE_BRICKS.defaultBlockState(), Blocks.STONE_BRICKS.defaultBlockState(), false);
|
| 272 | this.placeBlock(level, Blocks.STONE_BRICK_SLAB.defaultBlockState(), 3, 1, 1, chunkBB);
|
| 273 | this.placeBlock(level, Blocks.STONE_BRICK_SLAB.defaultBlockState(), 3, 1, 5, chunkBB);
|
| 274 | this.placeBlock(level, Blocks.STONE_BRICK_SLAB.defaultBlockState(), 3, 2, 2, chunkBB);
|
| 275 | this.placeBlock(level, Blocks.STONE_BRICK_SLAB.defaultBlockState(), 3, 2, 4, chunkBB);
|
| 276 |
|
| 277 | for (int z = 2; z <= 4; z++) {
|
| 278 | this.placeBlock(level, Blocks.STONE_BRICK_SLAB.defaultBlockState(), 2, 1, z, chunkBB);
|
| 279 | }
|
| 280 |
|
| 281 | if (!this.hasPlacedChest && chunkBB.isInside(this.getWorldPos(3, 2, 3))) {
|
| 282 | this.hasPlacedChest = true;
|
| 283 | this.createChest(level, chunkBB, random, 3, 2, 3, BuiltInLootTables.STRONGHOLD_CORRIDOR);
|
| 284 | }
|
| 285 | }
|
| 286 | }
|
| 287 |
|
| 288 | public static class FillerCorridor extends StrongholdPieces.StrongholdPiece {
|
| 289 | private final int steps;
|
| 290 |
|
| 291 | public FillerCorridor(final int genDepth, final BoundingBox boundingBox, final Direction direction) {
|
| 292 | super(StructurePieceType.STRONGHOLD_FILLER_CORRIDOR, genDepth, boundingBox);
|
| 293 | this.setOrientation(direction);
|
| 294 | this.steps = direction != Direction.NORTH && direction != Direction.SOUTH ? boundingBox.getXSpan() : boundingBox.getZSpan();
|
| 295 | }
|
| 296 |
|
| 297 | public FillerCorridor(final CompoundTag tag) {
|
| 298 | super(StructurePieceType.STRONGHOLD_FILLER_CORRIDOR, tag);
|
| 299 | this.steps = tag.getIntOr("Steps", 0);
|
| 300 | }
|
| 301 |
|
| 302 | @Override
|
| 303 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 304 | super.addAdditionalSaveData(context, tag);
|
| 305 | tag.putInt("Steps", this.steps);
|
| 306 | }
|
| 307 |
|
| 308 | public static @Nullable BoundingBox findPieceBox(
|
| 309 | final StructurePiecesBuilder builder, final RandomSource random, final int footX, final int footY, final int footZ, final Direction direction
|
| 310 | ) {
|
| 311 | int maxLength = 3;
|
| 312 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, 4, direction);
|
| 313 | StructurePiece collisionPiece = builder.findCollisionPiece(box);
|
| 314 | if (collisionPiece == null) {
|
| 315 | return null;
|
| 316 | }
|
| 317 |
|
| 318 | if (collisionPiece.getBoundingBox().minY() == box.minY()) {
|
| 319 | for (int depth = 2; depth >= 1; depth--) {
|
| 320 | box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, depth, direction);
|
| 321 | if (!collisionPiece.getBoundingBox().intersects(box)) {
|
| 322 | return BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, depth + 1, direction);
|
| 323 | }
|
| 324 | }
|
| 325 | }
|
| 326 |
|
| 327 | return null;
|
| 328 | }
|
| 329 |
|
| 330 | @Override
|
| 331 | public void postProcess(
|
| 332 | final WorldGenLevel level,
|
| 333 | final StructureManager structureManager,
|
| 334 | final ChunkGenerator generator,
|
| 335 | final RandomSource random,
|
| 336 | final BoundingBox chunkBB,
|
| 337 | final ChunkPos chunkPos,
|
| 338 | final BlockPos referencePos
|
| 339 | ) {
|
| 340 | for (int i = 0; i < this.steps; i++) {
|
| 341 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 0, 0, i, chunkBB);
|
| 342 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 0, i, chunkBB);
|
| 343 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 2, 0, i, chunkBB);
|
| 344 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 0, i, chunkBB);
|
| 345 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 4, 0, i, chunkBB);
|
| 346 |
|
| 347 | for (int y = 1; y <= 3; y++) {
|
| 348 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 0, y, i, chunkBB);
|
| 349 | this.placeBlock(level, Blocks.CAVE_AIR.defaultBlockState(), 1, y, i, chunkBB);
|
| 350 | this.placeBlock(level, Blocks.CAVE_AIR.defaultBlockState(), 2, y, i, chunkBB);
|
| 351 | this.placeBlock(level, Blocks.CAVE_AIR.defaultBlockState(), 3, y, i, chunkBB);
|
| 352 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 4, y, i, chunkBB);
|
| 353 | }
|
| 354 |
|
| 355 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 0, 4, i, chunkBB);
|
| 356 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 4, i, chunkBB);
|
| 357 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 2, 4, i, chunkBB);
|
| 358 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 4, i, chunkBB);
|
| 359 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 4, 4, i, chunkBB);
|
| 360 | }
|
| 361 | }
|
| 362 | }
|
| 363 |
|
| 364 | public static class FiveCrossing extends StrongholdPieces.StrongholdPiece {
|
| 365 | protected static final int WIDTH = 10;
|
| 366 | protected static final int HEIGHT = 9;
|
| 367 | protected static final int DEPTH = 11;
|
| 368 | private final boolean leftLow;
|
| 369 | private final boolean leftHigh;
|
| 370 | private final boolean rightLow;
|
| 371 | private final boolean rightHigh;
|
| 372 |
|
| 373 | public FiveCrossing(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 374 | super(StructurePieceType.STRONGHOLD_FIVE_CROSSING, genDepth, boundingBox);
|
| 375 | this.setOrientation(direction);
|
| 376 | this.entryDoor = this.randomSmallDoor(random);
|
| 377 | this.leftLow = random.nextBoolean();
|
| 378 | this.leftHigh = random.nextBoolean();
|
| 379 | this.rightLow = random.nextBoolean();
|
| 380 | this.rightHigh = random.nextInt(3) > 0;
|
| 381 | }
|
| 382 |
|
| 383 | public FiveCrossing(final CompoundTag tag) {
|
| 384 | super(StructurePieceType.STRONGHOLD_FIVE_CROSSING, tag);
|
| 385 | this.leftLow = tag.getBooleanOr("leftLow", false);
|
| 386 | this.leftHigh = tag.getBooleanOr("leftHigh", false);
|
| 387 | this.rightLow = tag.getBooleanOr("rightLow", false);
|
| 388 | this.rightHigh = tag.getBooleanOr("rightHigh", false);
|
| 389 | }
|
| 390 |
|
| 391 | @Override
|
| 392 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 393 | super.addAdditionalSaveData(context, tag);
|
| 394 | tag.putBoolean("leftLow", this.leftLow);
|
| 395 | tag.putBoolean("leftHigh", this.leftHigh);
|
| 396 | tag.putBoolean("rightLow", this.rightLow);
|
| 397 | tag.putBoolean("rightHigh", this.rightHigh);
|
| 398 | }
|
| 399 |
|
| 400 | @Override
|
| 401 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 402 | int zOffA = 3;
|
| 403 | int zOffB = 5;
|
| 404 | Direction orientation = this.getOrientation();
|
| 405 | if (orientation == Direction.WEST || orientation == Direction.NORTH) {
|
| 406 | zOffA = 8 - zOffA;
|
| 407 | zOffB = 8 - zOffB;
|
| 408 | }
|
| 409 |
|
| 410 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 5, 1);
|
| 411 | if (this.leftLow) {
|
| 412 | this.generateSmallDoorChildLeft((StrongholdPieces.StartPiece)startPiece, builder, random, zOffA, 1);
|
| 413 | }
|
| 414 |
|
| 415 | if (this.leftHigh) {
|
| 416 | this.generateSmallDoorChildLeft((StrongholdPieces.StartPiece)startPiece, builder, random, zOffB, 7);
|
| 417 | }
|
| 418 |
|
| 419 | if (this.rightLow) {
|
| 420 | this.generateSmallDoorChildRight((StrongholdPieces.StartPiece)startPiece, builder, random, zOffA, 1);
|
| 421 | }
|
| 422 |
|
| 423 | if (this.rightHigh) {
|
| 424 | this.generateSmallDoorChildRight((StrongholdPieces.StartPiece)startPiece, builder, random, zOffB, 7);
|
| 425 | }
|
| 426 | }
|
| 427 |
|
| 428 | public static StrongholdPieces.@Nullable FiveCrossing createPiece(
|
| 429 | final StructurePiecesBuilder builder,
|
| 430 | final RandomSource random,
|
| 431 | final int footX,
|
| 432 | final int footY,
|
| 433 | final int footZ,
|
| 434 | final Direction direction,
|
| 435 | final int genDepth
|
| 436 | ) {
|
| 437 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -4, -3, 0, 10, 9, 11, direction);
|
| 438 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.FiveCrossing(genDepth, random, box, direction) : null;
|
| 439 | }
|
| 440 |
|
| 441 | @Override
|
| 442 | public void postProcess(
|
| 443 | final WorldGenLevel level,
|
| 444 | final StructureManager structureManager,
|
| 445 | final ChunkGenerator generator,
|
| 446 | final RandomSource random,
|
| 447 | final BoundingBox chunkBB,
|
| 448 | final ChunkPos chunkPos,
|
| 449 | final BlockPos referencePos
|
| 450 | ) {
|
| 451 | this.generateBox(level, chunkBB, 0, 0, 0, 9, 8, 10, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 452 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 4, 3, 0);
|
| 453 | if (this.leftLow) {
|
| 454 | this.generateBox(level, chunkBB, 0, 3, 1, 0, 5, 3, CAVE_AIR, CAVE_AIR, false);
|
| 455 | }
|
| 456 |
|
| 457 | if (this.rightLow) {
|
| 458 | this.generateBox(level, chunkBB, 9, 3, 1, 9, 5, 3, CAVE_AIR, CAVE_AIR, false);
|
| 459 | }
|
| 460 |
|
| 461 | if (this.leftHigh) {
|
| 462 | this.generateBox(level, chunkBB, 0, 5, 7, 0, 7, 9, CAVE_AIR, CAVE_AIR, false);
|
| 463 | }
|
| 464 |
|
| 465 | if (this.rightHigh) {
|
| 466 | this.generateBox(level, chunkBB, 9, 5, 7, 9, 7, 9, CAVE_AIR, CAVE_AIR, false);
|
| 467 | }
|
| 468 |
|
| 469 | this.generateBox(level, chunkBB, 5, 1, 10, 7, 3, 10, CAVE_AIR, CAVE_AIR, false);
|
| 470 | this.generateBox(level, chunkBB, 1, 2, 1, 8, 2, 6, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 471 | this.generateBox(level, chunkBB, 4, 1, 5, 4, 4, 9, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 472 | this.generateBox(level, chunkBB, 8, 1, 5, 8, 4, 9, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 473 | this.generateBox(level, chunkBB, 1, 4, 7, 3, 4, 9, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 474 | this.generateBox(level, chunkBB, 1, 3, 5, 3, 3, 6, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 475 | this.generateBox(level, chunkBB, 1, 3, 4, 3, 3, 4, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), false);
|
| 476 | this.generateBox(level, chunkBB, 1, 4, 6, 3, 4, 6, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), false);
|
| 477 | this.generateBox(level, chunkBB, 5, 1, 7, 7, 1, 8, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 478 | this.generateBox(level, chunkBB, 5, 1, 9, 7, 1, 9, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), false);
|
| 479 | this.generateBox(level, chunkBB, 5, 2, 7, 7, 2, 7, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), false);
|
| 480 | this.generateBox(level, chunkBB, 4, 5, 7, 4, 5, 9, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), false);
|
| 481 | this.generateBox(level, chunkBB, 8, 5, 7, 8, 5, 9, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), false);
|
| 482 | this.generateBox(
|
| 483 | level,
|
| 484 | chunkBB,
|
| 485 | 5,
|
| 486 | 5,
|
| 487 | 7,
|
| 488 | 7,
|
| 489 | 5,
|
| 490 | 9,
|
| 491 | Blocks.SMOOTH_STONE_SLAB.defaultBlockState().setValue(SlabBlock.TYPE, SlabType.DOUBLE),
|
| 492 | Blocks.SMOOTH_STONE_SLAB.defaultBlockState().setValue(SlabBlock.TYPE, SlabType.DOUBLE),
|
| 493 | false
|
| 494 | );
|
| 495 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.SOUTH), 6, 5, 6, chunkBB);
|
| 496 | }
|
| 497 | }
|
| 498 |
|
| 499 | public static class LeftTurn extends StrongholdPieces.Turn {
|
| 500 | public LeftTurn(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 501 | super(StructurePieceType.STRONGHOLD_LEFT_TURN, genDepth, boundingBox);
|
| 502 | this.setOrientation(direction);
|
| 503 | this.entryDoor = this.randomSmallDoor(random);
|
| 504 | }
|
| 505 |
|
| 506 | public LeftTurn(final CompoundTag tag) {
|
| 507 | super(StructurePieceType.STRONGHOLD_LEFT_TURN, tag);
|
| 508 | }
|
| 509 |
|
| 510 | @Override
|
| 511 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 512 | Direction orientation = this.getOrientation();
|
| 513 | if (orientation != Direction.NORTH && orientation != Direction.EAST) {
|
| 514 | this.generateSmallDoorChildRight((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 515 | } else {
|
| 516 | this.generateSmallDoorChildLeft((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 517 | }
|
| 518 | }
|
| 519 |
|
| 520 | public static StrongholdPieces.@Nullable LeftTurn createPiece(
|
| 521 | final StructurePiecesBuilder builder,
|
| 522 | final RandomSource random,
|
| 523 | final int footX,
|
| 524 | final int footY,
|
| 525 | final int footZ,
|
| 526 | final Direction direction,
|
| 527 | final int genDepth
|
| 528 | ) {
|
| 529 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, 5, direction);
|
| 530 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.LeftTurn(genDepth, random, box, direction) : null;
|
| 531 | }
|
| 532 |
|
| 533 | @Override
|
| 534 | public void postProcess(
|
| 535 | final WorldGenLevel level,
|
| 536 | final StructureManager structureManager,
|
| 537 | final ChunkGenerator generator,
|
| 538 | final RandomSource random,
|
| 539 | final BoundingBox chunkBB,
|
| 540 | final ChunkPos chunkPos,
|
| 541 | final BlockPos referencePos
|
| 542 | ) {
|
| 543 | this.generateBox(level, chunkBB, 0, 0, 0, 4, 4, 4, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 544 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 1, 0);
|
| 545 | Direction orientation = this.getOrientation();
|
| 546 | if (orientation != Direction.NORTH && orientation != Direction.EAST) {
|
| 547 | this.generateBox(level, chunkBB, 4, 1, 1, 4, 3, 3, CAVE_AIR, CAVE_AIR, false);
|
| 548 | } else {
|
| 549 | this.generateBox(level, chunkBB, 0, 1, 1, 0, 3, 3, CAVE_AIR, CAVE_AIR, false);
|
| 550 | }
|
| 551 | }
|
| 552 | }
|
| 553 |
|
| 554 | public static class Library extends StrongholdPieces.StrongholdPiece {
|
| 555 | protected static final int WIDTH = 14;
|
| 556 | protected static final int HEIGHT = 6;
|
| 557 | protected static final int TALL_HEIGHT = 11;
|
| 558 | protected static final int DEPTH = 15;
|
| 559 | private final boolean isTall;
|
| 560 |
|
| 561 | public Library(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 562 | super(StructurePieceType.STRONGHOLD_LIBRARY, genDepth, boundingBox);
|
| 563 | this.setOrientation(direction);
|
| 564 | this.entryDoor = this.randomSmallDoor(random);
|
| 565 | this.isTall = boundingBox.getYSpan() > 6;
|
| 566 | }
|
| 567 |
|
| 568 | public Library(final CompoundTag tag) {
|
| 569 | super(StructurePieceType.STRONGHOLD_LIBRARY, tag);
|
| 570 | this.isTall = tag.getBooleanOr("Tall", false);
|
| 571 | }
|
| 572 |
|
| 573 | @Override
|
| 574 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 575 | super.addAdditionalSaveData(context, tag);
|
| 576 | tag.putBoolean("Tall", this.isTall);
|
| 577 | }
|
| 578 |
|
| 579 | public static StrongholdPieces.@Nullable Library createPiece(
|
| 580 | final StructurePiecesBuilder builder,
|
| 581 | final RandomSource random,
|
| 582 | final int footX,
|
| 583 | final int footY,
|
| 584 | final int footZ,
|
| 585 | final Direction direction,
|
| 586 | final int genDepth
|
| 587 | ) {
|
| 588 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -4, -1, 0, 14, 11, 15, direction);
|
| 589 | if (!isOkBox(box) || builder.findCollisionPiece(box) != null) {
|
| 590 | box = BoundingBox.orientBox(footX, footY, footZ, -4, -1, 0, 14, 6, 15, direction);
|
| 591 | if (!isOkBox(box) || builder.findCollisionPiece(box) != null) {
|
| 592 | return null;
|
| 593 | }
|
| 594 | }
|
| 595 |
|
| 596 | return new StrongholdPieces.Library(genDepth, random, box, direction);
|
| 597 | }
|
| 598 |
|
| 599 | @Override
|
| 600 | public void postProcess(
|
| 601 | final WorldGenLevel level,
|
| 602 | final StructureManager structureManager,
|
| 603 | final ChunkGenerator generator,
|
| 604 | final RandomSource random,
|
| 605 | final BoundingBox chunkBB,
|
| 606 | final ChunkPos chunkPos,
|
| 607 | final BlockPos referencePos
|
| 608 | ) {
|
| 609 | int currentHeight = 11;
|
| 610 | if (!this.isTall) {
|
| 611 | currentHeight = 6;
|
| 612 | }
|
| 613 |
|
| 614 | this.generateBox(level, chunkBB, 0, 0, 0, 13, currentHeight - 1, 14, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 615 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 4, 1, 0);
|
| 616 | this.generateMaybeBox(level, chunkBB, random, 0.07F, 2, 1, 1, 11, 4, 13, Blocks.COBWEB.defaultBlockState(), Blocks.COBWEB.defaultBlockState(), false, false);
|
| 617 | int bookLeft = 1;
|
| 618 | int bookRight = 12;
|
| 619 |
|
| 620 | for (int d = 1; d <= 13; d++) {
|
| 621 | if ((d - 1) % 4 == 0) {
|
| 622 | this.generateBox(level, chunkBB, 1, 1, d, 1, 4, d, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 623 | this.generateBox(level, chunkBB, 12, 1, d, 12, 4, d, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 624 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.EAST), 2, 3, d, chunkBB);
|
| 625 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.WEST), 11, 3, d, chunkBB);
|
| 626 | if (this.isTall) {
|
| 627 | this.generateBox(level, chunkBB, 1, 6, d, 1, 9, d, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 628 | this.generateBox(level, chunkBB, 12, 6, d, 12, 9, d, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 629 | }
|
| 630 | } else {
|
| 631 | this.generateBox(level, chunkBB, 1, 1, d, 1, 4, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 632 | this.generateBox(level, chunkBB, 12, 1, d, 12, 4, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 633 | if (this.isTall) {
|
| 634 | this.generateBox(level, chunkBB, 1, 6, d, 1, 9, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 635 | this.generateBox(level, chunkBB, 12, 6, d, 12, 9, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 636 | }
|
| 637 | }
|
| 638 | }
|
| 639 |
|
| 640 | for (int d = 3; d < 12; d += 2) {
|
| 641 | this.generateBox(level, chunkBB, 3, 1, d, 4, 3, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 642 | this.generateBox(level, chunkBB, 6, 1, d, 7, 3, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 643 | this.generateBox(level, chunkBB, 9, 1, d, 10, 3, d, Blocks.BOOKSHELF.defaultBlockState(), Blocks.BOOKSHELF.defaultBlockState(), false);
|
| 644 | }
|
| 645 |
|
| 646 | if (this.isTall) {
|
| 647 | this.generateBox(level, chunkBB, 1, 5, 1, 3, 5, 13, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 648 | this.generateBox(level, chunkBB, 10, 5, 1, 12, 5, 13, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 649 | this.generateBox(level, chunkBB, 4, 5, 1, 9, 5, 2, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 650 | this.generateBox(level, chunkBB, 4, 5, 12, 9, 5, 13, Blocks.OAK_PLANKS.defaultBlockState(), Blocks.OAK_PLANKS.defaultBlockState(), false);
|
| 651 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 9, 5, 11, chunkBB);
|
| 652 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 8, 5, 11, chunkBB);
|
| 653 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 9, 5, 10, chunkBB);
|
| 654 | BlockState weFence = Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.WEST, true).setValue(FenceBlock.EAST, true);
|
| 655 | BlockState nsFence = Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.NORTH, true).setValue(FenceBlock.SOUTH, true);
|
| 656 | this.generateBox(level, chunkBB, 3, 6, 3, 3, 6, 11, nsFence, nsFence, false);
|
| 657 | this.generateBox(level, chunkBB, 10, 6, 3, 10, 6, 9, nsFence, nsFence, false);
|
| 658 | this.generateBox(level, chunkBB, 4, 6, 2, 9, 6, 2, weFence, weFence, false);
|
| 659 | this.generateBox(level, chunkBB, 4, 6, 12, 7, 6, 12, weFence, weFence, false);
|
| 660 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.NORTH, true).setValue(FenceBlock.EAST, true), 3, 6, 2, chunkBB);
|
| 661 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.SOUTH, true).setValue(FenceBlock.EAST, true), 3, 6, 12, chunkBB);
|
| 662 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.NORTH, true).setValue(FenceBlock.WEST, true), 10, 6, 2, chunkBB);
|
| 663 |
|
| 664 | for (int i = 0; i <= 2; i++) {
|
| 665 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.SOUTH, true).setValue(FenceBlock.WEST, true), 8 + i, 6, 12 - i, chunkBB);
|
| 666 | if (i != 2) {
|
| 667 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.NORTH, true).setValue(FenceBlock.EAST, true), 8 + i, 6, 11 - i, chunkBB);
|
| 668 | }
|
| 669 | }
|
| 670 |
|
| 671 | BlockState ladder = Blocks.LADDER.defaultBlockState().setValue(LadderBlock.FACING, Direction.SOUTH);
|
| 672 | this.placeBlock(level, ladder, 10, 1, 13, chunkBB);
|
| 673 | this.placeBlock(level, ladder, 10, 2, 13, chunkBB);
|
| 674 | this.placeBlock(level, ladder, 10, 3, 13, chunkBB);
|
| 675 | this.placeBlock(level, ladder, 10, 4, 13, chunkBB);
|
| 676 | this.placeBlock(level, ladder, 10, 5, 13, chunkBB);
|
| 677 | this.placeBlock(level, ladder, 10, 6, 13, chunkBB);
|
| 678 | this.placeBlock(level, ladder, 10, 7, 13, chunkBB);
|
| 679 | int x = 7;
|
| 680 | int z = 7;
|
| 681 | BlockState eFence = Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.EAST, true);
|
| 682 | this.placeBlock(level, eFence, 6, 9, 7, chunkBB);
|
| 683 | BlockState wFence = Blocks.OAK_FENCE.defaultBlockState().setValue(FenceBlock.WEST, true);
|
| 684 | this.placeBlock(level, wFence, 7, 9, 7, chunkBB);
|
| 685 | this.placeBlock(level, eFence, 6, 8, 7, chunkBB);
|
| 686 | this.placeBlock(level, wFence, 7, 8, 7, chunkBB);
|
| 687 | BlockState nsweFence = nsFence.setValue(FenceBlock.WEST, true).setValue(FenceBlock.EAST, true);
|
| 688 | this.placeBlock(level, nsweFence, 6, 7, 7, chunkBB);
|
| 689 | this.placeBlock(level, nsweFence, 7, 7, 7, chunkBB);
|
| 690 | this.placeBlock(level, eFence, 5, 7, 7, chunkBB);
|
| 691 | this.placeBlock(level, wFence, 8, 7, 7, chunkBB);
|
| 692 | this.placeBlock(level, eFence.setValue(FenceBlock.NORTH, true), 6, 7, 6, chunkBB);
|
| 693 | this.placeBlock(level, eFence.setValue(FenceBlock.SOUTH, true), 6, 7, 8, chunkBB);
|
| 694 | this.placeBlock(level, wFence.setValue(FenceBlock.NORTH, true), 7, 7, 6, chunkBB);
|
| 695 | this.placeBlock(level, wFence.setValue(FenceBlock.SOUTH, true), 7, 7, 8, chunkBB);
|
| 696 | BlockState torch = Blocks.TORCH.defaultBlockState();
|
| 697 | this.placeBlock(level, torch, 5, 8, 7, chunkBB);
|
| 698 | this.placeBlock(level, torch, 8, 8, 7, chunkBB);
|
| 699 | this.placeBlock(level, torch, 6, 8, 6, chunkBB);
|
| 700 | this.placeBlock(level, torch, 6, 8, 8, chunkBB);
|
| 701 | this.placeBlock(level, torch, 7, 8, 6, chunkBB);
|
| 702 | this.placeBlock(level, torch, 7, 8, 8, chunkBB);
|
| 703 | }
|
| 704 |
|
| 705 | this.createChest(level, chunkBB, random, 3, 3, 5, BuiltInLootTables.STRONGHOLD_LIBRARY);
|
| 706 | if (this.isTall) {
|
| 707 | this.placeBlock(level, CAVE_AIR, 12, 9, 1, chunkBB);
|
| 708 | this.createChest(level, chunkBB, random, 12, 8, 1, BuiltInLootTables.STRONGHOLD_LIBRARY);
|
| 709 | }
|
| 710 | }
|
| 711 | }
|
| 712 |
|
| 713 | private static class PieceWeight {
|
| 714 | public final Class<? extends StrongholdPieces.StrongholdPiece> pieceClass;
|
| 715 | public final int weight;
|
| 716 | public int placeCount;
|
| 717 | public final int maxPlaceCount;
|
| 718 |
|
| 719 | public PieceWeight(final Class<? extends StrongholdPieces.StrongholdPiece> pieceClass, final int weight, final int maxPlaceCount) {
|
| 720 | this.pieceClass = pieceClass;
|
| 721 | this.weight = weight;
|
| 722 | this.maxPlaceCount = maxPlaceCount;
|
| 723 | }
|
| 724 |
|
| 725 | public boolean doPlace(final int depth) {
|
| 726 | return this.maxPlaceCount == 0 || this.placeCount < this.maxPlaceCount;
|
| 727 | }
|
| 728 |
|
| 729 | public boolean isValid() {
|
| 730 | return this.maxPlaceCount == 0 || this.placeCount < this.maxPlaceCount;
|
| 731 | }
|
| 732 | }
|
| 733 |
|
| 734 | public static class PortalRoom extends StrongholdPieces.StrongholdPiece {
|
| 735 | protected static final int WIDTH = 11;
|
| 736 | protected static final int HEIGHT = 8;
|
| 737 | protected static final int DEPTH = 16;
|
| 738 | private boolean hasPlacedSpawner;
|
| 739 |
|
| 740 | public PortalRoom(final int genDepth, final BoundingBox boundingBox, final Direction direction) {
|
| 741 | super(StructurePieceType.STRONGHOLD_PORTAL_ROOM, genDepth, boundingBox);
|
| 742 | this.setOrientation(direction);
|
| 743 | }
|
| 744 |
|
| 745 | public PortalRoom(final CompoundTag tag) {
|
| 746 | super(StructurePieceType.STRONGHOLD_PORTAL_ROOM, tag);
|
| 747 | this.hasPlacedSpawner = tag.getBooleanOr("Mob", false);
|
| 748 | }
|
| 749 |
|
| 750 | @Override
|
| 751 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 752 | super.addAdditionalSaveData(context, tag);
|
| 753 | tag.putBoolean("Mob", this.hasPlacedSpawner);
|
| 754 | }
|
| 755 |
|
| 756 | @Override
|
| 757 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 758 | if (startPiece != null) {
|
| 759 | ((StrongholdPieces.StartPiece)startPiece).portalRoomPiece = this;
|
| 760 | }
|
| 761 | }
|
| 762 |
|
| 763 | public static StrongholdPieces.@Nullable PortalRoom createPiece(
|
| 764 | final StructurePiecesBuilder builder, final int footX, final int footY, final int footZ, final Direction direction, final int genDepth
|
| 765 | ) {
|
| 766 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -4, -1, 0, 11, 8, 16, direction);
|
| 767 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.PortalRoom(genDepth, box, direction) : null;
|
| 768 | }
|
| 769 |
|
| 770 | @Override
|
| 771 | public void postProcess(
|
| 772 | final WorldGenLevel level,
|
| 773 | final StructureManager structureManager,
|
| 774 | final ChunkGenerator generator,
|
| 775 | final RandomSource random,
|
| 776 | final BoundingBox chunkBB,
|
| 777 | final ChunkPos chunkPos,
|
| 778 | final BlockPos referencePos
|
| 779 | ) {
|
| 780 | this.generateBox(level, chunkBB, 0, 0, 0, 10, 7, 15, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 781 | this.generateSmallDoor(level, random, chunkBB, StrongholdPieces.StrongholdPiece.SmallDoorType.GRATES, 4, 1, 0);
|
| 782 | int y = 6;
|
| 783 | this.generateBox(level, chunkBB, 1, 6, 1, 1, 6, 14, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 784 | this.generateBox(level, chunkBB, 9, 6, 1, 9, 6, 14, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 785 | this.generateBox(level, chunkBB, 2, 6, 1, 8, 6, 2, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 786 | this.generateBox(level, chunkBB, 2, 6, 14, 8, 6, 14, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 787 | this.generateBox(level, chunkBB, 1, 1, 1, 2, 1, 4, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 788 | this.generateBox(level, chunkBB, 8, 1, 1, 9, 1, 4, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 789 | this.generateBox(level, chunkBB, 1, 1, 1, 1, 1, 3, Blocks.LAVA.defaultBlockState(), Blocks.LAVA.defaultBlockState(), false);
|
| 790 | this.generateBox(level, chunkBB, 9, 1, 1, 9, 1, 3, Blocks.LAVA.defaultBlockState(), Blocks.LAVA.defaultBlockState(), false);
|
| 791 | this.generateBox(level, chunkBB, 3, 1, 8, 7, 1, 12, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 792 | this.generateBox(level, chunkBB, 4, 1, 9, 6, 1, 11, Blocks.LAVA.defaultBlockState(), Blocks.LAVA.defaultBlockState(), false);
|
| 793 | BlockState nsBars = Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, true).setValue(IronBarsBlock.SOUTH, true);
|
| 794 | BlockState weBars = Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.WEST, true).setValue(IronBarsBlock.EAST, true);
|
| 795 |
|
| 796 | for (int z = 3; z < 14; z += 2) {
|
| 797 | this.generateBox(level, chunkBB, 0, 3, z, 0, 4, z, nsBars, nsBars, false);
|
| 798 | this.generateBox(level, chunkBB, 10, 3, z, 10, 4, z, nsBars, nsBars, false);
|
| 799 | }
|
| 800 |
|
| 801 | for (int x = 2; x < 9; x += 2) {
|
| 802 | this.generateBox(level, chunkBB, x, 3, 15, x, 4, 15, weBars, weBars, false);
|
| 803 | }
|
| 804 |
|
| 805 | BlockState blockState = Blocks.STONE_BRICK_STAIRS.defaultBlockState().setValue(StairBlock.FACING, Direction.NORTH);
|
| 806 | this.generateBox(level, chunkBB, 4, 1, 5, 6, 1, 7, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 807 | this.generateBox(level, chunkBB, 4, 2, 6, 6, 2, 7, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 808 | this.generateBox(level, chunkBB, 4, 3, 7, 6, 3, 7, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 809 |
|
| 810 | for (int x = 4; x <= 6; x++) {
|
| 811 | this.placeBlock(level, blockState, x, 1, 4, chunkBB);
|
| 812 | this.placeBlock(level, blockState, x, 2, 5, chunkBB);
|
| 813 | this.placeBlock(level, blockState, x, 3, 6, chunkBB);
|
| 814 | }
|
| 815 |
|
| 816 | BlockState northFrame = Blocks.END_PORTAL_FRAME.defaultBlockState().setValue(EndPortalFrameBlock.FACING, Direction.NORTH);
|
| 817 | BlockState southFrame = Blocks.END_PORTAL_FRAME.defaultBlockState().setValue(EndPortalFrameBlock.FACING, Direction.SOUTH);
|
| 818 | BlockState eastFrame = Blocks.END_PORTAL_FRAME.defaultBlockState().setValue(EndPortalFrameBlock.FACING, Direction.EAST);
|
| 819 | BlockState westFrame = Blocks.END_PORTAL_FRAME.defaultBlockState().setValue(EndPortalFrameBlock.FACING, Direction.WEST);
|
| 820 | boolean allEyes = true;
|
| 821 | boolean[] eyes = new boolean[12];
|
| 822 |
|
| 823 | for (int i = 0; i < eyes.length; i++) {
|
| 824 | eyes[i] = random.nextFloat() > 0.9F;
|
| 825 | allEyes &= eyes[i];
|
| 826 | }
|
| 827 |
|
| 828 | this.placeBlock(level, northFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[0]), 4, 3, 8, chunkBB);
|
| 829 | this.placeBlock(level, northFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[1]), 5, 3, 8, chunkBB);
|
| 830 | this.placeBlock(level, northFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[2]), 6, 3, 8, chunkBB);
|
| 831 | this.placeBlock(level, southFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[3]), 4, 3, 12, chunkBB);
|
| 832 | this.placeBlock(level, southFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[4]), 5, 3, 12, chunkBB);
|
| 833 | this.placeBlock(level, southFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[5]), 6, 3, 12, chunkBB);
|
| 834 | this.placeBlock(level, eastFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[6]), 3, 3, 9, chunkBB);
|
| 835 | this.placeBlock(level, eastFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[7]), 3, 3, 10, chunkBB);
|
| 836 | this.placeBlock(level, eastFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[8]), 3, 3, 11, chunkBB);
|
| 837 | this.placeBlock(level, westFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[9]), 7, 3, 9, chunkBB);
|
| 838 | this.placeBlock(level, westFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[10]), 7, 3, 10, chunkBB);
|
| 839 | this.placeBlock(level, westFrame.setValue(EndPortalFrameBlock.HAS_EYE, eyes[11]), 7, 3, 11, chunkBB);
|
| 840 | if (allEyes) {
|
| 841 | BlockState portal = Blocks.END_PORTAL.defaultBlockState();
|
| 842 | this.placeBlock(level, portal, 4, 3, 9, chunkBB);
|
| 843 | this.placeBlock(level, portal, 5, 3, 9, chunkBB);
|
| 844 | this.placeBlock(level, portal, 6, 3, 9, chunkBB);
|
| 845 | this.placeBlock(level, portal, 4, 3, 10, chunkBB);
|
| 846 | this.placeBlock(level, portal, 5, 3, 10, chunkBB);
|
| 847 | this.placeBlock(level, portal, 6, 3, 10, chunkBB);
|
| 848 | this.placeBlock(level, portal, 4, 3, 11, chunkBB);
|
| 849 | this.placeBlock(level, portal, 5, 3, 11, chunkBB);
|
| 850 | this.placeBlock(level, portal, 6, 3, 11, chunkBB);
|
| 851 | }
|
| 852 |
|
| 853 | if (!this.hasPlacedSpawner) {
|
| 854 | BlockPos pos = this.getWorldPos(5, 3, 6);
|
| 855 | if (chunkBB.isInside(pos)) {
|
| 856 | this.hasPlacedSpawner = true;
|
| 857 | level.setBlock(pos, Blocks.SPAWNER.defaultBlockState(), 2);
|
| 858 | if (level.getBlockEntity(pos) instanceof SpawnerBlockEntity spawner) {
|
| 859 | spawner.setEntityId(EntityTypes.SILVERFISH, random);
|
| 860 | }
|
| 861 | }
|
| 862 | }
|
| 863 | }
|
| 864 | }
|
| 865 |
|
| 866 | public static class PrisonHall extends StrongholdPieces.StrongholdPiece {
|
| 867 | protected static final int WIDTH = 9;
|
| 868 | protected static final int HEIGHT = 5;
|
| 869 | protected static final int DEPTH = 11;
|
| 870 |
|
| 871 | public PrisonHall(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 872 | super(StructurePieceType.STRONGHOLD_PRISON_HALL, genDepth, boundingBox);
|
| 873 | this.setOrientation(direction);
|
| 874 | this.entryDoor = this.randomSmallDoor(random);
|
| 875 | }
|
| 876 |
|
| 877 | public PrisonHall(final CompoundTag tag) {
|
| 878 | super(StructurePieceType.STRONGHOLD_PRISON_HALL, tag);
|
| 879 | }
|
| 880 |
|
| 881 | @Override
|
| 882 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 883 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 884 | }
|
| 885 |
|
| 886 | public static StrongholdPieces.@Nullable PrisonHall createPiece(
|
| 887 | final StructurePiecesBuilder builder,
|
| 888 | final RandomSource random,
|
| 889 | final int footX,
|
| 890 | final int footY,
|
| 891 | final int footZ,
|
| 892 | final Direction direction,
|
| 893 | final int genDepth
|
| 894 | ) {
|
| 895 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 9, 5, 11, direction);
|
| 896 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.PrisonHall(genDepth, random, box, direction) : null;
|
| 897 | }
|
| 898 |
|
| 899 | @Override
|
| 900 | public void postProcess(
|
| 901 | final WorldGenLevel level,
|
| 902 | final StructureManager structureManager,
|
| 903 | final ChunkGenerator generator,
|
| 904 | final RandomSource random,
|
| 905 | final BoundingBox chunkBB,
|
| 906 | final ChunkPos chunkPos,
|
| 907 | final BlockPos referencePos
|
| 908 | ) {
|
| 909 | this.generateBox(level, chunkBB, 0, 0, 0, 8, 4, 10, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 910 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 1, 0);
|
| 911 | this.generateBox(level, chunkBB, 1, 1, 10, 3, 3, 10, CAVE_AIR, CAVE_AIR, false);
|
| 912 | this.generateBox(level, chunkBB, 4, 1, 1, 4, 3, 1, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 913 | this.generateBox(level, chunkBB, 4, 1, 3, 4, 3, 3, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 914 | this.generateBox(level, chunkBB, 4, 1, 7, 4, 3, 7, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 915 | this.generateBox(level, chunkBB, 4, 1, 9, 4, 3, 9, false, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 916 |
|
| 917 | for (int y = 1; y <= 3; y++) {
|
| 918 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, true).setValue(IronBarsBlock.SOUTH, true), 4, y, 4, chunkBB);
|
| 919 | this.placeBlock(
|
| 920 | level,
|
| 921 | Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, true).setValue(IronBarsBlock.SOUTH, true).setValue(IronBarsBlock.EAST, true),
|
| 922 | 4,
|
| 923 | y,
|
| 924 | 5,
|
| 925 | chunkBB
|
| 926 | );
|
| 927 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, true).setValue(IronBarsBlock.SOUTH, true), 4, y, 6, chunkBB);
|
| 928 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.WEST, true).setValue(IronBarsBlock.EAST, true), 5, y, 5, chunkBB);
|
| 929 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.WEST, true).setValue(IronBarsBlock.EAST, true), 6, y, 5, chunkBB);
|
| 930 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.WEST, true).setValue(IronBarsBlock.EAST, true), 7, y, 5, chunkBB);
|
| 931 | }
|
| 932 |
|
| 933 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, true).setValue(IronBarsBlock.SOUTH, true), 4, 3, 2, chunkBB);
|
| 934 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, true).setValue(IronBarsBlock.SOUTH, true), 4, 3, 8, chunkBB);
|
| 935 | BlockState doorBottom = Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.FACING, Direction.WEST);
|
| 936 | BlockState doorTop = Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.FACING, Direction.WEST).setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER);
|
| 937 | this.placeBlock(level, doorBottom, 4, 1, 2, chunkBB);
|
| 938 | this.placeBlock(level, doorTop, 4, 2, 2, chunkBB);
|
| 939 | this.placeBlock(level, doorBottom, 4, 1, 8, chunkBB);
|
| 940 | this.placeBlock(level, doorTop, 4, 2, 8, chunkBB);
|
| 941 | }
|
| 942 | }
|
| 943 |
|
| 944 | public static class RightTurn extends StrongholdPieces.Turn {
|
| 945 | public RightTurn(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 946 | super(StructurePieceType.STRONGHOLD_RIGHT_TURN, genDepth, boundingBox);
|
| 947 | this.setOrientation(direction);
|
| 948 | this.entryDoor = this.randomSmallDoor(random);
|
| 949 | }
|
| 950 |
|
| 951 | public RightTurn(final CompoundTag tag) {
|
| 952 | super(StructurePieceType.STRONGHOLD_RIGHT_TURN, tag);
|
| 953 | }
|
| 954 |
|
| 955 | @Override
|
| 956 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 957 | Direction orientation = this.getOrientation();
|
| 958 | if (orientation != Direction.NORTH && orientation != Direction.EAST) {
|
| 959 | this.generateSmallDoorChildLeft((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 960 | } else {
|
| 961 | this.generateSmallDoorChildRight((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 962 | }
|
| 963 | }
|
| 964 |
|
| 965 | public static StrongholdPieces.@Nullable RightTurn createPiece(
|
| 966 | final StructurePiecesBuilder builder,
|
| 967 | final RandomSource random,
|
| 968 | final int footX,
|
| 969 | final int footY,
|
| 970 | final int footZ,
|
| 971 | final Direction direction,
|
| 972 | final int genDepth
|
| 973 | ) {
|
| 974 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, 5, direction);
|
| 975 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.RightTurn(genDepth, random, box, direction) : null;
|
| 976 | }
|
| 977 |
|
| 978 | @Override
|
| 979 | public void postProcess(
|
| 980 | final WorldGenLevel level,
|
| 981 | final StructureManager structureManager,
|
| 982 | final ChunkGenerator generator,
|
| 983 | final RandomSource random,
|
| 984 | final BoundingBox chunkBB,
|
| 985 | final ChunkPos chunkPos,
|
| 986 | final BlockPos referencePos
|
| 987 | ) {
|
| 988 | this.generateBox(level, chunkBB, 0, 0, 0, 4, 4, 4, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 989 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 1, 0);
|
| 990 | Direction orientation = this.getOrientation();
|
| 991 | if (orientation != Direction.NORTH && orientation != Direction.EAST) {
|
| 992 | this.generateBox(level, chunkBB, 0, 1, 1, 0, 3, 3, CAVE_AIR, CAVE_AIR, false);
|
| 993 | } else {
|
| 994 | this.generateBox(level, chunkBB, 4, 1, 1, 4, 3, 3, CAVE_AIR, CAVE_AIR, false);
|
| 995 | }
|
| 996 | }
|
| 997 | }
|
| 998 |
|
| 999 | public static class RoomCrossing extends StrongholdPieces.StrongholdPiece {
|
| 1000 | protected static final int WIDTH = 11;
|
| 1001 | protected static final int HEIGHT = 7;
|
| 1002 | protected static final int DEPTH = 11;
|
| 1003 | protected final int type;
|
| 1004 |
|
| 1005 | public RoomCrossing(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 1006 | super(StructurePieceType.STRONGHOLD_ROOM_CROSSING, genDepth, boundingBox);
|
| 1007 | this.setOrientation(direction);
|
| 1008 | this.entryDoor = this.randomSmallDoor(random);
|
| 1009 | this.type = random.nextInt(5);
|
| 1010 | }
|
| 1011 |
|
| 1012 | public RoomCrossing(final CompoundTag tag) {
|
| 1013 | super(StructurePieceType.STRONGHOLD_ROOM_CROSSING, tag);
|
| 1014 | this.type = tag.getIntOr("Type", 0);
|
| 1015 | }
|
| 1016 |
|
| 1017 | @Override
|
| 1018 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 1019 | super.addAdditionalSaveData(context, tag);
|
| 1020 | tag.putInt("Type", this.type);
|
| 1021 | }
|
| 1022 |
|
| 1023 | @Override
|
| 1024 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 1025 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 4, 1);
|
| 1026 | this.generateSmallDoorChildLeft((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 4);
|
| 1027 | this.generateSmallDoorChildRight((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 4);
|
| 1028 | }
|
| 1029 |
|
| 1030 | public static StrongholdPieces.@Nullable RoomCrossing createPiece(
|
| 1031 | final StructurePiecesBuilder builder,
|
| 1032 | final RandomSource random,
|
| 1033 | final int footX,
|
| 1034 | final int footY,
|
| 1035 | final int footZ,
|
| 1036 | final Direction direction,
|
| 1037 | final int genDepth
|
| 1038 | ) {
|
| 1039 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -4, -1, 0, 11, 7, 11, direction);
|
| 1040 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.RoomCrossing(genDepth, random, box, direction) : null;
|
| 1041 | }
|
| 1042 |
|
| 1043 | @Override
|
| 1044 | public void postProcess(
|
| 1045 | final WorldGenLevel level,
|
| 1046 | final StructureManager structureManager,
|
| 1047 | final ChunkGenerator generator,
|
| 1048 | final RandomSource random,
|
| 1049 | final BoundingBox chunkBB,
|
| 1050 | final ChunkPos chunkPos,
|
| 1051 | final BlockPos referencePos
|
| 1052 | ) {
|
| 1053 | this.generateBox(level, chunkBB, 0, 0, 0, 10, 6, 10, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 1054 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 4, 1, 0);
|
| 1055 | this.generateBox(level, chunkBB, 4, 1, 10, 6, 3, 10, CAVE_AIR, CAVE_AIR, false);
|
| 1056 | this.generateBox(level, chunkBB, 0, 1, 4, 0, 3, 6, CAVE_AIR, CAVE_AIR, false);
|
| 1057 | this.generateBox(level, chunkBB, 10, 1, 4, 10, 3, 6, CAVE_AIR, CAVE_AIR, false);
|
| 1058 | switch (this.type) {
|
| 1059 | case 0:
|
| 1060 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 5, 1, 5, chunkBB);
|
| 1061 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 5, 2, 5, chunkBB);
|
| 1062 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 5, 3, 5, chunkBB);
|
| 1063 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.WEST), 4, 3, 5, chunkBB);
|
| 1064 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.EAST), 6, 3, 5, chunkBB);
|
| 1065 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.SOUTH), 5, 3, 4, chunkBB);
|
| 1066 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.NORTH), 5, 3, 6, chunkBB);
|
| 1067 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 4, 1, 4, chunkBB);
|
| 1068 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 4, 1, 5, chunkBB);
|
| 1069 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 4, 1, 6, chunkBB);
|
| 1070 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 6, 1, 4, chunkBB);
|
| 1071 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 6, 1, 5, chunkBB);
|
| 1072 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 6, 1, 6, chunkBB);
|
| 1073 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 5, 1, 4, chunkBB);
|
| 1074 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 5, 1, 6, chunkBB);
|
| 1075 | break;
|
| 1076 | case 1:
|
| 1077 | for (int i = 0; i < 5; i++) {
|
| 1078 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 1, 3 + i, chunkBB);
|
| 1079 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 7, 1, 3 + i, chunkBB);
|
| 1080 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3 + i, 1, 3, chunkBB);
|
| 1081 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3 + i, 1, 7, chunkBB);
|
| 1082 | }
|
| 1083 |
|
| 1084 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 5, 1, 5, chunkBB);
|
| 1085 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 5, 2, 5, chunkBB);
|
| 1086 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 5, 3, 5, chunkBB);
|
| 1087 | this.placeBlock(level, Blocks.WATER.defaultBlockState(), 5, 4, 5, chunkBB);
|
| 1088 | break;
|
| 1089 | case 2:
|
| 1090 | for (int z = 1; z <= 9; z++) {
|
| 1091 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 1, 3, z, chunkBB);
|
| 1092 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 9, 3, z, chunkBB);
|
| 1093 | }
|
| 1094 |
|
| 1095 | for (int x = 1; x <= 9; x++) {
|
| 1096 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), x, 3, 1, chunkBB);
|
| 1097 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), x, 3, 9, chunkBB);
|
| 1098 | }
|
| 1099 |
|
| 1100 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 5, 1, 4, chunkBB);
|
| 1101 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 5, 1, 6, chunkBB);
|
| 1102 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 5, 3, 4, chunkBB);
|
| 1103 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 5, 3, 6, chunkBB);
|
| 1104 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 4, 1, 5, chunkBB);
|
| 1105 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 6, 1, 5, chunkBB);
|
| 1106 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 4, 3, 5, chunkBB);
|
| 1107 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 6, 3, 5, chunkBB);
|
| 1108 |
|
| 1109 | for (int y = 1; y <= 3; y++) {
|
| 1110 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 4, y, 4, chunkBB);
|
| 1111 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 6, y, 4, chunkBB);
|
| 1112 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 4, y, 6, chunkBB);
|
| 1113 | this.placeBlock(level, Blocks.COBBLESTONE.defaultBlockState(), 6, y, 6, chunkBB);
|
| 1114 | }
|
| 1115 |
|
| 1116 | this.placeBlock(level, Blocks.WALL_TORCH.defaultBlockState(), 5, 3, 5, chunkBB);
|
| 1117 |
|
| 1118 | for (int z = 2; z <= 8; z++) {
|
| 1119 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 2, 3, z, chunkBB);
|
| 1120 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 3, 3, z, chunkBB);
|
| 1121 | if (z <= 3 || z >= 7) {
|
| 1122 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 4, 3, z, chunkBB);
|
| 1123 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 5, 3, z, chunkBB);
|
| 1124 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 6, 3, z, chunkBB);
|
| 1125 | }
|
| 1126 |
|
| 1127 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 7, 3, z, chunkBB);
|
| 1128 | this.placeBlock(level, Blocks.OAK_PLANKS.defaultBlockState(), 8, 3, z, chunkBB);
|
| 1129 | }
|
| 1130 |
|
| 1131 | BlockState ladder = Blocks.LADDER.defaultBlockState().setValue(LadderBlock.FACING, Direction.WEST);
|
| 1132 | this.placeBlock(level, ladder, 9, 1, 3, chunkBB);
|
| 1133 | this.placeBlock(level, ladder, 9, 2, 3, chunkBB);
|
| 1134 | this.placeBlock(level, ladder, 9, 3, 3, chunkBB);
|
| 1135 | this.createChest(level, chunkBB, random, 3, 4, 8, BuiltInLootTables.STRONGHOLD_CROSSING);
|
| 1136 | }
|
| 1137 | }
|
| 1138 | }
|
| 1139 |
|
| 1140 | private static class SmoothStoneSelector extends StructurePiece.BlockSelector {
|
| 1141 | @Override
|
| 1142 | public void next(final RandomSource random, final int worldX, final int worldY, final int worldZ, final boolean isEdge) {
|
| 1143 | if (isEdge) {
|
| 1144 | float selection = random.nextFloat();
|
| 1145 | if (selection < 0.2F) {
|
| 1146 | this.next = Blocks.CRACKED_STONE_BRICKS.defaultBlockState();
|
| 1147 | } else if (selection < 0.5F) {
|
| 1148 | this.next = Blocks.MOSSY_STONE_BRICKS.defaultBlockState();
|
| 1149 | } else if (selection < 0.55F) {
|
| 1150 | this.next = Blocks.INFESTED_STONE_BRICKS.defaultBlockState();
|
| 1151 | } else {
|
| 1152 | this.next = Blocks.STONE_BRICKS.defaultBlockState();
|
| 1153 | }
|
| 1154 | } else {
|
| 1155 | this.next = Blocks.CAVE_AIR.defaultBlockState();
|
| 1156 | }
|
| 1157 | }
|
| 1158 | }
|
| 1159 |
|
| 1160 | public static class StairsDown extends StrongholdPieces.StrongholdPiece {
|
| 1161 | private static final int WIDTH = 5;
|
| 1162 | private static final int HEIGHT = 11;
|
| 1163 | private static final int DEPTH = 5;
|
| 1164 | private final boolean isSource;
|
| 1165 |
|
| 1166 | public StairsDown(final StructurePieceType type, final int genDepth, final int west, final int north, final Direction direction) {
|
| 1167 | super(type, genDepth, makeBoundingBox(west, 64, north, direction, 5, 11, 5));
|
| 1168 | this.isSource = true;
|
| 1169 | this.setOrientation(direction);
|
| 1170 | this.entryDoor = StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING;
|
| 1171 | }
|
| 1172 |
|
| 1173 | public StairsDown(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 1174 | super(StructurePieceType.STRONGHOLD_STAIRS_DOWN, genDepth, boundingBox);
|
| 1175 | this.isSource = false;
|
| 1176 | this.setOrientation(direction);
|
| 1177 | this.entryDoor = this.randomSmallDoor(random);
|
| 1178 | }
|
| 1179 |
|
| 1180 | public StairsDown(final StructurePieceType type, final CompoundTag tag) {
|
| 1181 | super(type, tag);
|
| 1182 | this.isSource = tag.getBooleanOr("Source", false);
|
| 1183 | }
|
| 1184 |
|
| 1185 | public StairsDown(final CompoundTag tag) {
|
| 1186 | this(StructurePieceType.STRONGHOLD_STAIRS_DOWN, tag);
|
| 1187 | }
|
| 1188 |
|
| 1189 | @Override
|
| 1190 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 1191 | super.addAdditionalSaveData(context, tag);
|
| 1192 | tag.putBoolean("Source", this.isSource);
|
| 1193 | }
|
| 1194 |
|
| 1195 | @Override
|
| 1196 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 1197 | if (this.isSource) {
|
| 1198 | StrongholdPieces.imposedPiece = StrongholdPieces.FiveCrossing.class;
|
| 1199 | }
|
| 1200 |
|
| 1201 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 1202 | }
|
| 1203 |
|
| 1204 | public static StrongholdPieces.@Nullable StairsDown createPiece(
|
| 1205 | final StructurePiecesBuilder builder,
|
| 1206 | final RandomSource random,
|
| 1207 | final int footX,
|
| 1208 | final int footY,
|
| 1209 | final int footZ,
|
| 1210 | final Direction direction,
|
| 1211 | final int genDepth
|
| 1212 | ) {
|
| 1213 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -7, 0, 5, 11, 5, direction);
|
| 1214 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.StairsDown(genDepth, random, box, direction) : null;
|
| 1215 | }
|
| 1216 |
|
| 1217 | @Override
|
| 1218 | public void postProcess(
|
| 1219 | final WorldGenLevel level,
|
| 1220 | final StructureManager structureManager,
|
| 1221 | final ChunkGenerator generator,
|
| 1222 | final RandomSource random,
|
| 1223 | final BoundingBox chunkBB,
|
| 1224 | final ChunkPos chunkPos,
|
| 1225 | final BlockPos referencePos
|
| 1226 | ) {
|
| 1227 | this.generateBox(level, chunkBB, 0, 0, 0, 4, 10, 4, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 1228 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 7, 0);
|
| 1229 | this.generateSmallDoor(level, random, chunkBB, StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING, 1, 1, 4);
|
| 1230 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 2, 6, 1, chunkBB);
|
| 1231 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 5, 1, chunkBB);
|
| 1232 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 1, 6, 1, chunkBB);
|
| 1233 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 5, 2, chunkBB);
|
| 1234 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 4, 3, chunkBB);
|
| 1235 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 1, 5, 3, chunkBB);
|
| 1236 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 2, 4, 3, chunkBB);
|
| 1237 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 3, 3, chunkBB);
|
| 1238 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 3, 4, 3, chunkBB);
|
| 1239 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 3, 2, chunkBB);
|
| 1240 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 2, 1, chunkBB);
|
| 1241 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 3, 3, 1, chunkBB);
|
| 1242 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 2, 2, 1, chunkBB);
|
| 1243 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 1, 1, chunkBB);
|
| 1244 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 1, 2, 1, chunkBB);
|
| 1245 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 1, 2, chunkBB);
|
| 1246 | this.placeBlock(level, Blocks.SMOOTH_STONE_SLAB.defaultBlockState(), 1, 1, 3, chunkBB);
|
| 1247 | }
|
| 1248 | }
|
| 1249 |
|
| 1250 | public static class StartPiece extends StrongholdPieces.StairsDown {
|
| 1251 | public StrongholdPieces.@Nullable PieceWeight previousPiece;
|
| 1252 | public StrongholdPieces.@Nullable PortalRoom portalRoomPiece;
|
| 1253 | public final List<StructurePiece> pendingChildren = Lists.newArrayList();
|
| 1254 |
|
| 1255 | public StartPiece(final RandomSource random, final int west, final int north) {
|
| 1256 | super(StructurePieceType.STRONGHOLD_START, 0, west, north, getRandomHorizontalDirection(random));
|
| 1257 | }
|
| 1258 |
|
| 1259 | public StartPiece(final CompoundTag tag) {
|
| 1260 | super(StructurePieceType.STRONGHOLD_START, tag);
|
| 1261 | }
|
| 1262 |
|
| 1263 | @Override
|
| 1264 | public BlockPos getLocatorPosition() {
|
| 1265 | return this.portalRoomPiece != null ? this.portalRoomPiece.getLocatorPosition() : super.getLocatorPosition();
|
| 1266 | }
|
| 1267 | }
|
| 1268 |
|
| 1269 | public static class Straight extends StrongholdPieces.StrongholdPiece {
|
| 1270 | private static final int WIDTH = 5;
|
| 1271 | private static final int HEIGHT = 5;
|
| 1272 | private static final int DEPTH = 7;
|
| 1273 | private final boolean leftChild;
|
| 1274 | private final boolean rightChild;
|
| 1275 |
|
| 1276 | public Straight(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 1277 | super(StructurePieceType.STRONGHOLD_STRAIGHT, genDepth, boundingBox);
|
| 1278 | this.setOrientation(direction);
|
| 1279 | this.entryDoor = this.randomSmallDoor(random);
|
| 1280 | this.leftChild = random.nextInt(2) == 0;
|
| 1281 | this.rightChild = random.nextInt(2) == 0;
|
| 1282 | }
|
| 1283 |
|
| 1284 | public Straight(final CompoundTag tag) {
|
| 1285 | super(StructurePieceType.STRONGHOLD_STRAIGHT, tag);
|
| 1286 | this.leftChild = tag.getBooleanOr("Left", false);
|
| 1287 | this.rightChild = tag.getBooleanOr("Right", false);
|
| 1288 | }
|
| 1289 |
|
| 1290 | @Override
|
| 1291 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 1292 | super.addAdditionalSaveData(context, tag);
|
| 1293 | tag.putBoolean("Left", this.leftChild);
|
| 1294 | tag.putBoolean("Right", this.rightChild);
|
| 1295 | }
|
| 1296 |
|
| 1297 | @Override
|
| 1298 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 1299 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 1300 | if (this.leftChild) {
|
| 1301 | this.generateSmallDoorChildLeft((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 2);
|
| 1302 | }
|
| 1303 |
|
| 1304 | if (this.rightChild) {
|
| 1305 | this.generateSmallDoorChildRight((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 2);
|
| 1306 | }
|
| 1307 | }
|
| 1308 |
|
| 1309 | public static StrongholdPieces.@Nullable Straight createPiece(
|
| 1310 | final StructurePiecesBuilder builder,
|
| 1311 | final RandomSource random,
|
| 1312 | final int footX,
|
| 1313 | final int footY,
|
| 1314 | final int footZ,
|
| 1315 | final Direction direction,
|
| 1316 | final int genDepth
|
| 1317 | ) {
|
| 1318 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -1, 0, 5, 5, 7, direction);
|
| 1319 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.Straight(genDepth, random, box, direction) : null;
|
| 1320 | }
|
| 1321 |
|
| 1322 | @Override
|
| 1323 | public void postProcess(
|
| 1324 | final WorldGenLevel level,
|
| 1325 | final StructureManager structureManager,
|
| 1326 | final ChunkGenerator generator,
|
| 1327 | final RandomSource random,
|
| 1328 | final BoundingBox chunkBB,
|
| 1329 | final ChunkPos chunkPos,
|
| 1330 | final BlockPos referencePos
|
| 1331 | ) {
|
| 1332 | this.generateBox(level, chunkBB, 0, 0, 0, 4, 4, 6, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 1333 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 1, 0);
|
| 1334 | this.generateSmallDoor(level, random, chunkBB, StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING, 1, 1, 6);
|
| 1335 | BlockState eastTorch = Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.EAST);
|
| 1336 | BlockState westTorch = Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, Direction.WEST);
|
| 1337 | this.maybeGenerateBlock(level, chunkBB, random, 0.1F, 1, 2, 1, eastTorch);
|
| 1338 | this.maybeGenerateBlock(level, chunkBB, random, 0.1F, 3, 2, 1, westTorch);
|
| 1339 | this.maybeGenerateBlock(level, chunkBB, random, 0.1F, 1, 2, 5, eastTorch);
|
| 1340 | this.maybeGenerateBlock(level, chunkBB, random, 0.1F, 3, 2, 5, westTorch);
|
| 1341 | if (this.leftChild) {
|
| 1342 | this.generateBox(level, chunkBB, 0, 1, 2, 0, 3, 4, CAVE_AIR, CAVE_AIR, false);
|
| 1343 | }
|
| 1344 |
|
| 1345 | if (this.rightChild) {
|
| 1346 | this.generateBox(level, chunkBB, 4, 1, 2, 4, 3, 4, CAVE_AIR, CAVE_AIR, false);
|
| 1347 | }
|
| 1348 | }
|
| 1349 | }
|
| 1350 |
|
| 1351 | public static class StraightStairsDown extends StrongholdPieces.StrongholdPiece {
|
| 1352 | private static final int WIDTH = 5;
|
| 1353 | private static final int HEIGHT = 11;
|
| 1354 | private static final int DEPTH = 8;
|
| 1355 |
|
| 1356 | public StraightStairsDown(final int genDepth, final RandomSource random, final BoundingBox boundingBox, final Direction direction) {
|
| 1357 | super(StructurePieceType.STRONGHOLD_STRAIGHT_STAIRS_DOWN, genDepth, boundingBox);
|
| 1358 | this.setOrientation(direction);
|
| 1359 | this.entryDoor = this.randomSmallDoor(random);
|
| 1360 | }
|
| 1361 |
|
| 1362 | public StraightStairsDown(final CompoundTag tag) {
|
| 1363 | super(StructurePieceType.STRONGHOLD_STRAIGHT_STAIRS_DOWN, tag);
|
| 1364 | }
|
| 1365 |
|
| 1366 | @Override
|
| 1367 | public void addChildren(final StructurePiece startPiece, final StructurePiecesBuilder builder, final RandomSource random) {
|
| 1368 | this.generateSmallDoorChildForward((StrongholdPieces.StartPiece)startPiece, builder, random, 1, 1);
|
| 1369 | }
|
| 1370 |
|
| 1371 | public static StrongholdPieces.@Nullable StraightStairsDown createPiece(
|
| 1372 | final StructurePiecesBuilder builder,
|
| 1373 | final RandomSource random,
|
| 1374 | final int footX,
|
| 1375 | final int footY,
|
| 1376 | final int footZ,
|
| 1377 | final Direction direction,
|
| 1378 | final int genDepth
|
| 1379 | ) {
|
| 1380 | BoundingBox box = BoundingBox.orientBox(footX, footY, footZ, -1, -7, 0, 5, 11, 8, direction);
|
| 1381 | return isOkBox(box) && builder.findCollisionPiece(box) == null ? new StrongholdPieces.StraightStairsDown(genDepth, random, box, direction) : null;
|
| 1382 | }
|
| 1383 |
|
| 1384 | @Override
|
| 1385 | public void postProcess(
|
| 1386 | final WorldGenLevel level,
|
| 1387 | final StructureManager structureManager,
|
| 1388 | final ChunkGenerator generator,
|
| 1389 | final RandomSource random,
|
| 1390 | final BoundingBox chunkBB,
|
| 1391 | final ChunkPos chunkPos,
|
| 1392 | final BlockPos referencePos
|
| 1393 | ) {
|
| 1394 | this.generateBox(level, chunkBB, 0, 0, 0, 4, 10, 7, true, random, StrongholdPieces.SMOOTH_STONE_SELECTOR);
|
| 1395 | this.generateSmallDoor(level, random, chunkBB, this.entryDoor, 1, 7, 0);
|
| 1396 | this.generateSmallDoor(level, random, chunkBB, StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING, 1, 1, 7);
|
| 1397 | BlockState stairs = Blocks.COBBLESTONE_STAIRS.defaultBlockState().setValue(StairBlock.FACING, Direction.SOUTH);
|
| 1398 |
|
| 1399 | for (int i = 0; i < 6; i++) {
|
| 1400 | this.placeBlock(level, stairs, 1, 6 - i, 1 + i, chunkBB);
|
| 1401 | this.placeBlock(level, stairs, 2, 6 - i, 1 + i, chunkBB);
|
| 1402 | this.placeBlock(level, stairs, 3, 6 - i, 1 + i, chunkBB);
|
| 1403 | if (i < 5) {
|
| 1404 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 1, 5 - i, 1 + i, chunkBB);
|
| 1405 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 2, 5 - i, 1 + i, chunkBB);
|
| 1406 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), 3, 5 - i, 1 + i, chunkBB);
|
| 1407 | }
|
| 1408 | }
|
| 1409 | }
|
| 1410 | }
|
| 1411 |
|
| 1412 | private abstract static class StrongholdPiece extends StructurePiece {
|
| 1413 | protected StrongholdPieces.StrongholdPiece.SmallDoorType entryDoor = StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING;
|
| 1414 |
|
| 1415 | protected StrongholdPiece(final StructurePieceType type, final int genDepth, final BoundingBox boundingBox) {
|
| 1416 | super(type, genDepth, boundingBox);
|
| 1417 | }
|
| 1418 |
|
| 1419 | public StrongholdPiece(final StructurePieceType type, final CompoundTag tag) {
|
| 1420 | super(type, tag);
|
| 1421 | this.entryDoor = tag.read("EntryDoor", StrongholdPieces.StrongholdPiece.SmallDoorType.LEGACY_CODEC).orElseThrow();
|
| 1422 | }
|
| 1423 |
|
| 1424 | @Override
|
| 1425 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 1426 | tag.store("EntryDoor", StrongholdPieces.StrongholdPiece.SmallDoorType.LEGACY_CODEC, this.entryDoor);
|
| 1427 | }
|
| 1428 |
|
| 1429 | protected void generateSmallDoor(
|
| 1430 | final WorldGenLevel level,
|
| 1431 | final RandomSource random,
|
| 1432 | final BoundingBox chunkBB,
|
| 1433 | final StrongholdPieces.StrongholdPiece.SmallDoorType doorType,
|
| 1434 | final int footX,
|
| 1435 | final int footY,
|
| 1436 | final int footZ
|
| 1437 | ) {
|
| 1438 | switch (doorType) {
|
| 1439 | case OPENING:
|
| 1440 | this.generateBox(level, chunkBB, footX, footY, footZ, footX + 3 - 1, footY + 3 - 1, footZ, CAVE_AIR, CAVE_AIR, false);
|
| 1441 | break;
|
| 1442 | case WOOD_DOOR:
|
| 1443 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX, footY, footZ, chunkBB);
|
| 1444 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX, footY + 1, footZ, chunkBB);
|
| 1445 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX, footY + 2, footZ, chunkBB);
|
| 1446 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 1, footY + 2, footZ, chunkBB);
|
| 1447 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 2, footY + 2, footZ, chunkBB);
|
| 1448 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 2, footY + 1, footZ, chunkBB);
|
| 1449 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 2, footY, footZ, chunkBB);
|
| 1450 | this.placeBlock(level, Blocks.OAK_DOOR.defaultBlockState(), footX + 1, footY, footZ, chunkBB);
|
| 1451 | this.placeBlock(level, Blocks.OAK_DOOR.defaultBlockState().setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER), footX + 1, footY + 1, footZ, chunkBB);
|
| 1452 | break;
|
| 1453 | case GRATES:
|
| 1454 | this.placeBlock(level, Blocks.CAVE_AIR.defaultBlockState(), footX + 1, footY, footZ, chunkBB);
|
| 1455 | this.placeBlock(level, Blocks.CAVE_AIR.defaultBlockState(), footX + 1, footY + 1, footZ, chunkBB);
|
| 1456 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.WEST, true), footX, footY, footZ, chunkBB);
|
| 1457 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.WEST, true), footX, footY + 1, footZ, chunkBB);
|
| 1458 | this.placeBlock(
|
| 1459 | level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.EAST, true).setValue(IronBarsBlock.WEST, true), footX, footY + 2, footZ, chunkBB
|
| 1460 | );
|
| 1461 | this.placeBlock(
|
| 1462 | level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.EAST, true).setValue(IronBarsBlock.WEST, true), footX + 1, footY + 2, footZ, chunkBB
|
| 1463 | );
|
| 1464 | this.placeBlock(
|
| 1465 | level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.EAST, true).setValue(IronBarsBlock.WEST, true), footX + 2, footY + 2, footZ, chunkBB
|
| 1466 | );
|
| 1467 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.EAST, true), footX + 2, footY + 1, footZ, chunkBB);
|
| 1468 | this.placeBlock(level, Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.EAST, true), footX + 2, footY, footZ, chunkBB);
|
| 1469 | break;
|
| 1470 | case IRON_DOOR:
|
| 1471 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX, footY, footZ, chunkBB);
|
| 1472 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX, footY + 1, footZ, chunkBB);
|
| 1473 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX, footY + 2, footZ, chunkBB);
|
| 1474 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 1, footY + 2, footZ, chunkBB);
|
| 1475 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 2, footY + 2, footZ, chunkBB);
|
| 1476 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 2, footY + 1, footZ, chunkBB);
|
| 1477 | this.placeBlock(level, Blocks.STONE_BRICKS.defaultBlockState(), footX + 2, footY, footZ, chunkBB);
|
| 1478 | this.placeBlock(level, Blocks.IRON_DOOR.defaultBlockState(), footX + 1, footY, footZ, chunkBB);
|
| 1479 | this.placeBlock(level, Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER), footX + 1, footY + 1, footZ, chunkBB);
|
| 1480 | this.placeBlock(level, Blocks.STONE_BUTTON.defaultBlockState().setValue(ButtonBlock.FACING, Direction.NORTH), footX + 2, footY + 1, footZ + 1, chunkBB);
|
| 1481 | this.placeBlock(level, Blocks.STONE_BUTTON.defaultBlockState().setValue(ButtonBlock.FACING, Direction.SOUTH), footX + 2, footY + 1, footZ - 1, chunkBB);
|
| 1482 | }
|
| 1483 | }
|
| 1484 |
|
| 1485 | protected StrongholdPieces.StrongholdPiece.SmallDoorType randomSmallDoor(final RandomSource random) {
|
| 1486 | int selection = random.nextInt(5);
|
| 1487 | switch (selection) {
|
| 1488 | case 0:
|
| 1489 | case 1:
|
| 1490 | default:
|
| 1491 | return StrongholdPieces.StrongholdPiece.SmallDoorType.OPENING;
|
| 1492 | case 2:
|
| 1493 | return StrongholdPieces.StrongholdPiece.SmallDoorType.WOOD_DOOR;
|
| 1494 | case 3:
|
| 1495 | return StrongholdPieces.StrongholdPiece.SmallDoorType.GRATES;
|
| 1496 | case 4:
|
| 1497 | return StrongholdPieces.StrongholdPiece.SmallDoorType.IRON_DOOR;
|
| 1498 | }
|
| 1499 | }
|
| 1500 |
|
| 1501 | protected @Nullable StructurePiece generateSmallDoorChildForward(
|
| 1502 | final StrongholdPieces.StartPiece startPiece, final StructurePiecesBuilder builder, final RandomSource random, final int xOff, final int yOff
|
| 1503 | ) {
|
| 1504 | Direction orientation = this.getOrientation();
|
| 1505 | if (orientation != null) {
|
| 1506 | switch (orientation) {
|
| 1507 | case NORTH:
|
| 1508 | return StrongholdPieces.generateAndAddPiece(
|
| 1509 | startPiece,
|
| 1510 | builder,
|
| 1511 | random,
|
| 1512 | this.boundingBox.minX() + xOff,
|
| 1513 | this.boundingBox.minY() + yOff,
|
| 1514 | this.boundingBox.minZ() - 1,
|
| 1515 | orientation,
|
| 1516 | this.getGenDepth()
|
| 1517 | );
|
| 1518 | case SOUTH:
|
| 1519 | return StrongholdPieces.generateAndAddPiece(
|
| 1520 | startPiece,
|
| 1521 | builder,
|
| 1522 | random,
|
| 1523 | this.boundingBox.minX() + xOff,
|
| 1524 | this.boundingBox.minY() + yOff,
|
| 1525 | this.boundingBox.maxZ() + 1,
|
| 1526 | orientation,
|
| 1527 | this.getGenDepth()
|
| 1528 | );
|
| 1529 | case WEST:
|
| 1530 | return StrongholdPieces.generateAndAddPiece(
|
| 1531 | startPiece,
|
| 1532 | builder,
|
| 1533 | random,
|
| 1534 | this.boundingBox.minX() - 1,
|
| 1535 | this.boundingBox.minY() + yOff,
|
| 1536 | this.boundingBox.minZ() + xOff,
|
| 1537 | orientation,
|
| 1538 | this.getGenDepth()
|
| 1539 | );
|
| 1540 | case EAST:
|
| 1541 | return StrongholdPieces.generateAndAddPiece(
|
| 1542 | startPiece,
|
| 1543 | builder,
|
| 1544 | random,
|
| 1545 | this.boundingBox.maxX() + 1,
|
| 1546 | this.boundingBox.minY() + yOff,
|
| 1547 | this.boundingBox.minZ() + xOff,
|
| 1548 | orientation,
|
| 1549 | this.getGenDepth()
|
| 1550 | );
|
| 1551 | }
|
| 1552 | }
|
| 1553 |
|
| 1554 | return null;
|
| 1555 | }
|
| 1556 |
|
| 1557 | protected @Nullable StructurePiece generateSmallDoorChildLeft(
|
| 1558 | final StrongholdPieces.StartPiece startPiece, final StructurePiecesBuilder builder, final RandomSource random, final int yOff, final int zOff
|
| 1559 | ) {
|
| 1560 | Direction orientation = this.getOrientation();
|
| 1561 | if (orientation != null) {
|
| 1562 | switch (orientation) {
|
| 1563 | case NORTH:
|
| 1564 | return StrongholdPieces.generateAndAddPiece(
|
| 1565 | startPiece,
|
| 1566 | builder,
|
| 1567 | random,
|
| 1568 | this.boundingBox.minX() - 1,
|
| 1569 | this.boundingBox.minY() + yOff,
|
| 1570 | this.boundingBox.minZ() + zOff,
|
| 1571 | Direction.WEST,
|
| 1572 | this.getGenDepth()
|
| 1573 | );
|
| 1574 | case SOUTH:
|
| 1575 | return StrongholdPieces.generateAndAddPiece(
|
| 1576 | startPiece,
|
| 1577 | builder,
|
| 1578 | random,
|
| 1579 | this.boundingBox.minX() - 1,
|
| 1580 | this.boundingBox.minY() + yOff,
|
| 1581 | this.boundingBox.minZ() + zOff,
|
| 1582 | Direction.WEST,
|
| 1583 | this.getGenDepth()
|
| 1584 | );
|
| 1585 | case WEST:
|
| 1586 | return StrongholdPieces.generateAndAddPiece(
|
| 1587 | startPiece,
|
| 1588 | builder,
|
| 1589 | random,
|
| 1590 | this.boundingBox.minX() + zOff,
|
| 1591 | this.boundingBox.minY() + yOff,
|
| 1592 | this.boundingBox.minZ() - 1,
|
| 1593 | Direction.NORTH,
|
| 1594 | this.getGenDepth()
|
| 1595 | );
|
| 1596 | case EAST:
|
| 1597 | return StrongholdPieces.generateAndAddPiece(
|
| 1598 | startPiece,
|
| 1599 | builder,
|
| 1600 | random,
|
| 1601 | this.boundingBox.minX() + zOff,
|
| 1602 | this.boundingBox.minY() + yOff,
|
| 1603 | this.boundingBox.minZ() - 1,
|
| 1604 | Direction.NORTH,
|
| 1605 | this.getGenDepth()
|
| 1606 | );
|
| 1607 | }
|
| 1608 | }
|
| 1609 |
|
| 1610 | return null;
|
| 1611 | }
|
| 1612 |
|
| 1613 | protected @Nullable StructurePiece generateSmallDoorChildRight(
|
| 1614 | final StrongholdPieces.StartPiece startPiece, final StructurePiecesBuilder builder, final RandomSource random, final int yOff, final int zOff
|
| 1615 | ) {
|
| 1616 | Direction orientation = this.getOrientation();
|
| 1617 | if (orientation != null) {
|
| 1618 | switch (orientation) {
|
| 1619 | case NORTH:
|
| 1620 | return StrongholdPieces.generateAndAddPiece(
|
| 1621 | startPiece,
|
| 1622 | builder,
|
| 1623 | random,
|
| 1624 | this.boundingBox.maxX() + 1,
|
| 1625 | this.boundingBox.minY() + yOff,
|
| 1626 | this.boundingBox.minZ() + zOff,
|
| 1627 | Direction.EAST,
|
| 1628 | this.getGenDepth()
|
| 1629 | );
|
| 1630 | case SOUTH:
|
| 1631 | return StrongholdPieces.generateAndAddPiece(
|
| 1632 | startPiece,
|
| 1633 | builder,
|
| 1634 | random,
|
| 1635 | this.boundingBox.maxX() + 1,
|
| 1636 | this.boundingBox.minY() + yOff,
|
| 1637 | this.boundingBox.minZ() + zOff,
|
| 1638 | Direction.EAST,
|
| 1639 | this.getGenDepth()
|
| 1640 | );
|
| 1641 | case WEST:
|
| 1642 | return StrongholdPieces.generateAndAddPiece(
|
| 1643 | startPiece,
|
| 1644 | builder,
|
| 1645 | random,
|
| 1646 | this.boundingBox.minX() + zOff,
|
| 1647 | this.boundingBox.minY() + yOff,
|
| 1648 | this.boundingBox.maxZ() + 1,
|
| 1649 | Direction.SOUTH,
|
| 1650 | this.getGenDepth()
|
| 1651 | );
|
| 1652 | case EAST:
|
| 1653 | return StrongholdPieces.generateAndAddPiece(
|
| 1654 | startPiece,
|
| 1655 | builder,
|
| 1656 | random,
|
| 1657 | this.boundingBox.minX() + zOff,
|
| 1658 | this.boundingBox.minY() + yOff,
|
| 1659 | this.boundingBox.maxZ() + 1,
|
| 1660 | Direction.SOUTH,
|
| 1661 | this.getGenDepth()
|
| 1662 | );
|
| 1663 | }
|
| 1664 | }
|
| 1665 |
|
| 1666 | return null;
|
| 1667 | }
|
| 1668 |
|
| 1669 | protected static boolean isOkBox(final BoundingBox box) {
|
| 1670 | return box.minY() > 10;
|
| 1671 | }
|
| 1672 |
|
| 1673 | protected enum SmallDoorType {
|
| 1674 | OPENING,
|
| 1675 | WOOD_DOOR,
|
| 1676 | GRATES,
|
| 1677 | IRON_DOOR;
|
| 1678 |
|
| 1679 | @Deprecated
|
| 1680 | public static final Codec<StrongholdPieces.StrongholdPiece.SmallDoorType> LEGACY_CODEC = ExtraCodecs.legacyEnum(
|
| 1681 | StrongholdPieces.StrongholdPiece.SmallDoorType::valueOf
|
| 1682 | );
|
| 1683 | }
|
| 1684 | }
|
| 1685 |
|
| 1686 | public abstract static class Turn extends StrongholdPieces.StrongholdPiece {
|
| 1687 | protected static final int WIDTH = 5;
|
| 1688 | protected static final int HEIGHT = 5;
|
| 1689 | protected static final int DEPTH = 5;
|
| 1690 |
|
| 1691 | protected Turn(final StructurePieceType type, final int genDepth, final BoundingBox boundingBox) {
|
| 1692 | super(type, genDepth, boundingBox);
|
| 1693 | }
|
| 1694 |
|
| 1695 | public Turn(final StructurePieceType type, final CompoundTag tag) {
|
| 1696 | super(type, tag);
|
| 1697 | }
|
| 1698 | }
|
| 1699 | }
|
| 1700 |
|