protected void a(
      Random rand,
      int i,
      int j,
      byte abyte0[],
      double d,
      double d1,
      double d2,
      float f,
      float f1,
      float f2,
      int k,
      int l,
      double d3) {
    if (generator != null) {
      generator.setNoise(i, j);
    }
    double d4 = i * 16 + 8;
    double d5 = j * 16 + 8;
    float f3 = 0.0F;
    float f4 = 0.0F;
    Random random = new Random(rand.nextLong());
    if (l <= 0) {
      int i1 = 8 * 16 - 16;
      l = i1 - random.nextInt(i1 / 4);
    }
    boolean flag = false;
    if (k == -1) {
      k = l / 2;
      flag = true;
    }
    int j1 = random.nextInt(l / 2) + l / 4;
    boolean flag1 = random.nextInt(6) == 0;
    for (; k < l; k++) {

      double d6 = 1.5D + (double) (MathHelper.sin(((float) k * 3.141593F) / (float) l) * f * 1.0F);
      double d7 = d6 * d3;
      float f5 = MathHelper.cos(f2);
      float f6 = MathHelper.sin(f2);
      d += MathHelper.cos(f1) * f5;
      d1 += f6;
      d2 += MathHelper.sin(f1) * f5;
      if (flag1) {
        f2 *= 0.92F;
      } else {
        f2 *= 0.7F;
      }
      f2 += f4 * 0.1F;
      f1 += f3 * 0.1F;
      f4 *= 0.9F;
      f3 *= 0.75F;
      f4 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2.0F;
      f3 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4F;
      if (!flag && k == j1 && f > 1.0F) {
        a(
            rand,
            i,
            j,
            abyte0,
            d,
            d1,
            d2,
            random.nextFloat() * 0.5F + 0.5F,
            f1 - 1.570796F,
            f2 / 3F,
            k,
            l,
            1.0D);
        a(
            rand,
            i,
            j,
            abyte0,
            d,
            d1,
            d2,
            random.nextFloat() * 0.5F + 0.5F,
            f1 + 1.570796F,
            f2 / 3F,
            k,
            l,
            1.0D);
        return;
      }
      if (!flag && random.nextInt(4) == 0) {
        continue;
      }
      double d8 = d - d4;
      double d9 = d2 - d5;
      double d10 = l - k;
      double d11 = f + 2.0F + 16F;
      if ((d8 * d8 + d9 * d9) - d10 * d10 > d11 * d11) {
        return;
      }
      if (d < d4 - 16D - d6 * 2D
          || d2 < d5 - 16D - d6 * 2D
          || d > d4 + 16D + d6 * 2D
          || d2 > d5 + 16D + d6 * 2D) {
        continue;
      }
      int k1 = MathHelper.floor_double(d - d6) - i * 16 - 1;
      int l1 = (MathHelper.floor_double(d + d6) - i * 16) + 1;
      int i2 = MathHelper.floor_double(d1 - d7) - 1;
      int j2 = MathHelper.floor_double(d1 + d7) + 1;
      int k2 = MathHelper.floor_double(d2 - d6) - j * 16 - 1;
      int l2 = (MathHelper.floor_double(d2 + d6) - j * 16) + 1;
      if (k1 < 0) {
        k1 = 0;
      }
      if (l1 > 16) {
        l1 = 16;
      }
      if (i2 < 1) {
        i2 = 1;
      }
      if (j2 > 120) {
        j2 = 120;
      }
      if (k2 < 0) {
        k2 = 0;
      }
      if (l2 > 16) {
        l2 = 16;
      }
      boolean flag2 = false;
      for (int k3 = k1; !flag2 && k3 < l1; k3++) {
        for (int i4 = k2; !flag2 && i4 < l2; i4++) {
          for (int j4 = j2 + 1; !flag2 && j4 >= i2 - 1; j4--) {
            int i3 = (k3 * 16 + i4) * 128 + j4;
            if (j4 >= 0 && j4 < 128) {
              if (abyte0[i3] == Material.WATER.getId()
                  || abyte0[i3] == Material.STATIONARY_WATER.getId()
                  || abyte0[i3] == Material.LAVA.getId()
                  || abyte0[i3] == Material.STATIONARY_LAVA.getId()) {
                flag2 = true;
              }
              if (j4 != i2 - 1 && k3 != k1 && k3 != l1 - 1 && i4 != k2 && i4 != l2 - 1) {
                j4 = i2;
              }
            }
          }
        }
      }

      if (flag2) {
        continue;
      }
      for (int l3 = k1; l3 < l1; l3++) {
        double d12 = (((double) (l3 + i * 16) + 0.5D) - d) / d6;
        for (int j3 = k2; j3 < l2; j3++) {
          generator.midY = generator.getSurfaceLevel(l3, j3);
          double d13 = (((double) (j3 + j * 16) + 0.5D) - d2) / d6;
          int k4 = (l3 * 16 + j3) * 128 + j2;
          for (int l4 = j2 - 1; l4 >= i2; l4--) {
            double d14 = (((double) l4 + 0.5D) - d1) / d7;
            if (d14 > -0.69999999999999996D && d12 * d12 + d14 * d14 + d13 * d13 < 1.0D) {
              byte byte0 = abyte0[k4];
              if (byte0 == Material.STONE.getId()
                  || byte0 == Material.SAND.getId()
                  || byte0 == Material.GRAVEL.getId()
                  || byte0 == Material.DIAMOND_ORE.getId()
                  || byte0 == Material.LAPIS_ORE.getId()) {
                double d15 =
                    generator.getMainDistance(
                        (int) Math.round((d4 + (double) l3) - 8D),
                        l4 - 1,
                        (int) Math.round((d5 + (double) j3) - 8D));
                if (l4 < BiosphereGenerator.LAVA_LEVEL) {
                  if (generator != null) {
                    if (d15 >= generator.sphereRadius && d15 < generator.sphereRadius + 5D) {
                      abyte0[k4] = (byte) Material.BEDROCK.getId();
                    } else if (d15 < generator.sphereRadius) {
                      abyte0[k4] = (byte) Material.LAVA.getId();
                    }
                  } else {
                    abyte0[k4] = (byte) Material.LAVA.getId();
                  }
                } else if ((l4 < generator.midY - 2 || l4 > generator.midY - 1)
                    && (d15 <= 2 + generator.sphereRadius)) {
                  abyte0[k4] = 0;
                }
              }
            }
            k4--;
          }
        }
      }

      if (flag) {
        break;
      }
    }
  }
Ejemplo n.º 2
0
public abstract class BananaWellArchetype extends WellArchetype {

  // normal materials
  protected byte byteLiquid = (byte) Material.STATIONARY_WATER.getId();
  protected byte byteStone = (byte) Material.STONE.getId();
  protected byte byteDirt = (byte) Material.DIRT.getId();
  protected byte byteGrass = (byte) Material.GRASS.getId();
  protected byte byteLog = (byte) Material.LOG.getId();
  protected byte byteLeaves = (byte) Material.LEAVES.getId();
  protected byte byteAir = (byte) Material.AIR.getId();
  protected int intOre = byteStone;
  protected int intTreeBase = byteGrass;
  protected int intTreeTrunk = byteLog;
  protected int intTreeLeaves = byteLeaves;

  protected byte byteTreeData = 0;
  protected int intAir = Material.AIR.getId();
  protected int minTreeHeight = 5;
  protected int maxTreeHeight = 5;

  public BananaWellArchetype(World world, long seed, int wellX, int wellZ) {
    super(world, seed, wellX, wellZ);

    // figure out materials
    calculateMaterials();
  }

  // override this if you want something special
  protected void calculateMaterials() {
    randomizeMaterials();

    //  copy over the "seed" materials used by populateOres and populateFoliage
    intOre = byteStone;
    intTreeBase = byteGrass;
  }

  protected void randomizeMaterials() {
    switch (random.nextInt(5)) {
      case 0:
        // lava, sand/sandstone/stone, mushroom stalks
        byteLiquid = (byte) Material.STATIONARY_LAVA.getId();
        byteStone = (byte) Material.STONE.getId();
        byteDirt = (byte) Material.SANDSTONE.getId();
        byteGrass = (byte) Material.SAND.getId();
        intTreeTrunk = Material.HUGE_MUSHROOM_1.getId();
        intTreeLeaves = intAir;
        byteTreeData = (byte) (random.nextInt(2) == 0 ? 10 : 1);
        break;
      case 1:
        // air, sand/sandstone/stone, cactus
        byteLiquid = (byte) Material.AIR.getId();
        byteStone = (byte) Material.STONE.getId();
        byteDirt = (byte) Material.SANDSTONE.getId();
        byteGrass = (byte) Material.SAND.getId();
        intTreeTrunk = Material.CACTUS.getId();
        intTreeLeaves = intAir;
        minTreeHeight = 2;
        maxTreeHeight = 4;
        break;
      case 3:
        // water, glass/glowstone/endstone, crystals
        byteLiquid = (byte) Material.STATIONARY_WATER.getId();
        byteStone = (byte) Material.ENDER_STONE.getId();
        byteDirt = (byte) Material.SOUL_SAND.getId();
        byteGrass = (byte) Material.MYCEL.getId();
        intTreeTrunk = Material.GLOWSTONE.getId();
        intTreeLeaves = Material.THIN_GLASS.getId();
        break;
      default:
        // water, grass/dirt/stone, normal trees are the default
        byteTreeData = (byte) random.nextInt(3);
        break;
    }
  }

  @Override
  public void populateBlocks(Chunk chunk, int chunkX, int chunkZ) {
    // ores
    populateOres(chunk);

    // foliage
    populateFoliage(chunk);
  }

  /**
   * Populates the world with ores.
   *
   * @author Nightgunner5
   * @author Markus Persson
   */
  private static final int[] iterations = new int[] {10, 20, 20, 2, 8, 1, 1, 1};

  private static final int[] amount = new int[] {32, 16, 8, 8, 7, 7, 6};
  private static final int[] type =
      new int[] {
        Material.GRAVEL.getId(),
        Material.COAL_ORE.getId(),
        Material.IRON_ORE.getId(),
        Material.GOLD_ORE.getId(),
        Material.REDSTONE_ORE.getId(),
        Material.DIAMOND_ORE.getId(),
        Material.LAPIS_ORE.getId()
      };
  private static final int[] maxHeight = new int[] {128, 128, 128, 128, 128, 64, 32, 16, 16, 32};

  protected void populateOres(Chunk chunk) {
    // ores
    for (int i = 0; i < type.length; i++) {
      for (int j = 0; j < iterations[i]; j++) {
        placeOre(
            chunk,
            random.nextInt(16),
            random.nextInt(maxHeight[i]),
            random.nextInt(16),
            amount[i],
            type[i]);
      }
    }
  }

  private void placeOre(Chunk source, int originX, int originY, int originZ, int amount, int type) {
    for (int i = 0; i < amount; i++) {
      int x = originX + random.nextInt(amount / 2) - amount / 4;
      int y = originY + random.nextInt(amount / 4) - amount / 8;
      int z = originZ + random.nextInt(amount / 2) - amount / 4;
      x &= 0xf;
      z &= 0xf;
      if (y > 127 || y < 0) {
        continue;
      }
      Block block = source.getBlock(x, y, z);
      if (block.getTypeId() == intOre) {
        block.setTypeId(type, false);
      }
    }
  }

  private static final int chanceRange = 150;

  protected void populateFoliage(Chunk chunk) {

    //		int centerX = (chunk.getX() << 4) + random.nextInt(16);
    //		int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
    //		if (random.nextBoolean()) {
    //			data = 2;
    //			height = 5 + random.nextInt(3);
    //		}
    //
    //		//EC: tweaked the biome logic a bit
    //		switch (getBiome()) {
    //		case FOREST:
    //			chance = 160;
    //			multiplier = 10;
    //			break;
    //		case PLAINS:
    //			chance = 40;
    //			break;
    //		case RAINFOREST:
    //			chance = 160;
    //			multiplier = 10;
    //			break;
    //		case SAVANNA:
    //			chance = 20;
    //			break;
    //		case SEASONAL_FOREST:
    //			chance = 140;
    //			multiplier = 8;
    //			break;
    //		case SHRUBLAND:
    //			chance = 60;
    //			break;
    //		case SWAMPLAND:
    //			chance = 120;
    //			break;
    //		case TAIGA:
    //			chance = 120;
    //			data = 1;
    //			height = 8 + random.nextInt(3);
    //			multiplier = 3;
    //			break;
    //		case TUNDRA:
    //			chance = 10;
    //			data = 1;
    //			height = 7 + random.nextInt(3);
    //			break;
    //		case SKY:
    //		case DESERT:
    //		case HELL:
    //		case ICE_DESERT:
    //			chance = 5;
    //			return;
    //		}

    byte data = (byte) random.nextInt(3);
    int chance = chanceRange / 2;
    int height = minTreeHeight + random.nextInt(maxTreeHeight);
    int multiplier = 3 + random.nextInt(7);

    for (int i = 0; i < multiplier; i++) {
      int centerX = (chunk.getX() << 4) + random.nextInt(16);
      int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
      if (random.nextInt(chanceRange) < chance) {
        int centerY = world.getHighestBlockYAt(centerX, centerZ) - 1;
        Block sourceBlock = world.getBlockAt(centerX, centerY, centerZ);

        // found a place to put it?
        if (sourceBlock.getTypeId() == intTreeBase) {

          // leaves or leave?
          if (intTreeLeaves != intAir) {
            setBlock(centerX, centerY + height + 1, centerZ, intTreeLeaves, data);
            // world.getBlockAt(centerX, centerY + height + 1, centerZ).setTypeIdAndData(intLeaves,
            // data, true);
            for (int j = 0; j < 4; j++) {
              setBlock(centerX, centerY + height + 1 - j, centerZ - 1, intTreeLeaves, data);
              setBlock(centerX, centerY + height + 1 - j, centerZ + 1, intTreeLeaves, data);
              setBlock(centerX - 1, centerY + height + 1 - j, centerZ, intTreeLeaves, data);
              setBlock(centerX + 1, centerY + height + 1 - j, centerZ, intTreeLeaves, data);
              // world.getBlockAt(centerX, centerY + height + 1 - j, centerZ -
              // 1).setTypeIdAndData(intLeaves, data, true);
              // world.getBlockAt(centerX, centerY + height + 1 - j, centerZ +
              // 1).setTypeIdAndData(intLeaves, data, true);
              // world.getBlockAt(centerX - 1, centerY + height + 1 - j,
              // centerZ).setTypeIdAndData(intLeaves, data, true);
              // world.getBlockAt(centerX + 1, centerY + height + 1 - j,
              // centerZ).setTypeIdAndData(intLeaves, data, true);
            }

            if (random.nextBoolean()) {
              setBlock(centerX + 1, centerY + height, centerZ + 1, intTreeLeaves, data);
              // world.getBlockAt(centerX + 1, centerY + height, centerZ +
              // 1).setTypeIdAndData(intLeaves, data, true);
            }
            if (random.nextBoolean()) {
              setBlock(centerX + 1, centerY + height, centerZ - 1, intTreeLeaves, data);
              // world.getBlockAt(centerX + 1, centerY + height, centerZ -
              // 1).setTypeIdAndData(intLeaves, data, true);
            }
            if (random.nextBoolean()) {
              setBlock(centerX - 1, centerY + height, centerZ + 1, intTreeLeaves, data);
              // world.getBlockAt(centerX - 1, centerY + height, centerZ +
              // 1).setTypeIdAndData(intLeaves, data, true);
            }
            if (random.nextBoolean()) {
              setBlock(centerX - 1, centerY + height, centerZ - 1, intTreeLeaves, data);
              // world.getBlockAt(centerX - 1, centerY + height, centerZ -
              // 1).setTypeIdAndData(intLeaves, data, true);
            }

            setBlock(centerX + 1, centerY + height - 1, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX + 1, centerY + height - 1, centerZ - 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 1, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 1, centerZ - 1, intTreeLeaves, data);
            setBlock(centerX + 1, centerY + height - 2, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX + 1, centerY + height - 2, centerZ - 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 2, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 2, centerZ - 1, intTreeLeaves, data);
            // world.getBlockAt(centerX + 1, centerY + height - 1, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX + 1, centerY + height - 1, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 1, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 1, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX + 1, centerY + height - 2, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX + 1, centerY + height - 2, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 2, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 2, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);

            for (int j = 0; j < 2; j++) {
              for (int k = -2; k <= 2; k++) {
                for (int l = -2; l <= 2; l++) {
                  setBlock(centerX + k, centerY + height - 1 - j, centerZ + l, intTreeLeaves, data);
                  // world.getBlockAt(centerX + k, centerY + height
                  //	- 1 - j, centerZ + l).setTypeIdAndData(intLeaves, data, true);
                }
              }
            }

            for (int j = 0; j < 2; j++) {
              if (random.nextBoolean())
                clearBlock(centerX + 2, centerY + height - 1 - j, centerZ + 2);
              if (random.nextBoolean())
                clearBlock(centerX + 2, centerY + height - 1 - j, centerZ - 2);
              if (random.nextBoolean())
                clearBlock(centerX - 2, centerY + height - 1 - j, centerZ + 2);
              if (random.nextBoolean())
                clearBlock(centerX - 2, centerY + height - 1 - j, centerZ - 2);
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX + 2, centerY + height - 1
              //		- j, centerZ + 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX + 2, centerY + height - 1
              //		- j, centerZ - 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX - 2, centerY + height - 1
              //		- j, centerZ + 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX - 2, centerY + height - 1
              //		- j, centerZ - 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
            }
          }

          // Trunk
          for (int y = 1; y <= height; y++) {
            world
                .getBlockAt(centerX, centerY + y, centerZ)
                .setTypeIdAndData(intTreeTrunk, data, false);
          }
        }
      }
    }
  }
}