Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 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. // Break blocks on creative
  14. public boolean onBlockStartBreak(ItemStack itemStack, BlockPos pos, EntityPlayer player) {
  15. if (player.isCreative()) {
  16. EnumFacing facing = player.getHorizontalFacing();
  17. World worldIn = player.getEntityWorld();
  18. IBlockState state = worldIn.getBlockState(pos);
  19. Block block = state.getBlock();
  20. float headYaw = player.getRotationYawHead();
  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())) && ((double) state.getBlockHardness(worldIn,
  24. new BlockPos(x, y, pos.getZ()).offset(facing)) != 0.0D)) {
  25. state = worldIn.getBlockState(new BlockPos(x, y, pos.getZ()).offset(facing));
  26. if (state.getBlock().isToolEffective("pickaxe", state)) {
  27. itemStack.damageItem(1, player);
  28. } else {
  29. itemStack.damageItem(3, player);
  30. }
  31. }
  32. worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()).offset(facing));
  33. }
  34. }
  35. }
  36. return false;
  37. }
  38.  
  39. @Override
  40. // Break blocks on survival
  41. public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos,
  42. EntityLivingBase entityLiving) {
  43. EnumFacing facing = entityLiving.getHorizontalFacing();
  44. Block block = state.getBlock();
  45. float headYaw = entityLiving.getRotationYawHead();
  46. EntityPlayer player = (EntityPlayer) entityLiving;
  47. for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
  48. for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
  49. if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ())) && ((double) state.getBlockHardness(worldIn,
  50. new BlockPos(x, y, pos.getZ()).offset(facing)) != 0.0D)) {
  51. state = worldIn.getBlockState(new BlockPos(x, y, pos.getZ()).offset(facing));
  52. if (state.getBlock().isToolEffective("pickaxe", state)) {
  53. stack.damageItem(1, entityLiving);
  54. } else {
  55. stack.damageItem(3, entityLiving);
  56. }
  57. }
  58. if (block.canHarvestBlock(worldIn, new BlockPos(x, y, pos.getZ()).offset(facing), player)) {
  59. worldIn.destroyBlock(new BlockPos(x, y, pos.getZ()).offset(facing), true);
  60. } else {
  61. worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()).offset(facing));
  62. }
  63. }
  64. }
  65. return true;
  66. }
  67.  
  68. @Override
  69. public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
  70. itemStack.damageItem(1, attacker);
  71. return true;
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement