Skip to content

Commit

Permalink
Fix charging items that say they received negative energy (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swedz authored Sep 27, 2024
1 parent c5171de commit c450474
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ public final class ChargeInventoryHelper
public static long charge(ItemStack stack, long maxEu, boolean simulate)
{
ILongEnergyStorage energy = stack.getCapability(EnergyApi.ITEM);
return energy != null ? energy.receive(Math.max(0, maxEu), simulate) : 0;
return energy != null ? Math.max(0, energy.receive(Math.max(0, maxEu), simulate)) : 0;
}

public static long charge(Collection<ItemStack> items, long maxEu, boolean simulate)
{
long eu = 0;
for(ItemStack stack : items)
{
eu += charge(stack, Math.max(0, maxEu - eu), simulate);
if(eu == maxEu)
long charged = charge(stack, Math.max(0, maxEu - eu), simulate);
if(charged > 0)
{
break;
eu += charged;
if(eu == maxEu)
{
break;
}
}
}
return eu;
Expand Down

0 comments on commit c450474

Please sign in to comment.