Skip to content

Commit

Permalink
Fix Crash from mana P2P tunnels requesting negative power
Browse files Browse the repository at this point in the history
  • Loading branch information
Vruk11 committed Nov 6, 2024
1 parent ffa63a8 commit 63d9efe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions fabric/src/main/java/appbot/fabric/ae2/ManaP2PTunnelPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.common.base.Predicates;

Expand Down Expand Up @@ -66,13 +65,13 @@ public boolean canAttachSpark(ItemStack stack) {

@Override
public int getAvailableSpaceForMana() {
//var space = 0;
// var space = 0;

for (var output : getOutputs()) {
try (var guard = output.getAdjacentCapability()) {
var receiver = guard.get();
//space += ManaHelper.getCapacity(receiver);
if(!receiver.isFull()) {
// space += ManaHelper.getCapacity(receiver);
if (!receiver.isFull()) {
// This is fine because the spark system already voids extra mana usually
// and it won't run this function when the endpoints are marked as full
return Integer.MAX_VALUE;
Expand Down Expand Up @@ -165,7 +164,7 @@ public void receiveMana(int mana) {

Collections.shuffle(outputs);

queueTunnelDrain(PowerUnits.AE, mana / 100D);
queueTunnelDrain(PowerUnits.AE, Math.abs(mana) / 100D);
var manaForEach = mana / outputs.size();
var spill = mana % outputs.size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void receiveMana(int mana) {

Collections.shuffle(outputs);

queueTunnelDrain(PowerUnits.AE, mana / 100D);
queueTunnelDrain(PowerUnits.AE, Math.abs(mana) / 100D);
var manaForEach = mana / outputs.size();
var spill = mana % outputs.size();

Expand Down

0 comments on commit 63d9efe

Please sign in to comment.