Advertisement
Guest User

BlockPapaya

a guest
Mar 2nd, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 0
  1. package mymod.blocks;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.Random;
  8.  
  9. import mymod.Main;
  10. import net.minecraft.block.BlockDirectional;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.client.renderer.texture.IconRegister;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.AxisAlignedBB;
  17. import net.minecraft.util.Direction;
  18. import net.minecraft.util.Icon;
  19. import net.minecraft.util.MathHelper;
  20. import net.minecraft.world.IBlockAccess;
  21. import net.minecraft.world.World;
  22.  
  23. public class BlockPapaya extends BlockDirectional
  24. {
  25. @SideOnly(Side.CLIENT)
  26. private Icon[] iconArray;
  27.  
  28. public BlockPapaya(int par1)
  29. {
  30. super(par1, Material.plants);
  31. this.setTickRandomly(true);
  32. }
  33.  
  34. @SideOnly(Side.CLIENT)
  35.  
  36. /**
  37. * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
  38. */
  39. public Icon getIcon(int par1, int par2)
  40. {
  41. return this.iconArray[2];
  42. }
  43.  
  44. /**
  45. * Ticks the block if it's been scheduled
  46. */
  47. public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  48. {
  49. if (!this.canBlockStay(par1World, par2, par3, par4))
  50. {
  51. this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
  52. par1World.setBlock(par2, par3, par4, 0, 0, 2);
  53. }
  54. else if (par1World.rand.nextInt(5) == 0)
  55. {
  56. int l = par1World.getBlockMetadata(par2, par3, par4);
  57. int i1 = func_72219_c(l);
  58.  
  59. if (i1 < 2)
  60. {
  61. ++i1;
  62. par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 << 2 | getDirection(l), 2);
  63. }
  64. }
  65. }
  66.  
  67. @SideOnly(Side.CLIENT)
  68. public Icon getPapayaIcon(int par1)
  69. {
  70. if (par1 < 0 || par1 >= this.iconArray.length)
  71. {
  72. par1 = this.iconArray.length - 1;
  73. }
  74.  
  75. return this.iconArray[par1];
  76. }
  77.  
  78. /**
  79. * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
  80. */
  81. public boolean canBlockStay(World par1World, int par2, int par3, int par4)
  82. {
  83. int l = getDirection(par1World.getBlockMetadata(par2, par3, par4));
  84. par2 += Direction.offsetX[l];
  85. par4 += Direction.offsetZ[l];
  86. int i1 = par1World.getBlockId(par2, par3, par4);
  87. return i1 == Main.ModLogs.blockID && ModLogs.limitToValidMetadata(par1World.getBlockMetadata(par2, par3, par4)) == 3;
  88. }
  89.  
  90. /**
  91. * The type of render function that is called for this block
  92. */
  93. public int getRenderType()
  94. {
  95. return 28;
  96. }
  97.  
  98. /**
  99. * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  100. */
  101. public boolean renderAsNormalBlock()
  102. {
  103. return false;
  104. }
  105.  
  106. /**
  107. * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
  108. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  109. */
  110. public boolean isOpaqueCube()
  111. {
  112. return false;
  113. }
  114.  
  115. /**
  116. * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  117. * cleared to be reused)
  118. */
  119. public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
  120. {
  121. this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
  122. return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
  123. }
  124.  
  125. @SideOnly(Side.CLIENT)
  126.  
  127. /**
  128. * Returns the bounding box of the wired rectangular prism to render.
  129. */
  130. public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
  131. {
  132. this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
  133. return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
  134. }
  135.  
  136. /**
  137. * Updates the blocks bounds based on its current state. Args: world, x, y, z
  138. */
  139. public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
  140. {
  141. int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
  142. int i1 = getDirection(l);
  143. int j1 = func_72219_c(l);
  144. int k1 = 4 + j1 * 2;
  145. int l1 = 5 + j1 * 2;
  146. float f = (float)k1 / 2.0F;
  147.  
  148. switch (i1)
  149. {
  150. case 0:
  151. this.setBlockBounds((8.0F - f) / 16.0F, (12.0F - (float)l1) / 16.0F, (15.0F - (float)k1) / 16.0F, (8.0F + f) / 16.0F, 0.75F, 0.9375F);
  152. break;
  153. case 1:
  154. this.setBlockBounds(0.0625F, (12.0F - (float)l1) / 16.0F, (8.0F - f) / 16.0F, (1.0F + (float)k1) / 16.0F, 0.75F, (8.0F + f) / 16.0F);
  155. break;
  156. case 2:
  157. this.setBlockBounds((8.0F - f) / 16.0F, (12.0F - (float)l1) / 16.0F, 0.0625F, (8.0F + f) / 16.0F, 0.75F, (1.0F + (float)k1) / 16.0F);
  158. break;
  159. case 3:
  160. this.setBlockBounds((15.0F - (float)k1) / 16.0F, (12.0F - (float)l1) / 16.0F, (8.0F - f) / 16.0F, 0.9375F, 0.75F, (8.0F + f) / 16.0F);
  161. }
  162. }
  163.  
  164. /**
  165. * Called when the block is placed in the world.
  166. */
  167. public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
  168. {
  169. int l = ((MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) + 0) % 4;
  170. par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
  171. }
  172.  
  173. /**
  174. * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
  175. */
  176. public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
  177. {
  178. if (par5 == 1 || par5 == 0)
  179. {
  180. par5 = 2;
  181. }
  182.  
  183. return Direction.rotateOpposite[Direction.facingToDirection[par5]];
  184. }
  185.  
  186. /**
  187. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  188. * their own) Args: x, y, z, neighbor blockID
  189. */
  190. public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  191. {
  192. if (!this.canBlockStay(par1World, par2, par3, par4))
  193. {
  194. this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
  195. par1World.setBlock(par2, par3, par4, 0, 0, 2);
  196. }
  197. }
  198.  
  199. public static int func_72219_c(int par0)
  200. {
  201. return (par0 & 12) >> 2;
  202. }
  203.  
  204. /**
  205. * Drops the block items with a specified chance of dropping the specified items
  206. */
  207. public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
  208. {
  209. super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);
  210. }
  211.  
  212. @Override
  213. public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
  214. {
  215. ArrayList<ItemStack> dropped = super.getBlockDropped(world, x, y, z, metadata, fortune);
  216. int j1 = func_72219_c(metadata);
  217. byte b0 = 1;
  218.  
  219. if (j1 >= 2)
  220. {
  221. b0 = 3;
  222. }
  223.  
  224. for (int k1 = 0; k1 < b0; ++k1)
  225. {
  226. dropped.add(new ItemStack(Main.blockPapaya, 1, 3));
  227. }
  228. return dropped;
  229. }
  230.  
  231. @SideOnly(Side.CLIENT)
  232.  
  233. /**
  234. * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
  235. */
  236. public int idPicked(World par1World, int par2, int par3, int par4)
  237. {
  238. return Main.MyFood_1.itemID;
  239. }
  240.  
  241. /**
  242. * Get the block's damage value (for use with pick block).
  243. */
  244. public int getDamageValue(World par1World, int par2, int par3, int par4)
  245. {
  246. return 3;
  247. }
  248.  
  249. @SideOnly(Side.CLIENT)
  250.  
  251. /**
  252. * When this method is called, your block should register all the icons it needs with the given IconRegister. This
  253. * is the only chance you get to register icons.
  254. */
  255. public void registerIcons(IconRegister par1IconRegister)
  256. {
  257. this.iconArray = new Icon[3];
  258.  
  259. for (int i = 0; i < this.iconArray.length; ++i)
  260. {
  261. this.iconArray[i] = par1IconRegister.registerIcon("mymod:Papaya" + i);
  262. }
  263. }
  264.  
  265. @Override
  266. public int idDropped(int par1, Random par2Random, int par3)
  267. {
  268. return 0;
  269. }
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement