Guest User

sapling.java

a guest
Apr 9th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 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.WorldGenTrees;
  23. import net.minecraft.world.gen.feature.WorldGenerator;
  24.  
  25. public class mangoSapling extends BlockBush implements IGrowable
  26. {
  27. public static final String[] field_149882_a = new String[] {"Mango"};
  28. private static final IIcon[] saplingIcon = new IIcon[field_149882_a.length];
  29.  
  30. protected mangoSapling()
  31. {
  32. float f = 0.4F;
  33. this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
  34. this.setStepSound(this.soundTypeGrass);
  35. }
  36.  
  37. /**
  38. * Ticks the block if it's been scheduled
  39. */
  40. public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
  41. {
  42. if (!p_149674_1_.isRemote)
  43. {
  44. super.updateTick(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_5_);
  45.  
  46. if (p_149674_1_.getBlockLightValue(p_149674_2_, p_149674_3_ + 1, p_149674_4_) >= 9 && p_149674_5_.nextInt(7) == 0)
  47. {
  48. this.func_149879_c(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_5_);
  49. }
  50. }
  51. }
  52.  
  53. /**
  54. * Gets the block's texture. Args: side, meta
  55. */
  56. @SideOnly(Side.CLIENT)
  57. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  58. {
  59. p_149691_2_ &= 7;
  60. return saplingIcon[MathHelper.clamp_int(p_149691_2_, 0, 5)];
  61. }
  62.  
  63. public void func_149879_c(World p_149879_1_, int p_149879_2_, int p_149879_3_, int p_149879_4_, Random p_149879_5_)
  64. {
  65. int l = p_149879_1_.getBlockMetadata(p_149879_2_, p_149879_3_, p_149879_4_);
  66.  
  67. if ((l & 8) == 0)
  68. {
  69. p_149879_1_.setBlockMetadataWithNotify(p_149879_2_, p_149879_3_, p_149879_4_, l | 8, 4);
  70. }
  71. else
  72. {
  73. this.func_149878_d(p_149879_1_, p_149879_2_, p_149879_3_, p_149879_4_, p_149879_5_);
  74. }
  75. }
  76.  
  77. public void func_149878_d(World p_149878_1_, int p_149878_2_, int p_149878_3_, int p_149878_4_, Random p_149878_5_)
  78. {
  79. if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(p_149878_1_, p_149878_5_, p_149878_2_, p_149878_3_, p_149878_4_)) return;
  80. int l = p_149878_1_.getBlockMetadata(p_149878_2_, p_149878_3_, p_149878_4_) & 7;
  81. Object object = p_149878_5_.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
  82. int i1 = 0;
  83. int j1 = 0;
  84. boolean flag = false;
  85.  
  86. switch (l)
  87. {
  88. case 0:
  89. break;
  90. case 1:
  91. object = new WorldGenMangoTree(mod.mangoLog, mod.mangoLeaf, 0, 0, false, 10, 15, false);
  92. break;
  93. case 2:
  94. break;
  95. case 3:
  96. break;
  97. case 4:
  98. break;
  99. case 5:
  100. break;
  101. default:
  102. break;
  103.  
  104. }
  105. Block block = Blocks.air;
  106.  
  107. if (flag)
  108. {
  109. p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, block, 0, 4);
  110. p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, block, 0, 4);
  111. p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, block, 0, 4);
  112. p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, block, 0, 4);
  113. }
  114. else
  115. {
  116. p_149878_1_.setBlock(p_149878_2_, p_149878_3_, p_149878_4_, block, 0, 4);
  117. }
  118.  
  119. if (!((WorldGenerator)object).generate(p_149878_1_, p_149878_5_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1))
  120. {
  121. if (flag)
  122. {
  123. p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, this, l, 4);
  124. p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, this, l, 4);
  125. p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, this, l, 4);
  126. p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, this, l, 4);
  127. }
  128. else
  129. {
  130. p_149878_1_.setBlock(p_149878_2_, p_149878_3_, p_149878_4_, this, l, 4);
  131. }
  132. }
  133. }
  134.  
  135. public boolean func_149880_a(World p_149880_1_, int p_149880_2_, int p_149880_3_, int p_149880_4_, int p_149880_5_)
  136. {
  137. return p_149880_1_.getBlock(p_149880_2_, p_149880_3_, p_149880_4_) == this && (p_149880_1_.getBlockMetadata(p_149880_2_, p_149880_3_, p_149880_4_) & 7) == p_149880_5_;
  138. }
  139.  
  140. /**
  141. * Determines the damage on the item the block drops. Used in cloth and wood.
  142. */
  143. public int damageDropped(int p_149692_1_)
  144. {
  145. return MathHelper.clamp_int(p_149692_1_ & 7, 0, 5);
  146. }
  147.  
  148. /**
  149. * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
  150. */
  151. @SideOnly(Side.CLIENT)
  152. public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_)
  153. {
  154. p_149666_3_.add(new ItemStack(p_149666_1_, 1, 0));
  155. }
  156.  
  157. @SideOnly(Side.CLIENT)
  158. public void registerBlockIcons(IIconRegister icon)
  159. {
  160. for (int i = 0; i < saplingIcon.length; ++i)
  161. {
  162. saplingIcon[i] = icon.registerIcon("moem:SaplingMango");
  163. }
  164. }
  165.  
  166. public boolean func_149851_a(World p_149851_1_, int p_149851_2_, int p_149851_3_, int p_149851_4_, boolean p_149851_5_)
  167. {
  168. return true;
  169. }
  170.  
  171. public boolean func_149852_a(World p_149852_1_, Random p_149852_2_, int p_149852_3_, int p_149852_4_, int p_149852_5_)
  172. {
  173. return (double)p_149852_1_.rand.nextFloat() < 0.45D;
  174. }
  175.  
  176. public void func_149853_b(World p_149853_1_, Random p_149853_2_, int p_149853_3_, int p_149853_4_, int p_149853_5_)
  177. {
  178. this.func_149879_c(p_149853_1_, p_149853_3_, p_149853_4_, p_149853_5_, p_149853_2_);
  179. }
  180. }
Add Comment
Please, Sign In to add comment