package com.kirelcodes.RoboticCraft.pathFinders;

import org.bukkit.Location;

import com.kirelcodes.RoboticCraft.robot.RobotMiner;

public class MinerPathfinder extends BasicPathfinder {

	private RobotMiner robot;
	private int currentHeight;
	private int blockIterator;
	private int stairIterator;
	private Location previus;

	public MinerPathfinder(RobotMiner robot) {
		this.robot = robot;
		currentHeight = robot.getLocation().getBlockY();
		blockIterator = 0;
		stairIterator = 0;
	}

	@Override
	public boolean shouldStart() {
		return robot.isMining();
	}

	@Override
	public void onStart() {
		previus = robot.getStartBlock();
	}

	@Override
	public void updateTask() {
		if (robot.onDelay())
			return;
		if (blockIterator == 0) {
			currentHeight--;
			stairIterator++;
		}
		if (currentHeight == 1) {
			robot.setMining(false);
		}
		blockIterator++;
		Location mine = robot.getStartBlock().clone();
		mine.setY(currentHeight);
		try {
			robot.setTargetLocation(previus);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(blockIterator == 1 && stairIterator == 1){
			previus = mine;
			return;
		}
		switch (blockIterator) {
		case 1:
			if (stairIterator != 1)
				mine.add(0, 0, 0);
			else
				mine.add(0, 1, 0);
			break;
		case 2:
			if (stairIterator != 2)
				mine.add(1, 0, 0);
			break;
		case 3:
			if (stairIterator != 3)
				mine.add(2, 0, 0);
			break;
		case 4:
			if (stairIterator != 8)
				mine.add(0, 0, 1);
			if (stairIterator == 8)
				stairIterator = 1;
			break;
		case 5:
			mine.add(1, 0, 1);
			break;
		case 6:
			if (stairIterator != 4)
				mine.add(2, 0, 1);
			break;
		case 7:
			if (stairIterator != 7)
				mine.add(0, 0, 2);
			break;
		case 8:
			if (stairIterator != 6)
				mine.add(1, 0, 2);
			break;
		case 9:
			if (stairIterator != 5)
				mine.add(2, 0, 2);
			blockIterator = 0;
			break;
		}
		robot.mineBlock(mine);
		previus = mine;
	}

}

@@ -320,17 +320,16 @@
 revius;%0A
-%0A
 %09public 
@@ -552,25 +552,24 @@
 ining();%0A%09%7D%0A
-%0A
 %09@Override%0A%09
@@ -626,25 +626,24 @@
 Block();%0A%09%7D%0A
-%0A
 %09@Override%0A%09
@@ -728,18 +728,16 @@
 or == 0)
- %7B
 %0A%09%09%09curr
@@ -753,32 +753,8 @@
 --;%0A
-%09%09%09stairIterator++;%0A%09%09%7D%0A
 %09%09if
@@ -827,16 +827,35 @@
 ator++;%0A
+%09%09stairIterator++;%0A
 %09%09Locati
@@ -1064,90 +1064,8 @@
 %09%09%7D%0A
-%09%09if(blockIterator == 1 && stairIterator == 1)%7B%0A%09%09%09previus = mine;%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09sw
@@ -1098,25 +1098,24 @@
 ase 1:%0A%09%09%09if
- 
 (stairIterat
@@ -1116,20 +1116,18 @@
 Iterator
- 
 !=
- 
 1)%0A%09%09%09%09m
@@ -1148,39 +1148,8 @@
 0);%0A
-%09%09%09else%0A%09%09%09%09mine.add(0, 1, 0);%0A
 %09%09%09b
@@ -1165,25 +1165,24 @@
 ase 2:%0A%09%09%09if
- 
 (stairIterat
@@ -1183,20 +1183,18 @@
 Iterator
- 
 !=
- 
 2)%0A%09%09%09%09m
@@ -1232,25 +1232,24 @@
 ase 3:%0A%09%09%09if
- 
 (stairIterat
@@ -1250,20 +1250,18 @@
 Iterator
- 
 !=
- 
 3)%0A%09%09%09%09m
@@ -1299,25 +1299,24 @@
 ase 4:%0A%09%09%09if
- 
 (stairIterat
@@ -1317,20 +1317,18 @@
 Iterator
- 
 !=
- 
 8)%0A%09%09%09%09m
@@ -1349,58 +1349,8 @@
 1);%0A
-%09%09%09if (stairIterator == 8)%0A%09%09%09%09stairIterator = 1;%0A
 %09%09%09b
@@ -1408,25 +1408,24 @@
 ase 6:%0A%09%09%09if
- 
 (stairIterat
@@ -1426,20 +1426,18 @@
 Iterator
- 
 !=
- 
 4)%0A%09%09%09%09m
@@ -1475,25 +1475,24 @@
 ase 7:%0A%09%09%09if
- 
 (stairIterat
@@ -1493,20 +1493,18 @@
 Iterator
- 
 !=
- 
 7)%0A%09%09%09%09m
@@ -1542,25 +1542,24 @@
 ase 8:%0A%09%09%09if
- 
 (stairIterat
@@ -1560,20 +1560,18 @@
 Iterator
- 
 !=
- 
 6)%0A%09%09%09%09m
@@ -1613,17 +1613,16 @@
 9:%0A%09%09%09if
- 
 (stairIt
@@ -1631,12 +1631,10 @@
 ator
- 
 !=
- 
 5)%0A%09
@@ -1734,14 +1734,57 @@
 = mine;%0A
+%09%09if(stairIterator==8)%0A%09%09%09stairIterator=0;%0A
 %09%7D%0A%0A%7D%0A

Revert "GAL FIX THE FXKING BAG"