Guest User

mangoSapling.java

a guest
Apr 9th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.61 KB | None | 0 0
  1. package com.tristanvo.mod;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import com.tristanvo.mod.Generation.WorldGenMangoTree;
  7.  
  8. import cpw.mods.fml.relauncher.Side;
  9. import cpw.mods.fml.relauncher.SideOnly;
  10. import net.minecraft.block.Block;
  11. import net.minecraft.block.BlockBush;
  12. import net.minecraft.block.IGrowable;
  13. import net.minecraft.client.renderer.texture.IIconRegister;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.init.Blocks;
  16. import net.minecraft.item.Item;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.util.IIcon;
  19. import net.minecraft.util.MathHelper;
  20. import net.minecraft.world.World;
  21. import net.minecraft.world.gen.feature.WorldGenBigTree;
  22. import net.minecraft.world.gen.feature.WorldGenCanopyTree;
  23. import net.minecraft.world.gen.feature.WorldGenForest;
  24. import net.minecraft.world.gen.feature.WorldGenMegaJungle;
  25. import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
  26. import net.minecraft.world.gen.feature.WorldGenSavannaTree;
  27. import net.minecraft.world.gen.feature.WorldGenTaiga2;
  28. import net.minecraft.world.gen.feature.WorldGenTrees;
  29. import net.minecraft.world.gen.feature.WorldGenerator;
  30.  
  31. public class mangoSapling extends BlockBush implements IGrowable
  32. {
  33.     public static final String[] sapling = new String[] {"Mango"};
  34.     private static final IIcon[] saplingIcon = new IIcon[sapling.length];
  35.  
  36.     protected mangoSapling()
  37.     {
  38.         float f = 0.4F;
  39.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
  40.         this.setStepSound(this.soundTypeGrass);
  41.     }
  42.  
  43.     /**
  44.      * Ticks the block if it's been scheduled
  45.      */
  46.     public void updateTick(World world, int par2, int par3, int par4, Random random)
  47.     {
  48.         if (!world.isRemote)
  49.         {
  50.             super.updateTick(world, par2, par3, par4, random);
  51.  
  52.             if (world.getBlockLightValue(par2, par3 + 1, par4) >= 9 && random.nextInt(7) == 0)
  53.             {
  54.                 this.func_149879_c(world, par2, par3, par4, random);
  55.             }
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * Gets the block's texture. Args: side, meta
  61.      */
  62.     @SideOnly(Side.CLIENT)
  63.     public IIcon getIcon(int side, int meta)
  64.     {
  65.         meta &= 7;
  66.         return saplingIcon[MathHelper.clamp_int(meta, 0, 5)];
  67.     }
  68.  
  69.     public void func_149879_c(World world, int par2, int par3, int par4, Random random)
  70.     {
  71.         int l = world.getBlockMetadata(par2, par3, par4);
  72.  
  73.         if ((l & 8) == 0)
  74.         {
  75.             world.setBlockMetadataWithNotify(par2, par3, par4, l | 8, 4);
  76.         }
  77.         else
  78.         {
  79.             this.func_149878_d(world, par2, par3, par4, random);
  80.         }
  81.     }
  82.  
  83.     public void func_149878_d(World world, int par2, int par3, int par4, Random random)
  84.     {
  85.         if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, random, par2, par3, par4)) return;
  86.         int l = world.getBlockMetadata(par2, par3, par4) & 7;
  87.         Object object = random.nextInt(10) == 0 ? new WorldGenMangoTree(mod.mangoLog, mod.mangoLeaf, 1, 1, false, 10, 15, false) : new WorldGenMangoTree(mod.mangoLog, mod.mangoLeaf, 1, 1, false, 10, 15, false);
  88.         int i1 = 0;
  89.         int j1 = 0;
  90.         boolean flag = false;
  91.  
  92.         switch (l)
  93.         {
  94.             case 0:
  95.             default:
  96.                 break;
  97.             case 1:
  98.                 label78:
  99.  
  100.                 for (i1 = 0; i1 >= -1; --i1)
  101.                 {
  102.                     for (j1 = 0; j1 >= -1; --j1)
  103.                     {
  104.                         if (this.func_149880_a(world, par2 + i1, par3, par4 + j1, 1) && this.func_149880_a(world, par2 + i1 + 1, par3, par4 + j1, 1) && this.func_149880_a(world, par2 + i1, par3, par4 + j1 + 1, 1) && this.func_149880_a(world, par2 + i1 + 1, par3, par4 + j1 + 1, 1))
  105.                         {
  106.                             object = new WorldGenMegaPineTree(false, random.nextBoolean());
  107.                             flag = true;
  108.                             break label78;
  109.                         }
  110.                     }
  111.                 }
  112.  
  113.                 if (!flag)
  114.                 {
  115.                     j1 = 0;
  116.                     i1 = 0;
  117.                     object = new WorldGenTaiga2(true);
  118.                 }
  119.  
  120.                 break;
  121.             case 2:
  122.                 object = new WorldGenForest(true, false);
  123.                 break;
  124.             case 3:
  125.                 label93:
  126.  
  127.                 for (i1 = 0; i1 >= -1; --i1)
  128.                 {
  129.                     for (j1 = 0; j1 >= -1; --j1)
  130.                     {
  131.                         if (this.func_149880_a(world, par2 + i1, par3, par4 + j1, 3) && this.func_149880_a(world, par2 + i1 + 1, par3, par4 + j1, 3) && this.func_149880_a(world, par2 + i1, par3, par4 + j1 + 1, 3) && this.func_149880_a(world, par2 + i1 + 1, par3, par4 + j1 + 1, 3))
  132.                         {
  133.                             object = new WorldGenMegaJungle(true, 10, 20, 3, 3);
  134.                             flag = true;
  135.                             break label93;
  136.                         }
  137.                     }
  138.                 }
  139.  
  140.                 if (!flag)
  141.                 {
  142.                     j1 = 0;
  143.                     i1 = 0;
  144.                     object = new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false);
  145.                 }
  146.  
  147.                 break;
  148.             case 4:
  149.                 object = new WorldGenSavannaTree(true);
  150.                 break;
  151.             case 5:
  152.                 label108:
  153.  
  154.                 for (i1 = 0; i1 >= -1; --i1)
  155.                 {
  156.                     for (j1 = 0; j1 >= -1; --j1)
  157.                     {
  158.                         if (this.func_149880_a(world, par2 + i1, par3, par4 + j1, 5) && this.func_149880_a(world, par2 + i1 + 1, par3, par4 + j1, 5) && this.func_149880_a(world, par2 + i1, par3, par4 + j1 + 1, 5) && this.func_149880_a(world, par2 + i1 + 1, par3, par4 + j1 + 1, 5))
  159.                         {
  160.                             object = new WorldGenCanopyTree(true);
  161.                             flag = true;
  162.                             break label108;
  163.                         }
  164.                     }
  165.                 }
  166.  
  167.                 if (!flag)
  168.                 {
  169.                     return;
  170.                 }
  171.  
  172.         }
  173.         Block block = Blocks.air;
  174.  
  175.         if (flag)
  176.         {
  177.             world.setBlock(par2 + i1, par3, par4 + j1, block, 0, 4);
  178.             world.setBlock(par2 + i1 + 1, par3, par4 + j1, block, 0, 4);
  179.             world.setBlock(par2 + i1, par3, par4 + j1 + 1, block, 0, 4);
  180.             world.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, block, 0, 4);
  181.         }
  182.         else
  183.         {
  184.             world.setBlock(par2, par3, par4, block, 0, 4);
  185.         }
  186.  
  187.         if (!((WorldGenerator)object).generate(world, random, par2 + i1, par3, par4 + j1))
  188.         {
  189.             if (flag)
  190.             {
  191.                 world.setBlock(par2 + i1, par3, par4 + j1, this, l, 4);
  192.                 world.setBlock(par2 + i1 + 1, par3, par4 + j1, this, l, 4);
  193.                 world.setBlock(par2 + i1, par3, par4 + j1 + 1, this, l, 4);
  194.                 world.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, this, l, 4);
  195.             }
  196.             else
  197.             {
  198.                 world.setBlock(par2, par3, par4, this, l, 4);
  199.             }
  200.         }
  201.     }
  202.  
  203.     public boolean func_149880_a(World world, int par2, int par3, int par4, int par5)
  204.     {
  205.         return world.getBlock(par2, par3, par4) == this && (world.getBlockMetadata(par2, par3, par4) & 7) == par5;
  206.     }
  207.  
  208.     /**
  209.      * Determines the damage on the item the block drops. Used in cloth and wood.
  210.      */
  211.     public int damageDropped(int par1)
  212.     {
  213.         return MathHelper.clamp_int(par1 & 7, 0, 5);
  214.     }
  215.  
  216.     /**
  217.      * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
  218.      */
  219.     @SideOnly(Side.CLIENT)
  220.     public void getSubBlocks(Item item, CreativeTabs tabs, List list)
  221.     {
  222.         list.add(new ItemStack(item, 1, 0));
  223.     }
  224.  
  225.     @SideOnly(Side.CLIENT)
  226.     public void registerBlockIcons(IIconRegister icon)
  227.     {
  228.         for (int i = 0; i < saplingIcon.length; ++i)
  229.         {
  230.             saplingIcon[i] = icon.registerIcon("moem:SaplingMango");
  231.         }
  232.     }
  233.  
  234.     public boolean func_149851_a(World world, int par2, int par3, int par4, boolean par5)
  235.     {
  236.         return true;
  237.     }
  238.  
  239.     public boolean func_149852_a(World world, Random random, int par3, int par4, int par5)
  240.     {
  241.         return (double)world.rand.nextFloat() < 0.45D;
  242.     }
  243.  
  244.     public void func_149853_b(World world, Random random, int par3, int par4, int par5)
  245.     {
  246.         this.func_149879_c(world, par3, par4, par5, random);
  247.     }
  248. }
Add Comment
Please, Sign In to add comment