2013-04-13 16:35:13 +02:00
|
|
|
package universalelectricity.core.path;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
import universalelectricity.core.block.IConductor;
|
2013-07-27 00:16:21 +02:00
|
|
|
import universalelectricity.core.block.INetworkConnection;
|
2013-04-13 16:35:13 +02:00
|
|
|
import universalelectricity.core.vector.Vector3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a conductor connects with another.
|
|
|
|
*
|
|
|
|
* @author Calclavia
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class PathfinderChecker extends Pathfinder
|
|
|
|
{
|
2013-07-27 00:16:21 +02:00
|
|
|
public PathfinderChecker(final World world, final INetworkConnection targetConnector, final INetworkConnection... ignoreConnector)
|
2013-04-13 16:35:13 +02:00
|
|
|
{
|
|
|
|
super(new IPathCallBack()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
|
|
|
|
{
|
|
|
|
Set<Vector3> neighbors = new HashSet<Vector3>();
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
|
|
|
Vector3 position = currentNode.clone().modifyPositionFromSide(direction);
|
|
|
|
TileEntity connectedBlock = position.getTileEntity(world);
|
|
|
|
|
|
|
|
if (connectedBlock instanceof IConductor && !Arrays.asList(ignoreConnector).contains(connectedBlock))
|
|
|
|
{
|
|
|
|
if (((IConductor) connectedBlock).canConnect(direction.getOpposite()))
|
|
|
|
{
|
|
|
|
neighbors.add(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return neighbors;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSearch(Pathfinder finder, Vector3 node)
|
|
|
|
{
|
|
|
|
if (node.getTileEntity(world) == targetConnector)
|
|
|
|
{
|
|
|
|
finder.results.add(node);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|