Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. package fantasy_biomes.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockFlower;
  7. import net.minecraft.client.renderer.texture.IconRegister;
  8. import net.minecraft.world.World;
  9. import net.minecraft.world.gen.feature.WorldGenForest;
  10. import net.minecraft.world.gen.feature.WorldGenTaiga2;
  11. import net.minecraft.world.gen.feature.WorldGenerator;
  12. import net.minecraftforge.event.terraingen.TerrainGen;
  13. import fantasy_biomes.Main;
  14. import fantasy_biomes.trees.WorldGenTulipTree;
  15.  
  16.  
  17. public class BlockTulipTreeSapling extends BlockFlower
  18. {
  19. /** change the name to your sapling name **/
  20. public static final String[] WOOD_TYPES = new String[] {"Tulip"};
  21. public BlockTulipTreeSapling(int i, int j)
  22. {
  23. super(i);
  24. float var3 = 0.4F;
  25. this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, var3 * 2.0F, 0.5F + var3);
  26. }
  27.  
  28. @Override
  29. public void registerIcons(IconRegister iconRegister)
  30. {
  31. blockIcon = iconRegister.registerIcon(Main.modid.toLowerCase() + ":" + this.getUnlocalizedName().substring(5));
  32. }
  33.  
  34. /**
  35. * Ticks the block if it's been scheduled
  36. */
  37. public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  38. {
  39. if (!par1World.isRemote)
  40. {
  41. super.updateTick(par1World, par2, par3, par4, par5Random);
  42. if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9 && par5Random.nextInt(7) == 0)
  43. {
  44. this.func_96477_c(par1World, par2, par3, par4, par5Random);
  45. }
  46. }
  47. }
  48. public void func_96477_c(World par1World, int par2, int par3, int par4, Random par5Random)
  49. {
  50. int l = par1World.getBlockMetadata(par2, par3, par4);
  51. /** change this block to your custom grass block **/
  52. if ((l & 8) == Main.blockEnchantedGrass.blockID)
  53. {
  54. par1World.setBlockMetadataWithNotify(par2, par3, par4, l | 8, 4);
  55. }
  56. else
  57. {
  58. this.growTree(par1World, par2, par3, par4, par5Random);
  59. }
  60. }
  61. /**
  62. * Attempts to grow a sapling into a tree
  63. */
  64. public void growTree(World par1World, int par2, int par3, int par4, Random par5Random)
  65. {
  66. if (!TerrainGen.saplingGrowTree(par1World, par5Random, par2, par3, par4)) return;
  67. int l = par1World.getBlockMetadata(par2, par3, par4) & 3;
  68. Object object = null;
  69. int i1 = 0;
  70. int j1 = 0;
  71. boolean flag = false;
  72. if (l == 1)
  73. {
  74. object = new WorldGenTaiga2(true);
  75. }
  76. else if (l == 2)
  77. {
  78. object = new WorldGenForest(true);
  79. }
  80. else if (l == 3)
  81. {
  82. for (i1 = 0; i1 >= -1; --i1)
  83. {
  84. for (j1 = 0; j1 >= -1; --j1)
  85. {
  86. 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))
  87. {
  88. /** Change this to your WorldGenNAMETree **/
  89. object = new WorldGenTulipTree(true, 10 + par5Random.nextInt(20), 3, 3, false);
  90. flag = true;
  91. break;
  92. }
  93. }
  94. if (object != null)
  95. {
  96. break;
  97. }
  98. }
  99. if (object == null)
  100. {
  101. j1 = 0;
  102. i1 = 0;
  103. /** Change this to your WorldGenNAMETree **/
  104. object = new WorldGenTulipTree(true, 4 + par5Random.nextInt(7), 3, 3, false);
  105. }
  106. }
  107. else
  108. {
  109. /** Change this to your WorldGenNAMETree **/
  110. object = new WorldGenTulipTree(true); // Changed //
  111. if (par5Random.nextInt(10) == 0)
  112. {
  113. object = new WorldGenTulipTree(true);
  114. }
  115. }
  116. if (flag)
  117. {
  118. par1World.setBlock(par2 + i1, par3, par4 + j1, 0, 0, 4);
  119. par1World.setBlock(par2 + i1 + 1, par3, par4 + j1, 0, 0, 4);
  120. par1World.setBlock(par2 + i1, par3, par4 + j1 + 1, 0, 0, 4);
  121. par1World.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, 0, 0, 4);
  122. }
  123. else
  124. {
  125. par1World.setBlock(par2, par3, par4, 0, 0, 4);
  126. }
  127. if (!((WorldGenerator)object).generate(par1World, par5Random, par2 + i1, par3, par4 + j1))
  128. {
  129. if (flag)
  130. {
  131. par1World.setBlock(par2 + i1, par3, par4 + j1, this.blockID, l, 4);
  132. par1World.setBlock(par2 + i1 + 1, par3, par4 + j1, this.blockID, l, 4);
  133. par1World.setBlock(par2 + i1, par3, par4 + j1 + 1, this.blockID, l, 4);
  134. par1World.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, this.blockID, l, 4);
  135. }
  136. else
  137. {
  138. par1World.setBlock(par2, par3, par4, this.blockID, l, 4);
  139. }
  140. }
  141. }
  142. /**
  143. * Determines if the same sapling is present at the given location.
  144. */
  145. public boolean isSameSapling(World par1World, int par2, int par3, int par4, int par5)
  146. {
  147. return par1World.getBlockId(par2, par3, par4) == this.blockID && (par1World.getBlockMetadata(par2, par3, par4) & 3) == par5;
  148. }
  149. /**
  150. * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
  151. * blockID passed in. Args: blockID
  152. */
  153. @Override
  154. protected boolean canThisPlantGrowOnThisBlockID(int par1)
  155. {
  156. /** Change this to your custom grass **/
  157. return par1 == Main.blockEnchantedGrass.blockID || par1 == Block.dirt.blockID || par1 == Block.tilledField.blockID;
  158. }
  159.  
  160. public boolean boneFertilize (World world, int x, int y, int z, Random random)
  161. {
  162. int meta = world.getBlockMetadata(x, y, z);
  163.  
  164. /*if (meta % 8 == 0)
  165. return false;*/
  166.  
  167. if ((meta & 8) == 0)
  168. {
  169. world.setBlockMetadataWithNotify(x, y, z, meta | 8, 4);
  170. }
  171. else
  172. {
  173. this.growTree(world, x, y, z, random);
  174. }
  175.  
  176. return true;
  177. }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement