Guest User

MyBlockOre

a guest
Dec 26th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. package com.chef.mod.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.client.renderer.texture.IIconRegister;
  8. import net.minecraft.item.Item;
  9. import net.minecraft.util.MathHelper;
  10. import net.minecraft.world.IBlockAccess;
  11. import net.minecraft.world.World;
  12.  
  13. import com.chef.mod.Chef;
  14.  
  15. import cpw.mods.fml.relauncher.Side;
  16. import cpw.mods.fml.relauncher.SideOnly;
  17.  
  18. public class MyBlockOre extends Block
  19. {
  20.  
  21. public MyBlockOre()
  22. {
  23. super(Material.rock);
  24. this.setCreativeTab(Chef.chefTab);
  25. }
  26.  
  27.  
  28. int pickaxe = 1;
  29. private String[] harvestTool = new String[16];
  30. private int[] harvestLevel = new int[]{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  31.  
  32. @Override
  33. public int getHarvestLevel(int metadata)
  34. {
  35. if (this == Chef.oreSaltOre) {
  36. this.getHarvestLevel(2);
  37. } else if (this == Chef.oreSaltOre2) {
  38. this.getHarvestLevel(1);
  39. }
  40. return getHarvestLevel(0);
  41. }
  42.  
  43. public Item getItemDropped(int block, Random random, int j) {
  44. Item returnItem;
  45. if (this == Chef.oreSaltOre) {
  46. returnItem = Chef.itemSalt;
  47.  
  48. } else if (this == Chef.oreSaltOre2) {
  49. returnItem = Chef.itemSalt;
  50.  
  51. } else {
  52. returnItem = Item.getItemFromBlock(this);
  53. }
  54. return returnItem;
  55. }
  56.  
  57. /**
  58. * Returns the quantity of items to drop on block destruction.
  59. */
  60. public int quantityDropped(Random random)
  61. {
  62. return this == Chef.oreSaltOre ? 2 + random.nextInt(3) : 1;
  63. }
  64.  
  65. /**
  66. * Returns the usual quantity dropped by the block plus a bonus of 1 to 'i' (inclusive).
  67. */
  68. public int quantityDroppedWithBonus(int i, Random random)
  69. {
  70. if (i > 0 && Item.getItemFromBlock(this) != this.getItemDropped(0, random, i))
  71. {
  72. int j = random.nextInt(i + 2) - 1;
  73.  
  74. if (j < 0)
  75. {
  76. j = 0;
  77. }
  78.  
  79. return this.quantityDropped(random) * (j + 1);
  80. }
  81. else
  82. {
  83. return this.quantityDropped(random);
  84. }
  85. }
  86.  
  87. /**
  88. * Drops the block items with a specified chance of dropping the specified items
  89. */
  90. public void dropBlockAsItemWithChance(World world, int x, int y, int z, int i, float hitX, int hitZ)
  91. {
  92. super.dropBlockAsItemWithChance(world, x, y, z, i, hitX, hitZ);
  93. }
  94.  
  95. private Random rand = new Random();
  96. @Override
  97. public int getExpDrop(IBlockAccess p_149690_1_, int p_149690_5_, int p_149690_7_)
  98. {
  99. if (this.getItemDropped(p_149690_5_, rand, p_149690_7_) != Item.getItemFromBlock(this))
  100. {
  101. int exp = 0;
  102.  
  103. if (this == Chef.oreSaltOre)
  104. {
  105. exp = MathHelper.getRandomIntegerInRange(rand, 0, 2);
  106. }
  107.  
  108. else if (this == Chef.oreSaltOre2)
  109. {
  110. exp = MathHelper.getRandomIntegerInRange(rand, 0, 1);
  111. }
  112.  
  113. return exp;
  114. }
  115. return 0;
  116. }
  117.  
  118. /**
  119. * Determines the damage on the item the block drops. Used in cloth and wood.
  120. */
  121. public int damageDropped(int i)
  122. {
  123. return this == Chef.oreSaltOre ? 4 : 0;
  124. }
  125.  
  126. @SideOnly(Side.CLIENT)
  127. public void registerBlockIcons(IIconRegister iconRegister) {
  128. this.blockIcon = iconRegister.registerIcon(Chef.modid + ":" + this.getUnlocalizedName().substring(5));
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment