Advertisement
Guest User

ModSaplings

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