make "items on the way" only look at items going to the current INVENTORY, not the current pipe

This commit is contained in:
Ellpeck 2020-05-10 12:50:24 +02:00
parent 9fab982e6a
commit 8d347473af
3 changed files with 14 additions and 8 deletions

View file

@ -204,6 +204,10 @@ public class PipeItem implements INBTSerializable<CompoundNBT>, ILiquidContainer
return this.path.get(this.currentTile); return this.path.get(this.currentTile);
} }
public BlockPos getDestInventory(){
return this.destInventory;
}
@Override @Override
public CompoundNBT serializeNBT() { public CompoundNBT serializeNBT() {
CompoundNBT nbt = new CompoundNBT(); CompoundNBT nbt = new CompoundNBT();

View file

@ -375,15 +375,16 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
return this.pipeItems.get(pos); return this.pipeItems.get(pos);
} }
public Stream<PipeItem> getPipeItemsOnTheWay(BlockPos goalPipe) { private Stream<PipeItem> getPipeItemsOnTheWay(BlockPos goalInv) {
this.startProfile("get_pipe_items_on_the_way"); this.startProfile("get_pipe_items_on_the_way");
Stream<PipeItem> ret = this.pipeItems.values().stream().filter(i -> i.getDestPipe().equals(goalPipe)); Stream<PipeItem> ret = this.pipeItems.values().stream().filter(i -> i.getDestInventory().equals(goalInv));
this.endProfile(); this.endProfile();
return ret; return ret;
} }
public int getItemsOnTheWay(BlockPos goalPipe, ItemStack type, ItemEqualityType... equalityTypes) { public int getItemsOnTheWay(BlockPos goalInv, ItemStack type, ItemEqualityType... equalityTypes) {
return this.getPipeItemsOnTheWay(goalPipe) // 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)) .filter(i -> type == null || ItemEqualityType.compareItems(i.stack, type, equalityTypes))
.mapToInt(i -> i.stack.getCount()).sum(); .mapToInt(i -> i.stack.getCount()).sum();
} }

View file

@ -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); int maxAmount = this.streamModules().mapToInt(m -> m.getRight().getMaxInsertionAmount(m.getLeft(), this, stack, handler)).min().orElse(Integer.MAX_VALUE);
if (maxAmount < stack.getCount()) if (maxAmount < stack.getCount())
continue; continue;
BlockPos offset = this.pos.offset(dir);
if (preventOversending || maxAmount < Integer.MAX_VALUE) { if (preventOversending || maxAmount < Integer.MAX_VALUE) {
PipeNetwork network = PipeNetwork.get(this.world); PipeNetwork network = PipeNetwork.get(this.world);
// these are the items that are currently in the pipes, going to this pipe // these are the items that are currently in the pipes, going to this inventory
int onTheWay = network.getItemsOnTheWay(this.pos, null); int onTheWay = network.getItemsOnTheWay(offset, null);
if (onTheWay > 0) { if (onTheWay > 0) {
if (maxAmount < Integer.MAX_VALUE) { if (maxAmount < Integer.MAX_VALUE) {
// these are the items on the way, limited to items of the same type as stack // 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 // check if any modules are limiting us
if (onTheWaySame + stack.getCount() > maxAmount) if (onTheWaySame + stack.getCount() > maxAmount)
continue; continue;
@ -176,7 +177,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
continue; continue;
} }
} }
return this.pos.offset(dir); return offset;
} }
return null; return null;
} }