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 @Override
public ModelRenderer getRandomModelBox(Random rand) { 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; ModelRenderer mr;
do { do {
// try until it's not mr = boxList.get(index);
mr = super.getRandomModelBox(rand); if (!mr.cubeList.isEmpty()) return mr;
} while (mr.cubeList.isEmpty());
i = (i + 1) % boxList.size();
} while (i != index);
return mr; return mr;
} }
} }