Advertisement
marcopolo1613

density and fractal code methods

Jan 25th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.30 KB | None | 0 0
  1. /*
  2. This method generates a bell curve type of statistical distribution along a given axis based on a percentage input
  3. */
  4.         public int mPCalculateDensity(int oreDistance, float oreDensity) // returns the density value
  5.         {
  6.  
  7.               int loopCount = 0;
  8.               int densityValuePassInner = 0;
  9.               int densityValuePass = 0;
  10.               oreDensity = oreDensity * .01F;
  11.               oreDensity = (oreDensity * (oreDistance >> 1)) + 1F;// establishes number of times to loop
  12.               loopCount = (int)(oreDensity); //stores number of times to loop
  13.               densityValuePassInner = ((oreDistance/loopCount)); // distance devided by number of times it will loop, establishes the number for randomization
  14.               densityValuePassInner += (((oreDistance - (densityValuePassInner*loopCount))/loopCount));
  15.               densityValuePass = 0;
  16.               while (loopCount > 0) // loops to acumulate random values
  17.               {
  18.                     densityValuePass = densityValuePass + rand.nextInt(densityValuePassInner); // acumulate randoms
  19.                     loopCount = loopCount - 1; // decriment loop
  20.               }
  21.               return densityValuePass; // return proccesed random value
  22.         }
  23.  
  24. */
  25. This method generates veins in a branching manner from a single source location until a threshold of blocks is generated.
  26.  
  27. /*
  28.     public boolean BODgenerateVein(World world, Random rand, int parX, int parY, int parZ, int xyz)
  29.     {
  30.         //==========================================mp mod
  31.         int posX = parX;
  32.         int posY = parY;
  33.         int posZ = parZ;
  34.         int tempPosX =0;
  35.         int tempPosY =0;
  36.         int tempPosZ =0;
  37.         int posX2 = 0;
  38.         int posY2 = 0;
  39.         int posZ2 = 0;
  40.         int directionX =0;
  41.         int directionY =0;
  42.         int directionZ =0;
  43.         int directionX2 = 0;
  44.         int directionY2 = 0;
  45.         int directionZ2 = 0;
  46.         int directionX3 =0;
  47.         int directionY3 =0;
  48.         int directionZ3 =0;
  49.         int directionChange =0;
  50.         int directionChange2 =0;
  51.         int blocksToUse = xyz;//input number of blocks per vein
  52.         int blocksToUse2 =0;
  53.         for(int blocksMade=0; blocksMade <= blocksToUse;) // make veins
  54.         {
  55.             blocksToUse2 = 1 + (blocksToUse/30);
  56.             directionChange = rand.nextInt(6);
  57.             directionX = rand.nextInt(2);
  58.             directionY = rand.nextInt(2);
  59.             directionZ = rand.nextInt(2);
  60.  
  61.             for(int blocksMade1 = 0; blocksMade1 <= blocksToUse2; ) // make branch
  62.             {
  63.                 if(directionX == 0 && directionChange != 1){posX = posX + rand.nextInt(2);}
  64.                 if(directionX == 1 && directionChange != 1){posX = posX - rand.nextInt(2);}
  65.                 if(directionY == 0 && directionChange != 2){posY = posY + rand.nextInt(2);}
  66.                 if(directionY == 1 && directionChange != 2){posY = posY - rand.nextInt(2);}
  67.                 if(directionZ == 0 && directionChange != 3){posZ = posZ + rand.nextInt(2);}
  68.                 if(directionZ == 1 && directionChange != 3){posZ = posZ - rand.nextInt(2);}
  69.                 if(rand.nextInt(4) == 0){
  70.                     posX2 = posX2 + rand.nextInt(2);
  71.                     posY2 = posY2 + rand.nextInt(2);
  72.                     posZ2 = posZ2 + rand.nextInt(2);
  73.                     posX2 = posX2 - rand.nextInt(2);
  74.                     posY2 = posY2 - rand.nextInt(2);
  75.                     posZ2 = posZ2 - rand.nextInt(2);
  76.                 }
  77.                 if(rand.nextInt(3) == 0) // make sub-branch
  78.                 {
  79.                     posX2 = posX;
  80.                     posY2 = posY;
  81.                     posZ2 = posZ;
  82.  
  83.                     directionX2 = rand.nextInt(2);
  84.                     directionY2 = rand.nextInt(2);
  85.                     directionZ2 = rand.nextInt(2);
  86.                     directionChange2 = rand.nextInt(6);
  87.                     if(directionX2 == 0 && directionChange2 != 0){posX2 = posX2 + rand.nextInt(2);}
  88.                     if(directionY2 == 0 && directionChange2 != 1){posY2 = posY2 + rand.nextInt(2);}
  89.                     if(directionZ2 == 0 && directionChange2 != 2){posZ2 = posZ2 + rand.nextInt(2);}
  90.                     if(directionX2 == 1 && directionChange2 != 0){posX2 = posX2 - rand.nextInt(2);}
  91.                     if(directionY2 == 1 && directionChange2 != 1){posY2 = posY2 - rand.nextInt(2);}
  92.                     if(directionZ2 == 1 && directionChange2 != 2){posZ2 = posZ2 - rand.nextInt(2);}
  93.  
  94.  
  95.  
  96.                     for(int blocksMade2 = 0; blocksMade2 <= (1 +(blocksToUse2/5)); )
  97.                     {
  98.  
  99.                         if(directionX2 == 0 && directionChange2 != 0){posX2 = posX2 + rand.nextInt(2);}
  100.                         if(directionY2 == 0 && directionChange2 != 1){posY2 = posY2 + rand.nextInt(2);}
  101.                         if(directionZ2 == 0 && directionChange2 != 2){posZ2 = posZ2 + rand.nextInt(2);}
  102.                         if(directionX2 == 1 && directionChange2 != 0){posX2 = posX2 - rand.nextInt(2);}
  103.                         if(directionY2 == 1 && directionChange2 != 1){posY2 = posY2 - rand.nextInt(2);}
  104.                         if(directionZ2 == 1 && directionChange2 != 2){posZ2 = posZ2 - rand.nextInt(2);}
  105.                         if(world.getBlockId(posX, posY, posZ) == Block.stone.blockID || world.getBlockId(posX, posY, posZ) == 87)
  106.                         {
  107.                                 world.setBlock(posX, posY, posZ, MPBlockID, minableBlockMeta, 2);
  108.                         }
  109.                         blocksMade++;
  110.                         blocksMade1++;
  111.                         blocksMade2++;
  112.                     }
  113.                 }
  114.  
  115.                 if(world.getBlockId(posX, posY, posZ) == Block.stone.blockID || world.getBlockId(posX, posY, posZ) == 87) // only if it is stone
  116.                 {
  117.                         world.setBlock(posX, posY, posZ, MPBlockID, minableBlockMeta, 2); // place block in world
  118.                 }
  119.  
  120.                 blocksMade++;
  121.                 blocksMade1++;
  122.  
  123.             }
  124.  
  125.             parX = parX + (rand.nextInt(3) - 1);
  126.             parY = parY + (rand.nextInt(3) - 1);
  127.             parZ = parZ + (rand.nextInt(3) - 1);
  128.             posX = parX;
  129.             posY = parY;
  130.             posZ = parZ;
  131.  
  132.         }
  133.  
  134.  
  135.         return true;
  136.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement