mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-22 15:39:22 +01:00
fixed requestExistingItem returning an incorrect amount of already requested items
closes #229
This commit is contained in:
parent
7bd6bbc233
commit
21f2727b32
1 changed files with 10 additions and 11 deletions
|
@ -280,28 +280,27 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
|
||||||
if (location.getPos().equals(destInventory))
|
if (location.getPos().equals(destInventory))
|
||||||
return stack;
|
return stack;
|
||||||
// make sure we don't pull any locked items
|
// make sure we don't pull any locked items
|
||||||
var amount = location.getItemAmount(this.level, stack, equalityTypes);
|
var available = location.getItemAmount(this.level, stack, equalityTypes);
|
||||||
if (amount <= 0)
|
if (available <= 0)
|
||||||
return stack;
|
return stack;
|
||||||
amount -= this.getLockedAmount(location.getPos(), stack, ignoredLock, equalityTypes);
|
available -= this.getLockedAmount(location.getPos(), stack, ignoredLock, equalityTypes);
|
||||||
if (amount <= 0)
|
if (available <= 0)
|
||||||
return stack;
|
return stack;
|
||||||
// make sure we only extract less than or equal to the requested amount
|
var toExtract = Math.min(stack.getCount(), available);
|
||||||
if (stack.getCount() < amount)
|
var extractedSoFar = 0;
|
||||||
amount = stack.getCount();
|
|
||||||
for (int slot : location.getStackSlots(this.level, stack, equalityTypes)) {
|
for (int slot : location.getStackSlots(this.level, stack, equalityTypes)) {
|
||||||
// try to extract from that location's inventory and send the item
|
// try to extract from that location's inventory and send the item
|
||||||
var handler = location.getItemHandler(this.level);
|
var handler = location.getItemHandler(this.level);
|
||||||
var extracted = handler.extractItem(slot, amount, true);
|
var extracted = handler.extractItem(slot, toExtract - extractedSoFar, true);
|
||||||
if (this.routeItemToLocation(location.pipePos, location.getPos(), destPipe, destInventory, extracted, speed -> itemSupplier.apply(extracted, speed))) {
|
if (this.routeItemToLocation(location.pipePos, location.getPos(), destPipe, destInventory, extracted, speed -> itemSupplier.apply(extracted, speed))) {
|
||||||
handler.extractItem(slot, extracted.getCount(), false);
|
handler.extractItem(slot, extracted.getCount(), false);
|
||||||
amount -= extracted.getCount();
|
extractedSoFar += extracted.getCount();
|
||||||
if (amount <= 0)
|
if (extractedSoFar >= toExtract)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we reduce the amount by what we managed to extract & insert in the for loop, so the amount down here will be what we couldn't
|
// we reduce the amount by what we managed to extract & insert in the for loop, so the amount down here will be what we couldn't
|
||||||
return stack.copyWithCount(amount);
|
return stack.copyWithCount(stack.getCount() - extractedSoFar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PipeBlockEntity getPipe(BlockPos pos) {
|
public PipeBlockEntity getPipe(BlockPos pos) {
|
||||||
|
|
Loading…
Reference in a new issue