From 6dab61b0f90491ba076643b3c657b48445c52236 Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 29 May 2015 22:26:43 -0700 Subject: [PATCH] Fix crash in BeekeepingLogic when removing a flower near bee hives Fix Bee produceStacks logic --- .../forestry/apiculture/BeekeepingLogic.java | 3 +++ .../forestry/apiculture/genetics/Bee.java | 23 +++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/forestry/apiculture/BeekeepingLogic.java b/src/main/java/forestry/apiculture/BeekeepingLogic.java index 2eee0b380..911c5ee3d 100755 --- a/src/main/java/forestry/apiculture/BeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/BeekeepingLogic.java @@ -208,6 +208,9 @@ public class BeekeepingLogic implements IBeekeepingLogic { private void doProduction() { // Produce and add stacks ItemStack[] products = queen.produceStacks(housing); + if (products == null) { + return; + } housing.wearOutEquipment(1); for (ItemStack stack : products) { housing.addProduct(stack, false); diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index 6e95641a2..25260f9b7 100755 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -467,10 +467,6 @@ public class Bee extends IndividualLiving implements IBee { @Override public ItemStack[] produceStacks(IBeeHousing housing) { - if (!hasFlower(housing)) { - return null; - } - if (housing == null) { Proxies.log.warning("Failed to produce in an apiary because the beehousing was null."); return null; @@ -481,7 +477,7 @@ public class Bee extends IndividualLiving implements IBee { return null; } - ArrayList products = new ArrayList(); + List products = new ArrayList(); IAlleleBeeSpecies primary = genome.getPrimary(); IAlleleBeeSpecies secondary = genome.getSecondary(); @@ -507,20 +503,17 @@ public class Bee extends IndividualLiving implements IBee { } } - // We are done if the we are not jubilant. - if (!primary.isJubilant(genome, housing) || !secondary.isJubilant(genome, housing)) { - return products.toArray(new ItemStack[products.size()]); - } - // / Specialty products - for (Map.Entry entry : primary.getSpecialty().entrySet()) { - if (housing.getWorld().rand.nextInt(100) < entry.getValue() * speed) { - products.add(entry.getKey().copy()); + if (primary.isJubilant(genome, housing) && secondary.isJubilant(genome, housing)) { + for (Map.Entry entry : primary.getSpecialty().entrySet()) { + if (housing.getWorld().rand.nextInt(100) < entry.getValue() * speed) { + products.add(entry.getKey().copy()); + } } } - return genome.getFlowerProvider().affectProducts(housing.getWorld(), this, housing.getXCoord(), housing.getYCoord(), housing.getZCoord(), - products.toArray(new ItemStack[products.size()])); + ItemStack[] productsArray = products.toArray(new ItemStack[products.size()]); + return genome.getFlowerProvider().affectProducts(housing.getWorld(), this, housing.getXCoord(), housing.getYCoord(), housing.getZCoord(), productsArray); } /* REPRODUCTION */