Advertisement
Guest User

WorldGenMangoTree.java

a guest
Apr 9th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.88 KB | None | 0 0
  1. package com.tristanvo.mod.Generation;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.tristanvo.mod.mod;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockSapling;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.util.Direction;
  11. import net.minecraft.world.World;
  12. import net.minecraft.world.gen.feature.WorldGenAbstractTree;
  13. import net.minecraftforge.common.util.ForgeDirection;
  14.  
  15. public class WorldGenMangoTree extends WorldGenAbstractTree
  16. {
  17.     private final int minTreeHeight;
  18.     private final int randomTreeHeight;
  19.    
  20.     private final boolean vinesGrow;
  21.    
  22.     private final Block wood;
  23.     private final Block leaves;
  24.    
  25.     private final int metaWood;
  26.     private final int metaLeaves;
  27.  
  28.     public WorldGenMangoTree(Block wood, Block leaves, int metaWood, int metaLeaves)
  29.     {
  30.         this(wood, leaves, metaWood, metaLeaves, false, 4, 3, false);
  31.     }
  32.  
  33.     public WorldGenMangoTree(Block wood, Block leaves, int metaWood, int metaLeaves, boolean doBlockNotify, int minTreeHeight, int randomTreeHeight, boolean vinesGrow)
  34.     {
  35.         super(doBlockNotify);
  36.        
  37.         this.wood = wood;
  38.         this.leaves = leaves;
  39.        
  40.         this.minTreeHeight = minTreeHeight;
  41.         this.randomTreeHeight = randomTreeHeight;
  42.        
  43.         this.metaWood = metaWood;
  44.         this.metaLeaves = metaLeaves;
  45.         this.vinesGrow = vinesGrow;
  46.     }
  47.  
  48.     public boolean generate(World world, Random random, int par3, int par4, int par5)
  49.     {
  50.         int l = random.nextInt(3) + this.minTreeHeight;
  51.         boolean flag = true;
  52.  
  53.         if (par4 >= 1 && par4 + l + 1 <= 256)
  54.         {
  55.             byte b0;
  56.             int k1;
  57.             Block block;
  58.  
  59.             for (int i1 = par4; i1 <= par4 + 1 + l; ++i1)
  60.             {
  61.                 b0 = 1;
  62.  
  63.                 if (i1 == par4)
  64.                 {
  65.                     b0 = 0;
  66.                 }
  67.  
  68.                 if (i1 >= par4 + 1 + l - 2)
  69.                 {
  70.                     b0 = 2;
  71.                 }
  72.  
  73.                 for (int j1 = par3 - b0; j1 <= par3 + b0 && flag; ++j1)
  74.                 {
  75.                     for (k1 = par5 - b0; k1 <= par5 + b0 && flag; ++k1)
  76.                     {
  77.                         if (i1 >= 0 && i1 < 256)
  78.                         {
  79.                             block = world.getBlock(j1, i1, k1);
  80.  
  81.                             if (!this.isReplaceable(world, j1, i1, k1))
  82.                             {
  83.                                 flag = false;
  84.                             }
  85.                         }
  86.                         else
  87.                         {
  88.                             flag = false;
  89.                         }
  90.                     }
  91.                 }
  92.             }
  93.  
  94.             if (!flag)
  95.             {
  96.                 return false;
  97.             }
  98.             else
  99.             {
  100.                 Block block2 = world.getBlock(par3, par4 - 1, par5);
  101.  
  102.                 boolean isSoil = block2.canSustainPlant(world, par3, par4 - 1, par5, ForgeDirection.UP, (BlockSapling)mod.mangoSapling);
  103.                 if (isSoil && par4 < 256 - l - 1)
  104.                 {
  105.                     block2.onPlantGrow(world, par3, par4 - 1, par5, par3, par4, par5);
  106.                     b0 = 3;
  107.                     byte b1 = 0;
  108.                     int l1;
  109.                     int i2;
  110.                     int j2;
  111.                     int i3;
  112.  
  113.                     for (k1 = par4 - b0 + l; k1 <= par4 + l; ++k1)
  114.                     {
  115.                         i3 = k1 - (par4 + l);
  116.                         l1 = b1 + 1 - i3 / 2;
  117.  
  118.                         for (i2 = par3 - l1; i2 <= par3 + l1; ++i2)
  119.                         {
  120.                             j2 = i2 - par3;
  121.  
  122.                             for (int k2 = par5 - l1; k2 <= par5 + l1; ++k2)
  123.                             {
  124.                                 int l2 = k2 - par5;
  125.  
  126.                                 if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || random.nextInt(2) != 0 && i3 != 0)
  127.                                 {
  128.                                     Block block1 = world.getBlock(i2, k1, k2);
  129.  
  130.                                     if (block1.isAir(world, i2, k1, k2) || block1.isLeaves(world, i2, k1, k2))
  131.                                     {
  132.                                         this.setBlockAndNotifyAdequately(world, i2, k1, k2, mod.mangoLeaf, this.metaLeaves);
  133.                                     }
  134.                                 }
  135.                             }
  136.                         }
  137.                     }
  138.  
  139.                     for (k1 = 0; k1 < l; ++k1)
  140.                     {
  141.                         block = world.getBlock(par3, par4 + k1, par5);
  142.  
  143.                         if (block.isAir(world, par3, par4 + k1, par5) || block.isLeaves(world, par3, par4 + k1, par5))
  144.                         {
  145.                             this.setBlockAndNotifyAdequately(world, par3, par4 + k1, par5, mod.mangoLog, this.metaWood);
  146.  
  147.                             if (this.vinesGrow && k1 > 0)
  148.                             {
  149.                                 if (random.nextInt(3) > 0 && world.isAirBlock(par3 - 1, par4 + k1, par5))
  150.                                 {
  151.                                     this.setBlockAndNotifyAdequately(world, par3 - 1, par4 + k1, par5, Blocks.vine, 8);
  152.                                 }
  153.  
  154.                                 if (random.nextInt(3) > 0 && world.isAirBlock(par3 + 1, par4 + k1, par5))
  155.                                 {
  156.                                     this.setBlockAndNotifyAdequately(world, par3 + 1, par4 + k1, par5, Blocks.vine, 2);
  157.                                 }
  158.  
  159.                                 if (random.nextInt(3) > 0 && world.isAirBlock(par3, par4 + k1, par5 - 1))
  160.                                 {
  161.                                     this.setBlockAndNotifyAdequately(world, par3, par4 + k1, par5 - 1, Blocks.vine, 1);
  162.                                 }
  163.  
  164.                                 if (random.nextInt(3) > 0 && world.isAirBlock(par3, par4 + k1, par5 + 1))
  165.                                 {
  166.                                     this.setBlockAndNotifyAdequately(world, par3, par4 + k1, par5 + 1, Blocks.vine, 4);
  167.                                 }
  168.                             }
  169.                         }
  170.                     }
  171.  
  172.                     if (this.vinesGrow)
  173.                     {
  174.                         for (k1 = par4 - 3 + l; k1 <= par4 + l; ++k1)
  175.                         {
  176.                             i3 = k1 - (par4 + l);
  177.                             l1 = 2 - i3 / 2;
  178.  
  179.                             for (i2 = par3 - l1; i2 <= par3 + l1; ++i2)
  180.                             {
  181.                                 for (j2 = par5 - l1; j2 <= par5 + l1; ++j2)
  182.                                 {
  183.                                     if (world.getBlock(i2, k1, j2).isLeaves(world, i2, k1, j2))
  184.                                     {
  185.                                         if (random.nextInt(4) == 0 && world.getBlock(i2 - 1, k1, j2).isAir(world, i2 - 1, k1, j2))
  186.                                         {
  187.                                             this.growVines(world, i2 - 1, k1, j2, 8);
  188.                                         }
  189.  
  190.                                         if (random.nextInt(4) == 0 && world.getBlock(i2 + 1, k1, j2).isAir(world, i2 + 1, k1, j2))
  191.                                         {
  192.                                             this.growVines(world, i2 + 1, k1, j2, 2);
  193.                                         }
  194.  
  195.                                         if (random.nextInt(4) == 0 && world.getBlock(i2, k1, j2 - 1).isAir(world, i2, k1, j2 - 1))
  196.                                         {
  197.                                             this.growVines(world, i2, k1, j2 - 1, 1);
  198.                                         }
  199.  
  200.                                         if (random.nextInt(4) == 0 && world.getBlock(i2, k1, j2 + 1).isAir(world, i2, k1, j2 + 1))
  201.                                         {
  202.                                             this.growVines(world, i2, k1, j2 + 1, 4);
  203.                                         }
  204.                                     }
  205.                                 }
  206.                             }
  207.                         }
  208.  
  209.                         if (random.nextInt(5) == 0 && l > 5)
  210.                         {
  211.                             for (k1 = 0; k1 < 2; ++k1)
  212.                             {
  213.                                 for (i3 = 0; i3 < 4; ++i3)
  214.                                 {
  215.                                     if (random.nextInt(4 - k1) == 0)
  216.                                     {
  217.                                         l1 = random.nextInt(3);
  218.                                         this.setBlockAndNotifyAdequately(world, par3 + Direction.offsetX[Direction.rotateOpposite[i3]], par4 + l - 5 + k1, par5 + Direction.offsetZ[Direction.rotateOpposite[i3]], Blocks.cocoa, l1 << 2 | i3);
  219.                                     }
  220.                                 }
  221.                             }
  222.                         }
  223.                     }
  224.  
  225.                     return true;
  226.                 }
  227.                 else
  228.                 {
  229.                     return false;
  230.                 }
  231.             }
  232.         }
  233.         else
  234.         {
  235.             return false;
  236.         }
  237.     }
  238.  
  239.     /**
  240.      * Grows vines downward from the given block for a given length. Args: World, x, starty, z, vine-length
  241.      */
  242.     private void growVines(World world, int par2, int par3, int par4, int par5)
  243.     {
  244.         this.setBlockAndNotifyAdequately(world, par2, par3, par4, Blocks.vine, par5);
  245.         int i1 = 4;
  246.  
  247.         while (true)
  248.         {
  249.             --par3;
  250.  
  251.             if (!world.getBlock(par2, par3, par4).isAir(world, par2, par3, par4) || i1 <= 0)
  252.             {
  253.                 return;
  254.             }
  255.  
  256.             this.setBlockAndNotifyAdequately(world, par2, par3, par4, Blocks.vine, par5);
  257.             --i1;
  258.         }
  259.     }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement