private void step(IWorldEditor editor, Random rand, ITheme theme, Cardinal dir, Coord origin) {

    if (editor.getBlock(origin).isOpaqueCube()) return;

    Coord start;
    Coord end;

    IStair stair = theme.getPrimaryStair();
    IBlockFactory blocks = theme.getPrimaryWall();

    Cardinal[] orth = Cardinal.orthogonal(dir);

    start = new Coord(origin);
    end = new Coord(origin);
    start.add(orth[0]);
    end.add(orth[1]);
    end = new Coord(end.getX(), 60, end.getZ());
    RectSolid.fill(editor, rand, start, end, blocks, true, true);

    start = new Coord(origin);
    end = new Coord(origin);
    start.add(orth[0]);
    end.add(orth[1]);
    stair.setOrientation(dir, false);
    RectSolid.fill(editor, rand, start, end, stair, true, true);

    origin.add(Cardinal.DOWN);
    origin.add(dir);
    step(editor, rand, theme, dir, origin);
  }
示例#2
0
  public static boolean generate(World world, Cardinal dir, Coord pos) {

    MetaBlock container = new MetaBlock(Blocks.dispenser);
    container.withProperty(BlockDispenser.FACING, Cardinal.getFacing(dir));
    container.setBlock(world, pos);
    return true;
  }
  private static void lamp(World world, Coord pos) {

    MetaBlock spruce = new MetaBlock(Blocks.planks);
    MetaBlock fence = new MetaBlock(Blocks.oak_fence);
    spruce.withProperty(BlockPlanks.VARIANT_PROP, BlockPlanks.EnumType.SPRUCE);
    Coord cursor = new Coord(pos);
    cursor.add(Cardinal.UP, 4);
    spruce.setBlock(world, new Coord(cursor));
    cursor.add(Cardinal.DOWN);
    WorldGenPrimitive.setBlock(world, cursor, Blocks.oak_fence);
    cursor.add(Cardinal.DOWN);
    WorldGenPrimitive.setBlock(world, cursor, Blocks.glowstone);

    for (Cardinal dir : Cardinal.directions) {
      MetaBlock trapdoor = new MetaBlock(Blocks.trapdoor);
      trapdoor.withProperty(BlockTrapDoor.FACING_PROP, Cardinal.getFacing(dir));
      trapdoor.withProperty(BlockTrapDoor.OPEN_PROP, true);
      Coord p = new Coord(cursor);
      trapdoor.setBlock(world, p);
    }

    cursor.add(Cardinal.DOWN);
    fence.setBlock(world, cursor);
    cursor.add(Cardinal.DOWN);
    spruce.setBlock(world, cursor);
  }
  @Override
  public boolean validLocation(World world, Cardinal dir, int x, int y, int z) {
    Coord start;
    Coord end;

    start = new Coord(x, y, z);
    end = new Coord(start);
    start.add(Cardinal.reverse(dir), 9);
    end.add(dir, 9);
    Cardinal[] orth = Cardinal.getOrthogonal(dir);
    start.add(orth[0], 5);
    end.add(orth[1], 5);
    start.add(Cardinal.DOWN);
    end.add(Cardinal.UP, 3);

    for (Coord c : WorldGenPrimitive.getRectHollow(start, end)) {
      if (world.isAirBlock(c.getBlockPos())) return false;
    }

    return true;
  }
  @Override
  public boolean generate(
      World world, Random rand, LevelSettings settings, Cardinal[] entrances, Coord origin) {

    int x = origin.getX();
    int y = origin.getY();
    int z = origin.getZ();
    MetaBlock breadboard = new MetaBlock(Blocks.planks);

    Coord cursor;
    Coord start;
    Coord end;

    Cardinal dir = entrances[0];
    start = new Coord(x, y, z);
    end = new Coord(start);
    start.add(Cardinal.reverse(dir), 9);
    end.add(dir, 9);
    Cardinal[] orth = Cardinal.getOrthogonal(dir);
    start.add(orth[0], 4);
    end.add(orth[1], 4);
    start.add(Cardinal.DOWN);
    end.add(Cardinal.UP, 3);
    WorldGenPrimitive.fillRectHollow(
        world, rand, start, end, new MetaBlock(Blocks.cobblestone), false, true);

    start = new Coord(x, y, z);
    start.add(orth[0], 2);
    end = new Coord(start);
    start.add(Cardinal.reverse(dir), 3);
    end.add(dir, 7);
    end.add(Cardinal.UP);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, breadboard, true, true);

    start.add(orth[1], 2);
    end.add(orth[1], 2);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, breadboard, true, true);

    start.add(orth[1], 2);
    end.add(orth[1], 2);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, breadboard, true, true);

    cursor = new Coord(x, y, z);
    cursor.add(orth[0], 2);

    launcher(world, rand, dir, cursor);
    cursor.add(orth[1], 2);
    launcher(world, rand, dir, cursor);
    cursor.add(orth[1], 2);
    launcher(world, rand, dir, cursor);
    cursor.add(dir, 6);
    launcher(world, rand, dir, cursor);
    cursor.add(orth[0], 2);
    launcher(world, rand, dir, cursor);
    cursor.add(orth[0], 2);
    launcher(world, rand, dir, cursor);

    start = new Coord(x, y, z);
    start.add(dir, 4);
    end = new Coord(start);
    start.add(orth[0], 2);
    end.add(orth[1], 2);
    end.add(dir, 2);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, new MetaBlock(Blocks.air), true, true);

    cursor = new Coord(x, y, z);
    cursor.add(dir, 2);
    Repeater.generate(world, rand, dir, 0, cursor);
    cursor.add(orth[0], 2);
    Repeater.generate(world, rand, dir, 0, cursor);
    cursor.add(orth[1], 4);
    Repeater.generate(world, rand, dir, 0, cursor);

    cursor = new Coord(x, y, z);
    cursor.add(Cardinal.reverse(dir), 3);
    cursor.add(orth[0]);
    Repeater.generate(world, rand, orth[0], 0, cursor);
    cursor.add(orth[1], 2);
    Repeater.generate(world, rand, orth[1], 0, cursor);

    MetaBlock wire = new MetaBlock(Blocks.redstone_wire);

    start = new Coord(x, y, z);
    start.add(Cardinal.DOWN, 2);
    start.add(orth[1]);
    start.add(Cardinal.reverse(dir), 2);
    end = new Coord(start);
    end.add(orth[0], 5);
    end.add(Cardinal.reverse(dir), 5);
    end.add(Cardinal.DOWN, 2);
    WorldGenPrimitive.fillRectSolid(
        world, rand, start, end, new MetaBlock(Blocks.cobblestone), true, true);

    cursor = new Coord(x, y, z);
    cursor.add(Cardinal.reverse(dir), 3);
    cursor.add(Cardinal.DOWN);
    Torch.generate(world, Torch.REDSTONE, Cardinal.UP, cursor);
    cursor.add(Cardinal.DOWN);
    breadboard.setBlock(world, cursor);
    cursor.add(orth[0]);
    Torch.generate(world, Torch.REDSTONE, orth[0], cursor);
    cursor.add(orth[0]);
    wire.setBlock(world, cursor);
    cursor.add(Cardinal.reverse(dir));
    wire.setBlock(world, cursor);
    cursor.add(Cardinal.reverse(dir));
    wire.setBlock(world, cursor);
    cursor.add(orth[1]);
    wire.setBlock(world, cursor);
    cursor.add(orth[1]);
    wire.setBlock(world, cursor);
    cursor.add(dir);
    Repeater.generate(world, rand, Cardinal.reverse(dir), 4, cursor);
    cursor.add(Cardinal.UP);
    cursor.add(Cardinal.reverse(dir));
    breadboard.setBlock(world, cursor);
    cursor.add(Cardinal.UP);
    Lever.generate(world, Cardinal.UP, cursor, true);

    return false;
  }
  private void launcher(World world, Random rand, Cardinal dir, Coord pos) {
    Coord cursor = new Coord(pos);
    WorldGenPrimitive.setBlock(world, cursor, Blocks.redstone_wire);
    cursor.add(Cardinal.reverse(dir));
    WorldGenPrimitive.setBlock(world, cursor, Blocks.redstone_wire);
    cursor.add(Cardinal.reverse(dir));
    Repeater.generate(world, rand, dir, 0, cursor);
    cursor.add(Cardinal.reverse(dir));
    cursor.add(Cardinal.UP);

    Dropper dropper = new Dropper();
    dropper.generate(world, Cardinal.UP, cursor);
    for (int i = 0; i < 8; ++i) {
      dropper.add(world, cursor, i, new ItemStack(Items.dye, 1, i));
    }
    dropper.add(world, cursor, 8, new ItemStack(Items.wooden_hoe));

    cursor.add(Cardinal.UP);
    WorldGenPrimitive.setBlock(world, cursor, Blocks.hopper);
    cursor.add(dir);
    Comparator.generate(world, rand, dir, false, cursor);
    cursor.add(dir);
    WorldGenPrimitive.setBlock(world, cursor, Blocks.redstone_wire);
    cursor.add(dir);
    WorldGenPrimitive.setBlock(world, cursor, Blocks.redstone_wire);
    cursor.add(dir);

    Coord top = new Coord(pos.getX(), 80, pos.getZ());
    while (top.getY() > pos.getY()) {
      top.add(Cardinal.DOWN);
      if (WorldGenPrimitive.getBlock(world, top).getBlock().getMaterial().isSolid()) break;
    }

    if (top.getY() >= 100) return;

    Coord start = new Coord(cursor);
    start.add(Cardinal.UP);

    start.add(dir);
    Coord end = new Coord(start);

    MetaBlock breadboard = new MetaBlock(Blocks.planks);

    boolean torch = false;
    while (end.getY() < top.getY()) {
      if (torch) {
        Torch.generate(world, Torch.REDSTONE, Cardinal.UP, cursor);
      } else {
        breadboard.setBlock(world, cursor);
      }
      torch = !torch;
      cursor.add(Cardinal.UP);
      end.add(Cardinal.UP);
    }

    if (torch) {
      cursor.add(Cardinal.DOWN);
    }

    Dispenser.generate(world, Cardinal.UP, cursor);
    for (int i = 0; i < 9; i++) {
      Dispenser.add(world, cursor, i, Firework.get(rand, 16 + rand.nextInt(16)));
    }

    cursor.add(Cardinal.UP);
    MetaBlock cob = new MetaBlock(Blocks.cobblestone);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, cob, true, true);
    start.add(Cardinal.reverse(dir), 2);
    end.add(Cardinal.reverse(dir), 2);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, cob, true, true);
    Cardinal[] orth = Cardinal.getOrthogonal(dir);
    start.add(dir);
    end.add(dir);
    Coord above = new Coord(end);
    above.add(Cardinal.UP, 10);
    List<Coord> tubeEnd = WorldGenPrimitive.getRectSolid(cursor, above);
    MetaBlock air = new MetaBlock(Blocks.air);
    for (Coord c : tubeEnd) {
      if (WorldGenPrimitive.getBlock(world, c).getBlock().getMaterial().isSolid()) {
        air.setBlock(world, c);
      }
    }
    start.add(orth[0]);
    end.add(orth[0]);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, cob, true, true);
    start.add(orth[1], 2);
    end.add(orth[1], 2);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, cob, true, true);
  }
  @Override
  protected void genWall(
      World world,
      Random rand,
      IDungeonLevel level,
      Cardinal dir,
      ITheme theme,
      int x,
      int y,
      int z) {

    MetaBlock air = new MetaBlock(Blocks.air);
    MetaBlock stair = theme.getSecondaryStair();

    Coord cursor;
    Coord start;
    Coord end;

    Cardinal[] orth = Cardinal.getOrthogonal(dir);

    start = new Coord(x, y, z);
    start.add(dir, 2);
    end = new Coord(start);
    start.add(orth[0], 1);
    end.add(orth[1], 1);
    end.add(Cardinal.UP, 2);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, air, true, true);
    start.add(dir, 1);
    end.add(dir, 1);
    WorldGenPrimitive.fillRectSolid(world, rand, start, end, theme.getSecondaryWall(), true, true);

    for (Cardinal d : orth) {
      cursor = new Coord(x, y, z);
      cursor.add(Cardinal.UP, 2);
      cursor.add(dir, 2);
      cursor.add(d, 1);
      WorldGenPrimitive.blockOrientation(stair, Cardinal.reverse(dir), true);
      WorldGenPrimitive.setBlock(world, rand, cursor, stair, true, true);

      cursor = new Coord(x, y, z);
      cursor.add(dir, 2);
      cursor.add(d, 1);
      WorldGenPrimitive.blockOrientation(stair, Cardinal.reverse(d), false);
      WorldGenPrimitive.setBlock(world, rand, cursor, stair, true, true);
    }

    cursor = new Coord(x, y, z);
    cursor.add(Cardinal.UP, 1);
    cursor.add(dir, 3);
    WorldGenPrimitive.setBlock(world, rand, cursor, air, true, true);
    cursor.add(Cardinal.UP, 1);
    WorldGenPrimitive.blockOrientation(stair, Cardinal.reverse(dir), true);
    WorldGenPrimitive.setBlock(world, rand, cursor, stair, true, true);

    Coord shelf = new Coord(x, y, z);
    shelf.add(dir, 3);
    Coord below = new Coord(shelf);
    shelf.add(Cardinal.UP, 1);

    if (world.isAirBlock(below.getBlockPos())) return;

    boolean trapped = Dungeon.getLevel(y) == 3 && rand.nextInt(3) == 0;
    TreasureChest.generate(world, rand, level.getSettings(), shelf, Dungeon.getLevel(y), trapped);
    if (trapped) {
      WorldGenPrimitive.setBlock(world, shelf.getX(), shelf.getY() - 2, shelf.getZ(), Blocks.tnt);
      if (rand.nextBoolean())
        WorldGenPrimitive.setBlock(world, shelf.getX(), shelf.getY() - 3, shelf.getZ(), Blocks.tnt);
    }
  }
  @Override
  public void generate(IWorldEditor editor, Random rand, ITheme theme, Coord dungeon) {

    IBlockFactory primary = theme.getPrimaryWall();
    IBlockFactory pillar = theme.getSecondaryPillar();

    IStair stair = theme.getSecondaryStair();

    Coord floor = Tower.getBaseCoord(editor, dungeon);

    Coord start = new Coord(floor);
    Coord end = new Coord(start);
    Coord cursor;

    int x = dungeon.getX();
    int z = dungeon.getZ();

    start.add(Cardinal.NORTH, 3);
    start.add(Cardinal.WEST, 3);
    end.add(Cardinal.SOUTH, 3);
    end.add(Cardinal.EAST, 3);
    end.add(Cardinal.UP, 4);

    // WorldGenPrimitive.fillRectSolid(rand, start, end, air, true, true);

    start.add(Cardinal.NORTH);
    start.add(Cardinal.WEST);
    start.add(Cardinal.DOWN);
    end.add(Cardinal.SOUTH);
    end.add(Cardinal.EAST);
    end.add(Cardinal.UP);

    RectHollow.fill(editor, rand, start, end, primary, true, true);

    for (Cardinal dir : Cardinal.directions) {

      Cardinal[] orth = Cardinal.orthogonal(dir);
      start = new Coord(floor);
      start.add(dir, 3);
      start.add(orth[0], 3);
      end = new Coord(start);
      end.add(Cardinal.UP, 6);

      RectSolid.fill(editor, rand, start, end, pillar, true, true);

      for (Cardinal o : orth) {
        start = new Coord(floor);
        start.add(dir, 5);
        start.add(o, 4);
        end = new Coord(start);
        end.add(Cardinal.UP, 4);
        start.add(Cardinal.DOWN, 10);
        RectSolid.fill(editor, rand, start, end, pillar, true, true);

        end.add(Cardinal.UP);
        stair.setOrientation(dir, false).set(editor, end);

        end.add(Cardinal.reverse(dir));
        end.add(Cardinal.reverse(o));
        stair.setOrientation(Cardinal.reverse(o), false).set(editor, end);
        end.add(Cardinal.reverse(o));
        start = new Coord(end);
        start.add(Cardinal.reverse(o), 2);
        RectSolid.fill(editor, rand, start, end, stair.setOrientation(dir, false), true, true);

        end.add(Cardinal.reverse(dir));
        end.add(Cardinal.UP);
        start.add(Cardinal.reverse(dir));
        start.add(Cardinal.UP);
        RectSolid.fill(editor, rand, start, end, stair.setOrientation(dir, false), true, true);
        stair.setOrientation(Cardinal.reverse(o), false).set(editor, end);

        start = new Coord(floor);
        start.add(dir, 3);
        start.add(Cardinal.UP, 4);
        end = new Coord(start);
        end.add(o, 2);
        RectSolid.fill(
            editor,
            rand,
            start,
            end,
            stair.setOrientation(Cardinal.reverse(dir), true),
            true,
            true);
        start.add(Cardinal.reverse(dir));
        start.add(Cardinal.UP);
        end = new Coord(start);
        end.add(o, 2);
        RectSolid.fill(
            editor,
            rand,
            start,
            end,
            stair.setOrientation(Cardinal.reverse(dir), true),
            true,
            true);
        start.add(Cardinal.UP);
        end.add(Cardinal.UP);
        RectSolid.fill(editor, rand, start, end, pillar, true, true);
        cursor = new Coord(end);
        start = new Coord(end);
        start.add(Cardinal.UP, 3);
        RectSolid.fill(editor, rand, start, end, pillar, true, true);
        cursor.add(Cardinal.reverse(o));
        cursor.add(Cardinal.UP);
        stair.setOrientation(Cardinal.reverse(o), false).set(editor, cursor);
        cursor.add(Cardinal.UP, 2);
        stair.setOrientation(Cardinal.reverse(o), true).set(editor, cursor);
        start.add(Cardinal.UP);
        end = new Coord(start);
        end.add(Cardinal.reverse(o), 2);
        RectSolid.fill(editor, rand, start, end, stair.setOrientation(dir, false), true, true);
        cursor = new Coord(end);
        cursor.add(Cardinal.reverse(dir));
        stair.setOrientation(Cardinal.reverse(dir), true).set(editor, cursor);
        cursor.add(o);
        stair.setOrientation(Cardinal.reverse(dir), true).set(editor, cursor);
        cursor.add(Cardinal.UP);
        stair.setOrientation(dir, false).set(editor, cursor);
        cursor.add(Cardinal.reverse(o));
        stair.setOrientation(dir, false).set(editor, cursor);
      }
    }

    Cardinal front = Cardinal.NORTH;

    for (Cardinal dir : Cardinal.directions) {
      cursor = new Coord(floor);
      cursor.add(dir, 6);
      if (editor.isAirBlock(cursor)) {
        front = dir;
        break;
      }
    }

    for (Cardinal dir : Cardinal.directions) {

      if (dir == front) {

        for (Cardinal o : Cardinal.orthogonal(dir)) {
          cursor = new Coord(floor);
          cursor.add(dir, 5);
          cursor.add(o, 2);
          primary.set(editor, rand, cursor);
          cursor.add(o);
          stair.setOrientation(o, false).set(editor, cursor);
          cursor.add(dir);
          stair.setOrientation(o, false).set(editor, cursor);
          cursor.add(Cardinal.reverse(o));
          stair.setOrientation(dir, false).set(editor, cursor);
          cursor.add(Cardinal.reverse(dir));
          cursor.add(Cardinal.UP);
          stair.setOrientation(Cardinal.reverse(o), false).set(editor, cursor);
          cursor.add(Cardinal.UP);
          stair.setOrientation(dir, false).set(editor, cursor);
          cursor.add(o);
          stair.setOrientation(o, false).set(editor, cursor);
          cursor.add(Cardinal.reverse(o));
          cursor.add(Cardinal.UP);
          stair.setOrientation(Cardinal.reverse(o), false).set(editor, cursor);
          cursor.add(Cardinal.reverse(o));
          stair.setOrientation(Cardinal.reverse(o), true).set(editor, cursor);
          cursor.add(Cardinal.reverse(o));
          cursor.add(Cardinal.UP);
          stair.setOrientation(dir, false).set(editor, cursor);
          cursor.add(o);
          stair.setOrientation(dir, false).set(editor, cursor);
          cursor.add(o);
          stair.setOrientation(o, false).set(editor, cursor);
        }

        // carve doorway
        Cardinal[] orth = Cardinal.orthogonal(dir);
        cursor = new Coord(floor);
        cursor.add(dir, 4);
        start = new Coord(cursor);
        end = new Coord(start);
        start.add(orth[0]);
        end.add(Cardinal.UP, 2);
        end.add(orth[1]);
        RectSolid.fill(editor, rand, start, end, BlockType.get(BlockType.AIR), true, true);

        cursor = new Coord(floor);
        cursor.add(dir, 6);
        cursor.add(Cardinal.DOWN);
        step(editor, rand, theme, dir, cursor);

        continue;
      }

      for (Cardinal o : Cardinal.orthogonal(dir)) {
        start = new Coord(floor);
        start.add(Cardinal.UP, 4);
        start.add(dir, 5);
        end = new Coord(start);
        start.add(o, 2);
        RectSolid.fill(editor, rand, start, end, stair.setOrientation(dir, false), true, true);
        start.add(o);
        stair.setOrientation(Cardinal.reverse(o), false).set(editor, start);
        start.add(Cardinal.DOWN);
        stair.setOrientation(Cardinal.reverse(o), true).set(editor, start);
      }
    }

    for (int i = floor.getY() - 1; i >= 50; --i) {
      editor.spiralStairStep(rand, new Coord(x, i, z), stair, theme.getPrimaryPillar());
    }
  }