Package cofh.lib.world

Source Code of cofh.lib.world.WorldGenMinableLargeVein

package cofh.lib.world;

import static cofh.lib.world.WorldGenMinableCluster.*;

import cofh.lib.util.WeightedRandomBlock;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class WorldGenMinableLargeVein extends WorldGenerator {

  private final List<WeightedRandomBlock> cluster;
  private final WeightedRandomBlock[] genBlock;
  private final int genVeinSize;
  private final boolean sparse;

  public WorldGenMinableLargeVein(ItemStack ore, int clusterSize) {

    this(new WeightedRandomBlock(ore), clusterSize);
  }

  public WorldGenMinableLargeVein(WeightedRandomBlock resource, int clusterSize) {

    this(fabricateList(resource), clusterSize);
  }

  public WorldGenMinableLargeVein(List<WeightedRandomBlock> resource, int clusterSize) {

    this(resource, clusterSize, Blocks.stone);
  }

  public WorldGenMinableLargeVein(ItemStack ore, int clusterSize, Block block) {

    this(new WeightedRandomBlock(ore, 1), clusterSize, block);
  }

  public WorldGenMinableLargeVein(WeightedRandomBlock resource, int clusterSize, Block block) {

    this(fabricateList(resource), clusterSize, block);
  }

  public WorldGenMinableLargeVein(List<WeightedRandomBlock> resource, int clusterSize, Block block) {

    this(resource, clusterSize, fabricateList(block));
  }

  public WorldGenMinableLargeVein(List<WeightedRandomBlock> resource, int clusterSize, List<WeightedRandomBlock> block) {

    this(resource, clusterSize, block, true);
  }

  public WorldGenMinableLargeVein(List<WeightedRandomBlock> resource, int clusterSize, List<WeightedRandomBlock> block, boolean sparze) {

    cluster = resource;
    genVeinSize = clusterSize;
    genBlock = block.toArray(new WeightedRandomBlock[block.size()]);
    sparse = sparze;
  }

  @Override
  public boolean generate(World world, Random rand, int x, int y, int z) {

    final int veinSize = genVeinSize;
    final int branchSize = 1 + (veinSize / 30);
    final int subBranchSize = 1 + (branchSize / 5);

    boolean r = false;
    for (int blocksVein = 0; blocksVein <= veinSize;) {
      int posX = x;
      int posY = y;
      int posZ = z;

      int directionChange = rand.nextInt(6);

      int directionX = rand.nextInt(2);
      int directionY = rand.nextInt(2);
      int directionZ = rand.nextInt(2);
      { // random code block to circumvent eclipse freaking out on auto-indent with unsigned right shift
        directionX += ~directionX >>> 31;
    directionX += ~directionY >>> 31;
    directionX += ~directionZ >>> 31;
      }

      for (int blocksBranch = 0; blocksBranch <= branchSize;) {
        if (directionChange != 1) {
          posX += rand.nextInt(2) * directionX;
        }
        if (directionChange != 2) {
          posY += rand.nextInt(2) * directionY;
        }
        if (directionChange != 3) {
          posZ += rand.nextInt(2) * directionZ;
        }

        if (rand.nextInt(3) == 0) {
          int posX2 = posX;
          int posY2 = posY;
          int posZ2 = posZ;

          int directionChange2 = rand.nextInt(6);

          int directionX2 = -rand.nextInt(2);
          int directionY2 = -rand.nextInt(2);
          int directionZ2 = -rand.nextInt(2);
          { // freaking out does not occur here, for some reason. the number at the end of the variable?
            directionX2 += ~directionX2 >>> 31;
            directionX2 += ~directionY2 >>> 31;
            directionX2 += ~directionZ2 >>> 31;
          }

          for (int blocksSubBranch = 0; blocksSubBranch <= subBranchSize;) {
            if (directionChange2 != 0) {
              posX2 += rand.nextInt(2) * directionX2;
            }
            if (directionChange2 != 1) {
              posY2 += rand.nextInt(2) * directionY2;
            }
            if (directionChange2 != 2) {
              posZ2 += rand.nextInt(2) * directionZ2;
            }

            r |= generateBlock(world, posX2, posY2, posZ2, genBlock, cluster);

            if (sparse) {
              blocksVein++;
              blocksBranch++;
            }
            blocksSubBranch++;
          }
        }

        r |= generateBlock(world, posX, posY, posZ, genBlock, cluster);

        blocksBranch++;
      }

      x = x + (rand.nextInt(3) - 1);
      y = y + (rand.nextInt(3) - 1);
      z = z + (rand.nextInt(3) - 1);
      blocksVein++;
    }

    return r;
  }

}
TOP

Related Classes of cofh.lib.world.WorldGenMinableLargeVein

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.