mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-26 05:28:33 +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;
|
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) {
|
public List<Pair<BlockPos, ItemStack>> getAllCraftables(BlockPos node) {
|
||||||
if (!this.isNode(node))
|
if (!this.isNode(node))
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||||
|
|
||||||
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
||||||
|
ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||||
filter.isWhitelist = true;
|
filter.isWhitelist = true;
|
||||||
// loop through filter to see which items to pull
|
// loop through filter to see which items to pull
|
||||||
for (int f = 0; f < filter.getSlots(); f++) {
|
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);
|
Pair<BlockPos, ItemStack> dest = tile.getAvailableDestination(copy, true, this.preventOversending);
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
continue;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,10 +133,9 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
return;
|
return;
|
||||||
this.networkItems = this.collectItems();
|
this.networkItems = this.collectItems();
|
||||||
if (playersToSync.length > 0) {
|
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> clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||||
List<ItemStack> clientCraftables = craftables.stream().map(Pair::getRight).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(craftables).stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
List<ItemStack> currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||||
for (PlayerEntity player : playersToSync) {
|
for (PlayerEntity player : playersToSync) {
|
||||||
if (!(player.openContainer instanceof ItemTerminalContainer))
|
if (!(player.openContainer instanceof ItemTerminalContainer))
|
||||||
continue;
|
continue;
|
||||||
|
@ -192,28 +191,13 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ItemStack> getCurrentlyCrafting(List<Pair<BlockPos, ItemStack>> craftables) {
|
private List<ItemStack> getCurrentlyCrafting() {
|
||||||
PipeNetwork network = PipeNetwork.get(this.world);
|
PipeNetwork network = PipeNetwork.get(this.world);
|
||||||
List<Pair<BlockPos, ItemStack>> items = new ArrayList<>();
|
PipeTileEntity pipe = this.getConnectedPipe();
|
||||||
for (Pair<BlockPos, ItemStack> craftable : craftables) {
|
if (pipe == null)
|
||||||
PipeTileEntity pipe = network.getPipe(craftable.getLeft());
|
return Collections.emptyList();
|
||||||
if (pipe == null)
|
List<Pair<BlockPos, ItemStack>> crafting = network.getCurrentlyCrafting(pipe.getPos());
|
||||||
continue;
|
return crafting.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelCrafting() {
|
public void cancelCrafting() {
|
||||||
|
|
Loading…
Reference in a new issue