Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Multitool extends ItemTool {
- public Item repairItem;
- public static float attack_speed = -2.8F;
- public static float base_damage = 3.0F;
- public Multitool(ToolMaterial material, Item repairItem) {
- super(base_damage, attack_speed, material, Collections.emptySet());
- this.setHarvestLevel("pickaxe", material.getHarvestLevel());
- this.setHarvestLevel("axe", material.getHarvestLevel());
- this.setHarvestLevel("spade", material.getHarvestLevel());
- this.setHarvestLevel("hoe", material.getHarvestLevel());
- this.setHarvestLevel("sword", material.getHarvestLevel());
- this.repairItem = repairItem;
- }
- protected void func_185071_a(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state) {
- worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
- if (!worldIn.isRemote) {
- worldIn.setBlockState(pos, state, 11);
- stack.damageItem(1, player);
- }
- }
- @Override
- @SuppressWarnings("incomplete-switch")
- public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
- EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
- // Makes it work like a hoe
- if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack)) {
- return EnumActionResult.FAIL;
- } else {
- int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
- if (hook != 0)
- return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
- IBlockState iblockstate = worldIn.getBlockState(pos);
- Block block = iblockstate.getBlock();
- if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) {
- if (block == Blocks.GRASS || block == Blocks.GRASS_PATH) {
- this.func_185071_a(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
- return EnumActionResult.SUCCESS;
- }
- if (block == Blocks.DIRT) {
- switch ((BlockDirt.DirtType) iblockstate.getValue(BlockDirt.VARIANT)) {
- case DIRT:
- this.func_185071_a(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
- return EnumActionResult.SUCCESS;
- case COARSE_DIRT:
- this.func_185071_a(stack, playerIn, worldIn, pos,
- Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
- return EnumActionResult.SUCCESS;
- }
- }
- }
- return EnumActionResult.PASS;
- }
- }
- @Override
- public float getStrVsBlock(ItemStack stack, IBlockState state) {
- for (String type : getToolClasses(stack)) {
- if (state.getBlock().isToolEffective(type, state))
- return efficiencyOnProperMaterial;
- }
- if (state.getBlock() == Blocks.WEB) {
- return (efficiencyOnProperMaterial * 5);
- }
- return efficiencyOnProperMaterial;
- }
- @Override
- public boolean canHarvestBlock(IBlockState state, ItemStack stack) {
- if (!(state.getMaterial() == Material.AIR) && !(state.getMaterial() == Material.BARRIER)) {
- return true;
- } else {
- return false;
- }
- }
- @Override
- public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
- return repair.getItem() == repairItem ? true : super.getIsRepairable(toRepair, repair);
- }
- @Override
- public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
- // Only take one damage like a sword instead of 2
- itemStack.damageItem(1, attacker);
- return true;
- }
- }
Add Comment
Please, Sign In to add comment