Advertisement
Guest User

Untitled

a guest
May 25th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. package mod.pyrhatt.moplants;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import java.util.Random;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.util.AxisAlignedBB;
  11. import net.minecraft.world.World;
  12.  
  13. import net.minecraftforge.common.EnumPlantType;
  14. import net.minecraftforge.common.ForgeDirection;
  15. import net.minecraftforge.common.IPlantable;
  16.  
  17. public class BlockTomato extends Block implements IPlantable
  18. {
  19. protected BlockTomato(int par1)
  20. {
  21. super(par1, Material.plants);
  22. float f = 0.375F;
  23. this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
  24. this.setTickRandomly(true);
  25. this.disableStats();
  26. }
  27.  
  28. /**
  29. * Ticks the block if it's been scheduled
  30. */
  31. public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  32. {
  33. if (par1World.isAirBlock(par2, par3 + 1, par4))
  34. {
  35. int l;
  36.  
  37. for (l = 1; par1World.getBlockId(par2, par3 - l, par4) == this.blockID; ++l)
  38. {
  39. ;
  40. }
  41.  
  42. if (l < 2)
  43. {
  44. int i1 = par1World.getBlockMetadata(par2, par3, par4);
  45.  
  46. if (i1 == 15)
  47. {
  48. par1World.setBlock(par2, par3 + 1, par4, this.blockID);
  49. par1World.setBlockMetadataWithNotify(par2, par3, par4, 0, 4);
  50. }
  51. else
  52. {
  53. par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 + 1, 4);
  54. }
  55. }
  56. }
  57. }
  58.  
  59. /**
  60. * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
  61. */
  62. public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
  63. {
  64. Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
  65. return (block != null && block.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
  66. }
  67.  
  68. /**
  69. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  70. * their own) Args: x, y, z, neighbor blockID
  71. */
  72. public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  73. {
  74. this.checkBlockCoordValid(par1World, par2, par3, par4);
  75. }
  76.  
  77. /**
  78. * Checks if current block pos is valid, if not, breaks the block as dropable item. Used for reed and cactus.
  79. */
  80. protected final void checkBlockCoordValid(World par1World, int par2, int par3, int par4)
  81. {
  82. if (!this.canBlockStay(par1World, par2, par3, par4))
  83. {
  84. this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
  85. par1World.setBlockToAir(par2, par3, par4);
  86. }
  87. }
  88.  
  89. /**
  90. * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
  91. */
  92. public boolean canBlockStay(World par1World, int par2, int par3, int par4)
  93. {
  94. return this.canPlaceBlockAt(par1World, par2, par3, par4);
  95. }
  96.  
  97. /**
  98. * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  99. * cleared to be reused)
  100. */
  101. public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
  102. {
  103. return null;
  104. }
  105.  
  106. /**
  107. * Returns the ID of the items to drop on destruction.
  108. */
  109. public int idDropped(int par1, Random par2Random, int par3)
  110. {
  111. return BaseMoplants.tomato.itemID;
  112. }
  113.  
  114. /**
  115. * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
  116. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  117. */
  118. public boolean isOpaqueCube()
  119. {
  120. return false;
  121. }
  122.  
  123. /**
  124. * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  125. */
  126. public boolean renderAsNormalBlock()
  127. {
  128. return false;
  129. }
  130.  
  131. /**
  132. * The type of render function that is called for this block
  133. */
  134. public int getRenderType()
  135. {
  136. return 1;
  137. }
  138.  
  139. @SideOnly(Side.CLIENT)
  140.  
  141. /**
  142. * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
  143. */
  144. public int idPicked(World par1World, int par2, int par3, int par4)
  145. {
  146. return BaseMoplants.tomato.itemID;
  147. }
  148.  
  149. @Override
  150. public EnumPlantType getPlantType(World world, int x, int y, int z)
  151. {
  152. return EnumPlantType.Beach;
  153. }
  154.  
  155. @Override
  156. public int getPlantID(World world, int x, int y, int z)
  157. {
  158. return blockID;
  159. }
  160.  
  161. @Override
  162. public int getPlantMetadata(World world, int x, int y, int z)
  163. {
  164. return world.getBlockMetadata(x, y, z);
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement