Guest User

Untitled

a guest
Jul 27th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. public class Hammer extends ItemTool {
  2.  
  3. public static float attack_speed = -2.8F;
  4. public static float damage = 3.0F;
  5.  
  6. public Hammer(ToolMaterial toolMaterial, int durabillity) {
  7. super(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. World world = player.getEntityWorld();
  17. RayTraceResult sideHit = this.rayTrace(world, player, false);
  18. EnumFacing facing = sideHit.sideHit;
  19. EnumFacing facing1 = null, facing2 = null;
  20. for (EnumFacing.Axis axis : EnumFacing.Axis.values()) {
  21. if (axis == facing.getAxis()) {
  22. continue;
  23. }
  24. EnumFacing f = EnumFacing.getFacingFromAxis(EnumFacing.AxisDirection.POSITIVE, axis);
  25. if (facing1 == null) {
  26. facing1 = f;
  27. } else {
  28. facing2 = f;
  29. }
  30. }
  31.  
  32. for (int i = -1; i <= 1; i++) {
  33. BlockPos offset1 = pos.offset(facing1, i);
  34. for (int j = -1; j <= 1; j++) {
  35. if (i == 0 && j == 0)
  36. continue;
  37. BlockPos offset2 = offset1.offset(facing2, j);
  38. world.destroyBlock(offset2, false);
  39. }
  40. }
  41. }
  42. return false;
  43. }
  44.  
  45. @Override
  46. // Break blocks on survival
  47. public boolean onBlockDestroyed(ItemStack itemStack, World worldIn, IBlockState state, BlockPos pos,
  48. EntityLivingBase entityLiving) {
  49. EntityPlayer player = (EntityPlayer) entityLiving;
  50. RayTraceResult sideHit = this.rayTrace(worldIn, player, false);
  51. EnumFacing facing = sideHit.sideHit;
  52. EnumFacing facing1 = null, facing2 = null;
  53. for (EnumFacing.Axis axis : EnumFacing.Axis.values()) {
  54. if (axis == facing.getAxis()) {
  55. continue;
  56. }
  57. EnumFacing f = EnumFacing.getFacingFromAxis(EnumFacing.AxisDirection.POSITIVE, axis);
  58. if (facing1 == null) {
  59. facing1 = f;
  60. } else {
  61. facing2 = f;
  62. }
  63. }
  64.  
  65. for (int i = -1; i <= 1; i++) {
  66. BlockPos offset1 = pos.offset(facing1, i);
  67. for (int j = -1; j <= 1; j++) {
  68. if (i == 0 && j == 0)
  69. continue;
  70. BlockPos offset2 = offset1.offset(facing2, j);
  71. if (worldIn.getBlockState(offset2).getBlock().canHarvestBlock(worldIn, offset2, player)) {
  72. worldIn.destroyBlock(offset2, true);
  73. } else {
  74. worldIn.destroyBlock(offset2, false);
  75. }
  76. if (state.getBlock().isToolEffective("pickaxe", state)) {
  77. if ((double) state.getBlockHardness(worldIn, pos) != 0.0D && state.getBlock() != Blocks.AIR) {
  78. itemStack.damageItem(1, player);
  79. }
  80. } else {
  81. if ((double) state.getBlockHardness(worldIn, pos) != 0.0D && state.getBlock() != Blocks.AIR) {
  82. itemStack.damageItem(3, player);
  83. }
  84. }
  85. }
  86. }
  87. if ((double) state.getBlockHardness(worldIn, pos) != 0.0D) {
  88. itemStack.damageItem(1, entityLiving);
  89. }
  90. return true;
  91. }
  92.  
  93. @Override
  94. public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
  95. itemStack.damageItem(1, attacker);
  96. return true;
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment