/*
 * Copyright  2014 - 2016 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package tk.wurst_client.features.mods;

import net.minecraft.block.Block;
import tk.wurst_client.events.listeners.UpdateListener;

@Mod.Info(
	description = "Automatically mines a block as soon as you look at it.",
	name = "AutoMine",
	tags = "AutoBreak, auto mine, auto break",
	help = "Mods/AutoMine")
@Mod.Bypasses
public class AutoMineMod extends Mod implements UpdateListener
{
	@Override
	public void onEnable()
	{
		mc.gameSettings.keyBindAttack.pressed = false;
		wurst.events.add(UpdateListener.class, this);
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
		mc.gameSettings.keyBindAttack.pressed = false;
	}
	
	@Override
	public void onUpdate()
	{
		if(mc.objectMouseOver == null
			|| mc.objectMouseOver.getBlockPos() == null)
			return;
		if(Block.getIdFromBlock(mc.world
			.getBlockState(mc.objectMouseOver.getBlockPos()).getBlock()) != 0)
			mc.gameSettings.keyBindAttack.pressed = true;
		else
			mc.gameSettings.keyBindAttack.pressed = false;
		
	}
}

@@ -338,21 +338,33 @@
 t.block.
-Block
+material.Material
 ;%0Aimport
@@ -412,16 +412,57 @@
 istener;
+%0Aimport tk.wurst_client.utils.BlockUtils;
 %0A%0A@Mod.I
@@ -749,57 +749,8 @@
 %0A%09%7B%0A
-%09%09mc.gameSettings.keyBindAttack.pressed = false;%0A
 %09%09wu
@@ -888,16 +888,43 @@
  this);%0A
+%09%09%0A%09%09// release attack key%0A
 %09%09mc.gam
@@ -1007,16 +1007,37 @@
 te()%0A%09%7B%0A
+%09%09// check hitResult%0A
 %09%09if(mc.
@@ -1125,104 +1125,171 @@
 ;%0A%09%09
-if(Block.getIdFromBlock(mc.world%0A%09%09%09.getBlockState(mc.objectMouseOver.getBlockPos()).get
+%0A%09%09// if attack key is down but nothing happens, release it for one tick%0A%09%09if(mc.gameSettings.keyBindAttack.pressed%0A%09%09%09&& !mc.playerController.getIsHitting
 Block())
  != 
@@ -1288,14 +1288,12 @@
 k())
- != 0)
+%0A%09%09%7B
 %0A%09%09%09
@@ -1336,73 +1336,194 @@
 d = 
-true;%0A%09%09else%0A%09%09%09mc.gameSettings.keyBindAttack.pressed = false;%0A%09%09
+false;%0A%09%09%09return;%0A%09%09%7D%0A%09%09%0A%09%09// press attack key if looking at block%0A%09%09mc.gameSettings.keyBindAttack.pressed = BlockUtils%0A%09%09%09.getMaterial(mc.objectMouseOver.getBlockPos()) != Material.AIR;
 %0A%09%7D%0A

Fix AutoMine not mining sometimes