Skip to content

Commit

Permalink
clean up some dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Nov 30, 2024
1 parent 4d0e484 commit eb15011
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public ItemStack requestItem(BlockPos destPipe, BlockPos destInventory, ItemStac
if (remain.isEmpty())
return remain;
}
System.out.println(remain);
// check craftable items
return this.requestCraftedItem(destPipe, null, remain, new Stack<>(), equalityTypes).getLeft();
}
Expand Down Expand Up @@ -286,11 +287,9 @@ public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe
amount -= this.getLockedAmount(location.getPos(), stack, ignoredLock, equalityTypes);
if (amount <= 0)
return stack;
var remain = stack.copy();
// make sure we only extract less than or equal to the requested amount
if (remain.getCount() < amount)
amount = remain.getCount();
remain.shrink(amount);
if (stack.getCount() < amount)
amount = stack.getCount();
for (int slot : location.getStackSlots(this.level, stack, equalityTypes)) {
// try to extract from that location's inventory and send the item
var handler = location.getItemHandler(this.level);
Expand All @@ -302,7 +301,8 @@ public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe
break;
}
}
return remain;
// 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);
}

public PipeBlockEntity getPipe(BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,11 @@ public void tick(ItemStack module, PipeBlockEntity tile) {
var ensureItemOrder = module.get(Contents.TYPE).ensureItemOrder;
// if we're ensuring the correct item order and the item is already on the way, don't do anything yet
if (!ensureItemOrder || network.getPipeItemsOnTheWay(dest.getLeft()).findAny().isEmpty()) {
var requestRemain = network.requestExistingItem(lock.location, tile.getBlockPos(), dest.getLeft(), lock, dest.getRight(), equalityTypes);
network.requestExistingItem(lock.location, tile.getBlockPos(), dest.getLeft(), lock, dest.getRight(), equalityTypes);
network.resolveNetworkLock(lock);
craft.ingredientsToRequest.remove(lock);
craft.travelingIngredients.add(lock.stack.copy());
craft.inProgress = true;

var traveling = lock.stack.copy();
traveling.shrink(requestRemain.getCount());
craft.travelingIngredients.add(traveling);

// if we couldn't fit all items into the destination, create another request for the rest
var remain = lock.stack.copy();
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
if (!remain.isEmpty()) {
var remainRequest = new NetworkLock(lock.location, remain);
// if we're ensuring item order, we need to insert the remaining request at the start so that it gets processed first
var index = ensureItemOrder ? 0 : craft.ingredientsToRequest.size();
craft.ingredientsToRequest.add(index, remainRequest);
network.createNetworkLock(remainRequest);
}
}
}
network.endProfile();
Expand Down Expand Up @@ -218,11 +204,10 @@ public ItemStack store(ItemStack module, PipeBlockEntity tile, ItemStack stack,
var slot = tile.getModuleSlot(module);
var contents = module.get(Contents.TYPE);
var equalityTypes = ItemFilter.getEqualityTypes(tile);
var crafts = tile.getActiveCrafts();
var craft = crafts.stream()
.filter(c -> c.moduleSlot == slot && !c.getTravelingIngredient(stack, equalityTypes).isEmpty())
.findAny().orElse(null);
if (craft != null) {
var allCrafts = tile.getActiveCrafts();
var ourCrafts = allCrafts.stream().filter(c -> c.moduleSlot == slot && !c.getTravelingIngredient(stack, equalityTypes).isEmpty()).iterator();
while (ourCrafts.hasNext()) {
var craft = ourCrafts.next();
craft.travelingIngredients.remove(craft.getTravelingIngredient(stack, equalityTypes));

if (contents.insertSingles) {
Expand All @@ -245,7 +230,7 @@ public ItemStack store(ItemStack module, PipeBlockEntity tile, ItemStack stack,

// if we canceled the request and all input items are delivered (ie the machine actually got what it expected), remove it from the queue
if (craft.canceled)
crafts.remove(craft);
allCrafts.remove(craft);
}
}
return stack;
Expand Down

0 comments on commit eb15011

Please sign in to comment.