Entity[] deactEnts = getDeactivatedEntities();
if(deactEnts != null)
{
Vector3f entOrigin = new Vector3f();
Vector3f playerOrigin = new Vector3f(getPlayer().getPlayerMove().getOrigin());
int index = -1;
float curDist = 0;
float minDist = Float.MAX_VALUE;
for(int i = 0; i < deactEnts.length; i++)
{
deactEnts[i].setConfig(config);
entOrigin.set(deactEnts[i].getOrigin());
if(deactEnts[i].getNumber() != playerEntityNum + 1 && deactEnts[i].getNumber() > 0 && (curDist = playerOrigin.distance(entOrigin)) < minDist && deactEnts[i].getInventoryIndex() == pkup)
{
minDist = curDist;
index = deactEnts[i].getNumber();
}
}