mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-25 21:18:34 +01:00
fixed over-sending prevention only working for items of the same type
This commit is contained in:
parent
320abbe74e
commit
e1752bb46d
2 changed files with 12 additions and 5 deletions
|
@ -332,7 +332,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
||||||
|
|
||||||
public int getItemsOnTheWay(BlockPos goalPipe, ItemStack type, ItemEqualityType... equalityTypes) {
|
public int getItemsOnTheWay(BlockPos goalPipe, ItemStack type, ItemEqualityType... equalityTypes) {
|
||||||
return this.getPipeItemsOnTheWay(goalPipe)
|
return this.getPipeItemsOnTheWay(goalPipe)
|
||||||
.filter(i -> 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,17 +148,24 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
|
||||||
if (maxAmount < stack.getCount())
|
if (maxAmount < stack.getCount())
|
||||||
continue;
|
continue;
|
||||||
if (preventOversending || maxAmount < Integer.MAX_VALUE) {
|
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
|
// these are the items that are currently in the pipes, going to this pipe
|
||||||
int onTheWay = PipeNetwork.get(this.world).getItemsOnTheWay(this.pos, stack);
|
int onTheWay = network.getItemsOnTheWay(this.pos, null);
|
||||||
if (onTheWay > 0) {
|
if (onTheWay > 0) {
|
||||||
// check if any modules are limiting us
|
if (maxAmount < Integer.MAX_VALUE) {
|
||||||
if (onTheWay + stack.getCount() > maxAmount)
|
// these are the items on the way, limited to items of the same type as stack
|
||||||
continue;
|
int onTheWaySame = network.getItemsOnTheWay(this.pos, stack);
|
||||||
|
// check if any modules are limiting us
|
||||||
|
if (onTheWaySame + stack.getCount() > maxAmount)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ItemStack copy = stack.copy();
|
ItemStack copy = stack.copy();
|
||||||
copy.setCount(copy.getMaxStackSize());
|
copy.setCount(copy.getMaxStackSize());
|
||||||
// totalSpace will be the amount of items that fit into the attached container
|
// totalSpace will be the amount of items that fit into the attached container
|
||||||
int totalSpace = 0;
|
int totalSpace = 0;
|
||||||
for (int i = 0; i < handler.getSlots(); i++) {
|
for (int i = 0; i < handler.getSlots(); i++) {
|
||||||
|
// this is an inaccurate check since it ignores the fact that some slots might
|
||||||
|
// have space for items of other types, but it'll be good enough for us
|
||||||
ItemStack remain = handler.insertItem(i, copy, true);
|
ItemStack remain = handler.insertItem(i, copy, true);
|
||||||
totalSpace += copy.getMaxStackSize() - remain.getCount();
|
totalSpace += copy.getMaxStackSize() - remain.getCount();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue