Guest User

Untitled

a guest
Jul 14th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. public class Multitool extends ItemPickaxe {
  2.  
  3. public Item repairItem;
  4.  
  5. public Multitool(ToolMaterial material, Item repairItem) {
  6. super(material);
  7. this.repairItem = repairItem;
  8. }
  9.  
  10. @Override
  11. public Set<String> getToolClasses(ItemStack itemStack) {
  12. return ImmutableSet.of("pickaxe", "axe", "spade", "hoe", "shovel");
  13. }
  14.  
  15. private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] { Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE,
  16. Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE,
  17. Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE,
  18. Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE,
  19. Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE,
  20. Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON,
  21. Blocks.STONE_PRESSURE_PLATE, Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, Blocks.CHEST,
  22. Blocks.PUMPKIN, Blocks.LIT_PUMPKIN, Blocks.MELON_BLOCK, Blocks.LADDER, Blocks.WOODEN_BUTTON,
  23. Blocks.WOODEN_PRESSURE_PLATE, Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL,
  24. Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND, Blocks.GRASS_PATH});
  25.  
  26. protected void func_185071_a(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state) {
  27. worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
  28.  
  29. if (!worldIn.isRemote) {
  30. worldIn.setBlockState(pos, state, 11);
  31. stack.damageItem(1, player);
  32. }
  33. }
  34.  
  35. @Override
  36. @SuppressWarnings("incomplete-switch")
  37. public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
  38. EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  39. if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack)) {
  40. return EnumActionResult.FAIL;
  41. } else {
  42. int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
  43. if (hook != 0)
  44. return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
  45.  
  46. IBlockState iblockstate = worldIn.getBlockState(pos);
  47. Block block = iblockstate.getBlock();
  48.  
  49. if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) {
  50. if (block == Blocks.GRASS || block == Blocks.GRASS_PATH) {
  51. this.func_185071_a(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
  52. return EnumActionResult.SUCCESS;
  53. }
  54.  
  55. if (block == Blocks.DIRT) {
  56. switch ((BlockDirt.DirtType) iblockstate.getValue(BlockDirt.VARIANT)) {
  57. case DIRT:
  58. this.func_185071_a(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
  59. return EnumActionResult.SUCCESS;
  60. case COARSE_DIRT:
  61. this.func_185071_a(stack, playerIn, worldIn, pos,
  62. Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
  63. return EnumActionResult.SUCCESS;
  64. }
  65. }
  66. }
  67.  
  68. return EnumActionResult.PASS;
  69. }
  70. }
  71.  
  72. public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
  73. return repair.getItem() == repairItem ? true : super.getIsRepairable(toRepair, repair);
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment