package com.choonster.testmod3.item;

import com.choonster.testmod3.TestMod3;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;

import java.util.Collections;

/**
 * A tool that can function as a sword, pickaxe, axe or shovel.
 * <p>
 * Currently mines some blocks (e.g. Block of Coal, Dropper, Stairs, Doors) slower than the proper tool should while mining others at the proper speed.
 * I don't know why this is.
 * <p>
 * Test for this thread:
 * http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2550421-how-to-make-a-tool-e-g-a-sword-have-the-abilities
 */
public class ItemHarvestSword extends ItemTool {
	public ItemHarvestSword(ToolMaterial toolMaterial) {
		super(4.0f, toolMaterial, Collections.EMPTY_SET);
		setHarvestLevel("pickaxe", toolMaterial.getHarvestLevel());
		setHarvestLevel("axe", toolMaterial.getHarvestLevel());
		setHarvestLevel("shovel", toolMaterial.getHarvestLevel());
		setCreativeTab(TestMod3.creativeTab);
	}

	public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
		itemStack.damageItem(1, attacker); // Only reduce the durability by 1 point (like swords do) instead of 2 (like tools do)
		return true;
	}
}

@@ -71,16 +71,189 @@
 stMod3;%0A
+import com.google.common.collect.ImmutableSet;%0Aimport net.minecraft.block.Block;%0Aimport net.minecraft.block.material.Material;%0Aimport net.minecraft.block.state.IBlockState;%0A
 import n
@@ -290,16 +290,65 @@
 ngBase;%0A
+import net.minecraft.entity.player.EntityPlayer;%0A
 import n
@@ -411,16 +411,138 @@
 temTool;
+%0Aimport net.minecraft.util.BlockPos;%0Aimport net.minecraft.world.IBlockAccess;%0Aimport net.minecraftforge.common.ForgeHooks;
 %0A%0Aimport
@@ -564,16 +564,38 @@
 ections;
+%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -667,196 +667,8 @@
 %3Cp%3E%0A
- * Currently mines some blocks (e.g. Block of Coal, Dropper, Stairs, Doors) slower than the proper tool should while mining others at the proper speed.%0A * I don't know why this is.%0A * %3Cp%3E%0A
  * T
@@ -1230,16 +1230,1365 @@
 b);%0A%09%7D%0A%0A
+%09/**%0A%09 * The %7B@link Material%7Ds that this tool is effective on.%0A%09 */%0A%09public static final Set%3CMaterial%3E EFFECTIVE_MATERIALS = ImmutableSet.of(%0A%09%09%09// Pickaxe%0A%09%09%09Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil, Material.circuits,%0A%0A%09%09%09// Axe%0A%09%09%09Material.wood, Material.gourd, Material.plants, Material.vine,%0A%0A%09%09%09// Shovel%0A%09%09%09Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay%0A%09);%0A%0A%09/**%0A%09 * Can this tool harvest the %7B@link Block%7D?%0A%09 * %3Cp%3E%0A%09 * This should only be used by %7B@link ForgeHooks#canHarvestBlock(Block, EntityPlayer, IBlockAccess, BlockPos)%7D,%0A%09 * use the tool class/harvest level system where possible.%0A%09 *%0A%09 * @param block     The Block%0A%09 * @param itemStack The tool%0A%09 * @return Is this tool effective on the %7B@link Block's%7D %7B@link Material%7D?%0A%09 */%0A%09@Override%0A%09public boolean canHarvestBlock(Block block, ItemStack itemStack) %7B%0A%09%09return EFFECTIVE_MATERIALS.contains(block.getMaterial());%0A%09%7D%0A%0A%09@Override%0A%09public float getDigSpeed(ItemStack stack, IBlockState state) %7B%0A%09%09// Not all blocks have a harvest tool/level set, so we need to fall back to checking the Material like the vanilla tools do%0A%09%09if (EFFECTIVE_MATERIALS.contains(state.getBlock().getMaterial())) %7B%0A%09%09%09return efficiencyOnProperMaterial;%0A%09%09%7D%0A%0A%09%09return super.getDigSpeed(stack, state);%0A%09%7D%0A%0A
 %09public 

Fix harvest speed of Harvest Swords