package storagecraft.tile;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import storagecraft.block.BlockCable;

public class TileCable extends TileSC {
	class VisitedCable {
		public int x;
		public int y;
		public int z;

		public VisitedCable(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}
	}

	public static boolean isCable(World world, int x, int y, int z, ForgeDirection dir) {
		Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);

		return block instanceof BlockCable;
	}

	public boolean hasConnection(ForgeDirection dir) {
		if (!isCable(worldObj, xCoord, yCoord, zCoord, dir)) {
			TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);

			return tile instanceof IMachine || tile instanceof TileController;
		}

		return true;
	}

	public List<IMachine> findMachines() {
		return findMachines(new ArrayList(), true);
	}

	private List<IMachine> findMachines(List<VisitedCable> visited, boolean ignoreController) {
		List<IMachine> machines = new ArrayList<IMachine>();

		for (VisitedCable visitedCable : visited) {
			if (visitedCable.x == xCoord && visitedCable.y == yCoord && visitedCable.z == zCoord) {
				return machines;
			}
		}

		visited.add(new VisitedCable(xCoord, yCoord, zCoord));

		for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
			TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);

			if (tile instanceof IMachine) {
				machines.add((IMachine) tile);
			} else if (tile instanceof TileCable) {
				machines.addAll(((TileCable) tile).findMachines(visited, false));
			} else if (tile instanceof TileController && !ignoreController) {
				worldObj.createExplosion(null, xCoord, yCoord, zCoord, 4.5f, true);
			}
		}

		return machines;
	}
}

@@ -156,16 +156,49 @@
 ntity;%0D%0A
+import net.minecraft.util.Vec3;%0D%0A
 import n
@@ -224,16 +224,16 @@
 World;%0D%0A
-
 import n
@@ -320,16 +320,16 @@
 ble;%0D%0A%0D%0A
+
 public c
@@ -365,189 +365,8 @@
  %7B%0D%0A
-%09class VisitedCable %7B%0D%0A%09%09public int x;%0D%0A%09%09public int y;%0D%0A%09%09public int z;%0D%0A%0D%0A%09%09public VisitedCable(int x, int y, int z) %7B%0D%0A%09%09%09this.x = x;%0D%0A%09%09%09this.y = y;%0D%0A%09%09%09this.z = z;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A
 %09pub
@@ -1042,27 +1042,19 @@
 s(List%3CV
-isitedCable
+ec3
 %3E visite
@@ -1151,27 +1151,19 @@
 %09%09for (V
-isitedCable
+ec3
  visited
@@ -1203,16 +1203,21 @@
 dCable.x
+Coord
  == xCoo
@@ -1236,16 +1236,21 @@
 dCable.y
+Coord
  == yCoo
@@ -1269,16 +1269,21 @@
 dCable.z
+Coord
  == zCoo
@@ -1342,24 +1342,31 @@
 add(
-new VisitedCable
+Vec3.createVectorHelper
 (xCo

use Vec3 instead of VisitedCable