Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Fix wireless energy voiding (#236)
Browse files Browse the repository at this point in the history
* Fix wireless energy hatch voiding energy

* avoid bigint
  • Loading branch information
harrynull authored Jul 30, 2023
1 parent 685934f commit 086f7e4
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static com.gtnewhorizon.gtnhlib.util.AnimatedTooltipHandler.GRAY;
import static gregtech.api.enums.GT_Values.AuthorColen;
import static gregtech.api.enums.GT_Values.V;
import static java.lang.Long.min;

import java.math.BigInteger;

Expand Down Expand Up @@ -181,8 +182,7 @@ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {

strongCheckOrAddUser(owner_uuid, owner_name);

if (addEUToGlobalEnergyMap(owner_uuid, eu_transferred_per_operation.negate()))
setEUVar(eu_transferred_per_operation_long);
tryFetchingEnergy();
}
}

Expand All @@ -199,18 +199,17 @@ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {

// Every ticks_between_energy_addition add eu_transferred_per_operation to internal EU storage from network.
if (aTick % ticks_between_energy_addition == 0L) {
long total_eu = getBaseMetaTileEntity().getStoredEU();

// Can the machine store the EU being added?
long new_eu_storage = total_eu + eu_transferred_per_operation_long;
if (new_eu_storage <= maxEUStore()) {

// Attempt to remove energy from the network and add it to the internal buffer of the machine.
if (addEUToGlobalEnergyMap(owner_uuid, eu_transferred_per_operation.negate())) {
setEUVar(new_eu_storage);
}
}
tryFetchingEnergy();
}
}
}

private void tryFetchingEnergy() {
long currentEU = getBaseMetaTileEntity().getStoredEU();
long maxEU = maxEUStore();
long euToTransfer = min(maxEU - currentEU, eu_transferred_per_operation_long);
if (euToTransfer <= 0) return; // nothing to transfer
if (!addEUToGlobalEnergyMap(owner_uuid, -euToTransfer)) return;
setEUVar(currentEU + euToTransfer);
}
}

0 comments on commit 086f7e4

Please sign in to comment.