From b4a5c070e250fd972a2a43ff8abe878852f4a9d9 Mon Sep 17 00:00:00 2001 From: GlodBlock <1356392126@qq.com> Date: Tue, 14 Feb 2023 22:20:47 +0800 Subject: [PATCH] check every side in blocking mode --- .../FluidConvertingInventoryAdaptor.java | 71 +++++++++++++------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java b/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java index 848e641e..414130ea 100644 --- a/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java +++ b/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java @@ -164,15 +164,53 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor { @Override public boolean containsItems() { - if (invFluids == null && invItems == null) { + if (!this.onmi) { + return checkItemFluids(this.invFluids, this.invItems, this.side); + } + boolean result; + for (ForgeDirection dir : ForgeDirection.values()) { + result = checkItemFluids(this.getSideFluid(dir), this.getSideItem(dir), dir); + if (result) { + return true; + } + } + return false; + } + + public boolean hasSlots() { + return (invFluids != null && invFluids.getTankInfo(side).length > 0) || (invItems != null); + } + + @Override + public Iterator iterator() { + return new SlotIterator( + invFluids != null ? invFluids.getTankInfo(side) : new FluidTankInfo[0], + invItems != null ? invItems.iterator() : Collections.emptyIterator()); + } + + private IFluidHandler getSideFluid(ForgeDirection direction) { + TileEntity te = this.posInterface.getOffSet(direction).getTileEntity(); + if (te instanceof IFluidHandler) { + return (IFluidHandler) te; + } + return null; + } + + private InventoryAdaptor getSideItem(ForgeDirection direction) { + TileEntity te = this.posInterface.getOffSet(direction).getTileEntity(); + return InventoryAdaptor.getAdaptor(te, direction); + } + + private boolean checkItemFluids(IFluidHandler tank, InventoryAdaptor inv, ForgeDirection direction) { + if (tank == null && inv == null) { // If this entity doesn't have fluid or item inventory, we just view it as full of things. return true; } - if (invFluids != null && invFluids.getTankInfo(this.side) != null) { + if (tank != null && tank.getTankInfo(direction) != null) { List tankInfos = new LinkedList<>(); - if (Util.getPart(invFluids, this.side) instanceof PartP2PLiquids) { + if (Util.getPart(tank, direction) instanceof PartP2PLiquids) { // read other ends of p2p for blocking mode - PartP2PLiquids invFluidsP2P = (PartP2PLiquids) Util.getPart(invFluids, this.side); + PartP2PLiquids invFluidsP2P = (PartP2PLiquids) Util.getPart(tank, direction); try { Iterator it = invFluidsP2P.getOutputs().iterator(); boolean checkedInput = false; @@ -191,35 +229,22 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor { } } catch (GridAccessException ignore) {} } else { - tankInfos.add(invFluids.getTankInfo(this.side)); + tankInfos.add(tank.getTankInfo(direction)); } boolean hasTank = false; for (FluidTankInfo[] tankInfoArray : tankInfos) { - for (FluidTankInfo tank : tankInfoArray) { + for (FluidTankInfo tankInfo : tankInfoArray) { hasTank = true; - FluidStack fluid = tank.fluid; + FluidStack fluid = tankInfo.fluid; if (fluid != null && fluid.amount > 0) { return true; } } } - if (!hasTank && invItems == null) { - // If this entity doesn't have fluid or item inventory, we just view it as full of things. - return true; - } + // If this entity doesn't have fluid or item inventory, we just view it as full of things. + return !hasTank && inv == null; } - return invItems != null && invItems.containsItems(); - } - - public boolean hasSlots() { - return (invFluids != null && invFluids.getTankInfo(side).length > 0) || (invItems != null); - } - - @Override - public Iterator iterator() { - return new SlotIterator( - invFluids != null ? invFluids.getTankInfo(side) : new FluidTankInfo[0], - invItems != null ? invItems.iterator() : Collections.emptyIterator()); + return inv != null && inv.containsItems(); } private static class SlotIterator implements Iterator {