Advertisement
Guest User

TutSapling

a guest
Mar 25th, 2013
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.77 KB | None | 0 0
  1. package OliveCraft;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import net.minecraft.block.BlockFlower;
  7. import net.minecraft.client.renderer.texture.IconRegister;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.util.Icon;
  11. import net.minecraft.world.World;
  12. import net.minecraft.world.gen.feature.WorldGenBigTree;
  13. import net.minecraft.world.gen.feature.WorldGenForest;
  14. import net.minecraft.world.gen.feature.WorldGenHugeTrees;
  15. import net.minecraft.world.gen.feature.WorldGenTaiga2;
  16. import net.minecraft.world.gen.feature.WorldGenerator;
  17. import net.minecraftforge.event.terraingen.TerrainGen;
  18. import cpw.mods.fml.relauncher.Side;
  19. import cpw.mods.fml.relauncher.SideOnly;
  20.  
  21. public class TutSapling extends BlockFlower
  22. {
  23.     public static final String[] TutWOOD_TYPES = new String[] {"Tut"};
  24.     @SideOnly(Side.CLIENT)
  25.     private Icon[] field_94371_c;
  26.  
  27.     protected TutSapling(int par1)
  28.     {
  29.         super(par1);
  30.         float f = 0.4F;
  31.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
  32.         this.setCreativeTab(CreativeTabs.tabDecorations);
  33.     }
  34.  
  35.     /**
  36.      * Ticks the block if it's been scheduled
  37.      */
  38.     public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  39.     {
  40.         if (!par1World.isRemote)
  41.         {
  42.             super.updateTick(par1World, par2, par3, par4, par5Random);
  43.  
  44.             if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9 && par5Random.nextInt(7) == 0)
  45.             {
  46.                 this.func_96477_c(par1World, par2, par3, par4, par5Random);
  47.             }
  48.         }
  49.     }
  50.  
  51.     @SideOnly(Side.CLIENT)
  52.  
  53.     public void func_96477_c(World par1World, int par2, int par3, int par4, Random par5Random)
  54.     {
  55.         int l = par1World.getBlockMetadata(par2, par3, par4);
  56.  
  57.         if ((l & 8) == 0)
  58.         {
  59.             par1World.setBlockMetadataWithNotify(par2, par3, par4, l | 8, 4);
  60.         }
  61.         else
  62.         {
  63.             this.growTree(par1World, par2, par3, par4, par5Random);
  64.         }
  65.     }
  66.  
  67.     /**
  68.      * Attempts to grow a sapling into a tree
  69.      */
  70.     public void growTree(World par1World, int par2, int par3, int par4, Random par5Random)
  71.     {
  72.         if (!TerrainGen.saplingGrowTree(par1World, par5Random, par2, par3, par4)) return;
  73.  
  74.         int l = par1World.getBlockMetadata(par2, par3, par4) & 3;
  75.         Object object = null;
  76.         int i1 = 0;
  77.         int j1 = 0;
  78.         boolean flag = false;
  79.  
  80.         if (l == 1)
  81.         {
  82.             object = new WorldGenTaiga2(true);
  83.         }
  84.         else if (l == 2)
  85.         {
  86.             object = new WorldGenForest(true);
  87.         }
  88.         else if (l == 3)
  89.         {
  90.             for (i1 = 0; i1 >= -1; --i1)
  91.             {
  92.                 for (j1 = 0; j1 >= -1; --j1)
  93.                 {
  94.                     if (this.isSameSapling(par1World, par2 + i1, par3, par4 + j1, 3) && this.isSameSapling(par1World, par2 + i1 + 1, par3, par4 + j1, 3) && this.isSameSapling(par1World, par2 + i1, par3, par4 + j1 + 1, 3) && this.isSameSapling(par1World, par2 + i1 + 1, par3, par4 + j1 + 1, 3))
  95.                     {
  96.                         object = new WorldGenHugeTrees(true, 10 + par5Random.nextInt(20), 3, 3);
  97.                         flag = true;
  98.                         break;
  99.                     }
  100.                 }
  101.  
  102.                 if (object != null)
  103.                 {
  104.                     break;
  105.                 }
  106.             }
  107.  
  108.             if (object == null)
  109.             {
  110.                 j1 = 0;
  111.                 i1 = 0;
  112.                 object = new WorldGenTutTree(true, 4 + par5Random.nextInt(7), 3, 3, false);
  113.             }
  114.         }
  115.         else
  116.         {
  117.             object = new WorldGenTutTree(true);
  118.  
  119.             if (par5Random.nextInt(10) == 0)
  120.             {
  121.                 object = new WorldGenBigTree(true);
  122.             }
  123.         }
  124.  
  125.         if (flag)
  126.         {
  127.             par1World.setBlock(par2 + i1, par3, par4 + j1, 0, 0, 4);
  128.             par1World.setBlock(par2 + i1 + 1, par3, par4 + j1, 0, 0, 4);
  129.             par1World.setBlock(par2 + i1, par3, par4 + j1 + 1, 0, 0, 4);
  130.             par1World.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, 0, 0, 4);
  131.         }
  132.         else
  133.         {
  134.             par1World.setBlock(par2, par3, par4, 0, 0, 4);
  135.         }
  136.  
  137.         if (!((WorldGenerator)object).generate(par1World, par5Random, par2 + i1, par3, par4 + j1))
  138.         {
  139.             if (flag)
  140.             {
  141.                 par1World.setBlock(par2 + i1, par3, par4 + j1, this.blockID, l, 4);
  142.                 par1World.setBlock(par2 + i1 + 1, par3, par4 + j1, this.blockID, l, 4);
  143.                 par1World.setBlock(par2 + i1, par3, par4 + j1 + 1, this.blockID, l, 4);
  144.                 par1World.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, this.blockID, l, 4);
  145.             }
  146.             else
  147.             {
  148.                 par1World.setBlock(par2, par3, par4, this.blockID, l, 4);
  149.             }
  150.         }
  151.     }
  152.  
  153.     /**
  154.      * Determines if the same sapling is present at the given location.
  155.      */
  156.     public boolean isSameSapling(World par1World, int par2, int par3, int par4, int par5)
  157.     {
  158.         return par1World.getBlockId(par2, par3, par4) == this.blockID && (par1World.getBlockMetadata(par2, par3, par4) & 3) == par5;
  159.     }
  160.  
  161.     /**
  162.      * Determines the damage on the item the block drops. Used in cloth and wood.
  163.      */
  164.     public int damageDropped(int par1)
  165.     {
  166.         return par1 & 3;
  167.     }
  168.  
  169.     @SideOnly(Side.CLIENT)
  170.  
  171.     /**
  172.      * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
  173.      */
  174.     public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
  175.     {
  176.         par3List.add(new ItemStack(par1, 1, 0));
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement