diff --git a/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java b/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java index ed951eba..f34d5326 100644 --- a/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java +++ b/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java @@ -6,6 +6,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Nullable; + import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -425,7 +427,7 @@ public class NetworkedInventory { return inv; } - public ISidedInventory getInventoryRecheck() { + public @Nullable ISidedInventory getInventoryRecheck() { if (isInvalid()) { updateInventory(); } diff --git a/src/main/java/crazypants/enderio/machine/invpanel/server/NormalInventory.java b/src/main/java/crazypants/enderio/machine/invpanel/server/NormalInventory.java index 7aaab0b4..61eba47e 100644 --- a/src/main/java/crazypants/enderio/machine/invpanel/server/NormalInventory.java +++ b/src/main/java/crazypants/enderio/machine/invpanel/server/NormalInventory.java @@ -16,50 +16,53 @@ class NormalInventory extends AbstractInventory { @Override int scanInventory(InventoryDatabaseServer db) { ISidedInventory inv = ni.getInventoryRecheck(); - int side = ni.getInventorySide(); - int[] slotIndices = inv.getAccessibleSlotsFromSide(side); - if (slotIndices == null || slotIndices.length == 0) { - setEmpty(db); - return 0; - } - int count = slotIndices.length; - if (count != slotKeys.length) { - reset(db, count); - } - for (int slot = 0; slot < count; slot++) { - int invSlot = slotIndices[slot]; - ItemStack stack = inv.getStackInSlot(invSlot); - if (stack != null && !inv.canExtractItem(invSlot, stack, side)) { - stack = null; + if (inv != null) { + int side = ni.getInventorySide(); + int[] slotIndices = inv.getAccessibleSlotsFromSide(side); + if (slotIndices != null && slotIndices.length > 0) { + int count = slotIndices.length; + if (count != slotKeys.length) { + reset(db, count); + } + for (int slot = 0; slot < count; slot++) { + int invSlot = slotIndices[slot]; + ItemStack stack = inv.getStackInSlot(invSlot); + if (stack != null && !inv.canExtractItem(invSlot, stack, side)) { + stack = null; + } + updateSlot(db, slot, stack); + } + return count; } - updateSlot(db, slot, stack); } - return count; + + setEmpty(db); + return 0; } @Override public int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int count) { ISidedInventory inv = ni.getInventoryRecheck(); - int side = ni.getInventorySide(); - int[] slotIndices = inv.getAccessibleSlotsFromSide(side); - if (slotIndices == null || slot >= slotIndices.length) { - return 0; + if (inv != null) { + int side = ni.getInventorySide(); + int[] slotIndices = inv.getAccessibleSlotsFromSide(side); + if (slotIndices != null && slot < slotIndices.length) { + int invSlot = slotIndices[slot]; + ItemStack stack = inv.getStackInSlot(invSlot); + if (stack != null && inv.canExtractItem(invSlot, stack, side) + && db.lookupItem(stack, entry, false) == entry) { + int remaining = stack.stackSize; + if (count > remaining) { + count = remaining; + } + ni.itemExtracted(invSlot, count); + remaining -= count; + updateCount(db, slot, entry, remaining); + return count; + } + } } - int invSlot = slotIndices[slot]; - ItemStack stack = inv.getStackInSlot(invSlot); - if (stack == null || !inv.canExtractItem(invSlot, stack, side)) { - return 0; - } - if (db.lookupItem(stack, entry, false) != entry) { - return 0; - } - int remaining = stack.stackSize; - if (count > remaining) { - count = remaining; - } - ni.itemExtracted(invSlot, count); - remaining -= count; - updateCount(db, slot, entry, remaining); - return count; + + return 0; } }