From 2d095995e4309f113390d026bcd71d9234881ebc Mon Sep 17 00:00:00 2001 From: git-async <86495664+git-async@users.noreply.github.com> Date: Thu, 23 Dec 2021 17:38:02 -0500 Subject: [PATCH] Fix Stockpile Switch prioritizing item inventories --- .../redstone/StockpileSwitchTileEntity.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java index 9f678da7a..7381a2bed 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java @@ -78,23 +78,24 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { float totalSpace = 0; observedInventory.findNewCapability(); - if (observedInventory.hasInventory()) { - // Item inventory - IItemHandler inv = observedInventory.getInventory(); - for (int slot = 0; slot < inv.getSlots(); slot++) { - ItemStack stackInSlot = inv.getStackInSlot(slot); - int space = Math.min(stackInSlot.getMaxStackSize(), inv.getSlotLimit(slot)); - int count = stackInSlot.getCount(); - if (space == 0) - continue; + observedTank.findNewCapability(); + if (observedInventory.hasInventory() || observedTank.hasInventory()) { + if (observedInventory.hasInventory()) { + // Item inventory + IItemHandler inv = observedInventory.getInventory(); + for (int slot = 0; slot < inv.getSlots(); slot++) { + ItemStack stackInSlot = inv.getStackInSlot(slot); + int space = Math.min(stackInSlot.getMaxStackSize(), inv.getSlotLimit(slot)); + int count = stackInSlot.getCount(); + if (space == 0) + continue; - totalSpace += 1; - if (filtering.test(stackInSlot)) - occupied += count * (1f / space); + totalSpace += 1; + if (filtering.test(stackInSlot)) + occupied += count * (1f / space); + } } - } else { - observedTank.findNewCapability(); if (observedTank.hasInventory()) { // Fluid inventory IFluidHandler tank = observedTank.getInventory(); @@ -109,18 +110,17 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { if (filtering.test(stackInSlot)) occupied += count * (1f / space); } - - } else { - // No compatible inventories found - if (currentLevel == -1) - return; - level.setBlock(worldPosition, getBlockState().setValue(StockpileSwitchBlock.INDICATOR, 0), 3); - currentLevel = -1; - redstoneState = false; - sendData(); - scheduleBlockTick(); - return; } + } else { + // No compatible inventories found + if (currentLevel == -1) + return; + level.setBlock(worldPosition, getBlockState().setValue(StockpileSwitchBlock.INDICATOR, 0), 3); + currentLevel = -1; + redstoneState = false; + sendData(); + scheduleBlockTick(); + return; } float stockLevel = occupied / totalSpace;