mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Infinite loops are bad, mmmkay?
This commit is contained in:
parent
5964cf1bc4
commit
0c6e2a74ff
1 changed files with 11 additions and 5 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue