mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
made the retrieval module only retrieve when it's not waiting for crafting outputs
This commit is contained in:
parent
76f332c03e
commit
afd055c8b1
3 changed files with 44 additions and 25 deletions
|
@ -251,6 +251,37 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
|||
return tile;
|
||||
}
|
||||
|
||||
public List<Pair<BlockPos, ItemStack>> getCurrentlyCrafting(BlockPos node) {
|
||||
this.startProfile("get_currently_crafting");
|
||||
List<Pair<BlockPos, ItemStack>> items = new ArrayList<>();
|
||||
for (Pair<BlockPos, ItemStack> craftable : this.getAllCraftables(node)) {
|
||||
PipeTileEntity pipe = this.getPipe(craftable.getLeft());
|
||||
if (pipe == null)
|
||||
continue;
|
||||
for (Pair<BlockPos, ItemStack> request : pipe.craftResultRequests) {
|
||||
BlockPos dest = request.getLeft();
|
||||
ItemStack stack = request.getRight();
|
||||
// add up all the items that should go to the same location
|
||||
Optional<Pair<BlockPos, ItemStack>> existing = items.stream()
|
||||
.filter(s -> s.getLeft().equals(dest) && ItemEqualityType.compareItems(s.getRight(), stack, ItemEqualityType.NBT))
|
||||
.findFirst();
|
||||
if (existing.isPresent()) {
|
||||
existing.get().getRight().grow(stack.getCount());
|
||||
} else {
|
||||
items.add(Pair.of(dest, stack.copy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.endProfile();
|
||||
return items;
|
||||
}
|
||||
|
||||
public int getCurrentlyCraftingAmount(BlockPos destNode, ItemStack stack, ItemEqualityType... equalityTypes) {
|
||||
return this.getCurrentlyCrafting(destNode).stream()
|
||||
.filter(p -> p.getLeft().equals(destNode) && ItemEqualityType.compareItems(p.getRight(), stack, equalityTypes))
|
||||
.mapToInt(p -> p.getRight().getCount()).sum();
|
||||
}
|
||||
|
||||
public List<Pair<BlockPos, ItemStack>> getAllCraftables(BlockPos node) {
|
||||
if (!this.isNode(node))
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -43,6 +43,7 @@ public class RetrievalModuleItem extends ModuleItem {
|
|||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
|
||||
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
||||
ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
filter.isWhitelist = true;
|
||||
// loop through filter to see which items to pull
|
||||
for (int f = 0; f < filter.getSlots(); f++) {
|
||||
|
@ -54,7 +55,10 @@ public class RetrievalModuleItem extends ModuleItem {
|
|||
Pair<BlockPos, ItemStack> dest = tile.getAvailableDestination(copy, true, this.preventOversending);
|
||||
if (dest == null)
|
||||
continue;
|
||||
if (network.requestItem(tile.getPos(), dest.getLeft(), dest.getRight(), ItemFilter.getEqualityTypes(tile)).isEmpty())
|
||||
// are we already waiting for crafting results? If so, don't request more
|
||||
if (network.getCurrentlyCraftingAmount(tile.getPos(), copy, equalityTypes) >= this.maxExtraction)
|
||||
break;
|
||||
if (network.requestItem(tile.getPos(), dest.getLeft(), dest.getRight(), equalityTypes).isEmpty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,10 +133,9 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
return;
|
||||
this.networkItems = this.collectItems();
|
||||
if (playersToSync.length > 0) {
|
||||
List<Pair<BlockPos, ItemStack>> craftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos());
|
||||
List<ItemStack> clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||
List<ItemStack> clientCraftables = craftables.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
List<ItemStack> currentlyCrafting = this.getCurrentlyCrafting(craftables).stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||
List<ItemStack> clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
List<ItemStack> currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||
for (PlayerEntity player : playersToSync) {
|
||||
if (!(player.openContainer instanceof ItemTerminalContainer))
|
||||
continue;
|
||||
|
@ -192,28 +191,13 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
return items;
|
||||
}
|
||||
|
||||
private List<ItemStack> getCurrentlyCrafting(List<Pair<BlockPos, ItemStack>> craftables) {
|
||||
private List<ItemStack> getCurrentlyCrafting() {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
List<Pair<BlockPos, ItemStack>> items = new ArrayList<>();
|
||||
for (Pair<BlockPos, ItemStack> craftable : craftables) {
|
||||
PipeTileEntity pipe = network.getPipe(craftable.getLeft());
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
continue;
|
||||
for (Pair<BlockPos, ItemStack> request : pipe.craftResultRequests) {
|
||||
BlockPos dest = request.getLeft();
|
||||
ItemStack stack = request.getRight();
|
||||
// add up all the items that should go to the same location
|
||||
Optional<Pair<BlockPos, ItemStack>> existing = items.stream()
|
||||
.filter(s -> s.getLeft() == dest && ItemEqualityType.compareItems(s.getRight(), stack, ItemEqualityType.NBT))
|
||||
.findFirst();
|
||||
if (existing.isPresent()) {
|
||||
existing.get().getRight().grow(stack.getCount());
|
||||
} else {
|
||||
items.add(Pair.of(dest, stack.copy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return items.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
return Collections.emptyList();
|
||||
List<Pair<BlockPos, ItemStack>> crafting = network.getCurrentlyCrafting(pipe.getPos());
|
||||
return crafting.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void cancelCrafting() {
|
||||
|
|
Loading…
Reference in a new issue