From bf8025bdafec7c89cabc3dbe0c9b4c51d85dbe68 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 14 Aug 2018 19:05:54 +0200 Subject: [PATCH] Guard as best we can against shenanigans. Should fix rendering errors, or at least replace them with a clearer message that something or someone is misbehaving --- .../java/com/minelittlepony/model/AbstractPonyModel.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index 1ea98320..33031705 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -870,6 +870,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { public ModelRenderer getRandomModelBox(Random rand) { // 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 randomI = rand.nextInt(boxList.size()); int index = randomI; @@ -881,6 +882,14 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { index = (index + 1) % boxList.size(); } while (index != randomI); + if (result.cubeList.isEmpty()) { + result.addBox(0, 0, 0, 0, 0, 0); + } + + if (result.cubeList.isEmpty()) { + throw new IllegalStateException("This model contains absolutely no boxes and a box could not be added!"); + } + return result; } }