From cc8bcf384ace64ed0595a2677b342ec4cc95fe2d Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 23 Jun 2016 14:51:12 -0700 Subject: [PATCH] Fix rare crash when getting rewards from escritoire --- src/main/java/forestry/core/utils/ItemStackUtil.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/forestry/core/utils/ItemStackUtil.java b/src/main/java/forestry/core/utils/ItemStackUtil.java index 9a70f4bd4..f57866d04 100644 --- a/src/main/java/forestry/core/utils/ItemStackUtil.java +++ b/src/main/java/forestry/core/utils/ItemStackUtil.java @@ -423,9 +423,15 @@ public abstract class ItemStackUtil { } public static ItemStack copyWithRandomSize(ItemStack template, int max, Random rand) { - int size = rand.nextInt(max); + int size = max <= 0 ? 0 : rand.nextInt(max); ItemStack created = template.copy(); - created.stackSize = size <= 0 ? 1 : size > created.getMaxStackSize() ? created.getMaxStackSize() : size; + if (size <= 0) { + created.stackSize = 1; + } else if (size > created.getMaxStackSize()) { + created.stackSize = created.getMaxStackSize(); + } else { + created.stackSize = size; + } return created; }