Advertisement
ViiRuS

Tree Generation Tutorial Part 2

Jan 8th, 2012
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. WorldGenCandyTrees
  2. --------------------------------------------
  3. package net.minecraft.src;
  4.  
  5. import java.util.Random;
  6.  
  7. // Referenced classes of package net.minecraft.src:
  8. //            WorldGenerator, World, Block, BlockLeaves,
  9. //            BlockGrass
  10.  
  11. public class WorldGenCandyTrees extends WorldGenerator
  12. {
  13.  
  14.     public WorldGenCandyTrees()
  15.     {
  16.         super();
  17.     }
  18.  
  19.     public boolean generate(World world, Random random, int i, int j, int k)
  20.     {
  21.         int l = random.nextInt(3) + 4;
  22.         boolean flag = true;
  23.         if(j < 1 || j + l + 1 > world.worldYMax)
  24.         {
  25.             return false;
  26.         }
  27.         for(int i1 = j; i1 <= j + 1 + l; i1++)
  28.         {
  29.             byte byte0 = 1;
  30.             if(i1 == j)
  31.             {
  32.                 byte0 = 0;
  33.             }
  34.             if(i1 >= (j + 1 + l) - 2)
  35.             {
  36.                 byte0 = 2;
  37.             }
  38.             for(int i2 = i - byte0; i2 <= i + byte0 && flag; i2++)
  39.             {
  40.                 for(int l2 = k - byte0; l2 <= k + byte0 && flag; l2++)
  41.                 {
  42.                     if(i1 >= 0 && i1 < world.worldYMax)
  43.                     {
  44.                         int j3 = world.getBlockId(i2, i1, l2);
  45.                         if(j3 != 0 && j3 != mod_mobs.candyleaves.blockID)
  46.                         {
  47.                             flag = false;
  48.                         }
  49.                     } else
  50.                     {
  51.                         flag = false;
  52.                     }
  53.                 }
  54.  
  55.             }
  56.  
  57.         }
  58.  
  59.         if(!flag)
  60.         {
  61.             return false;
  62.         }
  63.         int j1 = world.getBlockId(i, j - 1, k);
  64.         if(j1 != Block.grass.blockID && j1 != Block.dirt.blockID || j >= world.worldYMax - l - 1)
  65.         {
  66.             return false;
  67.         }
  68.         world.setBlock(i, j - 1, k, Block.dirt.blockID);
  69.         for(int k1 = (j - 3) + l; k1 <= j + l; k1++)
  70.         {
  71.             int j2 = k1 - (j + l);
  72.             int i3 = 1 - j2 / 2;
  73.             for(int k3 = i - i3; k3 <= i + i3; k3++)
  74.             {
  75.                 int l3 = k3 - i;
  76.                 for(int i4 = k - i3; i4 <= k + i3; i4++)
  77.                 {
  78.                     int j4 = i4 - k;
  79.                     if((Math.abs(l3) != i3 || Math.abs(j4) != i3 || random.nextInt(2) != 0 && j2 != 0) && !Block.opaqueCubeLookup[world.getBlockId(k3, k1, i4)])
  80.                     {
  81.                         func_41060_a(world, k3, k1, i4, mod_mobs.candyleaves.blockID, 0);
  82.                     }
  83.                 }
  84.  
  85.             }
  86.  
  87.         }
  88.  
  89.         for(int l1 = 0; l1 < l; l1++)
  90.         {
  91.             int k2 = world.getBlockId(i, j + l1, k);
  92.             if(k2 == 0 || k2 == mod_mobs.candyleaves.blockID)
  93.             {
  94.                 func_41060_a(world, i, j + l1, k, mod_mobs.candylog.blockID, 0);
  95.             }
  96.         }
  97.  
  98.         return true;
  99.     }
  100. }
  101.  
  102.  
  103. mod_ file snippet
  104. ----------------------------------------
  105.  
  106.     public void GenerateSurface(World world, Random ran, int baseX, int baseZ)
  107.     {
  108.     BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(baseX, baseZ);
  109.     WorldGenCandyTrees tree = new WorldGenCandyTrees();
  110.     if((biome instanceof BiomeGenPlains)||(biome instanceof BiomeGenForest)||(biome instanceof BiomeGenHills)
  111.       ||(biome instanceof BiomeGenDesert)||(biome instanceof BiomeGenSwamp)||(biome instanceof BiomeGenTaiga)){
  112.      
  113.    
  114.      for(int x = 0;x<5;x++){
  115.       int k = baseX + ran.nextInt(16) + 8;
  116.       int l = baseZ + ran.nextInt(16) + 8;
  117.       int i1 = world.getHeightValue(k, l);
  118.       tree.generate(world, ran, k, i1, l);
  119.        
  120.       }
  121.      }
  122.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement