From 8d347473afc2601a02a1c80a2976045d5ccfa08a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 10 May 2020 12:50:24 +0200 Subject: [PATCH] make "items on the way" only look at items going to the current INVENTORY, not the current pipe --- .../java/de/ellpeck/prettypipes/network/PipeItem.java | 4 ++++ .../java/de/ellpeck/prettypipes/network/PipeNetwork.java | 9 +++++---- .../java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java | 9 +++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java index bad0e35..c9014ec 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java @@ -204,6 +204,10 @@ public class PipeItem implements INBTSerializable, ILiquidContainer return this.path.get(this.currentTile); } + public BlockPos getDestInventory(){ + return this.destInventory; + } + @Override public CompoundNBT serializeNBT() { CompoundNBT nbt = new CompoundNBT(); diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index b29b0f2..ac52186 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -375,15 +375,16 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return this.pipeItems.get(pos); } - public Stream getPipeItemsOnTheWay(BlockPos goalPipe) { + private Stream getPipeItemsOnTheWay(BlockPos goalInv) { this.startProfile("get_pipe_items_on_the_way"); - Stream ret = this.pipeItems.values().stream().filter(i -> i.getDestPipe().equals(goalPipe)); + Stream ret = this.pipeItems.values().stream().filter(i -> i.getDestInventory().equals(goalInv)); this.endProfile(); return ret; } - public int getItemsOnTheWay(BlockPos goalPipe, ItemStack type, ItemEqualityType... equalityTypes) { - return this.getPipeItemsOnTheWay(goalPipe) + public int getItemsOnTheWay(BlockPos goalInv, ItemStack type, ItemEqualityType... equalityTypes) { + // TODO pending auto-crafting requests should be marked as "on the way" here to allow over-sending prevention + return this.getPipeItemsOnTheWay(goalInv) .filter(i -> type == null || ItemEqualityType.compareItems(i.stack, type, equalityTypes)) .mapToInt(i -> i.stack.getCount()).sum(); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index 7cace89..a67eb78 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -149,14 +149,15 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide int maxAmount = this.streamModules().mapToInt(m -> m.getRight().getMaxInsertionAmount(m.getLeft(), this, stack, handler)).min().orElse(Integer.MAX_VALUE); if (maxAmount < stack.getCount()) continue; + BlockPos offset = this.pos.offset(dir); if (preventOversending || maxAmount < Integer.MAX_VALUE) { PipeNetwork network = PipeNetwork.get(this.world); - // these are the items that are currently in the pipes, going to this pipe - int onTheWay = network.getItemsOnTheWay(this.pos, null); + // these are the items that are currently in the pipes, going to this inventory + int onTheWay = network.getItemsOnTheWay(offset, null); if (onTheWay > 0) { if (maxAmount < Integer.MAX_VALUE) { // these are the items on the way, limited to items of the same type as stack - int onTheWaySame = network.getItemsOnTheWay(this.pos, stack); + int onTheWaySame = network.getItemsOnTheWay(offset, stack); // check if any modules are limiting us if (onTheWaySame + stack.getCount() > maxAmount) continue; @@ -176,7 +177,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide continue; } } - return this.pos.offset(dir); + return offset; } return null; }