Skip to content

Commit

Permalink
some additional profiling for crafting modules
Browse files Browse the repository at this point in the history
closes #230
  • Loading branch information
Ellpeck committed Dec 4, 2024
1 parent 4a04535 commit 1e027ff
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile)
@Override
public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
var network = PipeNetwork.get(tile.getLevel());
network.startProfile("get_craftable_amount");
var items = network.getOrderedNetworkItems(tile.getBlockPos());
var equalityTypes = ItemFilter.getEqualityTypes(tile);
var content = module.get(Contents.TYPE);
Expand All @@ -189,6 +190,7 @@ public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer<I
craftable += out.getCount() * availableCrafts;
}
}
network.endProfile();
return craftable;
}

Expand All @@ -198,12 +200,14 @@ public Pair<ItemStack, Collection<ActiveCraft>> craft(ItemStack module, PipeBloc
var craftableAmount = this.getCraftableAmount(module, tile, unavailableConsumer, stack, dependencyChain);
if (craftableAmount <= 0)
return Pair.of(stack, List.of());
var slot = tile.getModuleSlot(module);
var contents = module.get(Contents.TYPE);

var network = PipeNetwork.get(tile.getLevel());
var items = network.getOrderedNetworkItems(tile.getBlockPos());
network.startProfile("craft");

var items = network.getOrderedNetworkItems(tile.getBlockPos());
var slot = tile.getModuleSlot(module);
var contents = module.get(Contents.TYPE);

var equalityTypes = ItemFilter.getEqualityTypes(tile);
var resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes);
// calculate how many crafting *operations* to do (as opposed to how many *items* to craft)
Expand Down Expand Up @@ -246,6 +250,7 @@ public Pair<ItemStack, Collection<ActiveCraft>> craft(ItemStack module, PipeBloc
allCrafts.add(activeCraft);
leftOfRequest -= crafted;
}
network.endProfile();

var remain = stack.copy();
remain.shrink(resultAmount * toCraft);
Expand Down

0 comments on commit 1e027ff

Please sign in to comment.