Guest User

Untitled

a guest
Jul 16th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. public class Hammer extends ItemTool {
  2.  
  3. public static float attack_speed = -2.8F;
  4. public static float base_damage = 3.0F;
  5.  
  6. public Hammer(ToolMaterial toolMaterial, int durabillity) {
  7. super(base_damage, attack_speed, toolMaterial, Collections.emptySet());
  8. this.setHarvestLevel("pickaxe", toolMaterial.getHarvestLevel());
  9. this.setMaxDamage(durabillity);
  10. }
  11.  
  12. @Override
  13. public boolean onBlockStartBreak(ItemStack itemStack, BlockPos pos, EntityPlayer player) {
  14. if (player.isCreative()) {
  15. EnumFacing facing = player.getHorizontalFacing();
  16. World worldIn = player.getEntityWorld();
  17. IBlockState state = worldIn.getBlockState(pos);
  18. Block block = state.getBlock();
  19. float headYaw = player.getRotationYawHead();
  20. if (facing == facing.NORTH) {
  21. for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
  22. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  23. if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ()))
  24. && ((double) state.getBlockHardness(worldIn, new BlockPos(x, y, pos.getZ())) != 0.0D)) {
  25. if (state.getBlock().isToolEffective("pickaxe", state)) {
  26. itemStack.damageItem(1, player);
  27. } else {
  28. itemStack.damageItem(3, player);
  29. }
  30. }
  31. worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
  32. }
  33. }
  34. }
  35. if (facing == facing.SOUTH) {
  36. for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
  37. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  38. if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ()))
  39. && ((double) state.getBlockHardness(worldIn, new BlockPos(x, y, pos.getZ())) != 0.0D)) {
  40. if (state.getBlock().isToolEffective("pickaxe", state)) {
  41. itemStack.damageItem(1, player);
  42. } else {
  43. itemStack.damageItem(3, player);
  44. }
  45. }
  46. worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
  47. }
  48. }
  49. }
  50. if (facing == facing.EAST) {
  51. for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
  52. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  53. if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
  54. && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
  55. if (state.getBlock().isToolEffective("pickaxe", state)) {
  56. itemStack.damageItem(1, player);
  57. } else {
  58. itemStack.damageItem(3, player);
  59. }
  60. }
  61. worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
  62. }
  63. }
  64. }
  65. if (facing == facing.WEST) {
  66. for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
  67. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  68. if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
  69. && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
  70. if (state.getBlock().isToolEffective("pickaxe", state)) {
  71. itemStack.damageItem(1, player);
  72. } else {
  73. itemStack.damageItem(3, player);
  74. }
  75. }
  76. worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
  77. }
  78. }
  79. }
  80. }
  81. return false;
  82. }
  83.  
  84. @Override
  85. public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos,
  86. EntityLivingBase entityLiving) {
  87. EnumFacing facing = entityLiving.getHorizontalFacing();
  88. Block block = state.getBlock();
  89. float headYaw = entityLiving.getRotationYawHead();
  90. EntityPlayer player = (EntityPlayer) entityLiving;
  91. if (facing == facing.NORTH) {
  92. for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
  93. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  94. if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ()))
  95. && ((double) state.getBlockHardness(worldIn, new BlockPos(x, y, pos.getZ())) != 0.0D)) {
  96. if (state.getBlock().isToolEffective("pickaxe", state)) {
  97. stack.damageItem(1, entityLiving);
  98. } else {
  99. stack.damageItem(3, entityLiving);
  100. }
  101. }
  102. if (block.canHarvestBlock(worldIn, new BlockPos(x, y, pos.getZ()), player)) {
  103. worldIn.destroyBlock(new BlockPos(x, y, pos.getZ()), true);
  104. } else {
  105. worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
  106. }
  107. }
  108. }
  109. }
  110. if (facing == facing.SOUTH) {
  111. for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
  112. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  113. if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ()))
  114. && ((double) state.getBlockHardness(worldIn, new BlockPos(x, y, pos.getZ())) != 0.0D)) {
  115. if (state.getBlock().isToolEffective("pickaxe", state)) {
  116. stack.damageItem(1, entityLiving);
  117. } else {
  118. stack.damageItem(3, entityLiving);
  119. }
  120. }
  121. if (block.canHarvestBlock(worldIn, new BlockPos(x, y, pos.getZ()), player)) {
  122. worldIn.destroyBlock(new BlockPos(x, y, pos.getZ()), true);
  123. } else {
  124. worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
  125. }
  126. }
  127. }
  128. }
  129. if (facing == facing.EAST) {
  130. for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
  131. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  132. if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
  133. && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
  134. if (state.getBlock().isToolEffective("pickaxe", state)) {
  135. stack.damageItem(1, entityLiving);
  136. } else {
  137. stack.damageItem(3, entityLiving);
  138. }
  139. }
  140. if (block.canHarvestBlock(worldIn, new BlockPos(pos.getX(), y, z), player)) {
  141. worldIn.destroyBlock(new BlockPos(pos.getX(), y, z), true);
  142. } else {
  143. worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
  144. }
  145. }
  146. }
  147. }
  148. if (facing == facing.WEST) {
  149. for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
  150. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  151. if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
  152. && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
  153. if (state.getBlock().isToolEffective("pickaxe", state)) {
  154. stack.damageItem(1, entityLiving);
  155. } else {
  156. stack.damageItem(3, entityLiving);
  157. }
  158. }
  159. if (block.canHarvestBlock(worldIn, new BlockPos(pos.getX(), y, z), player)) {
  160. worldIn.destroyBlock(new BlockPos(pos.getX(), y, z), true);
  161. } else {
  162. worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
  163. }
  164. }
  165. }
  166. }
  167. return true;
  168. }
  169.  
  170. @Override
  171. public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
  172. itemStack.damageItem(1, attacker);
  173. return true;
  174. }
  175.  
  176. }
Add Comment
Please, Sign In to add comment