Skip to content

Commit

Permalink
Try to obtain Flux-Transfer-Rates on fully charged/completely empty b…
Browse files Browse the repository at this point in the history
…atteries to prevent distorted results.
  • Loading branch information
bonii-xx committed Aug 16, 2014
1 parent 906fe1d commit 1e4afd6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/main/java/tconstruct/modifiers/tools/ModFlux.java
Expand Up @@ -103,13 +103,32 @@ public void modify (ItemStack[] input, ItemStack tool)

// set the charge values
int charge = energyContainer.getEnergyStored(inputBattery);

// add already present charge in the tool
if(tags.hasKey("Energy"))
charge += tags.getInteger("Energy");
int maxCharge = energyContainer.getMaxEnergyStored(inputBattery);
// simulate transferring maximum amount of POWER to obtain the maximum receive-limit of the battery ;_;
int maxExtract = energyContainer.extractEnergy(inputBattery, Integer.MAX_VALUE, true);
int maxReceive = energyContainer.receiveEnergy(inputBattery, Integer.MAX_VALUE, true);

ItemStack subject42 = inputBattery.copy();

int progress = 0, change = 1; // prevent endless loops with creative battery, blah
// fill the battery full
while(progress < maxCharge && change > 0) {
change = energyContainer.receiveEnergy(subject42, 100000, false);
progress += change;
}
// get the maximum extraction rate
int maxExtract = energyContainer.extractEnergy(subject42, Integer.MAX_VALUE, true);

subject42 = inputBattery.copy();

// completely empty the battery
progress = 0; change = 1;
while(progress < maxCharge && change > 0) {
change = energyContainer.extractEnergy(subject42, 100000, false);
progress += change;
}
int maxReceive = energyContainer.receiveEnergy(subject42, Integer.MAX_VALUE, true);

// make sure we don't overcharge
charge = Math.min(charge, maxCharge);
Expand Down

0 comments on commit 1e4afd6

Please sign in to comment.