DialUp

SaplingEbony

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