Skip to content

Commit

Permalink
Add null check for tanks (#118)
Browse files Browse the repository at this point in the history
* Add null check for tanks

Some IFluidHandlers return null for getTankInfo(), so a null check is needed.

* spotless apply
  • Loading branch information
firenoo authored Apr 28, 2023
1 parent 258465a commit 77ec418
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,15 @@ public boolean hasSlots() {

@Override
public Iterator<ItemSlot> iterator() {
return new SlotIterator(
invFluids != null ? invFluids.getTankInfo(side) : new FluidTankInfo[0],
invItems != null ? invItems.iterator() : Collections.emptyIterator());
FluidTankInfo[] info = null;
if (invFluids != null) {
info = invFluids.getTankInfo(side);
}
// Null check is needed because some tank infos return null (EIO conduits...)
if (info == null) {
info = new FluidTankInfo[0];
}
return new SlotIterator(info, invItems != null ? invItems.iterator() : Collections.emptyIterator());
}

private IFluidHandler getSideFluid(ForgeDirection direction) {
Expand Down Expand Up @@ -466,7 +472,7 @@ private static class SlotIterator implements Iterator<ItemSlot> {

@Override
public boolean hasNext() {
return nextSlotIndex < tanks.length || itemSlots.hasNext();
return itemSlots.hasNext() || nextSlotIndex < tanks.length;
}

@Override
Expand Down

0 comments on commit 77ec418

Please sign in to comment.