/*
 * ******************************************************************************
 *  Copyright 2011-2015 CovertJaguar
 *
 *  This work (the API) is licensed under the "MIT" License, see LICENSE.md for details.
 * ***************************************************************************
 */

package mods.railcraft.api.electricity;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import mods.railcraft.api.core.WorldCoordinate;
import mods.railcraft.api.electricity.IElectricGrid.ChargeHandler.ConnectType;
import mods.railcraft.api.tracks.ITrackInstance;
import mods.railcraft.api.tracks.ITrackTile;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

/**
 *
 * @author CovertJaguar <http://www.railcraft.info/>
 */
public class GridTools {

    public static Set<IElectricGrid> getMutuallyConnectedObjects(IElectricGrid gridObject) {
        Set<IElectricGrid> connectedObjects = new HashSet<IElectricGrid>();

        WorldCoordinate myPos = new WorldCoordinate(gridObject.getTile());
        for (Map.Entry<WorldCoordinate, EnumSet<ConnectType>> position : gridObject.getChargeHandler().getPossibleConnectionLocations().entrySet()) {
            IElectricGrid otherObj = getGridObjectAt(gridObject.getTile().getWorldObj(), position.getKey());
            if (otherObj != null && position.getValue().contains(otherObj.getChargeHandler().getType())) {
                EnumSet<ConnectType> otherType = otherObj.getChargeHandler().getPossibleConnectionLocations().get(myPos);
                if (otherType != null && otherType.contains(gridObject.getChargeHandler().getType()))
                    connectedObjects.add(otherObj);
            }
        }
        return connectedObjects;
    }

    public static IElectricGrid getGridObjectAt(IBlockAccess world, WorldCoordinate pos) {
        return getGridObjectAt(world, pos.x, pos.y, pos.z);
    }

    public static IElectricGrid getGridObjectAt(IBlockAccess world, int x, int y, int z) {
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile == null)
            return null;
        if (tile instanceof IElectricGrid)
            return (IElectricGrid) tile;
        if (tile instanceof ITrackTile) {
            ITrackInstance track = ((ITrackTile) tile).getTrackInstance();
            if (track instanceof IElectricGrid)
                return (IElectricGrid) track;
        }
        return null;
    }

}

@@ -336,104 +336,8 @@
 y;%0A%0A
-import java.util.EnumSet;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A
 impo
@@ -380,16 +380,16 @@
 dinate;%0A
+
 import m
@@ -597,16 +597,52 @@
 Entity;%0A
+import net.minecraft.util.BlockPos;%0A
 import n
@@ -678,50 +678,110 @@
 ss;%0A
+%0A
 import 
-net.minecraft.world.World
+java.util.EnumSet;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set
 ;%0A%0A/**%0A
- *%0A
  * @
@@ -1336,19 +1336,16 @@
 getWorld
-Obj
 (), posi
@@ -1879,185 +1879,20 @@
 ld, 
-WorldCoordinate pos) %7B%0A        return getGridObjectAt(world, pos.x, pos.y, pos.z);%0A    %7D%0A%0A    public static IElectricGrid getGridObjectAt(IBlockAccess world, int x, int y, int z
+BlockPos pos
 ) %7B%0A
@@ -1941,15 +1941,11 @@
 ity(
-x, y, z
+pos
 );%0A 

Fix GridTools