Guest User

Untitled

a guest
Jul 31st, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. public class Multitool extends ItemTool {
  2.  
  3. public Item repairItem;
  4. public static float attack_speed = -2.8F;
  5. public static float base_damage = 3.0F;
  6.  
  7. public Multitool(ToolMaterial material, Item repairItem) {
  8. super(base_damage, attack_speed, material, Collections.emptySet());
  9. this.setHarvestLevel("pickaxe", material.getHarvestLevel());
  10. this.setHarvestLevel("axe", material.getHarvestLevel());
  11. this.setHarvestLevel("spade", material.getHarvestLevel());
  12. this.setHarvestLevel("hoe", material.getHarvestLevel());
  13. this.setHarvestLevel("sword", material.getHarvestLevel());
  14. this.repairItem = repairItem;
  15. }
  16.  
  17. protected void func_185071_a(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state) {
  18. worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
  19.  
  20. if (!worldIn.isRemote) {
  21. worldIn.setBlockState(pos, state, 11);
  22. stack.damageItem(1, player);
  23. }
  24. }
  25.  
  26. @Override
  27. @SuppressWarnings("incomplete-switch")
  28. public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
  29. EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  30. // Makes it work like a hoe
  31. if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack)) {
  32. return EnumActionResult.FAIL;
  33. } else {
  34. int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
  35. if (hook != 0)
  36. return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
  37.  
  38. IBlockState iblockstate = worldIn.getBlockState(pos);
  39. Block block = iblockstate.getBlock();
  40.  
  41. if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) {
  42. if (block == Blocks.GRASS || block == Blocks.GRASS_PATH) {
  43. this.func_185071_a(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
  44. return EnumActionResult.SUCCESS;
  45. }
  46.  
  47. if (block == Blocks.DIRT) {
  48. switch ((BlockDirt.DirtType) iblockstate.getValue(BlockDirt.VARIANT)) {
  49. case DIRT:
  50. this.func_185071_a(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
  51. return EnumActionResult.SUCCESS;
  52. case COARSE_DIRT:
  53. this.func_185071_a(stack, playerIn, worldIn, pos,
  54. Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
  55. return EnumActionResult.SUCCESS;
  56. }
  57. }
  58. }
  59.  
  60. return EnumActionResult.PASS;
  61. }
  62. }
  63.  
  64. @Override
  65. public float getStrVsBlock(ItemStack stack, IBlockState state) {
  66. for (String type : getToolClasses(stack)) {
  67. if (state.getBlock().isToolEffective(type, state))
  68. return efficiencyOnProperMaterial;
  69. }
  70. if (state.getBlock() == Blocks.WEB) {
  71. return (efficiencyOnProperMaterial * 5);
  72. }
  73. return efficiencyOnProperMaterial;
  74. }
  75.  
  76. @Override
  77. public boolean canHarvestBlock(IBlockState state, ItemStack stack) {
  78. if (!(state.getMaterial() == Material.AIR) && !(state.getMaterial() == Material.BARRIER)) {
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }
  84.  
  85. @Override
  86. public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
  87. return repair.getItem() == repairItem ? true : super.getIsRepairable(toRepair, repair);
  88. }
  89.  
  90. @Override
  91. public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
  92. // Only take one damage like a sword instead of 2
  93. itemStack.damageItem(1, attacker);
  94. return true;
  95. }
  96.  
  97. }
Add Comment
Please, Sign In to add comment