From d63377532cebc439bb097a576da8f9c9295dae25 Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 19 Dec 2014 23:40:07 -0800 Subject: [PATCH] Fix #384 Client crash at forestry.farming.gadgets.TileHatch --- .../apiculture/gadgets/TileAlvearyPlain.java | 47 ++++++++++-------- src/main/java/forestry/core/utils/Utils.java | 4 +- .../forestry/farming/gadgets/TileHatch.java | 48 +++++++++++-------- 3 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java index 2db92b886..b0e44b75e 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java @@ -140,8 +140,12 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB return; // Add swarm effects - if (worldObj.getTotalWorldTime() % 200 * 10 == 0) - onQueenChange(getStructureInventory().getStackInSlot(SLOT_QUEEN)); + if (worldObj.getTotalWorldTime() % 200 == 0) { + ISidedInventory inventory = getStructureInventory(); + if (inventory != null) + onQueenChange(inventory.getStackInSlot(SLOT_QUEEN)); + } + if (getErrorState() == EnumErrorCode.OK) queen.doFX(beekeepingLogic.getEffectData(), this); @@ -166,15 +170,18 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB if (!isMaster()) return; - if (getStructureInventory() == null) + ISidedInventory inventory = getStructureInventory(); + if (inventory == null) return; // / Multiplayer FX - if (PluginApiculture.beeInterface.isMated(getStructureInventory().getStackInSlot(SLOT_QUEEN))) + ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN); + if (PluginApiculture.beeInterface.isMated(queenStack)) { if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 == 0) { - IBee displayQueen = PluginApiculture.beeInterface.getMember(getStructureInventory().getStackInSlot(SLOT_QUEEN)); + IBee displayQueen = PluginApiculture.beeInterface.getMember(queenStack); displayQueen.doFX(beekeepingLogic.getEffectData(), this); } + } } private void equalizeTemperature() { @@ -544,37 +551,37 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB @Override public int getSizeInventory() { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getSizeInventory(); - else + if (inv == null) return 0; + + return inv.getSizeInventory(); } @Override public ItemStack getStackInSlot(int slotIndex) { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlot(slotIndex); - else + if (inv == null) return null; + + return inv.getStackInSlot(slotIndex); } @Override public ItemStack decrStackSize(int slotIndex, int amount) { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.decrStackSize(slotIndex, amount); - else + if (inv == null) return null; + + return inv.decrStackSize(slotIndex, amount); } @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlotOnClosing(slotIndex); - else + if (inv == null) return null; + + return inv.getStackInSlotOnClosing(slotIndex); } @Override @@ -598,10 +605,10 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB @Override public int getInventoryStackLimit() { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getInventoryStackLimit(); - else + if (inv == null) return 0; + + return inv.getInventoryStackLimit(); } @Override diff --git a/src/main/java/forestry/core/utils/Utils.java b/src/main/java/forestry/core/utils/Utils.java index b20588b68..9869e0cd5 100755 --- a/src/main/java/forestry/core/utils/Utils.java +++ b/src/main/java/forestry/core/utils/Utils.java @@ -60,7 +60,7 @@ public class Utils { if (tile instanceof ITileStructure) { IInventory inventory = ((ITileStructure) tile).getInventory(); - if (inventory != null) + if (inventory != null) { for (int i = 0; i < inventory.getSizeInventory(); i++) { if (inventory.getStackInSlot(i) == null) continue; @@ -68,7 +68,7 @@ public class Utils { StackUtils.dropItemStackAsEntity(inventory.getStackInSlot(i), world, x, y, z); inventory.setInventorySlotContents(i, null); } - + } } else { IInventory inventory; diff --git a/src/main/java/forestry/farming/gadgets/TileHatch.java b/src/main/java/forestry/farming/gadgets/TileHatch.java index dec38f7f0..5d6820471 100755 --- a/src/main/java/forestry/farming/gadgets/TileHatch.java +++ b/src/main/java/forestry/farming/gadgets/TileHatch.java @@ -13,6 +13,7 @@ package forestry.farming.gadgets; import buildcraft.api.statements.ITriggerExternal; import cpw.mods.fml.common.Optional; import forestry.api.core.ITileStructure; +import forestry.core.config.Defaults; import forestry.core.inventory.AdjacentInventoryCache; import forestry.core.inventory.ITileFilter; import forestry.core.inventory.InvTools; @@ -57,7 +58,11 @@ public class TileHatch extends TileFarm implements ISidedInventory { /* AUTO-EJECTING */ private IInventory getProductInventory() { - return new InventoryMapper(getStructureInventory(), TileFarmPlain.SLOT_PRODUCTION_1, TileFarmPlain.SLOT_COUNT_PRODUCTION); + TileInventoryAdapter inventory = getStructureInventory(); + if (inventory == null) + return null; + + return new InventoryMapper(inventory, TileFarmPlain.SLOT_PRODUCTION_1, TileFarmPlain.SLOT_COUNT_PRODUCTION); } protected void dumpStash() { @@ -87,37 +92,37 @@ public class TileHatch extends TileFarm implements ISidedInventory { @Override public int getSizeInventory() { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getSizeInventory(); - else + if (inv == null) return 0; + + return inv.getSizeInventory(); } @Override public ItemStack getStackInSlot(int slotIndex) { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlot(slotIndex); - else + if (inv == null) return null; + + return inv.getStackInSlot(slotIndex); } @Override public ItemStack decrStackSize(int slotIndex, int amount) { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.decrStackSize(slotIndex, amount); - else + if (inv == null) return null; + + return inv.decrStackSize(slotIndex, amount); } @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlotOnClosing(slotIndex); - else + if (inv == null) return null; + + return inv.getStackInSlotOnClosing(slotIndex); } @Override @@ -130,10 +135,10 @@ public class TileHatch extends TileFarm implements ISidedInventory { @Override public int getInventoryStackLimit() { IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getInventoryStackLimit(); - else + if (inv == null) return 0; + + return inv.getInventoryStackLimit(); } @Override @@ -171,7 +176,8 @@ public class TileHatch extends TileFarm implements ISidedInventory { if (!(struct instanceof TileFarmPlain)) return false; - if (!getStructureInventory().isItemValidForSlot(slotIndex, itemstack)) + TileInventoryAdapter inventory = getStructureInventory(); + if (inventory == null || !inventory.isItemValidForSlot(slotIndex, itemstack)) return false; TileFarmPlain housing = (TileFarmPlain) struct; @@ -196,7 +202,8 @@ public class TileHatch extends TileFarm implements ISidedInventory { @Override public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - if (!getStructureInventory().canExtractItem(slotIndex, itemstack, side)) + TileInventoryAdapter inventory = getStructureInventory(); + if (inventory == null || !inventory.canExtractItem(slotIndex, itemstack, side)) return false; return slotIndex >= TileFarmPlain.SLOT_PRODUCTION_1 && slotIndex < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION; @@ -204,7 +211,10 @@ public class TileHatch extends TileFarm implements ISidedInventory { @Override public int[] getAccessibleSlotsFromSide(int side) { - return getStructureInventory().getAccessibleSlotsFromSide(side); + TileInventoryAdapter inventory = getStructureInventory(); + if (inventory == null) + return Defaults.FACINGS_NONE; + return inventory.getAccessibleSlotsFromSide(side); } /* ITRIGGERPROVIDER */