Example #1
0
 public void handleTileEntities(Random rand) {
   final ArrayList<DungeonRoom> rooms = new ArrayList<DungeonRoom>();
   rooms.addAll(this.rooms);
   this.rooms.clear();
   for (final DungeonRoom room : rooms) {
     room.handleTileEntities(rand);
   }
 }
Example #2
0
  public void generate(
      World world,
      Random rand,
      int x,
      int y,
      int z,
      int chunkX,
      int chunkZ,
      Block[] blocks,
      byte[] metas,
      boolean useArrays) {
    MapGenDungeon.useArrays = useArrays;
    this.worldObj = world;

    final List<DungeonBoundingBox> boundingBoxes = new ArrayList<DungeonBoundingBox>();

    final int length = rand.nextInt(4) + 5;

    DungeonRoom currentRoom = DungeonRoom.makeRoom(this, rand, x, y, z, ForgeDirection.DOWN);
    currentRoom.generate(blocks, metas, chunkX, chunkZ);
    this.rooms.add(currentRoom);
    final DungeonBoundingBox cbb = currentRoom.getBoundingBox();
    boundingBoxes.add(cbb);
    this.generateEntranceCrater(
        blocks,
        metas,
        x + (cbb.maxX - cbb.minX) / 2,
        y,
        z + (cbb.maxZ - cbb.minZ) / 2,
        chunkX,
        chunkZ);

    for (int i = 0; i <= length; i++) {
      tryLoop:
      for (int j = 0; j < 8; j++) {
        int offsetX = 0;
        int offsetZ = 0;
        final ForgeDirection dir = this.randDir(rand);
        ForgeDirection entranceDir = dir;
        switch (dir)
        // East = 0, North = 1, South = 2, West = 3
        {
          case EAST: // East z++
            offsetZ = this.HALLWAY_LENGTH + rand.nextInt(15);
            if (rand.nextBoolean()) {
              if (rand.nextBoolean()) {
                entranceDir = ForgeDirection.NORTH;
                offsetX = this.HALLWAY_LENGTH + rand.nextInt(15);
              } else {
                entranceDir = ForgeDirection.SOUTH;
                offsetX = -this.HALLWAY_LENGTH - rand.nextInt(15);
              }
            }
            break;
          case NORTH: // North x++
            offsetX = this.HALLWAY_LENGTH + rand.nextInt(15);
            if (rand.nextBoolean()) {
              if (rand.nextBoolean()) {
                entranceDir = ForgeDirection.EAST;
                offsetZ = this.HALLWAY_LENGTH + rand.nextInt(15);
              } else {
                entranceDir = ForgeDirection.WEST;
                offsetZ = -this.HALLWAY_LENGTH - rand.nextInt(15);
              }
            }
            break;
          case SOUTH: // South x--
            offsetX = -this.HALLWAY_LENGTH - rand.nextInt(15);
            if (rand.nextBoolean()) {
              if (rand.nextBoolean()) {
                entranceDir = ForgeDirection.EAST;
                offsetZ = this.HALLWAY_LENGTH + rand.nextInt(15);
              } else {
                entranceDir = ForgeDirection.WEST;
                offsetZ = -this.HALLWAY_LENGTH - rand.nextInt(15);
              }
            }
            break;
          case WEST: // West z--
            offsetZ = -this.HALLWAY_LENGTH - rand.nextInt(15);
            if (rand.nextBoolean()) {
              if (rand.nextBoolean()) {
                entranceDir = ForgeDirection.NORTH;
                offsetX = this.HALLWAY_LENGTH + rand.nextInt(15);
              } else {
                entranceDir = ForgeDirection.SOUTH;
                offsetX = -this.HALLWAY_LENGTH - rand.nextInt(15);
              }
            }
            break;
          default:
            break;
        }

        DungeonRoom possibleRoom =
            DungeonRoom.makeRoom(
                this,
                rand,
                currentRoom.posX + offsetX,
                y,
                currentRoom.posZ + offsetZ,
                entranceDir.getOpposite()); // this.getOppositeDir(entranceDir));
        if (i == length - 1) {
          possibleRoom =
              DungeonRoom.makeBossRoom(
                  this,
                  rand,
                  currentRoom.posX + offsetX,
                  y,
                  currentRoom.posZ + offsetZ,
                  entranceDir.getOpposite()); // this.getOppositeDir(entranceDir));
        }
        if (i == length) {
          possibleRoom =
              DungeonRoom.makeTreasureRoom(
                  this,
                  rand,
                  currentRoom.posX + offsetX,
                  y,
                  currentRoom.posZ + offsetZ,
                  entranceDir.getOpposite()); // this.getOppositeDir(entranceDir));
        }
        final DungeonBoundingBox possibleRoomBb = possibleRoom.getBoundingBox();
        final DungeonBoundingBox currentRoomBb = currentRoom.getBoundingBox();
        if (!this.isIntersecting(possibleRoomBb, boundingBoxes)) {
          final int curCenterX = (currentRoomBb.minX + currentRoomBb.maxX) / 2;
          final int curCenterZ = (currentRoomBb.minZ + currentRoomBb.maxZ) / 2;
          final int possibleCenterX = (possibleRoomBb.minX + possibleRoomBb.maxX) / 2;
          final int possibleCenterZ = (possibleRoomBb.minZ + possibleRoomBb.maxZ) / 2;
          final int corridorX =
              this.clamp(
                  (curCenterX + possibleCenterX) / 2,
                  Math.max(currentRoomBb.minX + 1, possibleRoomBb.minX + 1),
                  Math.min(currentRoomBb.maxX - 1, possibleRoomBb.maxX - 1));
          final int corridorZ =
              this.clamp(
                  (curCenterZ + possibleCenterZ) / 2,
                  Math.max(currentRoomBb.minZ + 1, possibleRoomBb.minZ + 1),
                  Math.min(currentRoomBb.maxZ - 1, possibleRoomBb.maxZ - 1));
          if (offsetX == 0 || offsetZ == 0) // Only 1 hallway
          {
            DungeonBoundingBox corridor1 = null;
            switch (dir)
            // East = 0, North = 1, South = 2, West = 3
            {
              case EAST: // East z++
                corridor1 =
                    new DungeonBoundingBox(
                        corridorX - 1, currentRoomBb.maxZ, corridorX, possibleRoomBb.minZ - 1);
                break;
              case NORTH: // North x++
                corridor1 =
                    new DungeonBoundingBox(
                        currentRoomBb.maxX, corridorZ - 1, possibleRoomBb.minX - 1, corridorZ);
                break;
              case SOUTH: // South x--
                corridor1 =
                    new DungeonBoundingBox(
                        possibleRoomBb.maxX, corridorZ - 1, currentRoomBb.minX - 1, corridorZ);
                break;
              case WEST: // West z--
                corridor1 =
                    new DungeonBoundingBox(
                        corridorX - 1, possibleRoomBb.maxZ, corridorX, currentRoomBb.minZ - 1);
                break;
              default:
                break;
            }
            if (!this.isIntersecting(corridor1, boundingBoxes)
                && !corridor1.isOverlapping(possibleRoomBb)) {
              boundingBoxes.add(possibleRoomBb);
              boundingBoxes.add(corridor1);
              currentRoom = possibleRoom;
              currentRoom.generate(blocks, metas, chunkX, chunkZ);
              this.rooms.add(currentRoom);
              if (corridor1 != null) {
                this.genCorridor(
                    corridor1, rand, possibleRoom.posY, chunkX, chunkZ, dir, blocks, metas, false);
              }
              break;
            }
          } else
          // Two Hallways
          {
            DungeonBoundingBox corridor1 = null;
            DungeonBoundingBox corridor2 = null;
            ForgeDirection dir2 = ForgeDirection.EAST;
            int extraLength = 0;
            if (rand.nextInt(6) == 0) {
              extraLength = rand.nextInt(7);
            }
            switch (dir)
            // East = 0, North = 1, South = 2, West = 3
            {
              case EAST: // East z++
                corridor1 =
                    new DungeonBoundingBox(
                        curCenterX - 1, currentRoomBb.maxZ, curCenterX + 1, possibleCenterZ - 1);
                if (offsetX > 0) // x++
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          corridor1.minX - extraLength,
                          corridor1.maxZ + 1,
                          possibleRoomBb.minX,
                          corridor1.maxZ + 3);
                  dir2 = ForgeDirection.NORTH;
                } else
                // x--
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          possibleRoomBb.maxX,
                          corridor1.maxZ + 1,
                          corridor1.maxX + extraLength,
                          corridor1.maxZ + 3);
                  dir2 = ForgeDirection.SOUTH;
                }
                break;
              case NORTH: // North x++
                corridor1 =
                    new DungeonBoundingBox(
                        currentRoomBb.maxX, curCenterZ - 1, possibleCenterX - 1, curCenterZ + 1);
                if (offsetZ > 0) // z++
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          corridor1.maxX + 1,
                          corridor1.minZ - extraLength,
                          corridor1.maxX + 4,
                          possibleRoomBb.minZ);
                  dir2 = ForgeDirection.EAST;
                } else
                // z--
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          corridor1.maxX + 1,
                          possibleRoomBb.maxZ,
                          corridor1.maxX + 4,
                          corridor1.maxZ + extraLength);
                  dir2 = ForgeDirection.WEST;
                }
                break;
              case SOUTH: // South x--
                corridor1 =
                    new DungeonBoundingBox(
                        possibleCenterX + 1,
                        curCenterZ - 1,
                        currentRoomBb.minX - 1,
                        curCenterZ + 1);
                if (offsetZ > 0) // z++
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          corridor1.minX - 3,
                          corridor1.minZ - extraLength,
                          corridor1.minX - 1,
                          possibleRoomBb.minZ);
                  dir2 = ForgeDirection.EAST;
                } else
                // z--
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          corridor1.minX - 3,
                          possibleRoomBb.maxZ,
                          corridor1.minX - 1,
                          corridor1.maxZ + extraLength);
                  dir2 = ForgeDirection.WEST;
                }
                break;
              case WEST: // West z--
                corridor1 =
                    new DungeonBoundingBox(
                        curCenterX - 1,
                        possibleCenterZ + 1,
                        curCenterX + 1,
                        currentRoomBb.minZ - 1);
                if (offsetX > 0) // x++
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          corridor1.minX - extraLength,
                          corridor1.minZ - 3,
                          possibleRoomBb.minX,
                          corridor1.minZ - 1);
                  dir2 = ForgeDirection.NORTH;
                } else
                // x--
                {
                  corridor2 =
                      new DungeonBoundingBox(
                          possibleRoomBb.maxX,
                          corridor1.minZ - 3,
                          corridor1.maxX + extraLength,
                          corridor1.minZ - 1);
                  dir2 = ForgeDirection.SOUTH;
                }
                break;
              default:
                break;
            }
            if (!this.isIntersecting(corridor1, boundingBoxes)
                && !this.isIntersecting(corridor2, boundingBoxes)
                && !corridor1.isOverlapping(possibleRoomBb)
                && !corridor2.isOverlapping(possibleRoomBb)) {
              boundingBoxes.add(possibleRoomBb);
              boundingBoxes.add(corridor1);
              boundingBoxes.add(corridor2);
              currentRoom = possibleRoom;
              currentRoom.generate(blocks, metas, chunkX, chunkZ);
              this.rooms.add(currentRoom);
              if (corridor1 != null && corridor2 != null) {
                this.genCorridor(
                    corridor2, rand, possibleRoom.posY, chunkX, chunkZ, dir2, blocks, metas, true);
                this.genCorridor(
                    corridor1, rand, possibleRoom.posY, chunkX, chunkZ, dir, blocks, metas, false);
              }
              break;
            } else {
            }
          }
        } else {
        }
      }
    }
  }