Skip to content

Commit

Permalink
Fix high amp wireless uxv hatches (GTNewHorizons#3219)
Browse files Browse the repository at this point in the history
  • Loading branch information
GDCloudstrike authored Sep 17, 2024
1 parent 89b6865 commit 257a023
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3525,10 +3525,8 @@ private void addWirelessEnergyRecipes() {
for (int i = 0; i < wirelessLasers.length; i++) {

TTRecipeAdder.addResearchableAssemblylineRecipe(
i != 8 ? laserTargets_UXV[i] : wirelessLasers[i - 1], // If current laser registered is UXV 4MA switch
// research item to avoid duplicate qc result from
// normal UXV 4MA laser, see this:
// https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/17188
i != 7 ? laserTargets_UXV[i] : CustomItemList.eM_energyWirelessTunnel7_UXV.get(1),
// If current laser registered is UXV 4MA, switch research item to avoid research conflict
totalComputation * 64,
compPerSecond * 64,
researchEuPerTick * 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;

import com.google.common.math.LongMath;

import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.IWirelessEnergyHatchInformation;
Expand All @@ -25,9 +27,21 @@

public class MTEHatchWirelessMulti extends MTEHatchEnergyMulti implements IWirelessEnergyHatchInformation {

private final BigInteger eu_transferred_per_operation = BigInteger
.valueOf(Amperes * V[mTier] * ticks_between_energy_addition);
private final long eu_transferred_per_operation_long = eu_transferred_per_operation.longValue();
private final long precisionMultiplier = LongMath.pow(10, 15);
private final BigInteger eu_transferred_per_operation = BigInteger.valueOf(Amperes * V[mTier])
.multiply(BigInteger.valueOf(ticks_between_energy_addition));

private final double overflowDivisor = getOverflowDivisor(eu_transferred_per_operation);

private final long actualTicksBetweenEnergyAddition = overflowDivisor > 1
? (long) (ticks_between_energy_addition / (overflowDivisor * 2))
: ticks_between_energy_addition;

private final long eu_transferred_per_operation_long = overflowDivisor > 1
? eu_transferred_per_operation.divide(BigInteger.valueOf((long) (overflowDivisor * precisionMultiplier * 2)))
.multiply(BigInteger.valueOf(precisionMultiplier))
.longValue()
: eu_transferred_per_operation.longValue();

private UUID owner_uuid;

Expand All @@ -49,6 +63,13 @@ public MTEHatchWirelessMulti(String aName, int aTier, int aAmp, String[] aDescri
super(aName, aTier, aAmp, aDescription, aTextures);
}

private double getOverflowDivisor(BigInteger euTransferredPerOperation) {
if (euTransferredPerOperation.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
return euTransferredPerOperation.doubleValue() / Long.MAX_VALUE;
}
return 1d;
}

private ITexture[] TEXTURE_OVERLAY;

@Override
Expand Down Expand Up @@ -131,7 +152,7 @@ public long maxEUInput() {

@Override
public long maxEUStore() {
return totalStorage(V[mTier]) * Amperes / 2;
return (long) (totalStorage(V[mTier]) / (2 * overflowDivisor) * Amperes);
}

@Override
Expand Down Expand Up @@ -191,8 +212,9 @@ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
// network
// it should make no difference to them. Minimising the number of operations on BigInteger is essential.

// Every ticks_between_energy_addition add eu_transferred_per_operation to internal EU storage from network.
if (aTick % ticks_between_energy_addition == 0L) {
// Every actualTicksBetweenEnergyAddition add eu_transferred_per_operation to internal EU storage from
// network.
if (aTick % actualTicksBetweenEnergyAddition == 0L) {
tryFetchingEnergy();
}
}
Expand Down

0 comments on commit 257a023

Please sign in to comment.