Infinite loops are bad, mmmkay?

This commit is contained in:
Sollace 2018-04-25 22:01:31 +02:00
parent 5964cf1bc4
commit 0c6e2a74ff

View file

@ -252,15 +252,21 @@ public abstract class AbstractPonyModel extends ModelPlayer {
}
}
// TODO: This has potential to create an infinite loop.
@Override
public ModelRenderer getRandomModelBox(Random rand) {
// empty lists cause problems
// grab one at random, but cycle through the list until you find one that's filled.
// Return if you find one, or if you get back to where you started in which case there isn't any.
int index = rand.nextInt(boxList.size());
int i = index;
ModelRenderer mr;
do {
// try until it's not
mr = super.getRandomModelBox(rand);
} while (mr.cubeList.isEmpty());
mr = boxList.get(index);
if (!mr.cubeList.isEmpty()) return mr;
i = (i + 1) % boxList.size();
} while (i != index);
return mr;
}
}