Applied Energistics 2

Applied Energistics 2

137M Downloads

Item dupe via item p2p tunnels

indiscrete-void opened this issue ยท 1 comments

commented

Describe the bug
Creating simple p2p tunnel system with item p2p tunnels with one input and three outputs causes items in input to be duplicated across all outputs. Also this only works if items are pushed one-by-one in input p2p tunnel

To Reproduce

  1. Create identical p2p tunnel system to one provided on screenshot (left p2p tunnels are item p2p tunnels in output mode and right is item p2p tunnel with input mode)
  2. Put any items in input hopper
  3. Watch item duplication in chests

Expected behavior

No duplication of input items

Additional context
image

Environment

Custom modpack

commented

I'm not confident in this statement, but it seams like this line is causing issue:
https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/master/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java#L117

Because if amount is equal to one and amount of outputs is equal to three, then amountPerOutput is equal to one, so every tunnel gets one item when only one should get this item (which causes dupe).

final int amountPerOutput = Math.max(1, amount / outputTunnels);
int overflow = amountPerOutput == 0 ? amount : amount % amountPerOutput;
// ...
for (ItemP2PTunnelPart target : ItemP2PTunnelPart.this.getOutputs()) {
    // ..
    final int toSend = amountPerOutput + overflow;
    final ItemStack fillWithItemStack = stack.copy();
    fillWithItemStack.setCount(toSend);
    // ..
} 
// ...

EDIT: Sorry, didn't realize master branch isn't 1.16.5 version
In branch 8.4.x-1.16.x overflow is decreased at https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/8.4.x-1.16.x/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java#L104, so i don't really know what causes this issue...